OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/android/dev_tools_server.h" | 5 #include "chrome/browser/android/dev_tools_server.h" |
6 | 6 |
7 #include <pwd.h> | 7 #include <pwd.h> |
8 #include <cstring> | 8 #include <cstring> |
9 | 9 |
10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
16 #include "base/logging.h" | 16 #include "base/logging.h" |
17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
18 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
19 #include "chrome/browser/devtools/devtools_adb_bridge.h" | |
19 #include "chrome/browser/history/top_sites.h" | 20 #include "chrome/browser/history/top_sites.h" |
20 #include "chrome/browser/profiles/profile_manager.h" | 21 #include "chrome/browser/profiles/profile_manager.h" |
21 #include "chrome/browser/ui/android/tab_model/tab_model.h" | 22 #include "chrome/browser/ui/android/tab_model/tab_model.h" |
22 #include "chrome/browser/ui/android/tab_model/tab_model_list.h" | 23 #include "chrome/browser/ui/android/tab_model/tab_model_list.h" |
23 #include "chrome/common/chrome_version_info.h" | |
24 #include "content/public/browser/android/devtools_auth.h" | 24 #include "content/public/browser/android/devtools_auth.h" |
25 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
26 #include "content/public/browser/devtools_http_handler.h" | 26 #include "content/public/browser/devtools_http_handler.h" |
27 #include "content/public/browser/devtools_http_handler_delegate.h" | 27 #include "content/public/browser/devtools_http_handler_delegate.h" |
28 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
29 #include "content/public/common/content_switches.h" | 29 #include "content/public/common/content_switches.h" |
30 #include "content/public/common/url_constants.h" | 30 #include "content/public/common/url_constants.h" |
31 #include "grit/devtools_discovery_page_resources.h" | 31 #include "grit/devtools_discovery_page_resources.h" |
32 #include "jni/DevToolsServer_jni.h" | 32 #include "jni/DevToolsServer_jni.h" |
33 #include "net/socket/unix_domain_socket_posix.h" | 33 #include "net/socket/unix_domain_socket_posix.h" |
34 #include "net/url_request/url_request_context_getter.h" | 34 #include "net/url_request/url_request_context_getter.h" |
35 #include "ui/base/resource/resource_bundle.h" | 35 #include "ui/base/resource/resource_bundle.h" |
36 #include "webkit/common/user_agent/user_agent_util.h" | |
36 | 37 |
37 namespace { | 38 namespace { |
38 | 39 |
39 const char kFrontEndURL[] = | 40 const char kFrontEndURL[] = |
40 "http://chrome-devtools-frontend.appspot.com/static/%s/devtools.html"; | 41 "http://chrome-devtools-frontend.appspot.com/serve_rev/%s/devtools.html"; |
bulach
2013/06/21 09:02:17
nit: is "serve" correct or should it be serve"r"?
mnaganov (inactive)
2013/06/21 09:21:45
It is correct. It's not a "server revision", but r
| |
41 const char kDefaultSocketName[] = "chrome_devtools_remote"; | 42 const char kDefaultSocketNamePrefix[] = "chrome"; |
bulach
2013/06/21 09:02:17
as above, would telemetry need to change? it tries
mnaganov (inactive)
2013/06/21 09:21:45
No. Please note from the var name change, that it
| |
42 const char kTetheringSocketName[] = "chrome_devtools_tethering_%d_%d"; | 43 const char kTetheringSocketName[] = "chrome_devtools_tethering_%d_%d"; |
43 | 44 |
44 // Delegate implementation for the devtools http handler on android. A new | 45 // Delegate implementation for the devtools http handler on android. A new |
45 // instance of this gets created each time devtools is enabled. | 46 // instance of this gets created each time devtools is enabled. |
46 class DevToolsServerDelegate : public content::DevToolsHttpHandlerDelegate { | 47 class DevToolsServerDelegate : public content::DevToolsHttpHandlerDelegate { |
47 public: | 48 public: |
48 explicit DevToolsServerDelegate(bool use_bundled_frontend_resources) | 49 DevToolsServerDelegate() |
49 : use_bundled_frontend_resources_(use_bundled_frontend_resources), | 50 : last_tethering_socket_(0) { |
50 last_tethering_socket_(0) { | |
51 } | 51 } |
52 | 52 |
53 virtual std::string GetDiscoveryPageHTML() OVERRIDE { | 53 virtual std::string GetDiscoveryPageHTML() OVERRIDE { |
54 // TopSites updates itself after a delay. Ask TopSites to update itself | 54 // TopSites updates itself after a delay. Ask TopSites to update itself |
55 // when we're about to show the remote debugging landing page. | 55 // when we're about to show the remote debugging landing page. |
56 content::BrowserThread::PostTask( | 56 content::BrowserThread::PostTask( |
57 content::BrowserThread::UI, | 57 content::BrowserThread::UI, |
58 FROM_HERE, | 58 FROM_HERE, |
59 base::Bind(&DevToolsServerDelegate::PopulatePageThumbnails)); | 59 base::Bind(&DevToolsServerDelegate::PopulatePageThumbnails)); |
60 return ResourceBundle::GetSharedInstance().GetRawDataResource( | 60 return ResourceBundle::GetSharedInstance().GetRawDataResource( |
61 IDR_DEVTOOLS_DISCOVERY_PAGE_HTML).as_string(); | 61 IDR_DEVTOOLS_DISCOVERY_PAGE_HTML).as_string(); |
62 } | 62 } |
63 | 63 |
64 virtual bool BundlesFrontendResources() OVERRIDE { | 64 virtual bool BundlesFrontendResources() OVERRIDE { |
65 return use_bundled_frontend_resources_; | 65 return false; |
66 } | 66 } |
67 | 67 |
68 virtual base::FilePath GetDebugFrontendDir() OVERRIDE { | 68 virtual base::FilePath GetDebugFrontendDir() OVERRIDE { |
69 return base::FilePath(); | 69 return base::FilePath(); |
70 } | 70 } |
71 | 71 |
72 virtual std::string GetPageThumbnailData(const GURL& url) OVERRIDE { | 72 virtual std::string GetPageThumbnailData(const GURL& url) OVERRIDE { |
73 Profile* profile = | 73 Profile* profile = |
74 ProfileManager::GetLastUsedProfile()->GetOriginalProfile(); | 74 ProfileManager::GetLastUsedProfile()->GetOriginalProfile(); |
75 history::TopSites* top_sites = profile->GetTopSites(); | 75 history::TopSites* top_sites = profile->GetTopSites(); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
117 | 117 |
118 private: | 118 private: |
119 static void PopulatePageThumbnails() { | 119 static void PopulatePageThumbnails() { |
120 Profile* profile = | 120 Profile* profile = |
121 ProfileManager::GetLastUsedProfile()->GetOriginalProfile(); | 121 ProfileManager::GetLastUsedProfile()->GetOriginalProfile(); |
122 history::TopSites* top_sites = profile->GetTopSites(); | 122 history::TopSites* top_sites = profile->GetTopSites(); |
123 if (top_sites) | 123 if (top_sites) |
124 top_sites->SyncWithHistory(); | 124 top_sites->SyncWithHistory(); |
125 } | 125 } |
126 | 126 |
127 bool use_bundled_frontend_resources_; | |
128 int last_tethering_socket_; | 127 int last_tethering_socket_; |
129 | 128 |
130 DISALLOW_COPY_AND_ASSIGN(DevToolsServerDelegate); | 129 DISALLOW_COPY_AND_ASSIGN(DevToolsServerDelegate); |
131 }; | 130 }; |
132 | 131 |
133 } // namespace | 132 } // namespace |
134 | 133 |
135 DevToolsServer::DevToolsServer() | 134 DevToolsServer::DevToolsServer() |
136 : use_bundled_frontend_resources_(false), | 135 : socket_name_(base::StringPrintf(kDevToolsChannelNameFormat, |
137 socket_name_(kDefaultSocketName), | 136 kDefaultSocketNamePrefix)), |
138 protocol_handler_(NULL) { | 137 protocol_handler_(NULL) { |
139 // Override the default socket name if one is specified on the command line. | 138 // Override the default socket name if one is specified on the command line. |
140 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 139 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
141 if (command_line.HasSwitch(switches::kRemoteDebuggingSocketName)) { | 140 if (command_line.HasSwitch(switches::kRemoteDebuggingSocketName)) { |
142 socket_name_ = command_line.GetSwitchValueASCII( | 141 socket_name_ = command_line.GetSwitchValueASCII( |
143 switches::kRemoteDebuggingSocketName); | 142 switches::kRemoteDebuggingSocketName); |
144 } | 143 } |
145 } | 144 } |
146 | 145 |
147 DevToolsServer::DevToolsServer(bool use_bundled_frontend_resources, | 146 DevToolsServer::DevToolsServer(const std::string& socket_name_prefix) |
148 const std::string& socket_name) | 147 : socket_name_(base::StringPrintf(kDevToolsChannelNameFormat, |
149 : use_bundled_frontend_resources_(use_bundled_frontend_resources), | 148 socket_name_prefix.c_str())), |
150 socket_name_(socket_name), | |
151 protocol_handler_(NULL) { | 149 protocol_handler_(NULL) { |
152 } | 150 } |
153 | 151 |
154 DevToolsServer::~DevToolsServer() { | 152 DevToolsServer::~DevToolsServer() { |
155 Stop(); | 153 Stop(); |
156 } | 154 } |
157 | 155 |
158 void DevToolsServer::Start() { | 156 void DevToolsServer::Start() { |
159 if (protocol_handler_) | 157 if (protocol_handler_) |
160 return; | 158 return; |
161 | 159 |
162 chrome::VersionInfo version_info; | |
163 | |
164 protocol_handler_ = content::DevToolsHttpHandler::Start( | 160 protocol_handler_ = content::DevToolsHttpHandler::Start( |
165 new net::UnixDomainSocketWithAbstractNamespaceFactory( | 161 new net::UnixDomainSocketWithAbstractNamespaceFactory( |
166 socket_name_, | 162 socket_name_, |
167 base::StringPrintf("%s_%d", socket_name_.c_str(), getpid()), | 163 base::StringPrintf("%s_%d", socket_name_.c_str(), getpid()), |
168 base::Bind(&content::CanUserConnectToDevTools)), | 164 base::Bind(&content::CanUserConnectToDevTools)), |
169 use_bundled_frontend_resources_ ? | 165 base::StringPrintf(kFrontEndURL, |
170 "" : | 166 webkit_glue::GetWebKitRevision().c_str()), |
171 base::StringPrintf(kFrontEndURL, version_info.Version().c_str()), | 167 new DevToolsServerDelegate()); |
172 new DevToolsServerDelegate(use_bundled_frontend_resources_)); | |
173 } | 168 } |
174 | 169 |
175 void DevToolsServer::Stop() { | 170 void DevToolsServer::Stop() { |
176 if (!protocol_handler_) | 171 if (!protocol_handler_) |
177 return; | 172 return; |
178 // Note that the call to Stop() below takes care of |protocol_handler_| | 173 // Note that the call to Stop() below takes care of |protocol_handler_| |
179 // deletion. | 174 // deletion. |
180 protocol_handler_->Stop(); | 175 protocol_handler_->Stop(); |
181 protocol_handler_ = NULL; | 176 protocol_handler_ = NULL; |
182 } | 177 } |
183 | 178 |
184 bool DevToolsServer::IsStarted() const { | 179 bool DevToolsServer::IsStarted() const { |
185 return protocol_handler_; | 180 return protocol_handler_; |
186 } | 181 } |
187 | 182 |
188 bool RegisterDevToolsServer(JNIEnv* env) { | 183 bool RegisterDevToolsServer(JNIEnv* env) { |
189 return RegisterNativesImpl(env); | 184 return RegisterNativesImpl(env); |
190 } | 185 } |
191 | 186 |
192 static jint InitRemoteDebugging(JNIEnv* env, | 187 static jint InitRemoteDebugging(JNIEnv* env, |
193 jobject obj, | 188 jobject obj, |
194 jboolean use_bundled_frontend_resources, | 189 jstring socketNamePrefix) { |
pfeldman
2013/06/20 17:03:39
socket_name_prefix ?
mnaganov (inactive)
2013/06/21 09:21:45
Done. Writing JNI code is always challenging when
| |
195 jstring socketName) { | |
196 DevToolsServer* server = new DevToolsServer( | 190 DevToolsServer* server = new DevToolsServer( |
197 use_bundled_frontend_resources, | 191 base::android::ConvertJavaStringToUTF8(env, socketNamePrefix)); |
198 base::android::ConvertJavaStringToUTF8(env, socketName)); | |
199 return reinterpret_cast<jint>(server); | 192 return reinterpret_cast<jint>(server); |
200 } | 193 } |
201 | 194 |
202 static void DestroyRemoteDebugging(JNIEnv* env, jobject obj, jint server) { | 195 static void DestroyRemoteDebugging(JNIEnv* env, jobject obj, jint server) { |
203 delete reinterpret_cast<DevToolsServer*>(server); | 196 delete reinterpret_cast<DevToolsServer*>(server); |
204 } | 197 } |
205 | 198 |
206 static jboolean IsRemoteDebuggingEnabled(JNIEnv* env, | 199 static jboolean IsRemoteDebuggingEnabled(JNIEnv* env, |
207 jobject obj, | 200 jobject obj, |
208 jint server) { | 201 jint server) { |
209 return reinterpret_cast<DevToolsServer*>(server)->IsStarted(); | 202 return reinterpret_cast<DevToolsServer*>(server)->IsStarted(); |
210 } | 203 } |
211 | 204 |
212 static void SetRemoteDebuggingEnabled(JNIEnv* env, | 205 static void SetRemoteDebuggingEnabled(JNIEnv* env, |
213 jobject obj, | 206 jobject obj, |
214 jint server, | 207 jint server, |
215 jboolean enabled) { | 208 jboolean enabled) { |
216 DevToolsServer* devtools_server = reinterpret_cast<DevToolsServer*>(server); | 209 DevToolsServer* devtools_server = reinterpret_cast<DevToolsServer*>(server); |
217 if (enabled) { | 210 if (enabled) { |
218 devtools_server->Start(); | 211 devtools_server->Start(); |
219 } else { | 212 } else { |
220 devtools_server->Stop(); | 213 devtools_server->Stop(); |
221 } | 214 } |
222 } | 215 } |
OLD | NEW |