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

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

Issue 2295623002: DevTools: simplify http handler delegate as it is moving into content. (Closed)
Patch Set: lcean Created 4 years, 3 months 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
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
11 #include "base/json/json_writer.h" 11 #include "base/json/json_writer.h"
12 #include "base/json/string_escape.h" 12 #include "base/json/string_escape.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
16 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
17 #include "base/values.h" 17 #include "base/values.h"
18 #include "components/devtools_http_handler/devtools_http_handler.h" 18 #include "components/devtools_http_handler/devtools_http_handler.h"
19 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
20 #include "content/public/browser/render_frame_host.h" 20 #include "content/public/browser/render_frame_host.h"
21 #include "content/public/browser/render_view_host.h" 21 #include "content/public/browser/render_view_host.h"
22 #include "content/public/browser/storage_partition.h" 22 #include "content/public/browser/storage_partition.h"
23 #include "content/public/browser/web_contents.h" 23 #include "content/public/browser/web_contents.h"
24 #include "content/public/common/content_client.h" 24 #include "content/public/common/content_client.h"
25 #include "content/public/common/content_switches.h"
25 #include "content/shell/browser/shell.h" 26 #include "content/shell/browser/shell.h"
26 #include "content/shell/browser/shell_browser_context.h" 27 #include "content/shell/browser/shell_browser_context.h"
27 #include "content/shell/browser/shell_browser_main_parts.h" 28 #include "content/shell/browser/shell_browser_main_parts.h"
28 #include "content/shell/browser/shell_content_browser_client.h" 29 #include "content/shell/browser/shell_content_browser_client.h"
29 #include "content/shell/browser/shell_devtools_manager_delegate.h" 30 #include "content/shell/browser/shell_devtools_manager_delegate.h"
30 #include "content/shell/common/shell_switches.h" 31 #include "content/shell/common/shell_switches.h"
31 #include "net/base/io_buffer.h" 32 #include "net/base/io_buffer.h"
32 #include "net/base/net_errors.h" 33 #include "net/base/net_errors.h"
33 #include "net/http/http_response_headers.h" 34 #include "net/http/http_response_headers.h"
34 #include "net/url_request/url_fetcher.h" 35 #include "net/url_request/url_fetcher.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 base::Bind(&ShellDevToolsFrontend::CallClientFunction, 91 base::Bind(&ShellDevToolsFrontend::CallClientFunction,
91 shell_devtools_, "DevToolsAPI.streamWrite", 92 shell_devtools_, "DevToolsAPI.streamWrite",
92 base::Owned(id), base::Owned(chunkValue), nullptr)); 93 base::Owned(id), base::Owned(chunkValue), nullptr));
93 return num_bytes; 94 return num_bytes;
94 } 95 }
95 96
96 int ResponseWriter::Finish(const net::CompletionCallback& callback) { 97 int ResponseWriter::Finish(const net::CompletionCallback& callback) {
97 return net::OK; 98 return net::OK;
98 } 99 }
99 100
101 static GURL GetFrontendURL() {
102 const base::CommandLine& command_line =
103 *base::CommandLine::ForCurrentProcess();
104 uint16_t port = 0;
105 if (command_line.HasSwitch(switches::kRemoteDebuggingPort)) {
106 int temp_port;
107 std::string port_str =
108 command_line.GetSwitchValueASCII(switches::kRemoteDebuggingPort);
109 if (base::StringToInt(port_str, &temp_port) &&
110 temp_port >= 0 && temp_port < 65535) {
111 port = static_cast<uint16_t>(temp_port);
112 } else {
113 DLOG(WARNING) << "Invalid http debugger port number " << temp_port;
114 }
115 }
116 return GURL(
117 base::StringPrintf("http://127.0.0.1:%d/devtools/inspector.html", port));
118 }
119
100 } // namespace 120 } // namespace
101 121
102 // This constant should be in sync with 122 // This constant should be in sync with
103 // the constant at devtools_ui_bindings.cc. 123 // the constant at devtools_ui_bindings.cc.
104 const size_t kMaxMessageChunkSize = IPC::Channel::kMaximumMessageSize / 4; 124 const size_t kMaxMessageChunkSize = IPC::Channel::kMaximumMessageSize / 4;
105 125
106 // static 126 // static
107 ShellDevToolsFrontend* ShellDevToolsFrontend::Show( 127 ShellDevToolsFrontend* ShellDevToolsFrontend::Show(
108 WebContents* inspected_contents) { 128 WebContents* inspected_contents) {
109 Shell* shell = Shell::CreateNewWindow(inspected_contents->GetBrowserContext(), 129 Shell* shell = Shell::CreateNewWindow(inspected_contents->GetBrowserContext(),
110 GURL(), 130 GURL(),
111 NULL, 131 NULL,
112 gfx::Size()); 132 gfx::Size());
113 ShellDevToolsFrontend* devtools_frontend = new ShellDevToolsFrontend( 133 ShellDevToolsFrontend* devtools_frontend = new ShellDevToolsFrontend(
114 shell, 134 shell,
115 inspected_contents); 135 inspected_contents);
116 136 shell->LoadURL(GetFrontendURL());
117 devtools_http_handler::DevToolsHttpHandler* http_handler =
118 ShellContentBrowserClient::Get()
119 ->shell_browser_main_parts()
120 ->devtools_http_handler();
121 shell->LoadURL(http_handler->GetFrontendURL("/devtools/inspector.html"));
122
123 return devtools_frontend; 137 return devtools_frontend;
124 } 138 }
125 139
126 void ShellDevToolsFrontend::Activate() { 140 void ShellDevToolsFrontend::Activate() {
127 frontend_shell_->ActivateContents(web_contents()); 141 frontend_shell_->ActivateContents(web_contents());
128 } 142 }
129 143
130 void ShellDevToolsFrontend::Focus() { 144 void ShellDevToolsFrontend::Focus() {
131 web_contents()->Focus(); 145 web_contents()->Focus();
132 } 146 }
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 CallClientFunction("DevToolsAPI.embedderMessageAck", 386 CallClientFunction("DevToolsAPI.embedderMessageAck",
373 &id_value, arg, nullptr); 387 &id_value, arg, nullptr);
374 } 388 }
375 389
376 void ShellDevToolsFrontend::AgentHostClosed( 390 void ShellDevToolsFrontend::AgentHostClosed(
377 DevToolsAgentHost* agent_host, bool replaced) { 391 DevToolsAgentHost* agent_host, bool replaced) {
378 frontend_shell_->Close(); 392 frontend_shell_->Close();
379 } 393 }
380 394
381 } // namespace content 395 } // namespace content
OLDNEW
« no previous file with comments | « content/public/browser/devtools_socket_factory.h ('k') | content/shell/browser/shell_devtools_manager_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698