Rubber-stamped by Brady Eidson.
[webbrowser.git] / WebCore / inspector / InjectedScriptHost.cpp
blobf326f527d760c60ebbbee51cfdea9e4d7036ecb7
1 /*
2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com>
4 * Copyright (C) 2009 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
8 * are met:
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.
31 #include "config.h"
32 #include "InjectedScriptHost.h"
34 #if ENABLE(INSPECTOR)
37 #include "Element.h"
38 #include "Frame.h"
39 #include "FrameLoader.h"
40 #include "HTMLFrameOwnerElement.h"
41 #include "InspectorClient.h"
42 #include "InspectorController.h"
43 #include "InspectorDOMAgent.h"
44 #include "InspectorFrontend.h"
45 #include "InspectorResource.h"
46 #include "Pasteboard.h"
47 #include "ScriptArray.h"
48 #include "ScriptFunctionCall.h"
50 #if ENABLE(JAVASCRIPT_DEBUGGER)
51 #include "JavaScriptCallFrame.h"
52 #include "JavaScriptDebugServer.h"
53 using namespace JSC;
54 #endif
56 #if ENABLE(DATABASE)
57 #include "Database.h"
58 #endif
60 #if ENABLE(DOM_STORAGE)
61 #include "Storage.h"
62 #endif
64 #include "markup.h"
66 #include <wtf/RefPtr.h>
67 #include <wtf/StdLibExtras.h>
69 using namespace std;
71 namespace WebCore {
73 InjectedScriptHost::InjectedScriptHost(InspectorController* inspectorController)
74 : m_inspectorController(inspectorController)
78 InjectedScriptHost::~InjectedScriptHost()
82 void InjectedScriptHost::copyText(const String& text)
84 Pasteboard::generalPasteboard()->writePlainText(text);
87 Node* InjectedScriptHost::nodeForId(long nodeId)
89 if (InspectorDOMAgent* domAgent = inspectorDOMAgent())
90 return domAgent->nodeForId(nodeId);
91 return 0;
94 ScriptValue InjectedScriptHost::wrapObject(const ScriptValue& object, const String& objectGroup)
96 if (m_inspectorController)
97 return m_inspectorController->wrapObject(object, objectGroup);
98 return ScriptValue();
101 ScriptValue InjectedScriptHost::unwrapObject(const String& objectId)
103 if (m_inspectorController)
104 return m_inspectorController->unwrapObject(objectId);
105 return ScriptValue();
108 long InjectedScriptHost::pushNodePathToFrontend(Node* node, bool selectInUI)
110 InspectorFrontend* frontend = inspectorFrontend();
111 InspectorDOMAgent* domAgent = inspectorDOMAgent();
112 if (!domAgent || !frontend)
113 return 0;
114 long id = domAgent->pushNodePathToFrontend(node);
115 if (selectInUI)
116 frontend->updateFocusedNode(id);
117 return id;
120 void InjectedScriptHost::addNodesToSearchResult(const String& nodeIds)
122 if (InspectorFrontend* frontend = inspectorFrontend())
123 frontend->addNodesToSearchResult(nodeIds);
126 long InjectedScriptHost::pushNodeByPathToFrontend(const String& path)
128 InspectorDOMAgent* domAgent = inspectorDOMAgent();
129 if (!domAgent)
130 return 0;
132 Node* node = domAgent->nodeForPath(path);
133 if (!node)
134 return 0;
136 return domAgent->pushNodePathToFrontend(node);
139 #if ENABLE(JAVASCRIPT_DEBUGGER)
140 JavaScriptCallFrame* InjectedScriptHost::currentCallFrame() const
142 return JavaScriptDebugServer::shared().currentCallFrame();
144 #endif
146 #if ENABLE(DATABASE)
147 Database* InjectedScriptHost::databaseForId(long databaseId)
149 if (m_inspectorController)
150 return m_inspectorController->databaseForId(databaseId);
151 return 0;
154 void InjectedScriptHost::selectDatabase(Database* database)
156 if (m_inspectorController)
157 m_inspectorController->selectDatabase(database);
159 #endif
161 #if ENABLE(DOM_STORAGE)
162 void InjectedScriptHost::selectDOMStorage(Storage* storage)
164 if (m_inspectorController)
165 m_inspectorController->selectDOMStorage(storage);
167 #endif
169 void InjectedScriptHost::reportDidDispatchOnInjectedScript(long callId, const String& result, bool isException)
171 if (InspectorFrontend* frontend = inspectorFrontend())
172 frontend->didDispatchOnInjectedScript(callId, result, isException);
175 InspectorDOMAgent* InjectedScriptHost::inspectorDOMAgent()
177 if (!m_inspectorController)
178 return 0;
179 return m_inspectorController->domAgent();
182 InspectorFrontend* InjectedScriptHost::inspectorFrontend()
184 if (!m_inspectorController)
185 return 0;
186 return m_inspectorController->m_frontend.get();
189 } // namespace WebCore
191 #endif // ENABLE(INSPECTOR)