| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "Document.h" | 9 #include "Document.h" |
| 10 #include "DOMWindow.h" | 10 #include "DOMWindow.h" |
| 11 #include "Frame.h" | 11 #include "Frame.h" |
| 12 #include "InspectorController.h" | 12 #include "InspectorController.h" |
| 13 #include "Node.h" | 13 #include "Node.h" |
| 14 #include "Page.h" | 14 #include "Page.h" |
| 15 #include "PlatformString.h" | 15 #include "PlatformString.h" |
| 16 #include "SecurityOrigin.h" | 16 #include "SecurityOrigin.h" |
| 17 #include <wtf/OwnPtr.h> | 17 #include <wtf/OwnPtr.h> |
| 18 #include <wtf/Vector.h> | 18 #include <wtf/Vector.h> |
| 19 #undef LOG | 19 #undef LOG |
| 20 | 20 |
| 21 #include "V8Binding.h" | 21 #include "V8Binding.h" |
| 22 #include "v8_custom.h" | 22 #include "v8_custom.h" |
| 23 #include "v8_proxy.h" | 23 #include "v8_proxy.h" |
| 24 #include "v8_utility.h" | 24 #include "v8_utility.h" |
| 25 #include "base/string_util.h" | 25 #include "base/string_util.h" |
| 26 #include "base/values.h" | 26 #include "base/values.h" |
| 27 #include "webkit/api/public/WebScriptSource.h" | 27 #include "webkit/api/public/WebScriptSource.h" |
| 28 #include "webkit/glue/devtools/bound_object.h" |
| 28 #include "webkit/glue/devtools/debugger_agent.h" | 29 #include "webkit/glue/devtools/debugger_agent.h" |
| 29 #include "webkit/glue/devtools/devtools_rpc_js.h" | 30 #include "webkit/glue/devtools/devtools_rpc_js.h" |
| 30 #include "webkit/glue/devtools/dom_agent.h" | 31 #include "webkit/glue/devtools/dom_agent.h" |
| 31 #include "webkit/glue/devtools/net_agent.h" | |
| 32 #include "webkit/glue/devtools/tools_agent.h" | 32 #include "webkit/glue/devtools/tools_agent.h" |
| 33 #include "webkit/glue/glue_util.h" | 33 #include "webkit/glue/glue_util.h" |
| 34 #include "webkit/glue/webdevtoolsclient_delegate.h" | 34 #include "webkit/glue/webdevtoolsclient_delegate.h" |
| 35 #include "webkit/glue/webdevtoolsclient_impl.h" | 35 #include "webkit/glue/webdevtoolsclient_impl.h" |
| 36 #include "webkit/glue/webframe.h" | 36 #include "webkit/glue/webframe.h" |
| 37 #include "webkit/glue/webview_impl.h" | 37 #include "webkit/glue/webview_impl.h" |
| 38 | 38 |
| 39 using namespace WebCore; | 39 using namespace WebCore; |
| 40 using WebKit::WebScriptSource; | 40 using WebKit::WebScriptSource; |
| 41 using WebKit::WebString; | 41 using WebKit::WebString; |
| 42 | 42 |
| 43 DEFINE_RPC_JS_BOUND_OBJ(DebuggerAgent, DEBUGGER_AGENT_STRUCT, | 43 DEFINE_RPC_JS_BOUND_OBJ(DebuggerAgent, DEBUGGER_AGENT_STRUCT, |
| 44 DebuggerAgentDelegate, DEBUGGER_AGENT_DELEGATE_STRUCT) | 44 DebuggerAgentDelegate, DEBUGGER_AGENT_DELEGATE_STRUCT) |
| 45 DEFINE_RPC_JS_BOUND_OBJ(DomAgent, DOM_AGENT_STRUCT, | 45 DEFINE_RPC_JS_BOUND_OBJ(DomAgent, DOM_AGENT_STRUCT, |
| 46 DomAgentDelegate, DOM_AGENT_DELEGATE_STRUCT) | 46 DomAgentDelegate, DOM_AGENT_DELEGATE_STRUCT) |
| 47 DEFINE_RPC_JS_BOUND_OBJ(NetAgent, NET_AGENT_STRUCT, | |
| 48 NetAgentDelegate, NET_AGENT_DELEGATE_STRUCT) | |
| 49 DEFINE_RPC_JS_BOUND_OBJ(ToolsAgent, TOOLS_AGENT_STRUCT, | 47 DEFINE_RPC_JS_BOUND_OBJ(ToolsAgent, TOOLS_AGENT_STRUCT, |
| 50 ToolsAgentDelegate, TOOLS_AGENT_DELEGATE_STRUCT) | 48 ToolsAgentDelegate, TOOLS_AGENT_DELEGATE_STRUCT) |
| 51 | 49 |
| 52 namespace { | 50 namespace { |
| 53 | 51 |
| 54 class RemoteDebuggerCommandExecutor : public CppBoundClass { | 52 class RemoteDebuggerCommandExecutor : public CppBoundClass { |
| 55 public: | 53 public: |
| 56 RemoteDebuggerCommandExecutor( | 54 RemoteDebuggerCommandExecutor( |
| 57 WebDevToolsClientDelegate* delegate, | 55 WebDevToolsClientDelegate* delegate, |
| 58 WebFrame* frame, | 56 WebFrame* frame, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 delegate_(delegate), | 90 delegate_(delegate), |
| 93 loaded_(false) { | 91 loaded_(false) { |
| 94 WebFrameImpl* frame = web_view_impl_->main_frame(); | 92 WebFrameImpl* frame = web_view_impl_->main_frame(); |
| 95 | 93 |
| 96 // Debugger commands should be sent using special method. | 94 // Debugger commands should be sent using special method. |
| 97 debugger_command_executor_obj_.set(new RemoteDebuggerCommandExecutor( | 95 debugger_command_executor_obj_.set(new RemoteDebuggerCommandExecutor( |
| 98 delegate, frame, L"RemoteDebuggerCommandExecutor")); | 96 delegate, frame, L"RemoteDebuggerCommandExecutor")); |
| 99 debugger_agent_obj_.set(new JsDebuggerAgentBoundObj( | 97 debugger_agent_obj_.set(new JsDebuggerAgentBoundObj( |
| 100 this, frame, L"RemoteDebuggerAgent")); | 98 this, frame, L"RemoteDebuggerAgent")); |
| 101 dom_agent_obj_.set(new JsDomAgentBoundObj(this, frame, L"RemoteDomAgent")); | 99 dom_agent_obj_.set(new JsDomAgentBoundObj(this, frame, L"RemoteDomAgent")); |
| 102 net_agent_obj_.set(new JsNetAgentBoundObj(this, frame, L"RemoteNetAgent")); | |
| 103 tools_agent_obj_.set( | 100 tools_agent_obj_.set( |
| 104 new JsToolsAgentBoundObj(this, frame, L"RemoteToolsAgent")); | 101 new JsToolsAgentBoundObj(this, frame, L"RemoteToolsAgent")); |
| 105 WebDevToolsClientImpl::InitBoundObject(); | |
| 106 | 102 |
| 107 v8::HandleScope scope; | 103 v8::HandleScope scope; |
| 108 v8::Handle<v8::Context> frame_context = V8Proxy::GetContext(frame->frame()); | 104 v8::Handle<v8::Context> frame_context = V8Proxy::GetContext(frame->frame()); |
| 109 v8::Context::Scope frame_scope(frame_context); | 105 dev_tools_host_.set(new BoundObject(frame_context, this, "DevToolsHost")); |
| 110 | 106 dev_tools_host_->AddProtoFunction( |
| 111 v8::Local<v8::Function> constructor = host_template_->GetFunction(); | 107 "addSourceToFrame", |
| 112 v8::Local<v8::Object> host_obj = SafeAllocation::NewInstance(constructor); | 108 WebDevToolsClientImpl::JsAddSourceToFrame); |
| 113 | 109 dev_tools_host_->AddProtoFunction( |
| 114 v8::Handle<v8::Object> global = frame_context->Global(); | 110 "loaded", |
| 115 global->Set(v8::String::New("DevToolsHost"), host_obj); | 111 WebDevToolsClientImpl::JsLoaded); |
| 112 dev_tools_host_->AddProtoFunction( |
| 113 "search", |
| 114 WebCore::V8Custom::v8InspectorControllerSearchCallback); |
| 115 dev_tools_host_->AddProtoFunction( |
| 116 "activateWindow", |
| 117 WebDevToolsClientImpl::JsActivateWindow); |
| 118 dev_tools_host_->Build(); |
| 116 } | 119 } |
| 117 | 120 |
| 118 WebDevToolsClientImpl::~WebDevToolsClientImpl() { | 121 WebDevToolsClientImpl::~WebDevToolsClientImpl() { |
| 119 host_template_.Dispose(); | |
| 120 v8_this_.Dispose(); | |
| 121 } | |
| 122 | |
| 123 void WebDevToolsClientImpl::InitBoundObject() { | |
| 124 v8::HandleScope scope; | |
| 125 v8::Local<v8::FunctionTemplate> local_template = | |
| 126 v8::FunctionTemplate::New(V8Proxy::CheckNewLegal); | |
| 127 host_template_ = v8::Persistent<v8::FunctionTemplate>::New(local_template); | |
| 128 v8_this_ = v8::Persistent<v8::External>::New(v8::External::New(this)); | |
| 129 | |
| 130 InitProtoFunction("addSourceToFrame", | |
| 131 WebDevToolsClientImpl::JsAddSourceToFrame); | |
| 132 InitProtoFunction("loaded", | |
| 133 WebDevToolsClientImpl::JsLoaded); | |
| 134 InitProtoFunction("search", | |
| 135 WebCore::V8Custom::v8InspectorControllerSearchCallback); | |
| 136 InitProtoFunction("activateWindow", | |
| 137 WebDevToolsClientImpl::JsActivateWindow); | |
| 138 host_template_->SetClassName(v8::String::New("DevToolsHost")); | |
| 139 } | |
| 140 | |
| 141 void WebDevToolsClientImpl::InitProtoFunction( | |
| 142 const char* name, | |
| 143 v8::InvocationCallback callback) { | |
| 144 v8::Local<v8::Signature> signature = v8::Signature::New(host_template_); | |
| 145 v8::Local<v8::ObjectTemplate> proto = host_template_->PrototypeTemplate(); | |
| 146 proto->Set( | |
| 147 v8::String::New(name), | |
| 148 v8::FunctionTemplate::New( | |
| 149 callback, | |
| 150 v8_this_, | |
| 151 signature), | |
| 152 static_cast<v8::PropertyAttribute>(v8::DontDelete)); | |
| 153 } | 122 } |
| 154 | 123 |
| 155 void WebDevToolsClientImpl::DispatchMessageFromAgent( | 124 void WebDevToolsClientImpl::DispatchMessageFromAgent( |
| 156 const std::string& raw_msg) { | 125 const std::string& raw_msg) { |
| 157 if (!loaded_) { | 126 if (!loaded_) { |
| 158 pending_incoming_messages_.append(raw_msg); | 127 pending_incoming_messages_.append(raw_msg); |
| 159 return; | 128 return; |
| 160 } | 129 } |
| 161 std::string expr = StringPrintf("devtools.dispatch(%s)", raw_msg.c_str()); | 130 std::string expr = StringPrintf("devtools.dispatch(%s)", raw_msg.c_str()); |
| 162 web_view_impl_->GetMainFrame()->ExecuteScript( | 131 web_view_impl_->GetMainFrame()->ExecuteScript( |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 } | 187 } |
| 219 | 188 |
| 220 // static | 189 // static |
| 221 v8::Handle<v8::Value> WebDevToolsClientImpl::JsActivateWindow( | 190 v8::Handle<v8::Value> WebDevToolsClientImpl::JsActivateWindow( |
| 222 const v8::Arguments& args) { | 191 const v8::Arguments& args) { |
| 223 WebDevToolsClientImpl* client = static_cast<WebDevToolsClientImpl*>( | 192 WebDevToolsClientImpl* client = static_cast<WebDevToolsClientImpl*>( |
| 224 v8::External::Cast(*args.Data())->Value()); | 193 v8::External::Cast(*args.Data())->Value()); |
| 225 client->delegate_->ActivateWindow(); | 194 client->delegate_->ActivateWindow(); |
| 226 return v8::Undefined(); | 195 return v8::Undefined(); |
| 227 } | 196 } |
| OLD | NEW |