Chromium Code Reviews| 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" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 59 // Chrome for Android from a newer version of desktop Chrome is a very common | 59 // Chrome for Android from a newer version of desktop Chrome is a very common |
| 60 // scenario, the client code will have to be modified to recognize both the old | 60 // scenario, the client code will have to be modified to recognize both the old |
| 61 // and the new format. | 61 // and the new format. |
| 62 const char kDevToolsChannelNameFormat[] = "%s_devtools_remote"; | 62 const char kDevToolsChannelNameFormat[] = "%s_devtools_remote"; |
| 63 | 63 |
| 64 const char kFrontEndURL[] = | 64 const char kFrontEndURL[] = |
| 65 "http://chrome-devtools-frontend.appspot.com/serve_rev/%s/devtools.html"; | 65 "http://chrome-devtools-frontend.appspot.com/serve_rev/%s/devtools.html"; |
| 66 const char kTetheringSocketName[] = "chrome_devtools_tethering_%d_%d"; | 66 const char kTetheringSocketName[] = "chrome_devtools_tethering_%d_%d"; |
| 67 | 67 |
| 68 const char kTargetTypePage[] = "page"; | 68 const char kTargetTypePage[] = "page"; |
| 69 const char kTargetTypeServiceWorker[] = "service_worker"; | |
| 69 const char kTargetTypeOther[] = "other"; | 70 const char kTargetTypeOther[] = "other"; |
| 70 | 71 |
| 71 static GURL GetFaviconURLForContents(WebContents* web_contents) { | 72 static GURL GetFaviconURLForContents(WebContents* web_contents) { |
| 72 content::NavigationController& controller = web_contents->GetController(); | 73 content::NavigationController& controller = web_contents->GetController(); |
| 73 content::NavigationEntry* entry = controller.GetActiveEntry(); | 74 content::NavigationEntry* entry = controller.GetActiveEntry(); |
| 74 if (entry != NULL && entry->GetURL().is_valid()) | 75 if (entry != NULL && entry->GetURL().is_valid()) |
| 75 return entry->GetFavicon().url; | 76 return entry->GetFavicon().url; |
| 76 return GURL(); | 77 return GURL(); |
| 77 } | 78 } |
| 78 | 79 |
| 80 static GURL GetFaviconURLForAgentHost( | |
| 81 scoped_refptr<DevToolsAgentHost> agent_host) { | |
| 82 if (WebContents* web_contents = agent_host->GetWebContents()) | |
| 83 return GetFaviconURLForContents(web_contents); | |
| 84 return GURL(); | |
| 85 } | |
| 86 | |
| 87 static base::TimeTicks GetLastActiveTimeForAgentHost( | |
| 88 scoped_refptr<DevToolsAgentHost> agent_host) { | |
| 89 if (WebContents* web_contents = agent_host->GetWebContents()) | |
| 90 return web_contents->GetLastActiveTime(); | |
| 91 return base::TimeTicks(); | |
| 92 } | |
| 93 | |
| 79 bool AuthorizeSocketAccessWithDebugPermission( | 94 bool AuthorizeSocketAccessWithDebugPermission( |
| 80 const net::UnixDomainServerSocket::Credentials& credentials) { | 95 const net::UnixDomainServerSocket::Credentials& credentials) { |
| 81 JNIEnv* env = base::android::AttachCurrentThread(); | 96 JNIEnv* env = base::android::AttachCurrentThread(); |
| 82 return Java_DevToolsServer_checkDebugPermission( | 97 return Java_DevToolsServer_checkDebugPermission( |
| 83 env, base::android::GetApplicationContext(), | 98 env, base::android::GetApplicationContext(), |
| 84 credentials.process_id, credentials.user_id) || | 99 credentials.process_id, credentials.user_id) || |
| 85 content::CanUserConnectToDevTools(credentials); | 100 content::CanUserConnectToDevTools(credentials); |
| 86 } | 101 } |
| 87 | 102 |
| 88 class TargetBase : public content::DevToolsTarget { | 103 class TargetBase : public content::DevToolsTarget { |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 103 } | 118 } |
| 104 | 119 |
| 105 protected: | 120 protected: |
| 106 explicit TargetBase(WebContents* web_contents) | 121 explicit TargetBase(WebContents* web_contents) |
| 107 : title_(base::UTF16ToUTF8(web_contents->GetTitle())), | 122 : title_(base::UTF16ToUTF8(web_contents->GetTitle())), |
| 108 url_(web_contents->GetURL()), | 123 url_(web_contents->GetURL()), |
| 109 favicon_url_(GetFaviconURLForContents(web_contents)), | 124 favicon_url_(GetFaviconURLForContents(web_contents)), |
| 110 last_activity_time_(web_contents->GetLastActiveTime()) { | 125 last_activity_time_(web_contents->GetLastActiveTime()) { |
| 111 } | 126 } |
| 112 | 127 |
| 113 TargetBase(const base::string16& title, const GURL& url) | 128 explicit TargetBase(scoped_refptr<DevToolsAgentHost> agent_host) |
| 114 : title_(base::UTF16ToUTF8(title)), | 129 : title_(agent_host->GetTitle()), |
| 115 url_(url) | 130 url_(agent_host->GetURL()), |
| 116 {} | 131 favicon_url_(GetFaviconURLForAgentHost(agent_host)), |
| 132 last_activity_time_(GetLastActiveTimeForAgentHost(agent_host)) { | |
| 133 } | |
| 134 | |
| 135 TargetBase(const std::string& title, const GURL& url) | |
| 136 : title_(title), | |
| 137 url_(url) { | |
| 138 } | |
| 117 | 139 |
| 118 private: | 140 private: |
| 119 const std::string title_; | 141 const std::string title_; |
| 120 const GURL url_; | 142 const GURL url_; |
| 121 const GURL favicon_url_; | 143 const GURL favicon_url_; |
| 122 const base::TimeTicks last_activity_time_; | 144 const base::TimeTicks last_activity_time_; |
| 123 }; | 145 }; |
| 124 | 146 |
| 125 class TabTarget : public TargetBase { | 147 class TabTarget : public TargetBase { |
| 126 public: | 148 public: |
| 127 static TabTarget* CreateForWebContents(int tab_id, | 149 static TabTarget* CreateForWebContents(int tab_id, |
| 128 WebContents* web_contents) { | 150 WebContents* web_contents) { |
| 129 return new TabTarget(tab_id, web_contents); | 151 return new TabTarget(tab_id, web_contents); |
| 130 } | 152 } |
| 131 | 153 |
| 132 static TabTarget* CreateForUnloadedTab(int tab_id, | 154 static TabTarget* CreateForUnloadedTab(int tab_id, |
| 133 const base::string16& title, | 155 const base::string16& title, |
| 134 const GURL& url) { | 156 const GURL& url) { |
| 135 return new TabTarget(tab_id, title, url); | 157 return new TabTarget(tab_id, title, url); |
| 136 } | 158 } |
| 137 | 159 |
| 138 // content::DevToolsTarget implementation: | 160 // content::DevToolsTarget implementation: |
| 139 virtual std::string GetId() const OVERRIDE { | 161 virtual std::string GetId() const OVERRIDE { |
| 140 return base::IntToString(tab_id_); | 162 return base::IntToString(tab_id_); |
| 141 } | 163 } |
| 142 | 164 |
| 143 virtual std::string GetType() const OVERRIDE { return kTargetTypePage; } | 165 virtual std::string GetType() const OVERRIDE { |
| 166 return kTargetTypePage; | |
| 167 } | |
| 144 | 168 |
| 145 virtual bool IsAttached() const OVERRIDE { | 169 virtual bool IsAttached() const OVERRIDE { |
| 146 TabModel* model; | 170 TabModel* model; |
| 147 int index; | 171 int index; |
| 148 if (!FindTab(&model, &index)) | 172 if (!FindTab(&model, &index)) |
| 149 return false; | 173 return false; |
| 150 WebContents* web_contents = model->GetWebContentsAt(index); | 174 WebContents* web_contents = model->GetWebContentsAt(index); |
| 151 if (!web_contents) | 175 if (!web_contents) |
| 152 return false; | 176 return false; |
| 153 return DevToolsAgentHost::IsDebuggerAttached(web_contents); | 177 return DevToolsAgentHost::IsDebuggerAttached(web_contents); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 188 return true; | 212 return true; |
| 189 } | 213 } |
| 190 | 214 |
| 191 private: | 215 private: |
| 192 TabTarget(int tab_id, WebContents* web_contents) | 216 TabTarget(int tab_id, WebContents* web_contents) |
| 193 : TargetBase(web_contents), | 217 : TargetBase(web_contents), |
| 194 tab_id_(tab_id) { | 218 tab_id_(tab_id) { |
| 195 } | 219 } |
| 196 | 220 |
| 197 TabTarget(int tab_id, const base::string16& title, const GURL& url) | 221 TabTarget(int tab_id, const base::string16& title, const GURL& url) |
| 198 : TargetBase(title, url), | 222 : TargetBase(base::UTF16ToUTF8(title), url), |
| 199 tab_id_(tab_id) { | 223 tab_id_(tab_id) { |
| 200 } | 224 } |
| 201 | 225 |
| 202 bool FindTab(TabModel** model_result, int* index_result) const { | 226 bool FindTab(TabModel** model_result, int* index_result) const { |
| 203 for (TabModelList::const_iterator iter = TabModelList::begin(); | 227 for (TabModelList::const_iterator iter = TabModelList::begin(); |
| 204 iter != TabModelList::end(); ++iter) { | 228 iter != TabModelList::end(); ++iter) { |
| 205 TabModel* model = *iter; | 229 TabModel* model = *iter; |
| 206 for (int i = 0; i < model->GetTabCount(); ++i) { | 230 for (int i = 0; i < model->GetTabCount(); ++i) { |
| 207 TabAndroid* tab = model->GetTabAt(i); | 231 TabAndroid* tab = model->GetTabAt(i); |
| 208 if (tab->GetAndroidId() == tab_id_) { | 232 if (tab->GetAndroidId() == tab_id_) { |
| 209 *model_result = model; | 233 *model_result = model; |
| 210 *index_result = i; | 234 *index_result = i; |
| 211 return true; | 235 return true; |
| 212 } | 236 } |
| 213 } | 237 } |
| 214 } | 238 } |
| 215 return false; | 239 return false; |
| 216 } | 240 } |
| 217 | 241 |
| 218 const int tab_id_; | 242 const int tab_id_; |
| 219 }; | 243 }; |
| 220 | 244 |
| 221 class NonTabTarget : public TargetBase { | 245 class NonTabTarget : public TargetBase { |
| 222 public: | 246 public: |
| 223 explicit NonTabTarget(WebContents* web_contents) | 247 explicit NonTabTarget(scoped_refptr<DevToolsAgentHost> agent_host) |
| 224 : TargetBase(web_contents), | 248 : TargetBase(agent_host), |
| 225 agent_host_(DevToolsAgentHost::GetOrCreateFor(web_contents)) { | 249 agent_host_(agent_host) { |
| 226 } | 250 } |
| 227 | 251 |
| 228 // content::DevToolsTarget implementation: | 252 // content::DevToolsTarget implementation: |
| 229 virtual std::string GetId() const OVERRIDE { | 253 virtual std::string GetId() const OVERRIDE { |
| 230 return agent_host_->GetId(); | 254 return agent_host_->GetId(); |
| 231 } | 255 } |
| 232 | 256 |
| 233 virtual std::string GetType() const OVERRIDE { | 257 virtual std::string GetType() const OVERRIDE { |
| 234 if (TabModelList::begin() == TabModelList::end()) { | 258 switch (agent_host_->GetType()) { |
|
dgozman
2014/08/22 08:38:28
Please don't regress this.
vkuzkokov
2014/08/22 11:01:48
Done.
| |
| 235 // If there are no tab models we must be running in ChromeShell. | 259 case DevToolsAgentHost::AGENT_HOST_WEB_CONTENTS: |
| 236 // Return the 'page' target type for backwards compatibility. | 260 return kTargetTypePage; |
| 237 return kTargetTypePage; | 261 case DevToolsAgentHost::AGENT_HOST_SERVICE_WORKER: |
| 262 return kTargetTypeServiceWorker; | |
| 263 default: | |
| 264 {} // Do nothing. | |
| 238 } | 265 } |
| 239 return kTargetTypeOther; | 266 return kTargetTypeOther; |
| 240 } | 267 } |
| 241 | 268 |
| 242 virtual bool IsAttached() const OVERRIDE { | 269 virtual bool IsAttached() const OVERRIDE { |
| 243 return agent_host_->IsAttached(); | 270 return agent_host_->IsAttached(); |
| 244 } | 271 } |
| 245 | 272 |
| 246 virtual scoped_refptr<DevToolsAgentHost> GetAgentHost() const OVERRIDE { | 273 virtual scoped_refptr<DevToolsAgentHost> GetAgentHost() const OVERRIDE { |
| 247 return agent_host_; | 274 return agent_host_; |
| 248 } | 275 } |
| 249 | 276 |
| 250 virtual bool Activate() const OVERRIDE { | 277 virtual bool Activate() const OVERRIDE { |
| 251 WebContents* web_contents = agent_host_->GetWebContents(); | 278 return agent_host_->Activate(); |
| 252 if (!web_contents) | |
| 253 return false; | |
| 254 web_contents->GetDelegate()->ActivateContents(web_contents); | |
| 255 return true; | |
| 256 } | 279 } |
| 257 | 280 |
| 258 virtual bool Close() const OVERRIDE { | 281 virtual bool Close() const OVERRIDE { |
| 259 WebContents* web_contents = agent_host_->GetWebContents(); | 282 return agent_host_->Close(); |
| 260 if (!web_contents) | |
| 261 return false; | |
| 262 web_contents->GetRenderViewHost()->ClosePage(); | |
| 263 return true; | |
| 264 } | 283 } |
| 265 | 284 |
| 266 private: | 285 private: |
| 267 scoped_refptr<DevToolsAgentHost> agent_host_; | 286 scoped_refptr<DevToolsAgentHost> agent_host_; |
| 268 }; | 287 }; |
| 269 | 288 |
| 270 // Delegate implementation for the devtools http handler on android. A new | 289 // Delegate implementation for the devtools http handler on android. A new |
| 271 // instance of this gets created each time devtools is enabled. | 290 // instance of this gets created each time devtools is enabled. |
| 272 class DevToolsServerDelegate : public content::DevToolsHttpHandlerDelegate { | 291 class DevToolsServerDelegate : public content::DevToolsHttpHandlerDelegate { |
| 273 public: | 292 public: |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 344 web_contents)); | 363 web_contents)); |
| 345 } else { | 364 } else { |
| 346 targets.push_back(TabTarget::CreateForUnloadedTab(tab->GetAndroidId(), | 365 targets.push_back(TabTarget::CreateForUnloadedTab(tab->GetAndroidId(), |
| 347 tab->GetTitle(), | 366 tab->GetTitle(), |
| 348 tab->GetURL())); | 367 tab->GetURL())); |
| 349 } | 368 } |
| 350 } | 369 } |
| 351 } | 370 } |
| 352 | 371 |
| 353 // Add targets for WebContents not associated with any tabs. | 372 // Add targets for WebContents not associated with any tabs. |
| 354 std::vector<WebContents*> wc_list = | 373 DevToolsAgentHost::List agents = |
| 355 DevToolsAgentHost::GetInspectableWebContents(); | 374 DevToolsAgentHost::GetOrCreateAll(); |
| 356 for (std::vector<WebContents*>::iterator it = wc_list.begin(); | 375 for (DevToolsAgentHost::List::iterator it = agents.begin(); |
| 357 it != wc_list.end(); | 376 it != agents.end(); ++it) { |
| 358 ++it) { | 377 if (WebContents* web_contents = (*it)->GetWebContents()) { |
| 359 if (tab_web_contents.find(*it) != tab_web_contents.end()) | 378 if (tab_web_contents.find(web_contents) != tab_web_contents.end()) |
| 360 continue; | 379 continue; |
| 380 } | |
| 361 targets.push_back(new NonTabTarget(*it)); | 381 targets.push_back(new NonTabTarget(*it)); |
| 362 } | 382 } |
| 363 | 383 |
| 364 callback.Run(targets); | 384 callback.Run(targets); |
| 365 } | 385 } |
| 366 | 386 |
| 367 virtual scoped_ptr<net::StreamListenSocket> CreateSocketForTethering( | 387 virtual scoped_ptr<net::StreamListenSocket> CreateSocketForTethering( |
| 368 net::StreamListenSocket::Delegate* delegate, | 388 net::StreamListenSocket::Delegate* delegate, |
| 369 std::string* name) OVERRIDE { | 389 std::string* name) OVERRIDE { |
| 370 *name = base::StringPrintf( | 390 *name = base::StringPrintf( |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 470 jlong server, | 490 jlong server, |
| 471 jboolean enabled, | 491 jboolean enabled, |
| 472 jboolean allow_debug_permission) { | 492 jboolean allow_debug_permission) { |
| 473 DevToolsServer* devtools_server = reinterpret_cast<DevToolsServer*>(server); | 493 DevToolsServer* devtools_server = reinterpret_cast<DevToolsServer*>(server); |
| 474 if (enabled) { | 494 if (enabled) { |
| 475 devtools_server->Start(allow_debug_permission); | 495 devtools_server->Start(allow_debug_permission); |
| 476 } else { | 496 } else { |
| 477 devtools_server->Stop(); | 497 devtools_server->Stop(); |
| 478 } | 498 } |
| 479 } | 499 } |
| OLD | NEW |