2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com>
4 * Copyright (C) 2010 Google Inc. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
16 * its contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
20 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include "InjectedScriptHost.h"
39 #include "FrameLoader.h"
40 #include "HTMLFrameOwnerElement.h"
41 #include "InjectedScript.h"
42 #include "InspectorAgent.h"
43 #include "InspectorClient.h"
44 #include "InspectorConsoleAgent.h"
45 #include "InspectorDOMAgent.h"
46 #include "InspectorDOMStorageAgent.h"
47 #include "InspectorDatabaseAgent.h"
48 #include "InspectorDebuggerAgent.h"
49 #include "InspectorFrontend.h"
50 #include "InspectorValues.h"
51 #include "Pasteboard.h"
54 #if ENABLE(SQL_DATABASE)
60 #include <wtf/RefPtr.h>
61 #include <wtf/StdLibExtras.h>
67 PassRefPtr<InjectedScriptHost> InjectedScriptHost::create()
69 return adoptRef(new InjectedScriptHost());
72 InjectedScriptHost::InjectedScriptHost()
75 #if ENABLE(SQL_DATABASE)
78 , m_domStorageAgent(0)
81 m_defaultInspectableObject = adoptPtr(new InspectableObject());
84 InjectedScriptHost::~InjectedScriptHost()
88 void InjectedScriptHost::disconnect()
92 #if ENABLE(SQL_DATABASE)
95 m_domStorageAgent = 0;
99 void InjectedScriptHost::inspectImpl(PassRefPtr<InspectorValue> object, PassRefPtr<InspectorValue> hints)
101 if (m_inspectorAgent) {
102 RefPtr<TypeBuilder::Runtime::RemoteObject> remoteObject = TypeBuilder::Runtime::RemoteObject::runtimeCast(object);
103 m_inspectorAgent->inspect(remoteObject, hints->asObject());
107 void InjectedScriptHost::getEventListenersImpl(Node* node, Vector<EventListenerInfo>& listenersArray)
110 m_domAgent->getEventListeners(node, listenersArray, false);
113 void InjectedScriptHost::clearConsoleMessages()
115 if (m_consoleAgent) {
117 m_consoleAgent->clearMessages(&error);
121 void InjectedScriptHost::copyText(const String& text)
123 Pasteboard::generalPasteboard()->writePlainText(text, Pasteboard::CannotSmartReplace);
126 ScriptValue InjectedScriptHost::InspectableObject::get(ScriptState*)
128 return ScriptValue();
131 void InjectedScriptHost::addInspectedObject(PassOwnPtr<InjectedScriptHost::InspectableObject> object)
133 m_inspectedObjects.prepend(object);
134 while (m_inspectedObjects.size() > 5)
135 m_inspectedObjects.removeLast();
138 void InjectedScriptHost::clearInspectedObjects()
140 m_inspectedObjects.clear();
143 InjectedScriptHost::InspectableObject* InjectedScriptHost::inspectedObject(unsigned int num)
145 if (num >= m_inspectedObjects.size())
146 return m_defaultInspectableObject.get();
147 return m_inspectedObjects[num].get();
150 #if ENABLE(SQL_DATABASE)
151 String InjectedScriptHost::databaseIdImpl(Database* database)
154 return m_databaseAgent->databaseId(database);
159 String InjectedScriptHost::storageIdImpl(Storage* storage)
161 if (m_domStorageAgent)
162 return m_domStorageAgent->storageId(storage);
166 #if ENABLE(JAVASCRIPT_DEBUGGER)
167 ScriptDebugServer& InjectedScriptHost::scriptDebugServer()
169 return m_debuggerAgent->scriptDebugServer();
174 } // namespace WebCore
176 #endif // ENABLE(INSPECTOR)