| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/devtools/devtools_ui_bindings.h" | 5 #include "chrome/browser/devtools/devtools_ui_bindings.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 static const char kFrontendHostId[] = "id"; | 63 static const char kFrontendHostId[] = "id"; |
| 64 static const char kFrontendHostMethod[] = "method"; | 64 static const char kFrontendHostMethod[] = "method"; |
| 65 static const char kFrontendHostParams[] = "params"; | 65 static const char kFrontendHostParams[] = "params"; |
| 66 static const char kTitleFormat[] = "Developer Tools - %s"; | 66 static const char kTitleFormat[] = "Developer Tools - %s"; |
| 67 | 67 |
| 68 static const char kDevToolsActionTakenHistogram[] = "DevTools.ActionTaken"; | 68 static const char kDevToolsActionTakenHistogram[] = "DevTools.ActionTaken"; |
| 69 static const int kDevToolsActionTakenBoundary = 100; | 69 static const int kDevToolsActionTakenBoundary = 100; |
| 70 static const char kDevToolsPanelShownHistogram[] = "DevTools.PanelShown"; | 70 static const char kDevToolsPanelShownHistogram[] = "DevTools.PanelShown"; |
| 71 static const int kDevToolsPanelShownBoundary = 20; | 71 static const int kDevToolsPanelShownBoundary = 20; |
| 72 | 72 |
| 73 // This constant should be in sync with |
| 74 // the constant at shell_devtools_frontend.cc. |
| 73 const size_t kMaxMessageChunkSize = IPC::Channel::kMaximumMessageSize / 4; | 75 const size_t kMaxMessageChunkSize = IPC::Channel::kMaximumMessageSize / 4; |
| 74 | 76 |
| 75 typedef std::vector<DevToolsUIBindings*> DevToolsUIBindingsList; | 77 typedef std::vector<DevToolsUIBindings*> DevToolsUIBindingsList; |
| 76 base::LazyInstance<DevToolsUIBindingsList>::Leaky g_instances = | 78 base::LazyInstance<DevToolsUIBindingsList>::Leaky g_instances = |
| 77 LAZY_INSTANCE_INITIALIZER; | 79 LAZY_INSTANCE_INITIALIZER; |
| 78 | 80 |
| 79 std::string SkColorToRGBAString(SkColor color) { | 81 std::string SkColorToRGBAString(SkColor color) { |
| 80 // We avoid StringPrintf because it will use locale specific formatters for | 82 // We avoid StringPrintf because it will use locale specific formatters for |
| 81 // the double (e.g. ',' instead of '.' in German). | 83 // the double (e.g. ',' instead of '.' in German). |
| 82 return "rgba(" + base::IntToString(SkColorGetR(color)) + "," + | 84 return "rgba(" + base::IntToString(SkColorGetR(color)) + "," + |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 if (agent_host_.get()) | 444 if (agent_host_.get()) |
| 443 agent_host_->DispatchProtocolMessage(message); | 445 agent_host_->DispatchProtocolMessage(message); |
| 444 } | 446 } |
| 445 | 447 |
| 446 // content::DevToolsAgentHostClient implementation -------------------------- | 448 // content::DevToolsAgentHostClient implementation -------------------------- |
| 447 void DevToolsUIBindings::DispatchProtocolMessage( | 449 void DevToolsUIBindings::DispatchProtocolMessage( |
| 448 content::DevToolsAgentHost* agent_host, const std::string& message) { | 450 content::DevToolsAgentHost* agent_host, const std::string& message) { |
| 449 DCHECK(agent_host == agent_host_.get()); | 451 DCHECK(agent_host == agent_host_.get()); |
| 450 | 452 |
| 451 if (message.length() < kMaxMessageChunkSize) { | 453 if (message.length() < kMaxMessageChunkSize) { |
| 452 base::StringValue message_value(message); | 454 base::string16 javascript = base::UTF8ToUTF16( |
| 453 CallClientFunction("DevToolsAPI.dispatchMessage", | 455 "DevToolsAPI.dispatchMessage(" + message + ");"); |
| 454 &message_value, NULL, NULL); | 456 web_contents_->GetMainFrame()->ExecuteJavaScript(javascript); |
| 455 return; | 457 return; |
| 456 } | 458 } |
| 457 | 459 |
| 458 base::FundamentalValue total_size(static_cast<int>(message.length())); | 460 base::FundamentalValue total_size(static_cast<int>(message.length())); |
| 459 for (size_t pos = 0; pos < message.length(); pos += kMaxMessageChunkSize) { | 461 for (size_t pos = 0; pos < message.length(); pos += kMaxMessageChunkSize) { |
| 460 base::StringValue message_value(message.substr(pos, kMaxMessageChunkSize)); | 462 base::StringValue message_value(message.substr(pos, kMaxMessageChunkSize)); |
| 461 CallClientFunction("DevToolsAPI.dispatchMessageChunk", | 463 CallClientFunction("DevToolsAPI.dispatchMessageChunk", |
| 462 &message_value, pos ? NULL : &total_size, NULL); | 464 &message_value, pos ? NULL : &total_size, NULL); |
| 463 } | 465 } |
| 464 } | 466 } |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 901 if (frontend_loaded_) | 903 if (frontend_loaded_) |
| 902 return; | 904 return; |
| 903 frontend_loaded_ = true; | 905 frontend_loaded_ = true; |
| 904 | 906 |
| 905 // Call delegate first - it seeds importants bit of information. | 907 // Call delegate first - it seeds importants bit of information. |
| 906 delegate_->OnLoadCompleted(); | 908 delegate_->OnLoadCompleted(); |
| 907 | 909 |
| 908 UpdateTheme(); | 910 UpdateTheme(); |
| 909 AddDevToolsExtensionsToClient(); | 911 AddDevToolsExtensionsToClient(); |
| 910 } | 912 } |
| OLD | NEW |