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

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: Made RVDTAH::GetURL consistent with tests 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 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
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
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()) {
235 // If there are no tab models we must be running in ChromeShell. 259 case DevToolsAgentHost::TYPE_WEB_CONTENTS:
236 // Return the 'page' target type for backwards compatibility. 260 if (TabModelList::begin() == TabModelList::end()) {
237 return kTargetTypePage; 261 // If there are no tab models we must be running in ChromeShell.
262 // Return the 'page' target type for backwards compatibility.
263 return kTargetTypePage;
264 }
265 break;
266 case DevToolsAgentHost::TYPE_SERVICE_WORKER:
267 return kTargetTypeServiceWorker;
268 default:
269 break;
238 } 270 }
239 return kTargetTypeOther; 271 return kTargetTypeOther;
240 } 272 }
241 273
242 virtual bool IsAttached() const OVERRIDE { 274 virtual bool IsAttached() const OVERRIDE {
243 return agent_host_->IsAttached(); 275 return agent_host_->IsAttached();
244 } 276 }
245 277
246 virtual scoped_refptr<DevToolsAgentHost> GetAgentHost() const OVERRIDE { 278 virtual scoped_refptr<DevToolsAgentHost> GetAgentHost() const OVERRIDE {
247 return agent_host_; 279 return agent_host_;
248 } 280 }
249 281
250 virtual bool Activate() const OVERRIDE { 282 virtual bool Activate() const OVERRIDE {
251 WebContents* web_contents = agent_host_->GetWebContents(); 283 return agent_host_->Activate();
252 if (!web_contents)
253 return false;
254 web_contents->GetDelegate()->ActivateContents(web_contents);
255 return true;
256 } 284 }
257 285
258 virtual bool Close() const OVERRIDE { 286 virtual bool Close() const OVERRIDE {
259 WebContents* web_contents = agent_host_->GetWebContents(); 287 return agent_host_->Close();
260 if (!web_contents)
261 return false;
262 web_contents->GetRenderViewHost()->ClosePage();
263 return true;
264 } 288 }
265 289
266 private: 290 private:
267 scoped_refptr<DevToolsAgentHost> agent_host_; 291 scoped_refptr<DevToolsAgentHost> agent_host_;
268 }; 292 };
269 293
270 // Delegate implementation for the devtools http handler on android. A new 294 // Delegate implementation for the devtools http handler on android. A new
271 // instance of this gets created each time devtools is enabled. 295 // instance of this gets created each time devtools is enabled.
272 class DevToolsServerDelegate : public content::DevToolsHttpHandlerDelegate { 296 class DevToolsServerDelegate : public content::DevToolsHttpHandlerDelegate {
273 public: 297 public:
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 web_contents)); 368 web_contents));
345 } else { 369 } else {
346 targets.push_back(TabTarget::CreateForUnloadedTab(tab->GetAndroidId(), 370 targets.push_back(TabTarget::CreateForUnloadedTab(tab->GetAndroidId(),
347 tab->GetTitle(), 371 tab->GetTitle(),
348 tab->GetURL())); 372 tab->GetURL()));
349 } 373 }
350 } 374 }
351 } 375 }
352 376
353 // Add targets for WebContents not associated with any tabs. 377 // Add targets for WebContents not associated with any tabs.
354 std::vector<WebContents*> wc_list = 378 DevToolsAgentHost::List agents =
355 DevToolsAgentHost::GetInspectableWebContents(); 379 DevToolsAgentHost::GetOrCreateAll();
356 for (std::vector<WebContents*>::iterator it = wc_list.begin(); 380 for (DevToolsAgentHost::List::iterator it = agents.begin();
357 it != wc_list.end(); 381 it != agents.end(); ++it) {
358 ++it) { 382 if (WebContents* web_contents = (*it)->GetWebContents()) {
359 if (tab_web_contents.find(*it) != tab_web_contents.end()) 383 if (tab_web_contents.find(web_contents) != tab_web_contents.end())
360 continue; 384 continue;
385 }
361 targets.push_back(new NonTabTarget(*it)); 386 targets.push_back(new NonTabTarget(*it));
362 } 387 }
363 388
364 callback.Run(targets); 389 callback.Run(targets);
365 } 390 }
366 391
367 virtual scoped_ptr<net::StreamListenSocket> CreateSocketForTethering( 392 virtual scoped_ptr<net::StreamListenSocket> CreateSocketForTethering(
368 net::StreamListenSocket::Delegate* delegate, 393 net::StreamListenSocket::Delegate* delegate,
369 std::string* name) OVERRIDE { 394 std::string* name) OVERRIDE {
370 *name = base::StringPrintf( 395 *name = base::StringPrintf(
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 jlong server, 495 jlong server,
471 jboolean enabled, 496 jboolean enabled,
472 jboolean allow_debug_permission) { 497 jboolean allow_debug_permission) {
473 DevToolsServer* devtools_server = reinterpret_cast<DevToolsServer*>(server); 498 DevToolsServer* devtools_server = reinterpret_cast<DevToolsServer*>(server);
474 if (enabled) { 499 if (enabled) {
475 devtools_server->Start(allow_debug_permission); 500 devtools_server->Start(allow_debug_permission);
476 } else { 501 } else {
477 devtools_server->Stop(); 502 devtools_server->Stop();
478 } 503 }
479 } 504 }
OLDNEW
« no previous file with comments | « android_webview/native/aw_dev_tools_server.cc ('k') | chrome/browser/devtools/devtools_target_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698