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
33namespace WebCore {
34class InspectorController;
35class CertificateInfo;
36class FloatRect;
37}
38
39namespace WebKit {
40
41class WebPage;
42
43class WebInspectorUI : public RefCounted<WebInspectorUI>, private IPC::Connection::Client, public WebCore::InspectorFrontendClient {
44public:
45 static Ref<WebInspectorUI> create(WebPage&);
46
47 // Implemented in generated WebInspectorUIMessageReceiver.cpp
48 void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;
49
50 // IPC::Connection::Client
51 void didClose(IPC::Connection&) override { /* Do nothing, the inspected page process may have crashed and may be getting replaced. */ }
52 void didReceiveInvalidMessage(IPC::Connection&, IPC::StringReference, IPC::StringReference) override { closeWindow(); }
53
54 // Called by WebInspectorUI messages
55 void establishConnection(uint64_t inspectedPageIdentifier, bool underTest, unsigned inspectionLevel);
56 void updateConnection();
57
58 void showConsole();
59 void showResources();
60 void showTimelines();
61
62 void showMainResourceForFrame(const String& frameIdentifier);
63
64 void startPageProfiling();
65 void stopPageProfiling();
66
67 void startElementSelection();
68 void stopElementSelection();
69
70 void attachedBottom() { setDockSide(DockSide::Bottom); }
71 void attachedRight() { setDockSide(DockSide::Right); }
72 void attachedLeft() { setDockSide(DockSide::Left); }
73 void detached() { setDockSide(DockSide::Undocked); }
74
75 void setDockSide(DockSide);
76 void setDockingUnavailable(bool);
77
78 void setIsVisible(bool);
79
80 void didSave(const String& url);
81 void didAppend(const String& url);
82
83 void sendMessageToFrontend(const String&);
84
85 // WebCore::InspectorFrontendClient
86 void windowObjectCleared() override;
87 void frontendLoaded() override;
88
89 void startWindowDrag() override;
90 void moveWindowBy(float x, float y) override;
91
92 bool isRemote() const final { return false; }
93 String localizedStringsURL() override;
94
95 void bringToFront() override;
96 void closeWindow() override;
97 void reopen() override;
98
99 WebCore::UserInterfaceLayoutDirection userInterfaceLayoutDirection() const override;
100
101 void requestSetDockSide(DockSide) override;
102 void changeAttachedWindowHeight(unsigned) override;
103 void changeAttachedWindowWidth(unsigned) override;
104
105 void changeSheetRect(const WebCore::FloatRect&) override;
106
107 void openInNewTab(const String& url) override;
108
109 bool canSave() override;
110 void save(const WTF::String& url, const WTF::String& content, bool base64Encoded, bool forceSaveAs) override;
111 void append(const WTF::String& url, const WTF::String& content) override;
112
113 void inspectedURLChanged(const String&) override;
114 void showCertificate(const WebCore::CertificateInfo&) override;
115
116 void sendMessageToBackend(const String&) override;
117
118 void pagePaused() override;
119 void pageUnpaused() override;
120
121 bool isUnderTest() override { return m_underTest; }
122 unsigned inspectionLevel() const override { return m_inspectionLevel; }
123
124private:
125 explicit WebInspectorUI(WebPage&);
126
127 WebPage& m_page;
128 WebInspectorFrontendAPIDispatcher m_frontendAPIDispatcher;
129 RefPtr<WebCore::InspectorFrontendHost> m_frontendHost;
130 RefPtr<IPC::Connection> m_backendConnection;
131
132 // Keep a pointer to the frontend's inspector controller rather than going through
133 // corePage(), since we may need it after the frontend's page has started destruction.
134 WebCore::InspectorController* m_frontendController { nullptr };
135
136 uint64_t m_inspectedPageIdentifier { 0 };
137 bool m_underTest { false };
138 bool m_dockingUnavailable { false };
139 bool m_isVisible { false };
140 DockSide m_dockSide { DockSide::Undocked };
141 unsigned m_inspectionLevel { 1 };
142};
143
144} // namespace WebKit
145