| 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 "InspectorBackend.h" | 12 #include "InspectorBackend.h" |
| 13 #include "InspectorController.h" | 13 #include "InspectorController.h" |
| 14 #include "Node.h" | 14 #include "Node.h" |
| 15 #include "Page.h" | 15 #include "Page.h" |
| 16 #include "PlatformString.h" | 16 #include "PlatformString.h" |
| 17 #include "SecurityOrigin.h" | 17 #include "SecurityOrigin.h" |
| 18 #include "V8Binding.h" | 18 #include "V8Binding.h" |
| 19 #include "V8CustomBinding.h" | 19 #include "V8CustomBinding.h" |
| 20 #include "V8Proxy.h" | 20 #include "V8Proxy.h" |
| 21 #include "V8Utilities.h" | 21 #include "V8Utilities.h" |
| 22 #include <wtf/OwnPtr.h> | 22 #include <wtf/OwnPtr.h> |
| 23 #include <wtf/Vector.h> | 23 #include <wtf/Vector.h> |
| 24 #undef LOG | 24 #undef LOG |
| 25 | 25 |
| 26 #include "base/string_util.h" | 26 #include "base/string_util.h" |
| 27 #include "base/values.h" | |
| 28 #include "webkit/api/public/WebFrame.h" | 27 #include "webkit/api/public/WebFrame.h" |
| 29 #include "webkit/api/public/WebScriptSource.h" | 28 #include "webkit/api/public/WebScriptSource.h" |
| 30 #include "webkit/glue/devtools/bound_object.h" | 29 #include "webkit/glue/devtools/bound_object.h" |
| 31 #include "webkit/glue/devtools/debugger_agent.h" | 30 #include "webkit/glue/devtools/debugger_agent.h" |
| 32 #include "webkit/glue/devtools/devtools_rpc_js.h" | 31 #include "webkit/glue/devtools/devtools_rpc_js.h" |
| 33 #include "webkit/glue/devtools/tools_agent.h" | 32 #include "webkit/glue/devtools/tools_agent.h" |
| 34 #include "webkit/glue/glue_util.h" | 33 #include "webkit/glue/glue_util.h" |
| 35 #include "webkit/glue/webdevtoolsclient_delegate.h" | 34 #include "webkit/glue/webdevtoolsclient_delegate.h" |
| 36 #include "webkit/glue/webdevtoolsclient_impl.h" | 35 #include "webkit/glue/webdevtoolsclient_impl.h" |
| 37 #include "webkit/glue/webview_impl.h" | 36 #include "webkit/glue/webview_impl.h" |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 WebDevToolsClientImpl::JsGetApplicationLocale); | 193 WebDevToolsClientImpl::JsGetApplicationLocale); |
| 195 dev_tools_host_->Build(); | 194 dev_tools_host_->Build(); |
| 196 } | 195 } |
| 197 | 196 |
| 198 WebDevToolsClientImpl::~WebDevToolsClientImpl() { | 197 WebDevToolsClientImpl::~WebDevToolsClientImpl() { |
| 199 } | 198 } |
| 200 | 199 |
| 201 void WebDevToolsClientImpl::DispatchMessageFromAgent( | 200 void WebDevToolsClientImpl::DispatchMessageFromAgent( |
| 202 const std::string& class_name, | 201 const std::string& class_name, |
| 203 const std::string& method_name, | 202 const std::string& method_name, |
| 204 const std::string& raw_msg) { | 203 const std::string& param1, |
| 204 const std::string& param2, |
| 205 const std::string& param3) { |
| 205 if (ToolsAgentNativeDelegateDispatch::Dispatch( | 206 if (ToolsAgentNativeDelegateDispatch::Dispatch( |
| 206 tools_agent_native_delegate_impl_.get(), | 207 tools_agent_native_delegate_impl_.get(), |
| 207 class_name, | 208 class_name, |
| 208 method_name, | 209 method_name, |
| 209 raw_msg)) { | 210 param1, |
| 211 param2, |
| 212 param3)) { |
| 210 return; | 213 return; |
| 211 } | 214 } |
| 212 | 215 |
| 213 std::string expr = StringPrintf( | 216 Vector<std::string> v; |
| 214 "devtools.dispatch('%s','%s',%s)", | 217 v.append(class_name); |
| 215 class_name.c_str(), | 218 v.append(method_name); |
| 216 method_name.c_str(), | 219 v.append(param1); |
| 217 raw_msg.c_str()); | 220 v.append(param2); |
| 221 v.append(param3); |
| 218 if (!loaded_) { | 222 if (!loaded_) { |
| 219 pending_incoming_messages_.append(expr); | 223 pending_incoming_messages_.append(v); |
| 220 return; | 224 return; |
| 221 } | 225 } |
| 222 ExecuteScript(expr); | 226 ExecuteScript(v); |
| 223 } | 227 } |
| 224 | 228 |
| 225 void WebDevToolsClientImpl::AddResourceSourceToFrame(int resource_id, | 229 void WebDevToolsClientImpl::AddResourceSourceToFrame(int resource_id, |
| 226 String mime_type, | 230 String mime_type, |
| 227 Node* frame) { | 231 Node* frame) { |
| 228 if (tools_agent_native_delegate_impl_->WaitingForResponse(resource_id, | 232 if (tools_agent_native_delegate_impl_->WaitingForResponse(resource_id, |
| 229 frame)) { | 233 frame)) { |
| 230 return; | 234 return; |
| 231 } | 235 } |
| 232 tools_agent_obj_->GetResourceContent(resource_id, resource_id); | 236 tools_agent_obj_->GetResourceContent(resource_id, resource_id); |
| 233 tools_agent_native_delegate_impl_->RequestSent(resource_id, mime_type, frame); | 237 tools_agent_native_delegate_impl_->RequestSent(resource_id, mime_type, frame); |
| 234 } | 238 } |
| 235 | 239 |
| 236 void WebDevToolsClientImpl::ExecuteScript(const std::string& expr) { | 240 void WebDevToolsClientImpl::ExecuteScript(const Vector<std::string>& v) { |
| 237 web_view_impl_->GetMainFrame()->executeScript( | 241 WebFrameImpl* frame = web_view_impl_->main_frame(); |
| 238 WebScriptSource(WebString::fromUTF8(expr))); | 242 v8::HandleScope scope; |
| 243 v8::Handle<v8::Context> frame_context = V8Proxy::context(frame->frame()); |
| 244 v8::Context::Scope context_scope(frame_context); |
| 245 v8::Handle<v8::Value> dispatch_function = |
| 246 frame_context->Global()->Get(v8::String::New("devtools$$dispatch")); |
| 247 ASSERT(dispatch_function->IsFunction()); |
| 248 v8::Handle<v8::Function> function = v8::Handle<v8::Function>::Cast(dispatch_fu
nction); |
| 249 v8::Handle<v8::Value> args[] = { |
| 250 v8::String::New(v.at(0).c_str()), |
| 251 v8::String::New(v.at(1).c_str()), |
| 252 v8::String::New(v.at(2).c_str()), |
| 253 v8::String::New(v.at(3).c_str()), |
| 254 v8::String::New(v.at(4).c_str()) |
| 255 }; |
| 256 function->Call(frame_context->Global(), 5, args); |
| 239 } | 257 } |
| 240 | 258 |
| 241 | |
| 242 void WebDevToolsClientImpl::SendRpcMessage(const std::string& class_name, | 259 void WebDevToolsClientImpl::SendRpcMessage(const std::string& class_name, |
| 243 const std::string& method_name, | 260 const std::string& method_name, |
| 244 const std::string& raw_msg) { | 261 const std::string& param1, |
| 245 delegate_->SendMessageToAgent(class_name, method_name, raw_msg); | 262 const std::string& param2, |
| 263 const std::string& param3) { |
| 264 delegate_->SendMessageToAgent(class_name, method_name, param1, param2, |
| 265 param3); |
| 246 } | 266 } |
| 247 | 267 |
| 248 // static | 268 // static |
| 249 v8::Handle<v8::Value> WebDevToolsClientImpl::JsReset( | 269 v8::Handle<v8::Value> WebDevToolsClientImpl::JsReset( |
| 250 const v8::Arguments& args) { | 270 const v8::Arguments& args) { |
| 251 WebDevToolsClientImpl* client = static_cast<WebDevToolsClientImpl*>( | 271 WebDevToolsClientImpl* client = static_cast<WebDevToolsClientImpl*>( |
| 252 v8::External::Cast(*args.Data())->Value()); | 272 v8::External::Cast(*args.Data())->Value()); |
| 253 WebFrameImpl* frame = client->web_view_impl_->main_frame(); | 273 WebFrameImpl* frame = client->web_view_impl_->main_frame(); |
| 254 client->tools_agent_native_delegate_impl_.set( | 274 client->tools_agent_native_delegate_impl_.set( |
| 255 new ToolsAgentNativeDelegateImpl(frame)); | 275 new ToolsAgentNativeDelegateImpl(frame)); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 const v8::Arguments& args) { | 326 const v8::Arguments& args) { |
| 307 WebDevToolsClientImpl* client = static_cast<WebDevToolsClientImpl*>( | 327 WebDevToolsClientImpl* client = static_cast<WebDevToolsClientImpl*>( |
| 308 v8::External::Cast(*args.Data())->Value()); | 328 v8::External::Cast(*args.Data())->Value()); |
| 309 client->loaded_ = true; | 329 client->loaded_ = true; |
| 310 | 330 |
| 311 // Grant the devtools page the ability to have source view iframes. | 331 // Grant the devtools page the ability to have source view iframes. |
| 312 Page* page = V8Proxy::retrieveFrameForEnteredContext()->page(); | 332 Page* page = V8Proxy::retrieveFrameForEnteredContext()->page(); |
| 313 SecurityOrigin* origin = page->mainFrame()->domWindow()->securityOrigin(); | 333 SecurityOrigin* origin = page->mainFrame()->domWindow()->securityOrigin(); |
| 314 origin->grantUniversalAccess(); | 334 origin->grantUniversalAccess(); |
| 315 | 335 |
| 316 for (Vector<std::string>::iterator it = | 336 for (Vector<Vector<std::string> >::iterator it = |
| 317 client->pending_incoming_messages_.begin(); | 337 client->pending_incoming_messages_.begin(); |
| 318 it != client->pending_incoming_messages_.end(); | 338 it != client->pending_incoming_messages_.end(); |
| 319 ++it) { | 339 ++it) { |
| 320 client->ExecuteScript(*it); | 340 client->ExecuteScript(*it); |
| 321 } | 341 } |
| 322 client->pending_incoming_messages_.clear(); | 342 client->pending_incoming_messages_.clear(); |
| 323 return v8::Undefined(); | 343 return v8::Undefined(); |
| 324 } | 344 } |
| 325 | 345 |
| 326 // static | 346 // static |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 return v8::Undefined(); | 401 return v8::Undefined(); |
| 382 } | 402 } |
| 383 | 403 |
| 384 // static | 404 // static |
| 385 v8::Handle<v8::Value> WebDevToolsClientImpl::JsGetApplicationLocale( | 405 v8::Handle<v8::Value> WebDevToolsClientImpl::JsGetApplicationLocale( |
| 386 const v8::Arguments& args) { | 406 const v8::Arguments& args) { |
| 387 WebDevToolsClientImpl* client = static_cast<WebDevToolsClientImpl*>( | 407 WebDevToolsClientImpl* client = static_cast<WebDevToolsClientImpl*>( |
| 388 v8::External::Cast(*args.Data())->Value()); | 408 v8::External::Cast(*args.Data())->Value()); |
| 389 return v8String(client->application_locale_); | 409 return v8String(client->application_locale_); |
| 390 } | 410 } |
| OLD | NEW |