Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(807)

Side by Side Diff: content/shell/browser/shell_devtools_frontend.cc

Issue 784513002: DevTools: speed up DevToolsUIBindings::DispatchProtocolMessage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments addressed Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/devtools/devtools_ui_bindings.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "content/shell/browser/shell_devtools_frontend.h" 5 #include "content/shell/browser/shell_devtools_frontend.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/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "content/public/browser/devtools_http_handler.h" 13 #include "content/public/browser/devtools_http_handler.h"
14 #include "content/public/browser/render_frame_host.h" 14 #include "content/public/browser/render_frame_host.h"
15 #include "content/public/browser/render_view_host.h" 15 #include "content/public/browser/render_view_host.h"
16 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
17 #include "content/public/common/content_client.h" 17 #include "content/public/common/content_client.h"
18 #include "content/shell/browser/shell.h" 18 #include "content/shell/browser/shell.h"
19 #include "content/shell/browser/shell_browser_context.h" 19 #include "content/shell/browser/shell_browser_context.h"
20 #include "content/shell/browser/shell_browser_main_parts.h" 20 #include "content/shell/browser/shell_browser_main_parts.h"
21 #include "content/shell/browser/shell_content_browser_client.h" 21 #include "content/shell/browser/shell_content_browser_client.h"
22 #include "content/shell/browser/shell_devtools_manager_delegate.h" 22 #include "content/shell/browser/shell_devtools_manager_delegate.h"
23 #include "content/shell/browser/webkit_test_controller.h" 23 #include "content/shell/browser/webkit_test_controller.h"
24 #include "content/shell/common/shell_switches.h" 24 #include "content/shell/common/shell_switches.h"
25 #include "net/base/filename_util.h" 25 #include "net/base/filename_util.h"
26 26
27 namespace content { 27 namespace content {
28 28
29 // This constant should be in sync with
30 // the constant at devtools_ui_bindings.cc.
31 const size_t kMaxMessageChunkSize = IPC::Channel::kMaximumMessageSize / 4;
32
29 // static 33 // static
30 ShellDevToolsFrontend* ShellDevToolsFrontend::Show( 34 ShellDevToolsFrontend* ShellDevToolsFrontend::Show(
31 WebContents* inspected_contents) { 35 WebContents* inspected_contents) {
32 scoped_refptr<DevToolsAgentHost> agent( 36 scoped_refptr<DevToolsAgentHost> agent(
33 DevToolsAgentHost::GetOrCreateFor(inspected_contents)); 37 DevToolsAgentHost::GetOrCreateFor(inspected_contents));
34 Shell* shell = Shell::CreateNewWindow(inspected_contents->GetBrowserContext(), 38 Shell* shell = Shell::CreateNewWindow(inspected_contents->GetBrowserContext(),
35 GURL(), 39 GURL(),
36 NULL, 40 NULL,
37 MSG_ROUTING_NONE, 41 MSG_ROUTING_NONE,
38 gfx::Size()); 42 gfx::Size());
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 } 126 }
123 } 127 }
124 128
125 void ShellDevToolsFrontend::HandleMessageFromDevToolsFrontendToBackend( 129 void ShellDevToolsFrontend::HandleMessageFromDevToolsFrontendToBackend(
126 const std::string& message) { 130 const std::string& message) {
127 agent_host_->DispatchProtocolMessage(message); 131 agent_host_->DispatchProtocolMessage(message);
128 } 132 }
129 133
130 void ShellDevToolsFrontend::DispatchProtocolMessage( 134 void ShellDevToolsFrontend::DispatchProtocolMessage(
131 DevToolsAgentHost* agent_host, const std::string& message) { 135 DevToolsAgentHost* agent_host, const std::string& message) {
132 base::StringValue message_value(message); 136
133 std::string param; 137 if (message.length() < kMaxMessageChunkSize) {
134 base::JSONWriter::Write(&message_value, &param); 138 base::string16 javascript = base::UTF8ToUTF16(
135 std::string code = "DevToolsAPI.dispatchMessage(" + param + ");"; 139 "DevToolsAPI.dispatchMessage(" + message + ");");
136 base::string16 javascript = base::UTF8ToUTF16(code); 140 web_contents()->GetMainFrame()->ExecuteJavaScript(javascript);
137 web_contents()->GetMainFrame()->ExecuteJavaScript(javascript); 141 return;
142 }
143
144 base::FundamentalValue total_size(static_cast<int>(message.length()));
145 for (size_t pos = 0; pos < message.length(); pos += kMaxMessageChunkSize) {
146 base::StringValue message_value(message.substr(pos, kMaxMessageChunkSize));
147 std::string param;
148 base::JSONWriter::Write(&message_value, &param);
149 std::string code = "DevToolsAPI.dispatchMessageChunk(" + param + ");";
150 base::string16 javascript = base::UTF8ToUTF16(code);
151 web_contents()->GetMainFrame()->ExecuteJavaScript(javascript);
152 }
138 } 153 }
139 154
140 void ShellDevToolsFrontend::AgentHostClosed( 155 void ShellDevToolsFrontend::AgentHostClosed(
141 DevToolsAgentHost* agent_host, bool replaced) { 156 DevToolsAgentHost* agent_host, bool replaced) {
142 frontend_shell_->Close(); 157 frontend_shell_->Close();
143 } 158 }
144 159
145 } // namespace content 160 } // namespace content
OLDNEW
« no previous file with comments | « chrome/browser/devtools/devtools_ui_bindings.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698