1 /* 2 * Copyright (C) 2007 Apple Inc. All rights reserved. 3 * Copyright (C) 2009 Google Inc. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of 15 * its contributors may be used to endorse or promote products derived 16 * from this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 */ 29 30 #ifndef InjectedScriptHost_h 31 #define InjectedScriptHost_h 32 33 #include "Console.h" 34 #include "InspectorAgent.h" 35 #include "PlatformString.h" 36 #include "ScriptState.h" 37 38 #include <wtf/HashMap.h> 39 #include <wtf/RefCounted.h> 40 #include <wtf/Vector.h> 41 42 namespace WebCore { 43 44 class Database; 45 class InjectedScript; 46 class InspectorAgent; 47 class InspectorConsoleAgent; 48 class InspectorDOMStorageAgent; 49 class InspectorDatabaseAgent; 50 class InspectorDebuggerAgent; 51 class InspectorFrontend; 52 class InspectorObject; 53 class Node; 54 class ScriptObject; 55 class ScriptValue; 56 class Storage; 57 58 class InjectedScriptHost : public RefCounted<InjectedScriptHost> 59 { 60 public: 61 static PassRefPtr<InjectedScriptHost> create(); 62 ~InjectedScriptHost(); 63 init(InspectorAgent * inspectorAgent,InspectorConsoleAgent * consoleAgent,InspectorDatabaseAgent * databaseAgent,InspectorDOMStorageAgent * domStorageAgent,InspectorDebuggerAgent * debuggerAgent)64 void init(InspectorAgent* inspectorAgent 65 , InspectorConsoleAgent* consoleAgent 66 #if ENABLE(DATABASE) 67 , InspectorDatabaseAgent* databaseAgent 68 #endif 69 #if ENABLE(DOM_STORAGE) 70 , InspectorDOMStorageAgent* domStorageAgent 71 #endif 72 #if ENABLE(JAVASCRIPT_DEBUGGER) 73 , InspectorDebuggerAgent* debuggerAgent 74 #endif 75 ) 76 { 77 m_inspectorAgent = inspectorAgent; 78 m_consoleAgent = consoleAgent; 79 #if ENABLE(DATABASE) 80 m_databaseAgent = databaseAgent; 81 #endif 82 #if ENABLE(DOM_STORAGE) 83 m_domStorageAgent = domStorageAgent; 84 #endif 85 #if ENABLE(JAVASCRIPT_DEBUGGER) 86 m_debuggerAgent = debuggerAgent; 87 #endif 88 } setFrontend(InspectorFrontend * frontend)89 void setFrontend(InspectorFrontend* frontend) { m_frontend = frontend; } clearFrontend()90 void clearFrontend() { m_frontend = 0; } 91 92 static Node* scriptValueAsNode(ScriptValue); 93 static ScriptValue nodeAsScriptValue(ScriptState*, Node*); 94 95 void disconnect(); 96 97 void addInspectedNode(Node*); 98 void clearInspectedNodes(); 99 100 void inspectImpl(PassRefPtr<InspectorValue> objectToInspect, PassRefPtr<InspectorValue> hints); 101 void clearConsoleMessages(); 102 void copyText(const String& text); 103 Node* inspectedNode(unsigned int num); 104 #if ENABLE(DATABASE) 105 int databaseIdImpl(Database*); 106 #endif 107 #if ENABLE(DOM_STORAGE) 108 int storageIdImpl(Storage*); 109 #endif 110 #if ENABLE(WORKERS) 111 long nextWorkerId(); 112 void didCreateWorker(long id, const String& url, bool isSharedWorker); 113 void didDestroyWorker(long id); 114 #endif 115 #if ENABLE(JAVASCRIPT_DEBUGGER) debuggerAgent()116 InspectorDebuggerAgent* debuggerAgent() { return m_debuggerAgent; } 117 #endif 118 119 private: 120 InjectedScriptHost(); 121 122 InspectorAgent* m_inspectorAgent; 123 InspectorConsoleAgent* m_consoleAgent; 124 #if ENABLE(DATABASE) 125 InspectorDatabaseAgent* m_databaseAgent; 126 #endif 127 #if ENABLE(DOM_STORAGE) 128 InspectorDOMStorageAgent* m_domStorageAgent; 129 #endif 130 #if ENABLE(JAVASCRIPT_DEBUGGER) 131 InspectorDebuggerAgent* m_debuggerAgent; 132 #endif 133 InspectorFrontend* m_frontend; 134 long m_lastWorkerId; 135 Vector<RefPtr<Node> > m_inspectedNodes; 136 }; 137 138 } // namespace WebCore 139 140 #endif // !defined(InjectedScriptHost_h) 141