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

Side by Side Diff: android_webview/native/aw_devtools_server.cc

Issue 2300703005: DevTools: merge devtools_http_handler into content - it is used in all the embedders anyways. (Closed)
Patch Set: for_landing! 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
« no previous file with comments | « android_webview/native/aw_devtools_server.h ('k') | android_webview/native/webview_native.gyp » ('j') | 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 "android_webview/native/aw_dev_tools_server.h" 5 #include "android_webview/native/aw_devtools_server.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "android_webview/browser/browser_view_renderer.h"
9 #include "android_webview/common/aw_content_client.h" 10 #include "android_webview/common/aw_content_client.h"
10 #include "android_webview/native/aw_contents.h" 11 #include "android_webview/native/aw_contents.h"
11 #include "base/bind.h" 12 #include "base/bind.h"
12 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
13 #include "base/json/json_writer.h" 14 #include "base/json/json_writer.h"
15 #include "base/memory/ptr_util.h"
14 #include "base/strings/stringprintf.h" 16 #include "base/strings/stringprintf.h"
15 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
16 #include "base/values.h" 18 #include "base/values.h"
17 #include "components/devtools_http_handler/devtools_http_handler.h"
18 #include "components/devtools_http_handler/devtools_http_handler_delegate.h"
19 #include "content/public/browser/android/devtools_auth.h" 19 #include "content/public/browser/android/devtools_auth.h"
20 #include "content/public/browser/devtools_agent_host.h" 20 #include "content/public/browser/devtools_agent_host.h"
21 #include "content/public/browser/devtools_socket_factory.h" 21 #include "content/public/browser/devtools_socket_factory.h"
22 #include "content/public/browser/web_contents.h" 22 #include "content/public/browser/web_contents.h"
23 #include "content/public/common/user_agent.h" 23 #include "content/public/common/user_agent.h"
24 #include "jni/AwDevToolsServer_jni.h" 24 #include "jni/AwDevToolsServer_jni.h"
25 #include "net/base/net_errors.h" 25 #include "net/base/net_errors.h"
26 #include "net/socket/unix_domain_server_socket_posix.h" 26 #include "net/socket/unix_domain_server_socket_posix.h"
27 27
28 using base::android::JavaParamRef; 28 using base::android::JavaParamRef;
29 using content::DevToolsAgentHost; 29 using content::DevToolsAgentHost;
30 using content::RenderViewHost;
31 using content::WebContents;
32 using devtools_http_handler::DevToolsHttpHandler;
33 30
34 namespace { 31 namespace {
35 32
36 const char kFrontEndURL[] = 33 const char kFrontEndURL[] =
37 "http://chrome-devtools-frontend.appspot.com/serve_rev/%s/inspector.html"; 34 "http://chrome-devtools-frontend.appspot.com/serve_rev/%s/inspector.html";
38 const char kSocketNameFormat[] = "webview_devtools_remote_%d"; 35 const char kSocketNameFormat[] = "webview_devtools_remote_%d";
39 const char kTetheringSocketName[] = "webview_devtools_tethering_%d_%d"; 36 const char kTetheringSocketName[] = "webview_devtools_tethering_%d_%d";
40 37
41 const int kBackLog = 10; 38 const int kBackLog = 10;
42 39
43 // Delegate implementation for the devtools http handler for WebView. A new
44 // instance of this gets created each time web debugging is enabled.
45 class AwDevToolsServerDelegate :
46 public devtools_http_handler::DevToolsHttpHandlerDelegate {
47 public:
48 AwDevToolsServerDelegate() {
49 }
50
51 ~AwDevToolsServerDelegate() override {}
52
53 // devtools_http_handler::DevToolsHttpHandlerDelegate implementation.
54 std::string GetDiscoveryPageHTML() override;
55 std::string GetFrontendResource(const std::string& path) override;
56
57 private:
58
59 DISALLOW_COPY_AND_ASSIGN(AwDevToolsServerDelegate);
60 };
61
62
63 std::string AwDevToolsServerDelegate::GetDiscoveryPageHTML() {
64 const char html[] =
65 "<html>"
66 "<head><title>WebView remote debugging</title></head>"
67 "<body>Please use <a href=\'chrome://inspect\'>chrome://inspect</a>"
68 "</body>"
69 "</html>";
70 return html;
71 }
72
73 std::string AwDevToolsServerDelegate::GetFrontendResource(
74 const std::string& path) {
75 return std::string();
76 }
77
78 // Factory for UnixDomainServerSocket. 40 // Factory for UnixDomainServerSocket.
79 class UnixDomainServerSocketFactory : public content::DevToolsSocketFactory { 41 class UnixDomainServerSocketFactory : public content::DevToolsSocketFactory {
80 public: 42 public:
81 explicit UnixDomainServerSocketFactory(const std::string& socket_name) 43 explicit UnixDomainServerSocketFactory(const std::string& socket_name)
82 : socket_name_(socket_name), 44 : socket_name_(socket_name),
83 last_tethering_socket_(0) { 45 last_tethering_socket_(0) {
84 } 46 }
85 47
86 private: 48 private:
87 // devtools_http_handler::DevToolsHttpHandler::ServerSocketFactory. 49 // content::DevToolsAgentHost::ServerSocketFactory.
88 std::unique_ptr<net::ServerSocket> CreateForHttpServer() override { 50 std::unique_ptr<net::ServerSocket> CreateForHttpServer() override {
89 std::unique_ptr<net::UnixDomainServerSocket> socket( 51 std::unique_ptr<net::UnixDomainServerSocket> socket(
90 new net::UnixDomainServerSocket( 52 new net::UnixDomainServerSocket(
91 base::Bind(&content::CanUserConnectToDevTools), 53 base::Bind(&content::CanUserConnectToDevTools),
92 true /* use_abstract_namespace */)); 54 true /* use_abstract_namespace */));
93 if (socket->BindAndListen(socket_name_, kBackLog) != net::OK) 55 if (socket->BindAndListen(socket_name_, kBackLog) != net::OK)
94 return std::unique_ptr<net::ServerSocket>(); 56 return std::unique_ptr<net::ServerSocket>();
95 57
96 return std::move(socket); 58 return std::move(socket);
97 } 59 }
(...skipping 15 matching lines...) Expand all
113 std::string socket_name_; 75 std::string socket_name_;
114 int last_tethering_socket_; 76 int last_tethering_socket_;
115 77
116 DISALLOW_COPY_AND_ASSIGN(UnixDomainServerSocketFactory); 78 DISALLOW_COPY_AND_ASSIGN(UnixDomainServerSocketFactory);
117 }; 79 };
118 80
119 } // namespace 81 } // namespace
120 82
121 namespace android_webview { 83 namespace android_webview {
122 84
123 AwDevToolsServer::AwDevToolsServer() { 85 AwDevToolsServer::AwDevToolsServer() : is_started_(false) {
124 } 86 }
125 87
126 AwDevToolsServer::~AwDevToolsServer() { 88 AwDevToolsServer::~AwDevToolsServer() {
127 Stop(); 89 Stop();
128 } 90 }
129 91
130 void AwDevToolsServer::Start() { 92 void AwDevToolsServer::Start() {
131 if (devtools_http_handler_) 93 if (is_started_)
132 return; 94 return;
95 is_started_ = true;
133 96
134 std::unique_ptr<content::DevToolsSocketFactory> factory( 97 std::unique_ptr<content::DevToolsSocketFactory> factory(
135 new UnixDomainServerSocketFactory( 98 new UnixDomainServerSocketFactory(
136 base::StringPrintf(kSocketNameFormat, getpid()))); 99 base::StringPrintf(kSocketNameFormat, getpid())));
137 devtools_http_handler_.reset(new DevToolsHttpHandler( 100 DevToolsAgentHost::StartRemoteDebuggingServer(
138 std::move(factory), 101 std::move(factory),
139 base::StringPrintf(kFrontEndURL, content::GetWebKitRevision().c_str()), 102 base::StringPrintf(kFrontEndURL, content::GetWebKitRevision().c_str()),
140 new AwDevToolsServerDelegate(), base::FilePath(), base::FilePath(), 103 base::FilePath(), base::FilePath(),
141 GetProduct(), GetUserAgent())); 104 GetProduct(), GetUserAgent());
142 } 105 }
143 106
144 void AwDevToolsServer::Stop() { 107 void AwDevToolsServer::Stop() {
145 devtools_http_handler_.reset(); 108 DevToolsAgentHost::StopRemoteDebuggingServer();
109 is_started_ = false;
146 } 110 }
147 111
148 bool AwDevToolsServer::IsStarted() const { 112 bool AwDevToolsServer::IsStarted() const {
149 return !!devtools_http_handler_; 113 return is_started_;
150 } 114 }
151 115
152 bool RegisterAwDevToolsServer(JNIEnv* env) { 116 bool RegisterAwDevToolsServer(JNIEnv* env) {
153 return RegisterNativesImpl(env); 117 return RegisterNativesImpl(env);
154 } 118 }
155 119
156 static jlong InitRemoteDebugging(JNIEnv* env, 120 static jlong InitRemoteDebugging(JNIEnv* env,
157 const JavaParamRef<jobject>& obj) { 121 const JavaParamRef<jobject>& obj) {
158 AwDevToolsServer* server = new AwDevToolsServer(); 122 AwDevToolsServer* server = new AwDevToolsServer();
159 return reinterpret_cast<intptr_t>(server); 123 return reinterpret_cast<intptr_t>(server);
(...skipping 12 matching lines...) Expand all
172 AwDevToolsServer* devtools_server = 136 AwDevToolsServer* devtools_server =
173 reinterpret_cast<AwDevToolsServer*>(server); 137 reinterpret_cast<AwDevToolsServer*>(server);
174 if (enabled) { 138 if (enabled) {
175 devtools_server->Start(); 139 devtools_server->Start();
176 } else { 140 } else {
177 devtools_server->Stop(); 141 devtools_server->Stop();
178 } 142 }
179 } 143 }
180 144
181 } // namespace android_webview 145 } // namespace android_webview
OLDNEW
« no previous file with comments | « android_webview/native/aw_devtools_server.h ('k') | android_webview/native/webview_native.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698