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

Side by Side Diff: chrome/browser/android/dev_tools_server.cc

Issue 459403002: DevTools: Added service workers to remote debugging targets (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remote debugger is now properly notified of service worker being closed Created 6 years, 4 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 (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
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 kTargetTypeOther[] = "other";
70 69
71 static GURL GetFaviconURLForContents(WebContents* web_contents) { 70 static GURL GetFaviconURLForContents(WebContents* web_contents) {
72 content::NavigationController& controller = web_contents->GetController(); 71 content::NavigationController& controller = web_contents->GetController();
73 content::NavigationEntry* entry = controller.GetActiveEntry(); 72 content::NavigationEntry* entry = controller.GetActiveEntry();
74 if (entry != NULL && entry->GetURL().is_valid()) 73 if (entry != NULL && entry->GetURL().is_valid())
75 return entry->GetFavicon().url; 74 return entry->GetFavicon().url;
76 return GURL(); 75 return GURL();
77 } 76 }
78 77
78 static GURL GetFaviconURLForAgentHost(
79 scoped_refptr<DevToolsAgentHost> agent_host) {
80 if (WebContents* web_contents = agent_host->GetWebContents())
81 return GetFaviconURLForContents(web_contents);
82 return GURL();
83 }
84
85 static base::TimeTicks GetLastActiveTimeForAgentHost(
86 scoped_refptr<DevToolsAgentHost> agent_host) {
87 if (WebContents* web_contents = agent_host->GetWebContents())
88 return web_contents->GetLastActiveTime();
89 return base::TimeTicks();
90 }
91
79 bool AuthorizeSocketAccessWithDebugPermission( 92 bool AuthorizeSocketAccessWithDebugPermission(
80 const net::UnixDomainServerSocket::Credentials& credentials) { 93 const net::UnixDomainServerSocket::Credentials& credentials) {
81 JNIEnv* env = base::android::AttachCurrentThread(); 94 JNIEnv* env = base::android::AttachCurrentThread();
82 return Java_DevToolsServer_checkDebugPermission( 95 return Java_DevToolsServer_checkDebugPermission(
83 env, base::android::GetApplicationContext(), 96 env, base::android::GetApplicationContext(),
84 credentials.process_id, credentials.user_id) || 97 credentials.process_id, credentials.user_id) ||
85 content::CanUserConnectToDevTools(credentials); 98 content::CanUserConnectToDevTools(credentials);
86 } 99 }
87 100
88 class TargetBase : public content::DevToolsTarget { 101 class TargetBase : public content::DevToolsTarget {
(...skipping 14 matching lines...) Expand all
103 } 116 }
104 117
105 protected: 118 protected:
106 explicit TargetBase(WebContents* web_contents) 119 explicit TargetBase(WebContents* web_contents)
107 : title_(base::UTF16ToUTF8(web_contents->GetTitle())), 120 : title_(base::UTF16ToUTF8(web_contents->GetTitle())),
108 url_(web_contents->GetURL()), 121 url_(web_contents->GetURL()),
109 favicon_url_(GetFaviconURLForContents(web_contents)), 122 favicon_url_(GetFaviconURLForContents(web_contents)),
110 last_activity_time_(web_contents->GetLastActiveTime()) { 123 last_activity_time_(web_contents->GetLastActiveTime()) {
111 } 124 }
112 125
113 TargetBase(const base::string16& title, const GURL& url) 126 explicit TargetBase(scoped_refptr<DevToolsAgentHost> agent_host)
114 : title_(base::UTF16ToUTF8(title)), 127 : title_(agent_host->GetTitle()),
115 url_(url) 128 url_(agent_host->GetURL()),
116 {} 129 favicon_url_(GetFaviconURLForAgentHost(agent_host)),
130 last_activity_time_(GetLastActiveTimeForAgentHost(agent_host)) {
131 }
132
133 TargetBase(const std::string& title, const GURL& url)
134 : title_(title),
135 url_(url) {
136 }
117 137
118 private: 138 private:
119 const std::string title_; 139 const std::string title_;
120 const GURL url_; 140 const GURL url_;
121 const GURL favicon_url_; 141 const GURL favicon_url_;
122 const base::TimeTicks last_activity_time_; 142 const base::TimeTicks last_activity_time_;
123 }; 143 };
124 144
125 class TabTarget : public TargetBase { 145 class TabTarget : public TargetBase {
126 public: 146 public:
127 static TabTarget* CreateForWebContents(int tab_id, 147 static TabTarget* CreateForWebContents(int tab_id,
128 WebContents* web_contents) { 148 WebContents* web_contents) {
129 return new TabTarget(tab_id, web_contents); 149 return new TabTarget(tab_id, web_contents);
130 } 150 }
131 151
132 static TabTarget* CreateForUnloadedTab(int tab_id, 152 static TabTarget* CreateForUnloadedTab(int tab_id,
133 const base::string16& title, 153 const base::string16& title,
134 const GURL& url) { 154 const GURL& url) {
135 return new TabTarget(tab_id, title, url); 155 return new TabTarget(tab_id, title, url);
136 } 156 }
137 157
138 // content::DevToolsTarget implementation: 158 // content::DevToolsTarget implementation:
139 virtual std::string GetId() const OVERRIDE { 159 virtual std::string GetId() const OVERRIDE {
140 return base::IntToString(tab_id_); 160 return base::IntToString(tab_id_);
141 } 161 }
142 162
143 virtual std::string GetType() const OVERRIDE { return kTargetTypePage; } 163 virtual std::string GetType() const OVERRIDE {
164 return kTargetTypePage;
165 }
144 166
145 virtual bool IsAttached() const OVERRIDE { 167 virtual bool IsAttached() const OVERRIDE {
146 TabModel* model; 168 TabModel* model;
147 int index; 169 int index;
148 if (!FindTab(&model, &index)) 170 if (!FindTab(&model, &index))
149 return false; 171 return false;
150 WebContents* web_contents = model->GetWebContentsAt(index); 172 WebContents* web_contents = model->GetWebContentsAt(index);
151 if (!web_contents) 173 if (!web_contents)
152 return false; 174 return false;
153 return DevToolsAgentHost::IsDebuggerAttached(web_contents); 175 return DevToolsAgentHost::IsDebuggerAttached(web_contents);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 return true; 210 return true;
189 } 211 }
190 212
191 private: 213 private:
192 TabTarget(int tab_id, WebContents* web_contents) 214 TabTarget(int tab_id, WebContents* web_contents)
193 : TargetBase(web_contents), 215 : TargetBase(web_contents),
194 tab_id_(tab_id) { 216 tab_id_(tab_id) {
195 } 217 }
196 218
197 TabTarget(int tab_id, const base::string16& title, const GURL& url) 219 TabTarget(int tab_id, const base::string16& title, const GURL& url)
198 : TargetBase(title, url), 220 : TargetBase(base::UTF16ToUTF8(title), url),
199 tab_id_(tab_id) { 221 tab_id_(tab_id) {
200 } 222 }
201 223
202 bool FindTab(TabModel** model_result, int* index_result) const { 224 bool FindTab(TabModel** model_result, int* index_result) const {
203 for (TabModelList::const_iterator iter = TabModelList::begin(); 225 for (TabModelList::const_iterator iter = TabModelList::begin();
204 iter != TabModelList::end(); ++iter) { 226 iter != TabModelList::end(); ++iter) {
205 TabModel* model = *iter; 227 TabModel* model = *iter;
206 for (int i = 0; i < model->GetTabCount(); ++i) { 228 for (int i = 0; i < model->GetTabCount(); ++i) {
207 TabAndroid* tab = model->GetTabAt(i); 229 TabAndroid* tab = model->GetTabAt(i);
208 if (tab->GetAndroidId() == tab_id_) { 230 if (tab->GetAndroidId() == tab_id_) {
209 *model_result = model; 231 *model_result = model;
210 *index_result = i; 232 *index_result = i;
211 return true; 233 return true;
212 } 234 }
213 } 235 }
214 } 236 }
215 return false; 237 return false;
216 } 238 }
217 239
218 const int tab_id_; 240 const int tab_id_;
219 }; 241 };
220 242
221 class NonTabTarget : public TargetBase { 243 class NonTabTarget : public TargetBase {
222 public: 244 public:
223 explicit NonTabTarget(WebContents* web_contents) 245 explicit NonTabTarget(scoped_refptr<DevToolsAgentHost> agent_host)
224 : TargetBase(web_contents), 246 : TargetBase(agent_host),
225 agent_host_(DevToolsAgentHost::GetOrCreateFor(web_contents)) { 247 agent_host_(agent_host) {
226 } 248 }
227 249
228 // content::DevToolsTarget implementation: 250 // content::DevToolsTarget implementation:
229 virtual std::string GetId() const OVERRIDE { 251 virtual std::string GetId() const OVERRIDE {
230 return agent_host_->GetId(); 252 return agent_host_->GetId();
231 } 253 }
232 254
233 virtual std::string GetType() const OVERRIDE { 255 virtual std::string GetType() const OVERRIDE {
234 if (TabModelList::begin() == TabModelList::end()) { 256 std::string result = agent_host_->GetType();
235 // If there are no tab models we must be running in ChromeShell. 257 if (result == DevToolsAgentHost::kTypeWebContents)
236 // Return the 'page' target type for backwards compatibility. 258 result = kTargetTypePage;
237 return kTargetTypePage; 259 return result;
238 }
239 return kTargetTypeOther;
240 } 260 }
241 261
242 virtual bool IsAttached() const OVERRIDE { 262 virtual bool IsAttached() const OVERRIDE {
243 return agent_host_->IsAttached(); 263 return agent_host_->IsAttached();
244 } 264 }
245 265
246 virtual scoped_refptr<DevToolsAgentHost> GetAgentHost() const OVERRIDE { 266 virtual scoped_refptr<DevToolsAgentHost> GetAgentHost() const OVERRIDE {
247 return agent_host_; 267 return agent_host_;
248 } 268 }
249 269
250 virtual bool Activate() const OVERRIDE { 270 virtual bool Activate() const OVERRIDE {
251 WebContents* web_contents = agent_host_->GetWebContents(); 271 return agent_host_->Activate();
252 if (!web_contents)
253 return false;
254 web_contents->GetDelegate()->ActivateContents(web_contents);
255 return true;
256 } 272 }
257 273
258 virtual bool Close() const OVERRIDE { 274 virtual bool Close() const OVERRIDE {
259 WebContents* web_contents = agent_host_->GetWebContents(); 275 return agent_host_->Close();
260 if (!web_contents)
261 return false;
262 web_contents->GetRenderViewHost()->ClosePage();
263 return true;
264 } 276 }
265 277
266 private: 278 private:
267 scoped_refptr<DevToolsAgentHost> agent_host_; 279 scoped_refptr<DevToolsAgentHost> agent_host_;
268 }; 280 };
269 281
270 // Delegate implementation for the devtools http handler on android. A new 282 // Delegate implementation for the devtools http handler on android. A new
271 // instance of this gets created each time devtools is enabled. 283 // instance of this gets created each time devtools is enabled.
272 class DevToolsServerDelegate : public content::DevToolsHttpHandlerDelegate { 284 class DevToolsServerDelegate : public content::DevToolsHttpHandlerDelegate {
273 public: 285 public:
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 web_contents)); 356 web_contents));
345 } else { 357 } else {
346 targets.push_back(TabTarget::CreateForUnloadedTab(tab->GetAndroidId(), 358 targets.push_back(TabTarget::CreateForUnloadedTab(tab->GetAndroidId(),
347 tab->GetTitle(), 359 tab->GetTitle(),
348 tab->GetURL())); 360 tab->GetURL()));
349 } 361 }
350 } 362 }
351 } 363 }
352 364
353 // Add targets for WebContents not associated with any tabs. 365 // Add targets for WebContents not associated with any tabs.
354 std::vector<WebContents*> wc_list = 366 DevToolsAgentHost::List agents =
355 DevToolsAgentHost::GetInspectableWebContents(); 367 DevToolsAgentHost::GetOrCreateAll();
356 for (std::vector<WebContents*>::iterator it = wc_list.begin(); 368 for (DevToolsAgentHost::List::iterator it = agents.begin();
357 it != wc_list.end(); 369 it != agents.end(); ++it) {
358 ++it) { 370 if (WebContents* web_contents = (*it)->GetWebContents()) {
359 if (tab_web_contents.find(*it) != tab_web_contents.end()) 371 if (tab_web_contents.find(web_contents) != tab_web_contents.end())
360 continue; 372 continue;
373 }
361 targets.push_back(new NonTabTarget(*it)); 374 targets.push_back(new NonTabTarget(*it));
362 } 375 }
363 376
364 callback.Run(targets); 377 callback.Run(targets);
365 } 378 }
366 379
367 virtual scoped_ptr<net::StreamListenSocket> CreateSocketForTethering( 380 virtual scoped_ptr<net::StreamListenSocket> CreateSocketForTethering(
368 net::StreamListenSocket::Delegate* delegate, 381 net::StreamListenSocket::Delegate* delegate,
369 std::string* name) OVERRIDE { 382 std::string* name) OVERRIDE {
370 *name = base::StringPrintf( 383 *name = base::StringPrintf(
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 jlong server, 483 jlong server,
471 jboolean enabled, 484 jboolean enabled,
472 jboolean allow_debug_permission) { 485 jboolean allow_debug_permission) {
473 DevToolsServer* devtools_server = reinterpret_cast<DevToolsServer*>(server); 486 DevToolsServer* devtools_server = reinterpret_cast<DevToolsServer*>(server);
474 if (enabled) { 487 if (enabled) {
475 devtools_server->Start(allow_debug_permission); 488 devtools_server->Start(allow_debug_permission);
476 } else { 489 } else {
477 devtools_server->Stop(); 490 devtools_server->Stop();
478 } 491 }
479 } 492 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698