2 * Copyright (C) 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #ifndef InspectorController_h
30 #define InspectorController_h
32 #include "CharacterData.h"
36 #include "PlatformString.h"
37 #include <wtf/HashMap.h>
38 #include <wtf/HashSet.h>
39 #include <wtf/ListHashSet.h>
40 #include <wtf/RefCounted.h>
41 #include <wtf/Vector.h>
42 #include <wtf/text/StringHash.h>
53 class GraphicsContext;
56 class InjectedScriptHost;
58 class InspectorBackend;
59 class InspectorBackendDispatcher;
60 class InspectorClient;
61 class InspectorCSSStore;
62 class InspectorDOMAgent;
63 class InspectorDOMStorageResource;
64 class InspectorDatabaseResource;
65 class InspectorDebuggerAgent;
66 class InspectorFrontend;
67 class InspectorFrontendClient;
68 class InspectorObject;
69 class InspectorProfilerAgent;
70 class InspectorResourceAgent;
72 class InspectorStorageAgent;
73 class InspectorTimelineAgent;
75 class InspectorWorkerResource;
80 class ResourceRequest;
81 class ResourceResponse;
83 class ScriptCallStack;
89 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
90 class InspectorApplicationCacheAgent;
93 #if ENABLE(FILE_SYSTEM)
94 class InspectorFileSystemAgent;
97 #if ENABLE(WEB_SOCKETS)
98 class WebSocketHandshakeRequest;
99 class WebSocketHandshakeResponse;
102 class InspectorController : public Noncopyable {
104 typedef HashMap<int, RefPtr<InspectorDatabaseResource> > DatabaseResourcesMap;
105 typedef HashMap<int, RefPtr<InspectorDOMStorageResource> > DOMStorageResourcesMap;
107 static const char* const ConsolePanel;
108 static const char* const ElementsPanel;
109 static const char* const ProfilesPanel;
110 static const char* const ScriptsPanel;
112 InspectorController(Page*, InspectorClient*);
113 ~InspectorController();
115 InspectorBackend* inspectorBackend() { return m_inspectorBackend.get(); }
116 InspectorBackendDispatcher* inspectorBackendDispatcher() { return m_inspectorBackendDispatcher.get(); }
117 InspectorClient* inspectorClient() { return m_client; }
118 InjectedScriptHost* injectedScriptHost() { return m_injectedScriptHost.get(); }
120 void inspectedPageDestroyed();
122 bool enabled() const;
124 Page* inspectedPage() const { return m_inspectedPage; }
127 void restoreInspectorStateFromCookie(const String& inspectorCookie);
130 void highlight(Node*);
131 void hideHighlight();
132 void highlightDOMNode(long nodeId);
133 void hideDOMNodeHighlight() { hideHighlight(); }
135 void highlightFrame(unsigned long frameId);
136 void hideFrameHighlight() { hideHighlight(); }
139 void showPanel(const String&);
142 void connectFrontend();
143 void reuseFrontend();
144 void disconnectFrontend();
146 void setConsoleMessagesEnabled(bool enabled, bool* newState);
147 void addMessageToConsole(MessageSource, MessageType, MessageLevel, ScriptCallStack*, const String& message);
148 void addMessageToConsole(MessageSource, MessageType, MessageLevel, const String& message, unsigned lineNumber, const String& sourceID);
149 void clearConsoleMessages();
150 const Vector<OwnPtr<ConsoleMessage> >& consoleMessages() const { return m_consoleMessages; }
152 bool searchingForNodeInPage() const;
153 void mouseDidMoveOverElement(const HitTestResult&, unsigned modifierFlags);
154 void handleMousePress();
156 void setInspectorFrontendClient(PassOwnPtr<InspectorFrontendClient> client);
157 bool hasInspectorFrontendClient() const { return m_inspectorFrontendClient; }
159 void inspectedWindowScriptObjectCleared(Frame*);
161 void didCommitLoad(DocumentLoader*);
162 void frameDetachedFromParent(Frame*);
163 void didLoadResourceFromMemoryCache(DocumentLoader*, const CachedResource*);
165 void identifierForInitialRequest(unsigned long identifier, DocumentLoader*, const ResourceRequest&);
166 void willSendRequest(unsigned long identifier, ResourceRequest&, const ResourceResponse& redirectResponse);
167 void markResourceAsCached(unsigned long identifier);
168 void didReceiveResponse(unsigned long identifier, DocumentLoader*, const ResourceResponse&);
169 void didReceiveContentLength(unsigned long identifier, int lengthReceived);
170 void didFinishLoading(unsigned long identifier, double finishTime);
171 void didFailLoading(unsigned long identifier, const ResourceError&);
172 void resourceRetrievedByXMLHttpRequest(unsigned long identifier, const String& sourceString, const String& url, const String& sendURL, unsigned sendLineNumber);
173 void scriptImported(unsigned long identifier, const String& sourceString);
175 void ensureSettingsLoaded();
177 void startTimelineProfiler();
178 void stopTimelineProfiler();
179 InspectorTimelineAgent* timelineAgent() { return m_timelineAgent.get(); }
181 void getCookies(RefPtr<InspectorArray>* cookies, WTF::String* cookiesString);
182 void deleteCookie(const String& cookieName, const String& domain);
184 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
185 InspectorApplicationCacheAgent* applicationCacheAgent() { return m_applicationCacheAgent.get(); }
188 #if ENABLE(FILE_SYSTEM)
189 InspectorFileSystemAgent* fileSystemAgent() { return m_fileSystemAgent.get(); }
192 void mainResourceFiredLoadEvent(DocumentLoader*, const KURL&);
193 void mainResourceFiredDOMContentEvent(DocumentLoader*, const KURL&);
196 enum WorkerAction { WorkerCreated, WorkerDestroyed };
198 void postWorkerNotificationToFrontend(const InspectorWorkerResource&, WorkerAction);
199 void didCreateWorker(intptr_t, const String& url, bool isSharedWorker);
200 void didDestroyWorker(intptr_t);
204 void didOpenDatabase(PassRefPtr<Database>, const String& domain, const String& name, const String& version);
206 #if ENABLE(DOM_STORAGE)
207 void didUseDOMStorage(StorageArea* storageArea, bool isLocalStorage, Frame* frame);
208 void selectDOMStorage(Storage* storage);
209 void getDOMStorageEntries(long storageId, RefPtr<InspectorArray>* entries);
210 void setDOMStorageItem(long storageId, const String& key, const String& value, bool* success);
211 void removeDOMStorageItem(long storageId, const String& key, bool* success);
213 #if ENABLE(WEB_SOCKETS)
214 void didCreateWebSocket(unsigned long identifier, const KURL& requestURL, const KURL& documentURL);
215 void willSendWebSocketHandshakeRequest(unsigned long identifier, const WebSocketHandshakeRequest&);
216 void didReceiveWebSocketHandshakeResponse(unsigned long identifier, const WebSocketHandshakeResponse&);
217 void didCloseWebSocket(unsigned long identifier);
220 bool hasFrontend() const { return m_frontend; }
222 void drawNodeHighlight(GraphicsContext&) const;
223 void openInInspectedWindow(const String& url);
224 void drawElementTitle(GraphicsContext&, const IntRect& boundingBox, const FloatRect& overlayRect, WebCore::Settings*) const;
226 void count(const String& title, unsigned lineNumber, const String& sourceID);
228 void startTiming(const String& title);
229 bool stopTiming(const String& title, double& elapsed);
231 void startGroup(MessageSource source, ScriptCallStack* callFrame, bool collapsed = false);
232 void endGroup(MessageSource source, unsigned lineNumber, const String& sourceURL);
234 void markTimeline(const String& message);
236 #if ENABLE(JAVASCRIPT_DEBUGGER)
237 void addProfile(PassRefPtr<ScriptProfile>, unsigned lineNumber, const String& sourceURL);
238 void addProfileFinishedMessageToConsole(PassRefPtr<ScriptProfile>, unsigned lineNumber, const String& sourceURL);
239 void addStartProfilingMessageToConsole(const String& title, unsigned lineNumber, const String& sourceURL);
240 bool isRecordingUserInitiatedProfile() const;
241 String getCurrentUserInitiatedProfileName(bool incrementProfileNumber = false);
242 void startUserInitiatedProfiling();
243 void stopUserInitiatedProfiling();
244 void enableProfiler(bool always = false, bool skipRecompile = false);
245 void disableProfiler(bool always = false);
246 bool profilerEnabled() const;
247 InspectorProfilerAgent* profilerAgent() const { return m_profilerAgent.get(); }
249 void enableDebugger();
250 void disableDebugger(bool always = false);
251 bool debuggerEnabled() const { return m_debuggerAgent; }
252 InspectorDebuggerAgent* debuggerAgent() const { return m_debuggerAgent.get(); }
255 void setNativeBreakpoint(PassRefPtr<InspectorObject> breakpoint, String* breakpointId);
256 void removeNativeBreakpoint(const String& breakpointId);
259 void evaluateForTestInFrontend(long testCallId, const String& script);
261 InjectedScript injectedScriptForNodeId(long id);
263 void addScriptToEvaluateOnLoad(const String& source);
264 void removeAllScriptsToEvaluateOnLoad();
265 void setInspectorExtensionAPI(const String& source);
267 bool inspectorStartsAttached();
268 void setInspectorStartsAttached(bool);
269 void setInspectorAttachedHeight(long height);
270 int inspectorAttachedHeight() const;
272 static const unsigned defaultAttachedHeight;
275 void getInspectorState(RefPtr<InspectorObject>* state);
276 void setConsoleMessagesEnabled(bool enabled);
278 friend class InspectorBackend;
279 friend class InspectorBackendDispatcher;
280 friend class InspectorInstrumentation;
281 friend class InjectedScriptHost;
283 void populateScriptObjects();
284 void restoreDebugger();
285 void restoreProfiler();
286 void unbindAllResources();
287 void setSearchingForNode(bool enabled);
289 // Following are used from InspectorBackend and internally.
290 void setSearchingForNode(bool enabled, bool* newState);
292 void setMonitoringXHREnabled(bool enabled, bool* newState);
293 InspectorDOMAgent* domAgent() { return m_domAgent.get(); }
294 void releaseFrontendLifetimeAgents();
296 #if ENABLE(JAVASCRIPT_DEBUGGER)
297 void toggleRecordButton(bool);
298 void enableDebuggerFromFrontend(bool always);
300 String findEventListenerBreakpoint(const String& eventName);
301 String findXHRBreakpoint(const String& url);
302 void clearNativeBreakpoints();
305 void selectDatabase(Database* database);
306 Database* databaseForId(long databaseId);
308 #if ENABLE(DOM_STORAGE)
309 InspectorDOMStorageResource* getDOMStorageResourceForId(long storageId);
312 PassRefPtr<InspectorObject> buildObjectForCookie(const Cookie&);
313 PassRefPtr<InspectorArray> buildArrayForCookies(ListHashSet<Cookie>&);
317 void addConsoleMessage(PassOwnPtr<ConsoleMessage>);
319 bool isMainResourceLoader(DocumentLoader* loader, const KURL& requestUrl);
321 void didEvaluateForTestInFrontend(long callId, const String& jsonResult);
323 #if ENABLE(JAVASCRIPT_DEBUGGER)
324 friend class InspectorDebuggerAgent;
325 String breakpointsSettingKey();
326 PassRefPtr<InspectorValue> loadBreakpoints();
327 void saveBreakpoints(PassRefPtr<InspectorObject> breakpoints);
330 Page* m_inspectedPage;
331 InspectorClient* m_client;
332 OwnPtr<InspectorFrontendClient> m_inspectorFrontendClient;
333 bool m_openingFrontend;
334 OwnPtr<InspectorFrontend> m_frontend;
335 RefPtr<InspectorDOMAgent> m_domAgent;
336 RefPtr<InspectorStorageAgent> m_storageAgent;
337 OwnPtr<InspectorCSSStore> m_cssStore;
338 OwnPtr<InspectorTimelineAgent> m_timelineAgent;
339 OwnPtr<InspectorState> m_state;
341 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
342 OwnPtr<InspectorApplicationCacheAgent> m_applicationCacheAgent;
345 #if ENABLE(FILE_SYSTEM)
346 RefPtr<InspectorFileSystemAgent> m_fileSystemAgent;
349 RefPtr<Node> m_nodeToFocus;
350 RefPtr<InspectorResourceAgent> m_resourceAgent;
351 unsigned long m_mainResourceIdentifier;
352 double m_loadEventTime;
353 double m_domContentEventTime;
354 Vector<OwnPtr<ConsoleMessage> > m_consoleMessages;
355 unsigned m_expiredConsoleMessageCount;
356 HashMap<String, double> m_times;
357 HashMap<String, unsigned> m_counts;
359 DatabaseResourcesMap m_databaseResources;
361 #if ENABLE(DOM_STORAGE)
362 DOMStorageResourcesMap m_domStorageResources;
364 String m_showAfterVisible;
365 RefPtr<Node> m_highlightedNode;
366 unsigned m_groupLevel;
367 ConsoleMessage* m_previousMessage;
368 bool m_settingsLoaded;
369 RefPtr<InspectorBackend> m_inspectorBackend;
370 OwnPtr<InspectorBackendDispatcher> m_inspectorBackendDispatcher;
371 RefPtr<InjectedScriptHost> m_injectedScriptHost;
373 typedef HashMap<String, String> Settings;
374 mutable Settings m_settings;
376 Vector<pair<long, String> > m_pendingEvaluateTestCommands;
377 Vector<String> m_scriptsToEvaluateOnLoad;
378 String m_inspectorExtensionAPI;
379 #if ENABLE(JAVASCRIPT_DEBUGGER)
380 bool m_attachDebuggerWhenShown;
381 OwnPtr<InspectorDebuggerAgent> m_debuggerAgent;
383 HashMap<String, String> m_nativeBreakpoints;
384 HashSet<String> m_eventListenerBreakpoints;
385 HashMap<String, String> m_XHRBreakpoints;
387 unsigned int m_lastBreakpointId;
389 OwnPtr<InspectorProfilerAgent> m_profilerAgent;
392 typedef HashMap<intptr_t, RefPtr<InspectorWorkerResource> > WorkersMap;
394 WorkersMap m_workers;
398 } // namespace WebCore
400 #endif // !defined(InspectorController_h)