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(InjectedScriptManager* manager)
69 return adoptRef(new InjectedScriptHost(manager));
72 InjectedScriptHost::InjectedScriptHost(InjectedScriptManager* manager)
76 #if ENABLE(SQL_DATABASE)
79 , m_domStorageAgent(0)
82 m_defaultInspectableObject = adoptPtr(new InspectableObject());
85 InjectedScriptHost::~InjectedScriptHost()
89 void InjectedScriptHost::disconnect()
94 #if ENABLE(SQL_DATABASE)
97 m_domStorageAgent = 0;
101 void InjectedScriptHost::inspectImpl(PassRefPtr<InspectorValue> object, PassRefPtr<InspectorValue> hints)
103 if (m_inspectorAgent) {
104 RefPtr<TypeBuilder::Runtime::RemoteObject> remoteObject = TypeBuilder::Runtime::RemoteObject::runtimeCast(object);
105 m_inspectorAgent->inspect(remoteObject, hints->asObject());
109 void InjectedScriptHost::getEventListenersImpl(Node* node, Vector<EventListenerInfo>& listenersArray)
112 m_domAgent->getEventListeners(node, listenersArray, false);
115 void InjectedScriptHost::clearConsoleMessages()
117 if (m_consoleAgent) {
119 m_consoleAgent->clearMessages(&error);
123 void InjectedScriptHost::copyText(const String& text)
125 Pasteboard::generalPasteboard()->writePlainText(text, Pasteboard::CannotSmartReplace);
128 unsigned InjectedScriptHost::objectId(const ScriptObject& object)
132 return m_manager->objectId(object);
135 unsigned InjectedScriptHost::releaseObjectId(const ScriptObject& object)
139 return m_manager->releaseObjectId(object);
142 ScriptValue InjectedScriptHost::InspectableObject::get(ScriptState*)
144 return ScriptValue();
147 void InjectedScriptHost::addInspectedObject(PassOwnPtr<InjectedScriptHost::InspectableObject> object)
149 m_inspectedObjects.prepend(object);
150 while (m_inspectedObjects.size() > 5)
151 m_inspectedObjects.removeLast();
154 void InjectedScriptHost::clearInspectedObjects()
156 m_inspectedObjects.clear();
159 InjectedScriptHost::InspectableObject* InjectedScriptHost::inspectedObject(unsigned int num)
161 if (num >= m_inspectedObjects.size())
162 return m_defaultInspectableObject.get();
163 return m_inspectedObjects[num].get();
166 #if ENABLE(SQL_DATABASE)
167 String InjectedScriptHost::databaseIdImpl(Database* database)
170 return m_databaseAgent->databaseId(database);
175 String InjectedScriptHost::storageIdImpl(Storage* storage)
177 if (m_domStorageAgent)
178 return m_domStorageAgent->storageId(storage);
182 #if ENABLE(JAVASCRIPT_DEBUGGER)
183 ScriptDebugServer& InjectedScriptHost::scriptDebugServer()
185 return m_debuggerAgent->scriptDebugServer();
190 } // namespace WebCore
192 #endif // ENABLE(INSPECTOR)