1 /* 2 * Copyright (C) 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 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. 16 * 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. 27 */ 28 29 #ifndef InspectorAgent_h 30 #define InspectorAgent_h 31 32 #include "CharacterData.h" 33 #include "Console.h" 34 #include "Page.h" 35 #include "PlatformString.h" 36 #include <wtf/HashMap.h> 37 #include <wtf/RefCounted.h> 38 #include <wtf/Vector.h> 39 #include <wtf/text/StringHash.h> 40 41 namespace WebCore { 42 43 class CharacterData; 44 class Database; 45 class DOMWrapperWorld; 46 class Document; 47 class DocumentLoader; 48 class FloatRect; 49 class HTTPHeaderMap; 50 class InjectedScript; 51 class InjectedScriptManager; 52 class InspectorArray; 53 class InspectorBrowserDebuggerAgent; 54 class InspectorClient; 55 class InspectorConsoleAgent; 56 class InspectorCSSAgent; 57 class InspectorDOMAgent; 58 class InspectorDOMStorageAgent; 59 class InspectorDatabaseAgent; 60 class InspectorDatabaseResource; 61 class InspectorDebuggerAgent; 62 class InspectorFrontend; 63 class InspectorFrontendClient; 64 class InspectorObject; 65 class InspectorPageAgent; 66 class InspectorProfilerAgent; 67 class InspectorResourceAgent; 68 class InspectorRuntimeAgent; 69 class InspectorState; 70 class InspectorStorageAgent; 71 class InspectorTimelineAgent; 72 class InspectorValue; 73 class InspectorWorkerResource; 74 class InstrumentingAgents; 75 class IntRect; 76 class KURL; 77 class Node; 78 class Page; 79 class ResourceRequest; 80 class ResourceResponse; 81 class ResourceError; 82 class ScriptArguments; 83 class ScriptCallStack; 84 class ScriptProfile; 85 class SharedBuffer; 86 class StorageArea; 87 88 #if ENABLE(OFFLINE_WEB_APPLICATIONS) 89 class InspectorApplicationCacheAgent; 90 #endif 91 92 typedef String ErrorString; 93 94 class InspectorAgent { 95 WTF_MAKE_NONCOPYABLE(InspectorAgent); 96 WTF_MAKE_FAST_ALLOCATED; 97 public: 98 InspectorAgent(Page*, InspectorClient*, InjectedScriptManager*); 99 virtual ~InspectorAgent(); 100 inspectorClient()101 InspectorClient* inspectorClient() { return m_client; } 102 103 void inspectedPageDestroyed(); 104 105 bool enabled() const; 106 inspectedPage()107 Page* inspectedPage() const { return m_inspectedPage; } 108 KURL inspectedURL() const; 109 KURL inspectedURLWithoutFragment() const; 110 void reloadPage(ErrorString*, bool ignoreCache); 111 void showConsole(); 112 113 void restoreInspectorStateFromCookie(const String& inspectorCookie); 114 115 void setFrontend(InspectorFrontend*); frontend()116 InspectorFrontend* frontend() const { return m_frontend; } 117 void disconnectFrontend(); 118 instrumentingAgents()119 InstrumentingAgents* instrumentingAgents() const { return m_instrumentingAgents.get(); } 120 pageAgent()121 InspectorPageAgent* pageAgent() { return m_pageAgent.get(); } consoleAgent()122 InspectorConsoleAgent* consoleAgent() { return m_consoleAgent.get(); } cssAgent()123 InspectorCSSAgent* cssAgent() { return m_cssAgent.get(); } domAgent()124 InspectorDOMAgent* domAgent() { return m_domAgent.get(); } runtimeAgent()125 InspectorRuntimeAgent* runtimeAgent() { return m_runtimeAgent.get(); } timelineAgent()126 InspectorTimelineAgent* timelineAgent() { return m_timelineAgent.get(); } resourceAgent()127 InspectorResourceAgent* resourceAgent() { return m_resourceAgent.get(); } 128 #if ENABLE(DATABASE) databaseAgent()129 InspectorDatabaseAgent* databaseAgent() { return m_databaseAgent.get(); } 130 #endif 131 #if ENABLE(DOM_STORAGE) domStorageAgent()132 InspectorDOMStorageAgent* domStorageAgent() { return m_domStorageAgent.get(); } 133 #endif 134 #if ENABLE(JAVASCRIPT_DEBUGGER) browserDebuggerAgent()135 InspectorBrowserDebuggerAgent* browserDebuggerAgent() const { return m_browserDebuggerAgent.get(); } debuggerAgent()136 InspectorDebuggerAgent* debuggerAgent() const { return m_debuggerAgent.get(); } profilerAgent()137 InspectorProfilerAgent* profilerAgent() const { return m_profilerAgent.get(); } 138 #endif 139 #if ENABLE(OFFLINE_WEB_APPLICATIONS) applicationCacheAgent()140 InspectorApplicationCacheAgent* applicationCacheAgent() { return m_applicationCacheAgent.get(); } 141 #endif 142 143 void didClearWindowObjectInWorld(Frame*, DOMWrapperWorld*); 144 145 void didCommitLoad(); 146 void domContentLoadedEventFired(); 147 148 #if ENABLE(WORKERS) 149 enum WorkerAction { WorkerCreated, WorkerDestroyed }; 150 151 void postWorkerNotificationToFrontend(const InspectorWorkerResource&, WorkerAction); 152 void didCreateWorker(intptr_t, const String& url, bool isSharedWorker); 153 void didDestroyWorker(intptr_t); 154 #endif 155 hasFrontend()156 bool hasFrontend() const { return m_frontend; } 157 158 159 #if ENABLE(JAVASCRIPT_DEBUGGER) 160 void showProfilesPanel(); 161 #endif 162 163 // Generic code called from custom implementations. 164 void evaluateForTestInFrontend(long testCallId, const String& script); 165 166 void setInspectorExtensionAPI(const String& source); 167 state()168 InspectorState* state() { return m_state.get(); } 169 170 // InspectorAgent API 171 void getInspectorState(RefPtr<InspectorObject>* state); 172 void setMonitoringXHREnabled(bool enabled, bool* newState); 173 174 private: 175 void showPanel(const String& panel); 176 void unbindAllResources(); 177 178 #if ENABLE(JAVASCRIPT_DEBUGGER) 179 void toggleRecordButton(bool); 180 #endif 181 182 bool isMainResourceLoader(DocumentLoader*, const KURL& requestUrl); 183 void issueEvaluateForTestCommands(); 184 185 Page* m_inspectedPage; 186 InspectorClient* m_client; 187 InspectorFrontend* m_frontend; 188 OwnPtr<InstrumentingAgents> m_instrumentingAgents; 189 InjectedScriptManager* m_injectedScriptManager; 190 OwnPtr<InspectorState> m_state; 191 OwnPtr<InspectorPageAgent> m_pageAgent; 192 OwnPtr<InspectorDOMAgent> m_domAgent; 193 OwnPtr<InspectorCSSAgent> m_cssAgent; 194 195 #if ENABLE(DATABASE) 196 OwnPtr<InspectorDatabaseAgent> m_databaseAgent; 197 #endif 198 199 #if ENABLE(DOM_STORAGE) 200 OwnPtr<InspectorDOMStorageAgent> m_domStorageAgent; 201 #endif 202 203 OwnPtr<InspectorTimelineAgent> m_timelineAgent; 204 205 #if ENABLE(OFFLINE_WEB_APPLICATIONS) 206 OwnPtr<InspectorApplicationCacheAgent> m_applicationCacheAgent; 207 #endif 208 209 RefPtr<InspectorResourceAgent> m_resourceAgent; 210 OwnPtr<InspectorRuntimeAgent> m_runtimeAgent; 211 212 OwnPtr<InspectorConsoleAgent> m_consoleAgent; 213 214 Vector<pair<long, String> > m_pendingEvaluateTestCommands; 215 String m_showPanelAfterVisible; 216 String m_inspectorExtensionAPI; 217 #if ENABLE(JAVASCRIPT_DEBUGGER) 218 OwnPtr<InspectorDebuggerAgent> m_debuggerAgent; 219 OwnPtr<InspectorBrowserDebuggerAgent> m_browserDebuggerAgent; 220 OwnPtr<InspectorProfilerAgent> m_profilerAgent; 221 #endif 222 #if ENABLE(WORKERS) 223 typedef HashMap<intptr_t, RefPtr<InspectorWorkerResource> > WorkersMap; 224 WorkersMap m_workers; 225 #endif 226 bool m_canIssueEvaluateForTestInFrontend; 227 }; 228 229 } // namespace WebCore 230 231 #endif // !defined(InspectorAgent_h) 232