InjectedScriptHost.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
  3. * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com>
  4. * Copyright (C) 2010 Google Inc. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
  16. * its contributors may be used to endorse or promote products derived
  17. * from this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
  20. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
  23. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  26. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  28. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #include "config.h"
  31. #if ENABLE(INSPECTOR)
  32. #include "InjectedScriptHost.h"
  33. #include "Element.h"
  34. #include "Frame.h"
  35. #include "FrameLoader.h"
  36. #include "HTMLFrameOwnerElement.h"
  37. #include "InjectedScript.h"
  38. #include "InspectorAgent.h"
  39. #include "InspectorClient.h"
  40. #include "InspectorConsoleAgent.h"
  41. #include "InspectorDOMAgent.h"
  42. #include "InspectorDOMStorageAgent.h"
  43. #include "InspectorDatabaseAgent.h"
  44. #include "InspectorDebuggerAgent.h"
  45. #include "InspectorFrontend.h"
  46. #include "InspectorValues.h"
  47. #include "Pasteboard.h"
  48. #include "Storage.h"
  49. #if ENABLE(SQL_DATABASE)
  50. #include "Database.h"
  51. #endif
  52. #include "markup.h"
  53. #include <wtf/RefPtr.h>
  54. #include <wtf/StdLibExtras.h>
  55. using namespace std;
  56. namespace WebCore {
  57. PassRefPtr<InjectedScriptHost> InjectedScriptHost::create()
  58. {
  59. return adoptRef(new InjectedScriptHost());
  60. }
  61. InjectedScriptHost::InjectedScriptHost()
  62. : m_inspectorAgent(0)
  63. , m_consoleAgent(0)
  64. #if ENABLE(SQL_DATABASE)
  65. , m_databaseAgent(0)
  66. #endif
  67. , m_domStorageAgent(0)
  68. , m_domAgent(0)
  69. {
  70. m_defaultInspectableObject = adoptPtr(new InspectableObject());
  71. }
  72. InjectedScriptHost::~InjectedScriptHost()
  73. {
  74. }
  75. void InjectedScriptHost::disconnect()
  76. {
  77. m_inspectorAgent = 0;
  78. m_consoleAgent = 0;
  79. #if ENABLE(SQL_DATABASE)
  80. m_databaseAgent = 0;
  81. #endif
  82. m_domStorageAgent = 0;
  83. m_domAgent = 0;
  84. }
  85. void InjectedScriptHost::inspectImpl(PassRefPtr<InspectorValue> object, PassRefPtr<InspectorValue> hints)
  86. {
  87. if (m_inspectorAgent) {
  88. RefPtr<TypeBuilder::Runtime::RemoteObject> remoteObject = TypeBuilder::Runtime::RemoteObject::runtimeCast(object);
  89. m_inspectorAgent->inspect(remoteObject, hints->asObject());
  90. }
  91. }
  92. void InjectedScriptHost::getEventListenersImpl(Node* node, Vector<EventListenerInfo>& listenersArray)
  93. {
  94. if (m_domAgent)
  95. m_domAgent->getEventListeners(node, listenersArray, false);
  96. }
  97. void InjectedScriptHost::clearConsoleMessages()
  98. {
  99. if (m_consoleAgent) {
  100. ErrorString error;
  101. m_consoleAgent->clearMessages(&error);
  102. }
  103. }
  104. void InjectedScriptHost::copyText(const String& text)
  105. {
  106. Pasteboard::generalPasteboard()->writePlainText(text, Pasteboard::CannotSmartReplace);
  107. }
  108. ScriptValue InjectedScriptHost::InspectableObject::get(ScriptState*)
  109. {
  110. return ScriptValue();
  111. };
  112. void InjectedScriptHost::addInspectedObject(PassOwnPtr<InjectedScriptHost::InspectableObject> object)
  113. {
  114. m_inspectedObjects.insert(0, object);
  115. while (m_inspectedObjects.size() > 5)
  116. m_inspectedObjects.removeLast();
  117. }
  118. void InjectedScriptHost::clearInspectedObjects()
  119. {
  120. m_inspectedObjects.clear();
  121. }
  122. InjectedScriptHost::InspectableObject* InjectedScriptHost::inspectedObject(unsigned int num)
  123. {
  124. if (num >= m_inspectedObjects.size())
  125. return m_defaultInspectableObject.get();
  126. return m_inspectedObjects[num].get();
  127. }
  128. #if ENABLE(SQL_DATABASE)
  129. String InjectedScriptHost::databaseIdImpl(Database* database)
  130. {
  131. if (m_databaseAgent)
  132. return m_databaseAgent->databaseId(database);
  133. return String();
  134. }
  135. #endif
  136. String InjectedScriptHost::storageIdImpl(Storage* storage)
  137. {
  138. if (m_domStorageAgent)
  139. return m_domStorageAgent->storageId(storage);
  140. return String();
  141. }
  142. #if ENABLE(JAVASCRIPT_DEBUGGER)
  143. ScriptDebugServer& InjectedScriptHost::scriptDebugServer()
  144. {
  145. return m_debuggerAgent->scriptDebugServer();
  146. }
  147. #endif
  148. } // namespace WebCore
  149. #endif // ENABLE(INSPECTOR)