1 | /* |
2 | * Copyright (C) 2014-2016 Apple Inc. All rights reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
23 | * THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #pragma once |
27 | |
28 | #include "Connection.h" |
29 | #include "WebInspectorFrontendAPIDispatcher.h" |
30 | #include <WebCore/InspectorFrontendClient.h> |
31 | #include <WebCore/InspectorFrontendHost.h> |
32 | #include <WebCore/PageIdentifier.h> |
33 | |
34 | namespace WebCore { |
35 | class InspectorController; |
36 | class CertificateInfo; |
37 | class FloatRect; |
38 | } |
39 | |
40 | namespace WebKit { |
41 | |
42 | class WebPage; |
43 | |
44 | class WebInspectorUI : public RefCounted<WebInspectorUI>, private IPC::Connection::Client, public WebCore::InspectorFrontendClient { |
45 | public: |
46 | static Ref<WebInspectorUI> create(WebPage&); |
47 | |
48 | // Implemented in generated WebInspectorUIMessageReceiver.cpp |
49 | void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override; |
50 | |
51 | // IPC::Connection::Client |
52 | void didClose(IPC::Connection&) override { /* Do nothing, the inspected page process may have crashed and may be getting replaced. */ } |
53 | void didReceiveInvalidMessage(IPC::Connection&, IPC::StringReference, IPC::StringReference) override { closeWindow(); } |
54 | |
55 | // Called by WebInspectorUI messages |
56 | void establishConnection(WebCore::PageIdentifier inspectedPageIdentifier, bool underTest, unsigned inspectionLevel); |
57 | void updateConnection(); |
58 | |
59 | void showConsole(); |
60 | void showResources(); |
61 | void showTimelines(); |
62 | |
63 | void showMainResourceForFrame(const String& frameIdentifier); |
64 | |
65 | void startPageProfiling(); |
66 | void stopPageProfiling(); |
67 | |
68 | void startElementSelection(); |
69 | void stopElementSelection(); |
70 | |
71 | void attachedBottom() { setDockSide(DockSide::Bottom); } |
72 | void attachedRight() { setDockSide(DockSide::Right); } |
73 | void attachedLeft() { setDockSide(DockSide::Left); } |
74 | void detached() { setDockSide(DockSide::Undocked); } |
75 | |
76 | void setDockSide(DockSide); |
77 | void setDockingUnavailable(bool); |
78 | |
79 | void setIsVisible(bool); |
80 | |
81 | void didSave(const String& url); |
82 | void didAppend(const String& url); |
83 | |
84 | void sendMessageToFrontend(const String&); |
85 | |
86 | // WebCore::InspectorFrontendClient |
87 | void windowObjectCleared() override; |
88 | void frontendLoaded() override; |
89 | |
90 | void startWindowDrag() override; |
91 | void moveWindowBy(float x, float y) override; |
92 | |
93 | bool isRemote() const final { return false; } |
94 | String localizedStringsURL() override; |
95 | |
96 | void bringToFront() override; |
97 | void closeWindow() override; |
98 | void reopen() override; |
99 | |
100 | WebCore::UserInterfaceLayoutDirection userInterfaceLayoutDirection() const override; |
101 | |
102 | void requestSetDockSide(DockSide) override; |
103 | void changeAttachedWindowHeight(unsigned) override; |
104 | void changeAttachedWindowWidth(unsigned) override; |
105 | |
106 | void changeSheetRect(const WebCore::FloatRect&) override; |
107 | |
108 | void openInNewTab(const String& url) override; |
109 | |
110 | bool canSave() override; |
111 | void save(const WTF::String& url, const WTF::String& content, bool base64Encoded, bool forceSaveAs) override; |
112 | void append(const WTF::String& url, const WTF::String& content) override; |
113 | |
114 | void inspectedURLChanged(const String&) override; |
115 | void showCertificate(const WebCore::CertificateInfo&) override; |
116 | |
117 | void sendMessageToBackend(const String&) override; |
118 | |
119 | void pagePaused() override; |
120 | void pageUnpaused() override; |
121 | |
122 | bool isUnderTest() override { return m_underTest; } |
123 | unsigned inspectionLevel() const override { return m_inspectionLevel; } |
124 | |
125 | private: |
126 | explicit WebInspectorUI(WebPage&); |
127 | |
128 | WebPage& m_page; |
129 | WebInspectorFrontendAPIDispatcher m_frontendAPIDispatcher; |
130 | RefPtr<WebCore::InspectorFrontendHost> m_frontendHost; |
131 | RefPtr<IPC::Connection> m_backendConnection; |
132 | |
133 | // Keep a pointer to the frontend's inspector controller rather than going through |
134 | // corePage(), since we may need it after the frontend's page has started destruction. |
135 | WebCore::InspectorController* m_frontendController { nullptr }; |
136 | |
137 | WebCore::PageIdentifier m_inspectedPageIdentifier; |
138 | bool m_underTest { false }; |
139 | bool m_dockingUnavailable { false }; |
140 | bool m_isVisible { false }; |
141 | DockSide m_dockSide { DockSide::Undocked }; |
142 | unsigned m_inspectionLevel { 1 }; |
143 | }; |
144 | |
145 | } // namespace WebKit |
146 | |