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 InspectorFrontend; 51 class InspectorObject; 52 class Node; 53 class ScriptObject; 54 class ScriptValue; 55 class Storage; 56 57 class InjectedScriptHost : public RefCounted<InjectedScriptHost> 58 { 59 public: 60 static PassRefPtr<InjectedScriptHost> create(); 61 ~InjectedScriptHost(); 62 init(InspectorAgent * inspectorAgent,InspectorConsoleAgent * consoleAgent,InspectorDatabaseAgent * databaseAgent,InspectorDOMStorageAgent * domStorageAgent)63 void init(InspectorAgent* inspectorAgent 64 , InspectorConsoleAgent* consoleAgent 65 #if ENABLE(DATABASE) 66 , InspectorDatabaseAgent* databaseAgent 67 #endif 68 #if ENABLE(DOM_STORAGE) 69 , InspectorDOMStorageAgent* domStorageAgent 70 #endif 71 ) 72 { 73 m_inspectorAgent = inspectorAgent; 74 m_consoleAgent = consoleAgent; 75 #if ENABLE(DATABASE) 76 m_databaseAgent = databaseAgent; 77 #endif 78 #if ENABLE(DOM_STORAGE) 79 m_domStorageAgent = domStorageAgent; 80 #endif 81 } setFrontend(InspectorFrontend * frontend)82 void setFrontend(InspectorFrontend* frontend) { m_frontend = frontend; } clearFrontend()83 void clearFrontend() { m_frontend = 0; } 84 85 static Node* scriptValueAsNode(ScriptValue); 86 static ScriptValue nodeAsScriptValue(ScriptState*, Node*); 87 88 void disconnect(); 89 90 void addInspectedNode(Node*); 91 void clearInspectedNodes(); 92 93 void inspectImpl(PassRefPtr<InspectorValue> objectToInspect, PassRefPtr<InspectorValue> hints); 94 void clearConsoleMessages(); 95 void copyText(const String& text); 96 Node* inspectedNode(unsigned int num); 97 #if ENABLE(DATABASE) 98 int databaseIdImpl(Database*); 99 #endif 100 #if ENABLE(DOM_STORAGE) 101 int storageIdImpl(Storage*); 102 #endif 103 #if ENABLE(WORKERS) 104 long nextWorkerId(); 105 void didCreateWorker(long id, const String& url, bool isSharedWorker); 106 void didDestroyWorker(long id); 107 #endif 108 109 private: 110 InjectedScriptHost(); 111 112 InspectorAgent* m_inspectorAgent; 113 InspectorConsoleAgent* m_consoleAgent; 114 #if ENABLE(DATABASE) 115 InspectorDatabaseAgent* m_databaseAgent; 116 #endif 117 #if ENABLE(DOM_STORAGE) 118 InspectorDOMStorageAgent* m_domStorageAgent; 119 #endif 120 InspectorFrontend* m_frontend; 121 long m_lastWorkerId; 122 Vector<RefPtr<Node> > m_inspectedNodes; 123 }; 124 125 } // namespace WebCore 126 127 #endif // !defined(InjectedScriptHost_h) 128