| 1 | /* | 
| 2 |  * Copyright (C) 2011 Google Inc. All rights reserved. | 
| 3 |  * Copyright (C) 2015 Apple 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 are | 
| 7 |  * met: | 
| 8 |  * | 
| 9 |  *     * Redistributions of source code must retain the above copyright | 
| 10 |  * notice, this list of conditions and the following disclaimer. | 
| 11 |  *     * Redistributions in binary form must reproduce the above | 
| 12 |  * copyright notice, this list of conditions and the following disclaimer | 
| 13 |  * in the documentation and/or other materials provided with the | 
| 14 |  * distribution. | 
| 15 |  *     * Neither the name of Google Inc. nor the names of its | 
| 16 |  * contributors may be used to endorse or promote products derived from | 
| 17 |  * this software without specific prior written permission. | 
| 18 |  * | 
| 19 |  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 
| 20 |  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 
| 21 |  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 
| 22 |  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 
| 23 |  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 
| 24 |  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 
| 25 |  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 
| 26 |  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 
| 27 |  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 
| 28 |  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 
| 29 |  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
| 30 |  */ | 
| 31 |  | 
| 32 | #pragma once | 
| 33 |  | 
| 34 | #include "InspectorOverlay.h" | 
| 35 | #include "PageScriptDebugServer.h" | 
| 36 | #include <JavaScriptCore/InspectorAgentRegistry.h> | 
| 37 | #include <JavaScriptCore/InspectorEnvironment.h> | 
| 38 | #include <wtf/Forward.h> | 
| 39 | #include <wtf/Noncopyable.h> | 
| 40 | #include <wtf/text/WTFString.h> | 
| 41 |  | 
| 42 | namespace Inspector { | 
| 43 | class BackendDispatcher; | 
| 44 | class FrontendChannel; | 
| 45 | class FrontendRouter; | 
| 46 | class InspectorAgent; | 
| 47 | } | 
| 48 |  | 
| 49 | namespace WebCore { | 
| 50 |  | 
| 51 | class DOMWrapperWorld; | 
| 52 | class Frame; | 
| 53 | class GraphicsContext; | 
| 54 | class InspectorClient; | 
| 55 | class InspectorDOMAgent; | 
| 56 | class InspectorFrontendClient; | 
| 57 | class InspectorInstrumentation; | 
| 58 | class InspectorPageAgent; | 
| 59 | class InstrumentingAgents; | 
| 60 | class Node; | 
| 61 | class Page; | 
| 62 | class WebInjectedScriptManager; | 
| 63 | struct PageAgentContext; | 
| 64 |  | 
| 65 | class InspectorController final : public Inspector::InspectorEnvironment { | 
| 66 |     WTF_MAKE_NONCOPYABLE(InspectorController); | 
| 67 |     WTF_MAKE_FAST_ALLOCATED; | 
| 68 | public: | 
| 69 |     InspectorController(Page&, InspectorClient*); | 
| 70 |     virtual ~InspectorController(); | 
| 71 |  | 
| 72 |     void inspectedPageDestroyed(); | 
| 73 |  | 
| 74 |     bool enabled() const; | 
| 75 |     Page& inspectedPage() const; | 
| 76 |  | 
| 77 |     WEBCORE_EXPORT void show(); | 
| 78 |  | 
| 79 |     WEBCORE_EXPORT void setInspectorFrontendClient(InspectorFrontendClient*); | 
| 80 |     unsigned inspectionLevel() const; | 
| 81 |     void didClearWindowObjectInWorld(Frame&, DOMWrapperWorld&); | 
| 82 |  | 
| 83 |     WEBCORE_EXPORT void dispatchMessageFromFrontend(const String& message); | 
| 84 |  | 
| 85 |     bool hasLocalFrontend() const; | 
| 86 |     bool hasRemoteFrontend() const; | 
| 87 |  | 
| 88 |     WEBCORE_EXPORT void connectFrontend(Inspector::FrontendChannel&, bool isAutomaticInspection = false, bool immediatelyPause = false); | 
| 89 |     WEBCORE_EXPORT void disconnectFrontend(Inspector::FrontendChannel&); | 
| 90 |     WEBCORE_EXPORT void disconnectAllFrontends(); | 
| 91 |  | 
| 92 |     void inspect(Node*); | 
| 93 |     WEBCORE_EXPORT void drawHighlight(GraphicsContext&) const; | 
| 94 |     WEBCORE_EXPORT void getHighlight(Highlight&, InspectorOverlay::CoordinateSystem) const; | 
| 95 |     void hideHighlight(); | 
| 96 |     Node* highlightedNode() const; | 
| 97 |  | 
| 98 |     WEBCORE_EXPORT void setIndicating(bool); | 
| 99 |  | 
| 100 |     WEBCORE_EXPORT void didComposite(Frame&); | 
| 101 |  | 
| 102 |     bool isUnderTest() const { return m_isUnderTest; } | 
| 103 |     WEBCORE_EXPORT void setIsUnderTest(bool); | 
| 104 |     WEBCORE_EXPORT void evaluateForTestInFrontend(const String& script); | 
| 105 |  | 
| 106 |     InspectorClient* inspectorClient() const { return m_inspectorClient; } | 
| 107 |     InspectorFrontendClient* inspectorFrontendClient() const { return m_inspectorFrontendClient; } | 
| 108 |  | 
| 109 |     Inspector::InspectorAgent& ensureInspectorAgent(); | 
| 110 |     InspectorDOMAgent& ensureDOMAgent(); | 
| 111 |     WEBCORE_EXPORT InspectorPageAgent& ensurePageAgent(); | 
| 112 |  | 
| 113 |     // InspectorEnvironment | 
| 114 |     bool () const override; | 
| 115 |     bool canAccessInspectedScriptState(JSC::ExecState*) const override; | 
| 116 |     Inspector::InspectorFunctionCallHandler functionCallHandler() const override; | 
| 117 |     Inspector::InspectorEvaluateHandler evaluateHandler() const override; | 
| 118 |     void frontendInitialized() override; | 
| 119 |     Ref<WTF::Stopwatch> executionStopwatch() override; | 
| 120 |     PageScriptDebugServer& scriptDebugServer() override; | 
| 121 |     JSC::VM& vm() override; | 
| 122 |  | 
| 123 | private: | 
| 124 |     friend class InspectorInstrumentation; | 
| 125 |  | 
| 126 |     PageAgentContext pageAgentContext(); | 
| 127 |     void createLazyAgents(); | 
| 128 |  | 
| 129 |     Ref<InstrumentingAgents> m_instrumentingAgents; | 
| 130 |     std::unique_ptr<WebInjectedScriptManager> m_injectedScriptManager; | 
| 131 |     Ref<Inspector::FrontendRouter> m_frontendRouter; | 
| 132 |     Ref<Inspector::BackendDispatcher> m_backendDispatcher; | 
| 133 |     std::unique_ptr<InspectorOverlay> m_overlay; | 
| 134 |     Ref<WTF::Stopwatch> m_executionStopwatch; | 
| 135 |     PageScriptDebugServer m_scriptDebugServer; | 
| 136 |     Inspector::AgentRegistry m_agents; | 
| 137 |  | 
| 138 |     Page& m_page; | 
| 139 |     InspectorClient* m_inspectorClient; | 
| 140 |     InspectorFrontendClient* m_inspectorFrontendClient { nullptr }; | 
| 141 |  | 
| 142 |     // Lazy, but also on-demand agents. | 
| 143 |     Inspector::InspectorAgent* m_inspectorAgent { nullptr }; | 
| 144 |     InspectorDOMAgent* m_inspectorDOMAgent { nullptr }; | 
| 145 |     InspectorPageAgent* m_inspectorPageAgent { nullptr }; | 
| 146 |  | 
| 147 |     bool m_isUnderTest { false }; | 
| 148 |     bool m_isAutomaticInspection { false }; | 
| 149 |     bool m_pauseAfterInitialization = { false }; | 
| 150 |     bool m_didCreateLazyAgents { false }; | 
| 151 | }; | 
| 152 |  | 
| 153 | } // namespace WebCore | 
| 154 |  |