From 100f1a192118a1430f9cffa5b359ca7bb8247ec1 Mon Sep 17 00:00:00 2001 From: "pfeldman@chromium.org" Date: Wed, 28 Oct 2009 09:11:57 +0000 Subject: DevTools: Remove base/ dependencies from glue/devtools BUG=24622,24597 Review URL: http://codereview.chromium.org/330029 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30330 0039d316-1c4b-4281-b951-d872f2087c98 --- webkit/api/public/WebDevToolsFrontend.h | 62 ++++ webkit/api/public/WebDevToolsFrontendClient.h | 61 ++++ webkit/glue/devtools/bound_object.h | 5 +- webkit/glue/devtools/debugger_agent_impl.cc | 3 +- webkit/glue/devtools/debugger_agent_impl.h | 3 +- webkit/glue/devtools/debugger_agent_manager.cc | 15 +- webkit/glue/devtools/debugger_agent_manager.h | 13 +- webkit/glue/devtools/devtools_mock_rpc.h | 0 webkit/glue/devtools/devtools_rpc.cc | 0 webkit/glue/devtools/devtools_rpc.h | 26 +- webkit/glue/devtools/devtools_rpc_js.h | 3 +- webkit/glue/devtools/devtools_rpc_unittest.cc | 0 webkit/glue/webdevtoolsagent_impl.h | 1 - webkit/glue/webdevtoolsclient.h | 39 --- webkit/glue/webdevtoolsclient_delegate.h | 36 --- webkit/glue/webdevtoolsclient_impl.cc | 422 ------------------------- webkit/glue/webdevtoolsclient_impl.h | 94 ------ webkit/glue/webdevtoolsfrontend_impl.cc | 422 +++++++++++++++++++++++++ webkit/glue/webdevtoolsfrontend_impl.h | 95 ++++++ webkit/webkit.gyp | 8 +- 20 files changed, 669 insertions(+), 639 deletions(-) create mode 100644 webkit/api/public/WebDevToolsFrontend.h create mode 100644 webkit/api/public/WebDevToolsFrontendClient.h delete mode 100644 webkit/glue/devtools/devtools_mock_rpc.h delete mode 100644 webkit/glue/devtools/devtools_rpc.cc delete mode 100644 webkit/glue/devtools/devtools_rpc_unittest.cc delete mode 100644 webkit/glue/webdevtoolsclient.h delete mode 100644 webkit/glue/webdevtoolsclient_delegate.h delete mode 100644 webkit/glue/webdevtoolsclient_impl.cc delete mode 100644 webkit/glue/webdevtoolsclient_impl.h create mode 100644 webkit/glue/webdevtoolsfrontend_impl.cc create mode 100644 webkit/glue/webdevtoolsfrontend_impl.h (limited to 'webkit') diff --git a/webkit/api/public/WebDevToolsFrontend.h b/webkit/api/public/WebDevToolsFrontend.h new file mode 100644 index 0000000..098e49f --- /dev/null +++ b/webkit/api/public/WebDevToolsFrontend.h @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WebDevToolsFrontend_h +#define WebDevToolsFrontend_h + +#include "WebCommon.h" + +namespace WebKit { + +class WebDevToolsFrontendClient; +class WebString; +class WebView; + +// WebDevToolsFrontend represents DevTools client sitting in the Glue. It provides +// direct and delegate Apis to the host. +class WebDevToolsFrontend { +public: + static WebDevToolsFrontend* create(WebView* view, + WebDevToolsFrontendClient* client, + const WebString& applicationLocale); + + WebDevToolsFrontend() {} + virtual ~WebDevToolsFrontend() {} + + virtual void dispatchMessageFromAgent(const WebString& className, + const WebString& methodName, + const WebString& param1, + const WebString& param2, + const WebString& param3) = 0; +}; + +} // namespace WebKit + +#endif diff --git a/webkit/api/public/WebDevToolsFrontendClient.h b/webkit/api/public/WebDevToolsFrontendClient.h new file mode 100644 index 0000000..0c8397c --- /dev/null +++ b/webkit/api/public/WebDevToolsFrontendClient.h @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WebDevToolsFrontendClient_h +#define WebDevToolsFrontendClient_h + +namespace WebKit { + +class WebString; + +class WebDevToolsFrontendClient { +public: + WebDevToolsFrontendClient() {} + + virtual void sendMessageToAgent(const WebString& className, + const WebString& methodName, + const WebString& param1, + const WebString& param2, + const WebString& param3) = 0; + virtual void sendDebuggerCommandToAgent(const WebString& command) = 0; + + virtual void activateWindow() = 0; + virtual void closeWindow() = 0; + virtual void dockWindow() = 0; + virtual void undockWindow() = 0; + virtual void toggleInspectElementMode(bool enabled) = 0; + +protected: + virtual ~WebDevToolsFrontendClient() {} +}; + +} // namespace WebKit + +#endif diff --git a/webkit/glue/devtools/bound_object.h b/webkit/glue/devtools/bound_object.h index 9aa8757..c03cca2 100644 --- a/webkit/glue/devtools/bound_object.h +++ b/webkit/glue/devtools/bound_object.h @@ -5,11 +5,13 @@ #ifndef WEBKIT_GLUE_DEVTOOLS_BOUND_OBJECT_H_ #define WEBKIT_GLUE_DEVTOOLS_BOUND_OBJECT_H_ +#include + #include "v8.h" // BoundObject lets you map JavaScript method calls and property accesses // directly to C++ method calls and V8 variable access. -class BoundObject { +class BoundObject : public Noncopyable { public: BoundObject(v8::Handle context, void* v8_this, @@ -25,7 +27,6 @@ class BoundObject { v8::Persistent host_template_; v8::Persistent v8_this_; v8::Persistent bound_object_; - DISALLOW_COPY_AND_ASSIGN(BoundObject); }; #endif // WEBKIT_GLUE_DEVTOOLS_BOUND_OBJECT_H_ diff --git a/webkit/glue/devtools/debugger_agent_impl.cc b/webkit/glue/devtools/debugger_agent_impl.cc index afcfdcd..9080869 100644 --- a/webkit/glue/devtools/debugger_agent_impl.cc +++ b/webkit/glue/devtools/debugger_agent_impl.cc @@ -16,7 +16,6 @@ #include "V8Proxy.h" #undef LOG -#include "base/string_piece.h" #include "grit/webkit_resources.h" #include "webkit/glue/devtools/debugger_agent_impl.h" #include "webkit/glue/devtools/debugger_agent_manager.h" @@ -62,7 +61,7 @@ void DebuggerAgentImpl::GetContextId() { void DebuggerAgentImpl::StartProfiling(int flags) { v8::HandleScope scope; WebCore::Frame* frame = GetPage()->mainFrame(); - DCHECK(V8Proxy::retrieve(GetPage()->mainFrame())->isContextInitialized()); + ASSERT(V8Proxy::retrieve(GetPage()->mainFrame())->isContextInitialized()); v8::Context::Scope context_scope(V8Proxy::context(frame)); v8::V8::ResumeProfilerEx(flags); } diff --git a/webkit/glue/devtools/debugger_agent_impl.h b/webkit/glue/devtools/debugger_agent_impl.h index ebc78cc..0659dd7 100644 --- a/webkit/glue/devtools/debugger_agent_impl.h +++ b/webkit/glue/devtools/debugger_agent_impl.h @@ -6,6 +6,7 @@ #define WEBKIT_GLUE_DEVTOOLS_DEBUGGER_AGENT_IMPL_H_ #include +#include #include "v8.h" #include "webkit/glue/devtools/debugger_agent.h" @@ -72,8 +73,6 @@ class DebuggerAgentImpl : public DebuggerAgent { DebuggerAgentDelegate* delegate_; WebDevToolsAgentImpl* webdevtools_agent_; int profiler_log_position_; - - DISALLOW_COPY_AND_ASSIGN(DebuggerAgentImpl); }; #endif // WEBKIT_GLUE_DEVTOOLS_DEBUGGER_AGENT_IMPL_H_ diff --git a/webkit/glue/devtools/debugger_agent_manager.cc b/webkit/glue/devtools/debugger_agent_manager.cc index a905766..edf6738 100644 --- a/webkit/glue/devtools/debugger_agent_manager.cc +++ b/webkit/glue/devtools/debugger_agent_manager.cc @@ -10,7 +10,6 @@ #include #undef LOG -#include "base/string_util.h" #include "webkit/api/public/WebDevToolsAgent.h" #include "webkit/glue/devtools/debugger_agent_impl.h" #include "webkit/glue/devtools/debugger_agent_manager.h" @@ -117,18 +116,18 @@ void DebuggerAgentManager::DebugAttach(DebuggerAgentImpl* debugger_agent) { &DebuggerAgentManager::V8DebugHostDispatchHandler, 100 /* ms */); } int host_id = debugger_agent->webdevtools_agent()->host_id(); - DCHECK(host_id != 0); + ASSERT(host_id != 0); attached_agents_map_->set(host_id, debugger_agent); } // static void DebuggerAgentManager::DebugDetach(DebuggerAgentImpl* debugger_agent) { if (!attached_agents_map_) { - NOTREACHED(); + ASSERT_NOT_REACHED(); return; } int host_id = debugger_agent->webdevtools_agent()->host_id(); - DCHECK(attached_agents_map_->get(host_id) == debugger_agent); + ASSERT(attached_agents_map_->get(host_id) == debugger_agent); bool is_on_breakpoint = (FindAgentForCurrentV8Context() == debugger_agent); attached_agents_map_->remove(host_id); @@ -163,7 +162,7 @@ void DebuggerAgentManager::DebugDetach(DebuggerAgentImpl* debugger_agent) { // static void DebuggerAgentManager::DebugBreak(DebuggerAgentImpl* debugger_agent) { #if USE(V8) - DCHECK(DebuggerAgentForHostId(debugger_agent->webdevtools_agent()->host_id()) + ASSERT(DebuggerAgentForHostId(debugger_agent->webdevtools_agent()->host_id()) == debugger_agent); if (in_utility_context_) { debug_break_delayed_ = true; @@ -196,7 +195,7 @@ void DebuggerAgentManager::OnV8DebugMessage(const v8::Debug::Message& message) { } return; } // Otherwise it's an event message. - DCHECK(message.IsEvent()); + ASSERT(message.IsEvent()); // Ignore unsupported event types. if (message.GetEvent() != v8::AfterCompile && @@ -254,7 +253,7 @@ void DebuggerAgentManager::SetMessageLoopDispatchHandler( // static void DebuggerAgentManager::SetHostId(WebFrameImpl* webframe, int host_id) { - DCHECK(host_id > 0); + ASSERT(host_id > 0); WebCore::V8Proxy* proxy = WebCore::V8Proxy::retrieve(webframe->frame()); if (proxy) { proxy->setContextDebugId(host_id); @@ -297,7 +296,7 @@ DebuggerAgentImpl* DebuggerAgentManager::FindAgentForCurrentV8Context() { if (!attached_agents_map_) { return NULL; } - DCHECK(!attached_agents_map_->isEmpty()); + ASSERT(!attached_agents_map_->isEmpty()); WebCore::Frame* frame = WebCore::V8Proxy::retrieveFrameForEnteredContext(); if (!frame) { diff --git a/webkit/glue/devtools/debugger_agent_manager.h b/webkit/glue/devtools/debugger_agent_manager.h index b81ed76..22a1f93 100644 --- a/webkit/glue/devtools/debugger_agent_manager.h +++ b/webkit/glue/devtools/debugger_agent_manager.h @@ -6,9 +6,8 @@ #define WEBKIT_GLUE_DEVTOOLS_DEBUGGER_AGENT_MANAGER_H_ #include +#include -#include "base/basictypes.h" -#include "base/logging.h" #include "v8/include/v8-debug.h" #include "webkit/api/public/WebDevToolsAgent.h" @@ -33,7 +32,7 @@ class WebViewImpl; // would expect some actions from the handler. If there is no appropriate // debugger agent to handle such messages the manager will perform the action // itself, otherwise v8 may hang waiting for the action. -class DebuggerAgentManager { +class DebuggerAgentManager : public Noncopyable { public: static void DebugAttach(DebuggerAgentImpl* debugger_agent); static void DebugDetach(DebuggerAgentImpl* debugger_agent); @@ -53,10 +52,10 @@ class DebuggerAgentManager { static void OnNavigate(); - class UtilityContextScope { + class UtilityContextScope : public Noncopyable { public: UtilityContextScope() { - DCHECK(!in_utility_context_); + ASSERT(!in_utility_context_); in_utility_context_ = true; } ~UtilityContextScope() { @@ -66,8 +65,6 @@ class DebuggerAgentManager { } in_utility_context_ = false; } - private: - DISALLOW_COPY_AND_ASSIGN(UtilityContextScope); }; private: @@ -95,8 +92,6 @@ class DebuggerAgentManager { static bool in_utility_context_; static bool debug_break_delayed_; - - DISALLOW_COPY_AND_ASSIGN(DebuggerAgentManager); }; #endif // WEBKIT_GLUE_DEVTOOLS_DEBUGGER_AGENT_MANAGER_H_ diff --git a/webkit/glue/devtools/devtools_mock_rpc.h b/webkit/glue/devtools/devtools_mock_rpc.h deleted file mode 100644 index e69de29..0000000 diff --git a/webkit/glue/devtools/devtools_rpc.cc b/webkit/glue/devtools/devtools_rpc.cc deleted file mode 100644 index e69de29..0000000 diff --git a/webkit/glue/devtools/devtools_rpc.h b/webkit/glue/devtools/devtools_rpc.h index f0de3d9..819bd79 100644 --- a/webkit/glue/devtools/devtools_rpc.h +++ b/webkit/glue/devtools/devtools_rpc.h @@ -52,9 +52,7 @@ #include "PlatformString.h" -// TODO(darin): Remove these dependencies on Chromium base/. -#include "base/basictypes.h" -#include "base/compiler_specific.h" +#include namespace WebCore { class String; @@ -74,7 +72,7 @@ template<> struct RpcTypeTrait { typedef bool ApiType; static bool Parse(const WebCore::String& t) { - ALLOW_UNUSED bool success; + bool success; int i = t.toIntStrict(&success); ASSERT(success); return i; @@ -88,7 +86,7 @@ template<> struct RpcTypeTrait { typedef int ApiType; static int Parse(const WebCore::String& t) { - ALLOW_UNUSED bool success; + bool success; int i = t.toIntStrict(&success); ASSERT(success); return i; @@ -206,7 +204,7 @@ if (method_name == #Method) { \ // serializing method calls and ClassDispatch that is capable of dispatching // the serialized message into its delegate. #define DEFINE_RPC_CLASS(Class, STRUCT) \ -class Class {\ +class Class : public Noncopyable {\ public: \ Class() { \ class_name = #Class; \ @@ -219,11 +217,11 @@ class Class {\ TOOLS_RPC_API_METHOD2, \ TOOLS_RPC_API_METHOD3) \ WebCore::String class_name; \ - private: \ - DISALLOW_COPY_AND_ASSIGN(Class); \ }; \ \ -class Class##Stub : public Class, public DevToolsRpc { \ +class Class##Stub \ + : public Class, \ + public DevToolsRpc { \ public: \ explicit Class##Stub(Delegate* delegate) : DevToolsRpc(delegate) {} \ virtual ~Class##Stub() {} \ @@ -233,11 +231,9 @@ class Class##Stub : public Class, public DevToolsRpc { \ TOOLS_RPC_STUB_METHOD1, \ TOOLS_RPC_STUB_METHOD2, \ TOOLS_RPC_STUB_METHOD3) \ - private: \ - DISALLOW_COPY_AND_ASSIGN(Class##Stub); \ }; \ \ -class Class##Dispatch { \ +class Class##Dispatch : public Noncopyable { \ public: \ Class##Dispatch() {} \ virtual ~Class##Dispatch() {} \ @@ -259,8 +255,6 @@ class Class##Dispatch { \ TOOLS_RPC_DISPATCH3) \ return false; \ } \ - private: \ - DISALLOW_COPY_AND_ASSIGN(Class##Dispatch); \ }; /////////////////////////////////////////////////////// @@ -276,8 +270,6 @@ class DevToolsRpc { const WebCore::String& p1 = "", const WebCore::String& p2 = "", const WebCore::String& p3 = "") = 0; - private: - DISALLOW_COPY_AND_ASSIGN(Delegate); }; explicit DevToolsRpc(Delegate* delegate) @@ -286,8 +278,6 @@ class DevToolsRpc { protected: Delegate* delegate_; - private: - DISALLOW_COPY_AND_ASSIGN(DevToolsRpc); }; #endif // WEBKIT_GLUE_DEVTOOLS_DEVTOOLS_RPC_H_ diff --git a/webkit/glue/devtools/devtools_rpc_js.h b/webkit/glue/devtools/devtools_rpc_js.h index a72fde9..2bc9480 100644 --- a/webkit/glue/devtools/devtools_rpc_js.h +++ b/webkit/glue/devtools/devtools_rpc_js.h @@ -8,9 +8,9 @@ #define WEBKIT_GLUE_DEVTOOLS_DEVTOOLS_RPC_JS_H_ // Do not remove this one although it is not used. +#include #include -#include "base/basictypes.h" #include "webkit/api/public/WebFrame.h" #include "webkit/glue/devtools/bound_object.h" #include "webkit/glue/devtools/devtools_rpc.h" @@ -106,7 +106,6 @@ class Js##Class##BoundObj : public Class##Stub { \ param3); \ } \ OwnPtr bound_obj_; \ - DISALLOW_COPY_AND_ASSIGN(Js##Class##BoundObj); \ }; #endif // WEBKIT_GLUE_DEVTOOLS_DEVTOOLS_RPC_JS_H_ diff --git a/webkit/glue/devtools/devtools_rpc_unittest.cc b/webkit/glue/devtools/devtools_rpc_unittest.cc deleted file mode 100644 index e69de29..0000000 diff --git a/webkit/glue/webdevtoolsagent_impl.h b/webkit/glue/webdevtoolsagent_impl.h index 98c4f25..4bb19ff 100644 --- a/webkit/glue/webdevtoolsagent_impl.h +++ b/webkit/glue/webdevtoolsagent_impl.h @@ -119,7 +119,6 @@ class WebDevToolsAgentImpl : public WebKit::WebDevToolsAgent, v8::Persistent utility_context_; OwnPtr devtools_agent_host_; OwnPtr inspector_frontend_script_state_; - DISALLOW_COPY_AND_ASSIGN(WebDevToolsAgentImpl); }; #endif // WEBKIT_GLUE_WEBDEVTOOLSAGENT_IMPL_H_ diff --git a/webkit/glue/webdevtoolsclient.h b/webkit/glue/webdevtoolsclient.h deleted file mode 100644 index 75e4c6c..0000000 --- a/webkit/glue/webdevtoolsclient.h +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef WEBKIT_GLUE_WEBDEVTOOLSCLIENT_H_ -#define WEBKIT_GLUE_WEBDEVTOOLSCLIENT_H_ - -#include "base/basictypes.h" - -class WebDevToolsClientDelegate; - -namespace WebKit { -class WebString; -class WebView; -} - -// WebDevToolsClient represents DevTools client sitting in the Glue. It provides -// direct and delegate Apis to the host. -class WebDevToolsClient { - public: - static WebDevToolsClient* Create( - WebKit::WebView* view, - WebDevToolsClientDelegate* delegate, - const WebKit::WebString& application_locale); - - WebDevToolsClient() {} - virtual ~WebDevToolsClient() {} - - virtual void DispatchMessageFromAgent(const WebKit::WebString& class_name, - const WebKit::WebString& method_name, - const WebKit::WebString& param1, - const WebKit::WebString& param2, - const WebKit::WebString& param3) = 0; - - private: - DISALLOW_COPY_AND_ASSIGN(WebDevToolsClient); -}; - -#endif // WEBKIT_GLUE_WEBDEVTOOLSCLIENT_H_ diff --git a/webkit/glue/webdevtoolsclient_delegate.h b/webkit/glue/webdevtoolsclient_delegate.h deleted file mode 100644 index fab7309..0000000 --- a/webkit/glue/webdevtoolsclient_delegate.h +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef WEBKIT_GLUE_WEBDEVTOOLSCLIENT_DELEGATE_H_ -#define WEBKIT_GLUE_WEBDEVTOOLSCLIENT_DELEGATE_H_ - -#include "base/basictypes.h" - -namespace WebKit { -class WebString; -} - -class WebDevToolsClientDelegate { - public: - WebDevToolsClientDelegate() {} - virtual ~WebDevToolsClientDelegate() {} - - virtual void SendMessageToAgent(const WebKit::WebString& class_name, - const WebKit::WebString& method_name, - const WebKit::WebString& param1, - const WebKit::WebString& param2, - const WebKit::WebString& param3) = 0; - virtual void SendDebuggerCommandToAgent(const WebKit::WebString& command) = 0; - - virtual void ActivateWindow() = 0; - virtual void CloseWindow() = 0; - virtual void DockWindow() = 0; - virtual void UndockWindow() = 0; - virtual void ToggleInspectElementMode(bool enabled) = 0; - - private: - DISALLOW_COPY_AND_ASSIGN(WebDevToolsClientDelegate); -}; - -#endif // WEBKIT_GLUE_WEBDEVTOOLSAGENT_DELEGATE_H_ diff --git a/webkit/glue/webdevtoolsclient_impl.cc b/webkit/glue/webdevtoolsclient_impl.cc deleted file mode 100644 index 374f05d..0000000 --- a/webkit/glue/webdevtoolsclient_impl.cc +++ /dev/null @@ -1,422 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "config.h" - -#include - -#include "Document.h" -#include "DOMWindow.h" -#include "Frame.h" -#include "InspectorBackend.h" -#include "InspectorController.h" -#include "Node.h" -#include "Page.h" -#include "PlatformString.h" -#include "SecurityOrigin.h" -#include "Settings.h" -#include "V8Binding.h" -#include "V8CustomBinding.h" -#include "V8Proxy.h" -#include "V8Utilities.h" -#include -#include -#undef LOG - -#include "base/string_util.h" -#include "webkit/api/public/WebFrame.h" -#include "webkit/api/public/WebScriptSource.h" -#include "webkit/glue/devtools/bound_object.h" -#include "webkit/glue/devtools/debugger_agent.h" -#include "webkit/glue/devtools/devtools_rpc_js.h" -#include "webkit/glue/devtools/tools_agent.h" -#include "webkit/glue/glue_util.h" -#include "webkit/glue/webdevtoolsclient_delegate.h" -#include "webkit/glue/webdevtoolsclient_impl.h" -#include "webkit/glue/webview_impl.h" - -using namespace WebCore; -using WebKit::WebFrame; -using WebKit::WebScriptSource; -using WebKit::WebString; -using WebKit::WebView; - -static v8::Local ToV8String(const String& s) { - if (s.isNull()) - return v8::Local(); - - return v8::String::New(reinterpret_cast(s.characters()), - s.length()); -} - -DEFINE_RPC_JS_BOUND_OBJ(DebuggerAgent, DEBUGGER_AGENT_STRUCT, - DebuggerAgentDelegate, DEBUGGER_AGENT_DELEGATE_STRUCT) -DEFINE_RPC_JS_BOUND_OBJ(ToolsAgent, TOOLS_AGENT_STRUCT, - ToolsAgentDelegate, TOOLS_AGENT_DELEGATE_STRUCT) - -class ToolsAgentNativeDelegateImpl : public ToolsAgentNativeDelegate { - public: - struct ResourceContentRequestData { - String mime_type; - RefPtr frame; - }; - - ToolsAgentNativeDelegateImpl(WebFrameImpl* frame) : frame_(frame) {} - virtual ~ToolsAgentNativeDelegateImpl() {} - - // ToolsAgentNativeDelegate implementation. - virtual void DidGetResourceContent(int request_id, const String& content) { - if (!resource_content_requests_.contains(request_id)) { - NOTREACHED(); - return; - } - ResourceContentRequestData request = - resource_content_requests_.take(request_id); - - InspectorController* ic = frame_->frame()->page()->inspectorController(); - if (request.frame && request.frame->attached()) { - ic->inspectorBackend()->addSourceToFrame(request.mime_type, - content, - request.frame.get()); - } - } - - bool WaitingForResponse(int resource_id, Node* frame) { - if (resource_content_requests_.contains(resource_id)) { - DCHECK(resource_content_requests_.get(resource_id).frame.get() == frame) - << "Only one frame is expected to display given resource"; - return true; - } - return false; - } - - void RequestSent(int resource_id, String mime_type, Node* frame) { - ResourceContentRequestData data; - data.mime_type = mime_type; - data.frame = frame; - DCHECK(!resource_content_requests_.contains(resource_id)); - resource_content_requests_.set(resource_id, data); - } - - private: - WebFrameImpl* frame_; - HashMap resource_content_requests_; - DISALLOW_COPY_AND_ASSIGN(ToolsAgentNativeDelegateImpl); -}; - -// static -WebDevToolsClient* WebDevToolsClient::Create( - WebView* view, - WebDevToolsClientDelegate* delegate, - const WebString& application_locale) { - return new WebDevToolsClientImpl( - static_cast(view), - delegate, - webkit_glue::WebStringToString(application_locale)); -} - -WebDevToolsClientImpl::WebDevToolsClientImpl( - WebViewImpl* web_view_impl, - WebDevToolsClientDelegate* delegate, - const String& application_locale) - : web_view_impl_(web_view_impl), - delegate_(delegate), - application_locale_(application_locale), - loaded_(false) { - WebFrameImpl* frame = web_view_impl_->main_frame(); - v8::HandleScope scope; - v8::Handle frame_context = V8Proxy::context(frame->frame()); - - debugger_agent_obj_.set(new JsDebuggerAgentBoundObj( - this, frame_context, "RemoteDebuggerAgent")); - tools_agent_obj_.set( - new JsToolsAgentBoundObj(this, frame_context, "RemoteToolsAgent")); - - // Debugger commands should be sent using special method. - debugger_command_executor_obj_.set( - new BoundObject(frame_context, this, "RemoteDebuggerCommandExecutor")); - debugger_command_executor_obj_->AddProtoFunction( - "DebuggerCommand", - WebDevToolsClientImpl::JsDebuggerCommand); - debugger_command_executor_obj_->Build(); - - dev_tools_host_.set(new BoundObject(frame_context, this, "DevToolsHost")); - dev_tools_host_->AddProtoFunction( - "reset", - WebDevToolsClientImpl::JsReset); - dev_tools_host_->AddProtoFunction( - "addSourceToFrame", - WebDevToolsClientImpl::JsAddSourceToFrame); - dev_tools_host_->AddProtoFunction( - "addResourceSourceToFrame", - WebDevToolsClientImpl::JsAddResourceSourceToFrame); - dev_tools_host_->AddProtoFunction( - "loaded", - WebDevToolsClientImpl::JsLoaded); - dev_tools_host_->AddProtoFunction( - "search", - WebCore::V8Custom::v8InspectorBackendSearchCallback); - dev_tools_host_->AddProtoFunction( - "getPlatform", - WebDevToolsClientImpl::JsGetPlatform); - dev_tools_host_->AddProtoFunction( - "activateWindow", - WebDevToolsClientImpl::JsActivateWindow); - dev_tools_host_->AddProtoFunction( - "closeWindow", - WebDevToolsClientImpl::JsCloseWindow); - dev_tools_host_->AddProtoFunction( - "dockWindow", - WebDevToolsClientImpl::JsDockWindow); - dev_tools_host_->AddProtoFunction( - "undockWindow", - WebDevToolsClientImpl::JsUndockWindow); - dev_tools_host_->AddProtoFunction( - "toggleInspectElementMode", - WebDevToolsClientImpl::JsToggleInspectElementMode); - dev_tools_host_->AddProtoFunction( - "getApplicationLocale", - WebDevToolsClientImpl::JsGetApplicationLocale); - dev_tools_host_->AddProtoFunction( - "hiddenPanels", - WebDevToolsClientImpl::JsHiddenPanels); - dev_tools_host_->Build(); -} - -WebDevToolsClientImpl::~WebDevToolsClientImpl() { -} - -void WebDevToolsClientImpl::DispatchMessageFromAgent( - const WebString& class_name, - const WebString& method_name, - const WebString& param1, - const WebString& param2, - const WebString& param3) { - if (ToolsAgentNativeDelegateDispatch::Dispatch( - tools_agent_native_delegate_impl_.get(), - webkit_glue::WebStringToString(class_name), - webkit_glue::WebStringToString(method_name), - webkit_glue::WebStringToString(param1), - webkit_glue::WebStringToString(param2), - webkit_glue::WebStringToString(param3))) { - return; - } - - Vector v; - v.append(webkit_glue::WebStringToString(class_name)); - v.append(webkit_glue::WebStringToString(method_name)); - v.append(webkit_glue::WebStringToString(param1)); - v.append(webkit_glue::WebStringToString(param2)); - v.append(webkit_glue::WebStringToString(param3)); - if (!loaded_) { - pending_incoming_messages_.append(v); - return; - } - ExecuteScript(v); -} - -void WebDevToolsClientImpl::AddResourceSourceToFrame(int resource_id, - String mime_type, - Node* frame) { - if (tools_agent_native_delegate_impl_->WaitingForResponse(resource_id, - frame)) { - return; - } - tools_agent_obj_->GetResourceContent(resource_id, resource_id); - tools_agent_native_delegate_impl_->RequestSent(resource_id, mime_type, frame); -} - -void WebDevToolsClientImpl::ExecuteScript(const Vector& v) { - WebFrameImpl* frame = web_view_impl_->main_frame(); - v8::HandleScope scope; - v8::Handle frame_context = V8Proxy::context(frame->frame()); - v8::Context::Scope context_scope(frame_context); - v8::Handle dispatch_function = - frame_context->Global()->Get(v8::String::New("devtools$$dispatch")); - ASSERT(dispatch_function->IsFunction()); - v8::Handle function = v8::Handle::Cast(dispatch_function); - v8::Handle args[] = { - ToV8String(v.at(0)), - ToV8String(v.at(1)), - ToV8String(v.at(2)), - ToV8String(v.at(3)), - ToV8String(v.at(4)), - }; - function->Call(frame_context->Global(), 5, args); -} - -void WebDevToolsClientImpl::SendRpcMessage(const String& class_name, - const String& method_name, - const String& param1, - const String& param2, - const String& param3) { - delegate_->SendMessageToAgent( - webkit_glue::StringToWebString(class_name), - webkit_glue::StringToWebString(method_name), - webkit_glue::StringToWebString(param1), - webkit_glue::StringToWebString(param2), - webkit_glue::StringToWebString(param3)); -} - -// static -v8::Handle WebDevToolsClientImpl::JsReset( - const v8::Arguments& args) { - WebDevToolsClientImpl* client = static_cast( - v8::External::Cast(*args.Data())->Value()); - WebFrameImpl* frame = client->web_view_impl_->main_frame(); - client->tools_agent_native_delegate_impl_.set( - new ToolsAgentNativeDelegateImpl(frame)); - return v8::Undefined(); -} - -// static -v8::Handle WebDevToolsClientImpl::JsAddSourceToFrame( - const v8::Arguments& args) { - if (args.Length() < 2) { - return v8::Undefined(); - } - - v8::TryCatch exception_catcher; - - String mime_type = WebCore::toWebCoreStringWithNullCheck(args[0]); - if (mime_type.isEmpty() || exception_catcher.HasCaught()) { - return v8::Undefined(); - } - String source_string = WebCore::toWebCoreStringWithNullCheck(args[1]); - if (source_string.isEmpty() || exception_catcher.HasCaught()) { - return v8::Undefined(); - } - v8::Handle wrapper = v8::Handle::Cast(args[2]); - Node* node = V8DOMWrapper::convertDOMWrapperToNode(wrapper); - if (!node || !node->attached()) { - return v8::Undefined(); - } - - Page* page = V8Proxy::retrieveFrameForEnteredContext()->page(); - InspectorController* inspectorController = page->inspectorController(); - return WebCore::v8Boolean(inspectorController->inspectorBackend()-> - addSourceToFrame(mime_type, source_string, node)); -} - -// static -v8::Handle WebDevToolsClientImpl::JsAddResourceSourceToFrame( - const v8::Arguments& args) { - int resource_id = static_cast(args[0]->NumberValue()); - String mime_type = WebCore::toWebCoreStringWithNullCheck(args[1]); - if (mime_type.isEmpty()) { - return v8::Undefined(); - } - v8::Handle wrapper = v8::Handle::Cast(args[2]); - Node* node = V8DOMWrapper::convertDOMWrapperToNode(wrapper); - WebDevToolsClientImpl* client = static_cast( - v8::External::Cast(*args.Data())->Value()); - client->AddResourceSourceToFrame(resource_id, mime_type, node); - return v8::Undefined(); -} - -// static -v8::Handle WebDevToolsClientImpl::JsLoaded( - const v8::Arguments& args) { - WebDevToolsClientImpl* client = static_cast( - v8::External::Cast(*args.Data())->Value()); - client->loaded_ = true; - - // Grant the devtools page the ability to have source view iframes. - Page* page = V8Proxy::retrieveFrameForEnteredContext()->page(); - SecurityOrigin* origin = page->mainFrame()->domWindow()->securityOrigin(); - origin->grantUniversalAccess(); - - for (Vector >::iterator it = - client->pending_incoming_messages_.begin(); - it != client->pending_incoming_messages_.end(); - ++it) { - client->ExecuteScript(*it); - } - client->pending_incoming_messages_.clear(); - return v8::Undefined(); -} - -// static -v8::Handle WebDevToolsClientImpl::JsGetPlatform( - const v8::Arguments& args) { -#if defined OS_MACOSX - return v8String("mac-leopard"); -#elif defined OS_LINUX - return v8String("linux"); -#else - return v8String("windows"); -#endif -} - -// static -v8::Handle WebDevToolsClientImpl::JsActivateWindow( - const v8::Arguments& args) { - WebDevToolsClientImpl* client = static_cast( - v8::External::Cast(*args.Data())->Value()); - client->delegate_->ActivateWindow(); - return v8::Undefined(); -} - -// static -v8::Handle WebDevToolsClientImpl::JsCloseWindow( - const v8::Arguments& args) { - WebDevToolsClientImpl* client = static_cast( - v8::External::Cast(*args.Data())->Value()); - client->delegate_->CloseWindow(); - return v8::Undefined(); -} - -// static -v8::Handle WebDevToolsClientImpl::JsDockWindow( - const v8::Arguments& args) { - WebDevToolsClientImpl* client = static_cast( - v8::External::Cast(*args.Data())->Value()); - client->delegate_->DockWindow(); - return v8::Undefined(); -} - -// static -v8::Handle WebDevToolsClientImpl::JsUndockWindow( - const v8::Arguments& args) { - WebDevToolsClientImpl* client = static_cast( - v8::External::Cast(*args.Data())->Value()); - client->delegate_->UndockWindow(); - return v8::Undefined(); -} - -// static -v8::Handle WebDevToolsClientImpl::JsToggleInspectElementMode( - const v8::Arguments& args) { - WebDevToolsClientImpl* client = static_cast( - v8::External::Cast(*args.Data())->Value()); - int enabled = static_cast(args[0]->BooleanValue()); - client->delegate_->ToggleInspectElementMode(enabled); - return v8::Undefined(); -} - -// static -v8::Handle WebDevToolsClientImpl::JsGetApplicationLocale( - const v8::Arguments& args) { - WebDevToolsClientImpl* client = static_cast( - v8::External::Cast(*args.Data())->Value()); - return v8String(client->application_locale_); -} - -// static -v8::Handle WebDevToolsClientImpl::JsHiddenPanels( - const v8::Arguments& args) { - Page* page = V8Proxy::retrieveFrameForEnteredContext()->page(); - return v8String(page->settings()->databasesEnabled() ? "" : "databases"); -} - -// static -v8::Handle WebDevToolsClientImpl::JsDebuggerCommand( - const v8::Arguments& args) { - WebDevToolsClientImpl* client = static_cast( - v8::External::Cast(*args.Data())->Value()); - String command = WebCore::toWebCoreStringWithNullCheck(args[0]); - WebString std_command = webkit_glue::StringToWebString(command); - client->delegate_->SendDebuggerCommandToAgent(std_command); - return v8::Undefined(); -} diff --git a/webkit/glue/webdevtoolsclient_impl.h b/webkit/glue/webdevtoolsclient_impl.h deleted file mode 100644 index 820aae8..0000000 --- a/webkit/glue/webdevtoolsclient_impl.h +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef WEBKIT_GLUE_WEBDEVTOOLSCLIENT_IMPL_H_ -#define WEBKIT_GLUE_WEBDEVTOOLSCLIENT_IMPL_H_ - -#include - -#include -#include -#include - -#include "v8.h" -#include "webkit/glue/devtools/devtools_rpc.h" -#include "webkit/glue/webdevtoolsclient.h" - -namespace WebCore { -class Node; -class Page; -class String; -} - -class BoundObject; -class JsDebuggerAgentBoundObj; -class JsNetAgentBoundObj; -class JsToolsAgentBoundObj; -class ToolsAgentNativeDelegateImpl; -class WebDevToolsClientDelegate; -class WebViewImpl; - -class WebDevToolsClientImpl : public WebDevToolsClient, - public DevToolsRpc::Delegate { - public: - WebDevToolsClientImpl( - WebViewImpl* web_view_impl, - WebDevToolsClientDelegate* delegate, - const String& application_locale); - virtual ~WebDevToolsClientImpl(); - - // DevToolsRpc::Delegate implementation. - virtual void SendRpcMessage(const String& class_name, - const String& method_name, - const String& param1, - const String& param2, - const String& param3); - - // WebDevToolsClient implementation. - virtual void DispatchMessageFromAgent(const WebKit::WebString& class_name, - const WebKit::WebString& method_name, - const WebKit::WebString& param1, - const WebKit::WebString& param2, - const WebKit::WebString& param3); - - private: - void AddResourceSourceToFrame(int resource_id, - String mime_type, - WebCore::Node* frame); - - void ExecuteScript(const Vector& v); - static v8::Handle JsReset(const v8::Arguments& args); - static v8::Handle JsAddSourceToFrame(const v8::Arguments& args); - static v8::Handle JsAddResourceSourceToFrame( - const v8::Arguments& args); - static v8::Handle JsLoaded(const v8::Arguments& args); - static v8::Handle JsGetPlatform(const v8::Arguments& args); - - static v8::Handle JsActivateWindow(const v8::Arguments& args); - static v8::Handle JsCloseWindow(const v8::Arguments& args); - static v8::Handle JsDockWindow(const v8::Arguments& args); - static v8::Handle JsUndockWindow(const v8::Arguments& args); - static v8::Handle JsToggleInspectElementMode( - const v8::Arguments& args); - static v8::Handle JsGetApplicationLocale( - const v8::Arguments& args); - static v8::Handle JsHiddenPanels( - const v8::Arguments& args); - static v8::Handle JsDebuggerCommand( - const v8::Arguments& args); - - WebViewImpl* web_view_impl_; - WebDevToolsClientDelegate* delegate_; - String application_locale_; - OwnPtr debugger_command_executor_obj_; - OwnPtr debugger_agent_obj_; - OwnPtr tools_agent_obj_; - bool loaded_; - Vector > pending_incoming_messages_; - OwnPtr dev_tools_host_; - OwnPtr tools_agent_native_delegate_impl_; - DISALLOW_COPY_AND_ASSIGN(WebDevToolsClientImpl); -}; - -#endif // WEBKIT_GLUE_WEBDEVTOOLSCLIENT_IMPL_H_ diff --git a/webkit/glue/webdevtoolsfrontend_impl.cc b/webkit/glue/webdevtoolsfrontend_impl.cc new file mode 100644 index 0000000..db384fe --- /dev/null +++ b/webkit/glue/webdevtoolsfrontend_impl.cc @@ -0,0 +1,422 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "config.h" + +#include + +#include "Document.h" +#include "DOMWindow.h" +#include "Frame.h" +#include "InspectorBackend.h" +#include "InspectorController.h" +#include "Node.h" +#include "Page.h" +#include "PlatformString.h" +#include "SecurityOrigin.h" +#include "Settings.h" +#include "V8Binding.h" +#include "V8CustomBinding.h" +#include "V8Proxy.h" +#include "V8Utilities.h" +#include +#include +#undef LOG + +#include "webkit/api/public/WebDevToolsFrontendClient.h" +#include "webkit/api/public/WebFrame.h" +#include "webkit/api/public/WebScriptSource.h" +#include "webkit/glue/devtools/bound_object.h" +#include "webkit/glue/devtools/debugger_agent.h" +#include "webkit/glue/devtools/devtools_rpc_js.h" +#include "webkit/glue/devtools/tools_agent.h" +#include "webkit/glue/glue_util.h" +#include "webkit/glue/webdevtoolsfrontend_impl.h" +#include "webkit/glue/webview_impl.h" + +using namespace WebCore; +using WebKit::WebDevToolsFrontend; +using WebKit::WebDevToolsFrontendClient; +using WebKit::WebFrame; +using WebKit::WebScriptSource; +using WebKit::WebString; +using WebKit::WebView; + +static v8::Local ToV8String(const String& s) { + if (s.isNull()) + return v8::Local(); + + return v8::String::New(reinterpret_cast(s.characters()), + s.length()); +} + +DEFINE_RPC_JS_BOUND_OBJ(DebuggerAgent, DEBUGGER_AGENT_STRUCT, + DebuggerAgentDelegate, DEBUGGER_AGENT_DELEGATE_STRUCT) +DEFINE_RPC_JS_BOUND_OBJ(ToolsAgent, TOOLS_AGENT_STRUCT, + ToolsAgentDelegate, TOOLS_AGENT_DELEGATE_STRUCT) + +class ToolsAgentNativeDelegateImpl : public ToolsAgentNativeDelegate { + public: + struct ResourceContentRequestData { + String mime_type; + RefPtr frame; + }; + + ToolsAgentNativeDelegateImpl(WebFrameImpl* frame) : frame_(frame) {} + virtual ~ToolsAgentNativeDelegateImpl() {} + + // ToolsAgentNativeDelegate implementation. + virtual void DidGetResourceContent(int request_id, const String& content) { + if (!resource_content_requests_.contains(request_id)) { + ASSERT_NOT_REACHED(); + return; + } + ResourceContentRequestData request = + resource_content_requests_.take(request_id); + + InspectorController* ic = frame_->frame()->page()->inspectorController(); + if (request.frame && request.frame->attached()) { + ic->inspectorBackend()->addSourceToFrame(request.mime_type, + content, + request.frame.get()); + } + } + + bool WaitingForResponse(int resource_id, Node* frame) { + if (resource_content_requests_.contains(resource_id)) { + ASSERT(resource_content_requests_.get(resource_id).frame.get() == frame); + return true; + } + return false; + } + + void RequestSent(int resource_id, String mime_type, Node* frame) { + ResourceContentRequestData data; + data.mime_type = mime_type; + data.frame = frame; + ASSERT(!resource_content_requests_.contains(resource_id)); + resource_content_requests_.set(resource_id, data); + } + + private: + WebFrameImpl* frame_; + HashMap resource_content_requests_; + DISALLOW_COPY_AND_ASSIGN(ToolsAgentNativeDelegateImpl); +}; + +// static +WebDevToolsFrontend* WebDevToolsFrontend::create( + WebView* view, + WebDevToolsFrontendClient* client, + const WebString& application_locale) { + return new WebDevToolsFrontendImpl( + static_cast(view), + client, + webkit_glue::WebStringToString(application_locale)); +} + +WebDevToolsFrontendImpl::WebDevToolsFrontendImpl( + WebViewImpl* web_view_impl, + WebDevToolsFrontendClient* client, + const String& application_locale) + : web_view_impl_(web_view_impl), + client_(client), + application_locale_(application_locale), + loaded_(false) { + WebFrameImpl* frame = web_view_impl_->main_frame(); + v8::HandleScope scope; + v8::Handle frame_context = V8Proxy::context(frame->frame()); + + debugger_agent_obj_.set(new JsDebuggerAgentBoundObj( + this, frame_context, "RemoteDebuggerAgent")); + tools_agent_obj_.set( + new JsToolsAgentBoundObj(this, frame_context, "RemoteToolsAgent")); + + // Debugger commands should be sent using special method. + debugger_command_executor_obj_.set( + new BoundObject(frame_context, this, "RemoteDebuggerCommandExecutor")); + debugger_command_executor_obj_->AddProtoFunction( + "DebuggerCommand", + WebDevToolsFrontendImpl::JsDebuggerCommand); + debugger_command_executor_obj_->Build(); + + dev_tools_host_.set(new BoundObject(frame_context, this, "DevToolsHost")); + dev_tools_host_->AddProtoFunction( + "reset", + WebDevToolsFrontendImpl::JsReset); + dev_tools_host_->AddProtoFunction( + "addSourceToFrame", + WebDevToolsFrontendImpl::JsAddSourceToFrame); + dev_tools_host_->AddProtoFunction( + "addResourceSourceToFrame", + WebDevToolsFrontendImpl::JsAddResourceSourceToFrame); + dev_tools_host_->AddProtoFunction( + "loaded", + WebDevToolsFrontendImpl::JsLoaded); + dev_tools_host_->AddProtoFunction( + "search", + WebCore::V8Custom::v8InspectorBackendSearchCallback); + dev_tools_host_->AddProtoFunction( + "getPlatform", + WebDevToolsFrontendImpl::JsGetPlatform); + dev_tools_host_->AddProtoFunction( + "activateWindow", + WebDevToolsFrontendImpl::JsActivateWindow); + dev_tools_host_->AddProtoFunction( + "closeWindow", + WebDevToolsFrontendImpl::JsCloseWindow); + dev_tools_host_->AddProtoFunction( + "dockWindow", + WebDevToolsFrontendImpl::JsDockWindow); + dev_tools_host_->AddProtoFunction( + "undockWindow", + WebDevToolsFrontendImpl::JsUndockWindow); + dev_tools_host_->AddProtoFunction( + "toggleInspectElementMode", + WebDevToolsFrontendImpl::JsToggleInspectElementMode); + dev_tools_host_->AddProtoFunction( + "getApplicationLocale", + WebDevToolsFrontendImpl::JsGetApplicationLocale); + dev_tools_host_->AddProtoFunction( + "hiddenPanels", + WebDevToolsFrontendImpl::JsHiddenPanels); + dev_tools_host_->Build(); +} + +WebDevToolsFrontendImpl::~WebDevToolsFrontendImpl() { +} + +void WebDevToolsFrontendImpl::dispatchMessageFromAgent( + const WebString& class_name, + const WebString& method_name, + const WebString& param1, + const WebString& param2, + const WebString& param3) { + if (ToolsAgentNativeDelegateDispatch::Dispatch( + tools_agent_native_delegate_impl_.get(), + webkit_glue::WebStringToString(class_name), + webkit_glue::WebStringToString(method_name), + webkit_glue::WebStringToString(param1), + webkit_glue::WebStringToString(param2), + webkit_glue::WebStringToString(param3))) { + return; + } + + Vector v; + v.append(webkit_glue::WebStringToString(class_name)); + v.append(webkit_glue::WebStringToString(method_name)); + v.append(webkit_glue::WebStringToString(param1)); + v.append(webkit_glue::WebStringToString(param2)); + v.append(webkit_glue::WebStringToString(param3)); + if (!loaded_) { + pending_incoming_messages_.append(v); + return; + } + ExecuteScript(v); +} + +void WebDevToolsFrontendImpl::AddResourceSourceToFrame(int resource_id, + String mime_type, + Node* frame) { + if (tools_agent_native_delegate_impl_->WaitingForResponse(resource_id, + frame)) { + return; + } + tools_agent_obj_->GetResourceContent(resource_id, resource_id); + tools_agent_native_delegate_impl_->RequestSent(resource_id, mime_type, frame); +} + +void WebDevToolsFrontendImpl::ExecuteScript(const Vector& v) { + WebFrameImpl* frame = web_view_impl_->main_frame(); + v8::HandleScope scope; + v8::Handle frame_context = V8Proxy::context(frame->frame()); + v8::Context::Scope context_scope(frame_context); + v8::Handle dispatch_function = + frame_context->Global()->Get(v8::String::New("devtools$$dispatch")); + ASSERT(dispatch_function->IsFunction()); + v8::Handle function = v8::Handle::Cast(dispatch_function); + v8::Handle args[] = { + ToV8String(v.at(0)), + ToV8String(v.at(1)), + ToV8String(v.at(2)), + ToV8String(v.at(3)), + ToV8String(v.at(4)), + }; + function->Call(frame_context->Global(), 5, args); +} + +void WebDevToolsFrontendImpl::SendRpcMessage(const String& class_name, + const String& method_name, + const String& param1, + const String& param2, + const String& param3) { + client_->sendMessageToAgent( + webkit_glue::StringToWebString(class_name), + webkit_glue::StringToWebString(method_name), + webkit_glue::StringToWebString(param1), + webkit_glue::StringToWebString(param2), + webkit_glue::StringToWebString(param3)); +} + +// static +v8::Handle WebDevToolsFrontendImpl::JsReset( + const v8::Arguments& args) { + WebDevToolsFrontendImpl* frontend = static_cast( + v8::External::Cast(*args.Data())->Value()); + WebFrameImpl* frame = frontend->web_view_impl_->main_frame(); + frontend->tools_agent_native_delegate_impl_.set( + new ToolsAgentNativeDelegateImpl(frame)); + return v8::Undefined(); +} + +// static +v8::Handle WebDevToolsFrontendImpl::JsAddSourceToFrame( + const v8::Arguments& args) { + if (args.Length() < 2) { + return v8::Undefined(); + } + + v8::TryCatch exception_catcher; + + String mime_type = WebCore::toWebCoreStringWithNullCheck(args[0]); + if (mime_type.isEmpty() || exception_catcher.HasCaught()) { + return v8::Undefined(); + } + String source_string = WebCore::toWebCoreStringWithNullCheck(args[1]); + if (source_string.isEmpty() || exception_catcher.HasCaught()) { + return v8::Undefined(); + } + v8::Handle wrapper = v8::Handle::Cast(args[2]); + Node* node = V8DOMWrapper::convertDOMWrapperToNode(wrapper); + if (!node || !node->attached()) { + return v8::Undefined(); + } + + Page* page = V8Proxy::retrieveFrameForEnteredContext()->page(); + InspectorController* inspectorController = page->inspectorController(); + return WebCore::v8Boolean(inspectorController->inspectorBackend()-> + addSourceToFrame(mime_type, source_string, node)); +} + +// static +v8::Handle WebDevToolsFrontendImpl::JsAddResourceSourceToFrame( + const v8::Arguments& args) { + int resource_id = static_cast(args[0]->NumberValue()); + String mime_type = WebCore::toWebCoreStringWithNullCheck(args[1]); + if (mime_type.isEmpty()) { + return v8::Undefined(); + } + v8::Handle wrapper = v8::Handle::Cast(args[2]); + Node* node = V8DOMWrapper::convertDOMWrapperToNode(wrapper); + WebDevToolsFrontendImpl* frontend = static_cast( + v8::External::Cast(*args.Data())->Value()); + frontend->AddResourceSourceToFrame(resource_id, mime_type, node); + return v8::Undefined(); +} + +// static +v8::Handle WebDevToolsFrontendImpl::JsLoaded( + const v8::Arguments& args) { + WebDevToolsFrontendImpl* frontend = static_cast( + v8::External::Cast(*args.Data())->Value()); + frontend->loaded_ = true; + + // Grant the devtools page the ability to have source view iframes. + Page* page = V8Proxy::retrieveFrameForEnteredContext()->page(); + SecurityOrigin* origin = page->mainFrame()->domWindow()->securityOrigin(); + origin->grantUniversalAccess(); + + for (Vector >::iterator it = + frontend->pending_incoming_messages_.begin(); + it != frontend->pending_incoming_messages_.end(); + ++it) { + frontend->ExecuteScript(*it); + } + frontend->pending_incoming_messages_.clear(); + return v8::Undefined(); +} + +// static +v8::Handle WebDevToolsFrontendImpl::JsGetPlatform( + const v8::Arguments& args) { +#if defined OS_MACOSX + return v8String("mac-leopard"); +#elif defined OS_LINUX + return v8String("linux"); +#else + return v8String("windows"); +#endif +} + +// static +v8::Handle WebDevToolsFrontendImpl::JsActivateWindow( + const v8::Arguments& args) { + WebDevToolsFrontendImpl* frontend = static_cast( + v8::External::Cast(*args.Data())->Value()); + frontend->client_->activateWindow(); + return v8::Undefined(); +} + +// static +v8::Handle WebDevToolsFrontendImpl::JsCloseWindow( + const v8::Arguments& args) { + WebDevToolsFrontendImpl* frontend = static_cast( + v8::External::Cast(*args.Data())->Value()); + frontend->client_->closeWindow(); + return v8::Undefined(); +} + +// static +v8::Handle WebDevToolsFrontendImpl::JsDockWindow( + const v8::Arguments& args) { + WebDevToolsFrontendImpl* frontend = static_cast( + v8::External::Cast(*args.Data())->Value()); + frontend->client_->dockWindow(); + return v8::Undefined(); +} + +// static +v8::Handle WebDevToolsFrontendImpl::JsUndockWindow( + const v8::Arguments& args) { + WebDevToolsFrontendImpl* frontend = static_cast( + v8::External::Cast(*args.Data())->Value()); + frontend->client_->undockWindow(); + return v8::Undefined(); +} + +// static +v8::Handle WebDevToolsFrontendImpl::JsToggleInspectElementMode( + const v8::Arguments& args) { + WebDevToolsFrontendImpl* frontend = static_cast( + v8::External::Cast(*args.Data())->Value()); + int enabled = static_cast(args[0]->BooleanValue()); + frontend->client_->toggleInspectElementMode(enabled); + return v8::Undefined(); +} + +// static +v8::Handle WebDevToolsFrontendImpl::JsGetApplicationLocale( + const v8::Arguments& args) { + WebDevToolsFrontendImpl* frontend = static_cast( + v8::External::Cast(*args.Data())->Value()); + return v8String(frontend->application_locale_); +} + +// static +v8::Handle WebDevToolsFrontendImpl::JsHiddenPanels( + const v8::Arguments& args) { + Page* page = V8Proxy::retrieveFrameForEnteredContext()->page(); + return v8String(page->settings()->databasesEnabled() ? "" : "databases"); +} + +// static +v8::Handle WebDevToolsFrontendImpl::JsDebuggerCommand( + const v8::Arguments& args) { + WebDevToolsFrontendImpl* frontend = static_cast( + v8::External::Cast(*args.Data())->Value()); + String command = WebCore::toWebCoreStringWithNullCheck(args[0]); + WebString std_command = webkit_glue::StringToWebString(command); + frontend->client_->sendDebuggerCommandToAgent(std_command); + return v8::Undefined(); +} diff --git a/webkit/glue/webdevtoolsfrontend_impl.h b/webkit/glue/webdevtoolsfrontend_impl.h new file mode 100644 index 0000000..5f573a6 --- /dev/null +++ b/webkit/glue/webdevtoolsfrontend_impl.h @@ -0,0 +1,95 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef WEBKIT_GLUE_WEBDEVTOOLSFRONTEND_IMPL_H_ +#define WEBKIT_GLUE_WEBDEVTOOLSFRONTEND_IMPL_H_ + +#include + +#include +#include +#include +#include + +#include "v8.h" +#include "webkit/api/public/WebDevToolsFrontend.h" +#include "webkit/glue/devtools/devtools_rpc.h" + +namespace WebCore { +class Node; +class Page; +class String; +} + +class BoundObject; +class JsDebuggerAgentBoundObj; +class JsNetAgentBoundObj; +class JsToolsAgentBoundObj; +class ToolsAgentNativeDelegateImpl; +class WebDevToolsClientDelegate; +class WebViewImpl; + +class WebDevToolsFrontendImpl : public WebKit::WebDevToolsFrontend, + public DevToolsRpc::Delegate, + public Noncopyable { + public: + WebDevToolsFrontendImpl( + WebViewImpl* web_view_impl, + WebKit::WebDevToolsFrontendClient* client, + const String& application_locale); + virtual ~WebDevToolsFrontendImpl(); + + // DevToolsRpc::Delegate implementation. + virtual void SendRpcMessage(const String& class_name, + const String& method_name, + const String& param1, + const String& param2, + const String& param3); + + // WebDevToolsFrontend implementation. + virtual void dispatchMessageFromAgent(const WebKit::WebString& class_name, + const WebKit::WebString& method_name, + const WebKit::WebString& param1, + const WebKit::WebString& param2, + const WebKit::WebString& param3); + + private: + void AddResourceSourceToFrame(int resource_id, + String mime_type, + WebCore::Node* frame); + + void ExecuteScript(const Vector& v); + static v8::Handle JsReset(const v8::Arguments& args); + static v8::Handle JsAddSourceToFrame(const v8::Arguments& args); + static v8::Handle JsAddResourceSourceToFrame( + const v8::Arguments& args); + static v8::Handle JsLoaded(const v8::Arguments& args); + static v8::Handle JsGetPlatform(const v8::Arguments& args); + + static v8::Handle JsActivateWindow(const v8::Arguments& args); + static v8::Handle JsCloseWindow(const v8::Arguments& args); + static v8::Handle JsDockWindow(const v8::Arguments& args); + static v8::Handle JsUndockWindow(const v8::Arguments& args); + static v8::Handle JsToggleInspectElementMode( + const v8::Arguments& args); + static v8::Handle JsGetApplicationLocale( + const v8::Arguments& args); + static v8::Handle JsHiddenPanels( + const v8::Arguments& args); + static v8::Handle JsDebuggerCommand( + const v8::Arguments& args); + + WebViewImpl* web_view_impl_; + WebKit::WebDevToolsFrontendClient* client_; + String application_locale_; + OwnPtr debugger_command_executor_obj_; + OwnPtr debugger_agent_obj_; + OwnPtr tools_agent_obj_; + bool loaded_; + Vector > pending_incoming_messages_; + OwnPtr dev_tools_host_; + OwnPtr tools_agent_native_delegate_impl_; +}; + +#endif // WEBKIT_GLUE_WEBDEVTOOLSFRONTEND_IMPL_H_ diff --git a/webkit/webkit.gyp b/webkit/webkit.gyp index 7940c20..aa22025 100644 --- a/webkit/webkit.gyp +++ b/webkit/webkit.gyp @@ -98,6 +98,8 @@ 'api/public/WebDataSource.h', 'api/public/WebDevToolsAgent.h', 'api/public/WebDevToolsAgentClient.h', + 'api/public/WebDevToolsFrontend.h', + 'api/public/WebDevToolsFrontendClient.h', 'api/public/WebDragData.h', 'api/public/WebEditingAction.h', 'api/public/WebFileChooserCompletion.h', @@ -632,10 +634,8 @@ 'glue/webcursor_win.cc', 'glue/webdevtoolsagent_impl.cc', 'glue/webdevtoolsagent_impl.h', - 'glue/webdevtoolsclient.h', - 'glue/webdevtoolsclient_delegate.h', - 'glue/webdevtoolsclient_impl.cc', - 'glue/webdevtoolsclient_impl.h', + 'glue/webdevtoolsfrontend_impl.cc', + 'glue/webdevtoolsfrontend_impl.h', 'glue/webdropdata.cc', 'glue/webdropdata_win.cc', 'glue/webdropdata.h', -- cgit v1.1