1 /* 2 * Copyright (C) 2010 Google 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 are 6 * met: 7 * 8 * * Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * * Redistributions in binary form must reproduce the above 11 * copyright notice, this list of conditions and the following disclaimer 12 * in the documentation and/or other materials provided with the 13 * distribution. 14 * * Neither the name of Google Inc. nor the names of its 15 * contributors may be used to endorse or promote products derived from 16 * this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31 #ifndef WebDevToolsFrontendImpl_h 32 #define WebDevToolsFrontendImpl_h 33 34 #include "ContextMenu.h" 35 #include "ContextMenuProvider.h" 36 #include "DevToolsRPC.h" 37 #include "WebDevToolsFrontend.h" 38 #include <v8.h> 39 #include <wtf/HashMap.h> 40 #include <wtf/Noncopyable.h> 41 #include <wtf/OwnPtr.h> 42 #include <wtf/RefPtr.h> 43 #include <wtf/Vector.h> 44 45 namespace WebCore { 46 class ContextMenuItem; 47 class Node; 48 class Page; 49 class String; 50 } 51 52 namespace WebKit { 53 54 class JSDebuggerAgentBoundObj; 55 class JSProfilerAgentBoundObj; 56 class JSToolsAgentBoundObj; 57 class WebDevToolsClientDelegate; 58 class WebViewImpl; 59 struct WebDevToolsMessageData; 60 61 class WebDevToolsFrontendImpl : public WebKit::WebDevToolsFrontend 62 , public DevToolsRPC::Delegate 63 , public Noncopyable { 64 public: 65 WebDevToolsFrontendImpl( 66 WebKit::WebViewImpl* webViewImpl, 67 WebKit::WebDevToolsFrontendClient* client, 68 const String& applicationLocale); 69 virtual ~WebDevToolsFrontendImpl(); 70 71 // DevToolsRPC::Delegate implementation. 72 virtual void sendRpcMessage(const WebKit::WebDevToolsMessageData& data); 73 74 // WebDevToolsFrontend implementation. 75 virtual void dispatchMessageFromAgent(const WebKit::WebDevToolsMessageData& data); 76 77 private: 78 class MenuProvider : public WebCore::ContextMenuProvider { 79 public: 80 static PassRefPtr<MenuProvider> create(WebDevToolsFrontendImpl* frontendHost, const Vector<WebCore::ContextMenuItem*>& items) 81 { 82 return adoptRef(new MenuProvider(frontendHost, items)); 83 } 84 85 virtual ~MenuProvider() 86 { 87 contextMenuCleared(); 88 } 89 90 void disconnect() 91 { 92 m_frontendHost = 0; 93 } 94 95 virtual void populateContextMenu(WebCore::ContextMenu* menu) 96 { 97 for (size_t i = 0; i < m_items.size(); ++i) 98 menu->appendItem(*m_items[i]); 99 } 100 101 virtual void contextMenuItemSelected(WebCore::ContextMenuItem* item) 102 { 103 if (m_frontendHost) 104 m_frontendHost->contextMenuItemSelected(item); 105 } 106 107 virtual void contextMenuCleared() 108 { 109 if (m_frontendHost) 110 m_frontendHost->contextMenuCleared(); 111 deleteAllValues(m_items); 112 m_items.clear(); 113 } 114 115 private: 116 MenuProvider(WebDevToolsFrontendImpl* frontendHost, const Vector<WebCore::ContextMenuItem*>& items) 117 : m_frontendHost(frontendHost) 118 , m_items(items) { } 119 WebDevToolsFrontendImpl* m_frontendHost; 120 Vector<WebCore::ContextMenuItem*> m_items; 121 }; 122 123 void executeScript(const Vector<String>& v); 124 void dispatchOnWebInspector(const String& method, const String& param); 125 126 // friend class MenuSelectionHandler; 127 void contextMenuItemSelected(WebCore::ContextMenuItem* menuItem); 128 void contextMenuCleared(); 129 130 static v8::Handle<v8::Value> jsLoaded(const v8::Arguments& args); 131 static v8::Handle<v8::Value> jsPlatform(const v8::Arguments& args); 132 static v8::Handle<v8::Value> jsPort(const v8::Arguments& args); 133 static v8::Handle<v8::Value> jsCopyText(const v8::Arguments& args); 134 135 static v8::Handle<v8::Value> jsActivateWindow(const v8::Arguments& args); 136 static v8::Handle<v8::Value> jsCloseWindow(const v8::Arguments& args); 137 static v8::Handle<v8::Value> jsDockWindow(const v8::Arguments& args); 138 static v8::Handle<v8::Value> jsUndockWindow(const v8::Arguments& args); 139 static v8::Handle<v8::Value> jsLocalizedStringsURL(const v8::Arguments& args); 140 static v8::Handle<v8::Value> jsHiddenPanels(const v8::Arguments& args); 141 static v8::Handle<v8::Value> jsDebuggerCommand(const v8::Arguments& args); 142 static v8::Handle<v8::Value> jsSetting(const v8::Arguments& args); 143 static v8::Handle<v8::Value> jsSetSetting(const v8::Arguments& args); 144 static v8::Handle<v8::Value> jsDebuggerPauseScript(const v8::Arguments& args); 145 static v8::Handle<v8::Value> jsWindowUnloading(const v8::Arguments& args); 146 static v8::Handle<v8::Value> jsShowContextMenu(const v8::Arguments& args); 147 148 WebKit::WebViewImpl* m_webViewImpl; 149 WebKit::WebDevToolsFrontendClient* m_client; 150 String m_applicationLocale; 151 OwnPtr<JSDebuggerAgentBoundObj> m_debuggerAgentObj; 152 OwnPtr<JSProfilerAgentBoundObj> m_profilerAgentObj; 153 OwnPtr<JSToolsAgentBoundObj> m_toolsAgentObj; 154 bool m_loaded; 155 Vector<Vector<String> > m_pendingIncomingMessages; 156 RefPtr<MenuProvider> m_menuProvider; 157 }; 158 159 } // namespace WebKit 160 161 #endif 162