1/* 2 * Copyright (C) 2010 Apple Inc. All rights reserved. 3 * Portions Copyright (c) 2011 Motorola Mobility, 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 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 16 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 18 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 24 * THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27#ifndef WebInspectorProxy_h 28#define WebInspectorProxy_h 29 30#if ENABLE(INSPECTOR) 31 32#include "APIObject.h" 33#include "MessageReceiver.h" 34#include <wtf/Forward.h> 35#include <wtf/PassRefPtr.h> 36#include <wtf/RefPtr.h> 37#include <wtf/text/WTFString.h> 38 39#if PLATFORM(MAC) 40#include "WKGeometry.h" 41#include <wtf/HashMap.h> 42#include <wtf/RetainPtr.h> 43 44OBJC_CLASS NSButton; 45OBJC_CLASS NSURL; 46OBJC_CLASS NSWindow; 47OBJC_CLASS WKWebInspectorProxyObjCAdapter; 48OBJC_CLASS WKWebInspectorWKView; 49#endif 50 51#if PLATFORM(GTK) 52#include "WebInspectorClientGtk.h" 53#endif 54 55#if PLATFORM(EFL) 56#include <Ecore_Evas.h> 57#include <Evas.h> 58#endif 59 60namespace WebKit { 61 62class WebFrameProxy; 63class WebPageGroup; 64class WebPageProxy; 65struct WebPageCreationParameters; 66 67enum AttachmentSide { 68 AttachmentSideBottom, 69 AttachmentSideRight 70}; 71 72class WebInspectorProxy : public API::ObjectImpl<API::Object::Type::Inspector>, public IPC::MessageReceiver { 73public: 74 static PassRefPtr<WebInspectorProxy> create(WebPageProxy* page) 75 { 76 return adoptRef(new WebInspectorProxy(page)); 77 } 78 79 ~WebInspectorProxy(); 80 81 void invalidate(); 82 83 // Public APIs 84 WebPageProxy* page() const { return m_page; } 85 86 bool isConnected() const { return m_createdInspectorPage; } 87 bool isVisible() const { return m_isVisible; } 88 bool isFront(); 89 90 void connect(); 91 92 void show(); 93 void hide(); 94 void close(); 95 96#if PLATFORM(MAC) 97 void createInspectorWindow(); 98 void updateInspectorWindowTitle() const; 99 void inspectedViewFrameDidChange(CGFloat = 0); 100 void windowFrameDidChange(); 101 NSWindow* inspectorWindow() const { return m_inspectorWindow.get(); } 102 103 void setInspectorWindowFrame(WKRect&); 104 WKRect inspectorWindowFrame(); 105#endif 106 107#if PLATFORM(GTK) 108 GtkWidget* inspectorView() const { return m_inspectorView; }; 109 void initializeInspectorClientGtk(const WKInspectorClientGtkBase*); 110#endif 111 112 void showConsole(); 113 void showResources(); 114 void showMainResourceForFrame(WebFrameProxy*); 115 116 bool isAttached() const { return m_isAttached; } 117 void attachRight(); 118 void attachBottom(); 119 void attach(AttachmentSide = AttachmentSideBottom); 120 void detach(); 121 122 void setAttachedWindowHeight(unsigned); 123 void setAttachedWindowWidth(unsigned); 124 void setToolbarHeight(unsigned height) { platformSetToolbarHeight(height); } 125 126 bool isDebuggingJavaScript() const { return m_isDebuggingJavaScript; } 127 void toggleJavaScriptDebugging(); 128 129 bool isProfilingJavaScript() const { return m_isProfilingJavaScript; } 130 void toggleJavaScriptProfiling(); 131 132 bool isProfilingPage() const { return m_isProfilingPage; } 133 void togglePageProfiling(); 134 135 static bool isInspectorPage(WebPageProxy&); 136 137 // Provided by platform WebInspectorProxy implementations. 138 String inspectorPageURL() const; 139 String inspectorTestPageURL() const; 140 String inspectorBaseURL() const; 141 142#if ENABLE(INSPECTOR_SERVER) 143 void enableRemoteInspection(); 144 void remoteFrontendConnected(); 145 void remoteFrontendDisconnected(); 146 void dispatchMessageFromRemoteFrontend(const String& message); 147 int remoteInspectionPageID() const { return m_remoteInspectionPageId; } 148#endif 149 150private: 151 explicit WebInspectorProxy(WebPageProxy*); 152 153 // IPC::MessageReceiver 154 virtual void didReceiveMessage(IPC::Connection*, IPC::MessageDecoder&) override; 155 virtual void didReceiveSyncMessage(IPC::Connection*, IPC::MessageDecoder&, std::unique_ptr<IPC::MessageEncoder>&) override; 156 157 WebPageProxy* platformCreateInspectorPage(); 158 void platformOpen(); 159 void platformDidClose(); 160 void platformBringToFront(); 161 void platformHide(); 162 bool platformIsFront(); 163 void platformAttachAvailabilityChanged(bool); 164 void platformInspectedURLChanged(const String&); 165 unsigned platformInspectedWindowHeight(); 166 unsigned platformInspectedWindowWidth(); 167 void platformAttach(); 168 void platformDetach(); 169 void platformSetAttachedWindowHeight(unsigned); 170 void platformSetAttachedWindowWidth(unsigned); 171 void platformSetToolbarHeight(unsigned); 172 void platformSave(const String& filename, const String& content, bool base64Encoded, bool forceSaveAs); 173 void platformAppend(const String& filename, const String& content); 174 175 // Called by WebInspectorProxy messages 176 void createInspectorPage(uint64_t& inspectorPageID, WebPageCreationParameters&); 177 void createInspectorPageForTest(uint64_t& inspectorPageID, WebPageCreationParameters&); 178 void didClose(); 179 void bringToFront(); 180 void attachAvailabilityChanged(bool); 181 void inspectedURLChanged(const String&); 182 183 void save(const String& filename, const String& content, bool base64Encoded, bool forceSaveAs); 184 void append(const String& filename, const String& content); 185 186#if ENABLE(INSPECTOR_SERVER) 187 void sendMessageToRemoteFrontend(const String& message); 188#endif 189 190 bool canAttach(); 191 bool shouldOpenAttached(); 192 193 void open(); 194 195 WebPageGroup* inspectorPageGroup() const; 196 197#if PLATFORM(GTK) || PLATFORM(EFL) 198 void createInspectorWindow(); 199#endif 200 201 static const unsigned minimumWindowWidth; 202 static const unsigned minimumWindowHeight; 203 204 static const unsigned initialWindowWidth; 205 static const unsigned initialWindowHeight; 206 207 // Keep this in sync with the value in InspectorFrontendClientLocal. 208 static const unsigned minimumAttachedWidth; 209 static const unsigned minimumAttachedHeight; 210 211 WebPageProxy* m_page; 212 213 bool m_isVisible; 214 bool m_isAttached; 215 bool m_isDebuggingJavaScript; 216 bool m_isProfilingJavaScript; 217 bool m_isProfilingPage; 218 bool m_showMessageSent; 219 bool m_createdInspectorPage; 220 bool m_ignoreFirstBringToFront; 221 222 // The debugger stops all the pages in the same PageGroup. Having 223 // all the inspectors in the same group will make it impossible to debug 224 // the inspector code, so we use the level to make different page groups. 225 unsigned m_level; 226 227 AttachmentSide m_attachmentSide; 228 229#if PLATFORM(MAC) 230 RetainPtr<WKWebInspectorWKView> m_inspectorView; 231 RetainPtr<NSWindow> m_inspectorWindow; 232 RetainPtr<NSButton> m_dockBottomButton; 233 RetainPtr<NSButton> m_dockRightButton; 234 RetainPtr<WKWebInspectorProxyObjCAdapter> m_inspectorProxyObjCAdapter; 235 String m_urlString; 236 HashMap<String, RetainPtr<NSURL>> m_suggestedToActualURLMap; 237#elif PLATFORM(GTK) 238 WebInspectorClientGtk m_client; 239 GtkWidget* m_inspectorView; 240 GtkWidget* m_inspectorWindow; 241#elif PLATFORM(EFL) 242 Evas_Object* m_inspectorView; 243 Ecore_Evas* m_inspectorWindow; 244#endif 245#if ENABLE(INSPECTOR_SERVER) 246 int m_remoteInspectionPageId; 247#endif 248}; 249 250} // namespace WebKit 251 252#endif // ENABLE(INSPECTOR) 253 254#endif // WebInspectorProxy_h 255