InjectedScriptHost.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. #ifndef InjectedScriptHost_h
  30. #define InjectedScriptHost_h
  31. #include "ConsoleTypes.h"
  32. #include "InspectorAgent.h"
  33. #include "ScriptState.h"
  34. #include <wtf/RefCounted.h>
  35. #include <wtf/Vector.h>
  36. namespace WebCore {
  37. class Database;
  38. class InjectedScript;
  39. class InspectorAgent;
  40. class InspectorConsoleAgent;
  41. class InspectorDOMAgent;
  42. class InspectorDOMStorageAgent;
  43. class InspectorDatabaseAgent;
  44. class InspectorDebuggerAgent;
  45. class InspectorFrontend;
  46. class InspectorObject;
  47. class InspectorValue;
  48. class Node;
  49. class ScriptDebugServer;
  50. class ScriptObject;
  51. class ScriptValue;
  52. class Storage;
  53. struct EventListenerInfo;
  54. class InjectedScriptHost : public RefCounted<InjectedScriptHost> {
  55. public:
  56. static PassRefPtr<InjectedScriptHost> create();
  57. ~InjectedScriptHost();
  58. void init(InspectorAgent* inspectorAgent
  59. , InspectorConsoleAgent* consoleAgent
  60. #if ENABLE(SQL_DATABASE)
  61. , InspectorDatabaseAgent* databaseAgent
  62. #endif
  63. , InspectorDOMStorageAgent* domStorageAgent
  64. , InspectorDOMAgent* domAgent
  65. #if ENABLE(JAVASCRIPT_DEBUGGER)
  66. , InspectorDebuggerAgent* debuggerAgent
  67. #endif
  68. )
  69. {
  70. m_inspectorAgent = inspectorAgent;
  71. m_consoleAgent = consoleAgent;
  72. #if ENABLE(SQL_DATABASE)
  73. m_databaseAgent = databaseAgent;
  74. #endif
  75. m_domStorageAgent = domStorageAgent;
  76. m_domAgent = domAgent;
  77. #if ENABLE(JAVASCRIPT_DEBUGGER)
  78. m_debuggerAgent = debuggerAgent;
  79. #endif
  80. }
  81. static Node* scriptValueAsNode(ScriptValue);
  82. static ScriptValue nodeAsScriptValue(ScriptState*, Node*);
  83. void disconnect();
  84. class InspectableObject {
  85. WTF_MAKE_FAST_ALLOCATED;
  86. public:
  87. virtual ScriptValue get(ScriptState*);
  88. virtual ~InspectableObject() { }
  89. };
  90. void addInspectedObject(PassOwnPtr<InspectableObject>);
  91. void clearInspectedObjects();
  92. InspectableObject* inspectedObject(unsigned int num);
  93. void inspectImpl(PassRefPtr<InspectorValue> objectToInspect, PassRefPtr<InspectorValue> hints);
  94. void getEventListenersImpl(Node*, Vector<EventListenerInfo>& listenersArray);
  95. void clearConsoleMessages();
  96. void copyText(const String& text);
  97. #if ENABLE(SQL_DATABASE)
  98. String databaseIdImpl(Database*);
  99. #endif
  100. String storageIdImpl(Storage*);
  101. #if ENABLE(JAVASCRIPT_DEBUGGER)
  102. ScriptDebugServer& scriptDebugServer();
  103. #endif
  104. private:
  105. InjectedScriptHost();
  106. InspectorAgent* m_inspectorAgent;
  107. InspectorConsoleAgent* m_consoleAgent;
  108. #if ENABLE(SQL_DATABASE)
  109. InspectorDatabaseAgent* m_databaseAgent;
  110. #endif
  111. InspectorDOMStorageAgent* m_domStorageAgent;
  112. InspectorDOMAgent* m_domAgent;
  113. #if ENABLE(JAVASCRIPT_DEBUGGER)
  114. InspectorDebuggerAgent* m_debuggerAgent;
  115. #endif
  116. Vector<OwnPtr<InspectableObject> > m_inspectedObjects;
  117. OwnPtr<InspectableObject> m_defaultInspectableObject;
  118. };
  119. } // namespace WebCore
  120. #endif // !defined(InjectedScriptHost_h)