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

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

Issue 349033009: DevTools: Added service workers to chrome://inspect/#devices (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added GetOrCreateAllHosts Created 6 years, 5 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 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_dev_tools_server.h"
6 6
7 #include "android_webview/native/aw_contents.h" 7 #include "android_webview/native/aw_contents.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
(...skipping 19 matching lines...) Expand all
30 const char kFrontEndURL[] = 30 const char kFrontEndURL[] =
31 "http://chrome-devtools-frontend.appspot.com/serve_rev/%s/devtools.html"; 31 "http://chrome-devtools-frontend.appspot.com/serve_rev/%s/devtools.html";
32 const char kSocketNameFormat[] = "webview_devtools_remote_%d"; 32 const char kSocketNameFormat[] = "webview_devtools_remote_%d";
33 33
34 const char kTargetTypePage[] = "page"; 34 const char kTargetTypePage[] = "page";
35 35
36 std::string GetViewDescription(WebContents* web_contents); 36 std::string GetViewDescription(WebContents* web_contents);
37 37
38 class Target : public content::DevToolsTarget { 38 class Target : public content::DevToolsTarget {
39 public: 39 public:
40 explicit Target(WebContents* web_contents); 40 explicit Target(scoped_refptr<DevToolsAgentHost> agent_host);
41 41
42 virtual std::string GetId() const OVERRIDE { return id_; } 42 virtual std::string GetId() const OVERRIDE { return id_; }
43 virtual std::string GetParentId() const OVERRIDE { return std::string(); } 43 virtual std::string GetParentId() const OVERRIDE { return std::string(); }
44 virtual std::string GetType() const OVERRIDE { return kTargetTypePage; } 44 virtual std::string GetType() const OVERRIDE { return kTargetTypePage; }
45 virtual std::string GetTitle() const OVERRIDE { return title_; } 45 virtual std::string GetTitle() const OVERRIDE { return title_; }
46 virtual std::string GetDescription() const OVERRIDE { return description_; } 46 virtual std::string GetDescription() const OVERRIDE { return description_; }
47 virtual GURL GetURL() const OVERRIDE { return url_; } 47 virtual GURL GetURL() const OVERRIDE { return url_; }
48 virtual GURL GetFaviconURL() const OVERRIDE { return GURL(); } 48 virtual GURL GetFaviconURL() const OVERRIDE { return GURL(); }
49 virtual base::TimeTicks GetLastActivityTime() const OVERRIDE { 49 virtual base::TimeTicks GetLastActivityTime() const OVERRIDE {
50 return last_activity_time_; 50 return last_activity_time_;
51 } 51 }
52 virtual bool IsAttached() const OVERRIDE { 52 virtual bool IsAttached() const OVERRIDE {
53 return agent_host_->IsAttached(); 53 return agent_host_->IsAttached();
54 } 54 }
55 virtual scoped_refptr<DevToolsAgentHost> GetAgentHost() const OVERRIDE { 55 virtual scoped_refptr<DevToolsAgentHost> GetAgentHost() const OVERRIDE {
56 return agent_host_; 56 return agent_host_;
57 } 57 }
58 virtual bool Activate() const OVERRIDE { return false; } 58 virtual bool Activate() const OVERRIDE { return false; }
59 virtual bool Close() const OVERRIDE { return false; } 59 virtual bool Close() const OVERRIDE { return false; }
60 60
61 private: 61 private:
62 scoped_refptr<DevToolsAgentHost> agent_host_; 62 scoped_refptr<DevToolsAgentHost> agent_host_;
63 std::string id_; 63 std::string id_;
64 std::string title_; 64 std::string title_;
65 std::string description_; 65 std::string description_;
66 GURL url_; 66 GURL url_;
67 base::TimeTicks last_activity_time_; 67 base::TimeTicks last_activity_time_;
68 }; 68 };
69 69
70 Target::Target(WebContents* web_contents) { 70 Target::Target(scoped_refptr<DevToolsAgentHost> agent_host)
71 agent_host_ = 71 : agent_host_(agent_host),
72 DevToolsAgentHost::GetOrCreateFor(web_contents->GetRenderViewHost()); 72 id_(agent_host_->GetId()),
73 id_ = agent_host_->GetId(); 73 url_(agent_host_->GetURL()) {
74 description_ = GetViewDescription(web_contents); 74 if (RenderViewHost* rvh = agent_host_->GetRenderViewHost()) {
dgozman 2014/07/14 11:17:24 Targets without RVH should get informative title (
vkuzkokov 2014/07/14 15:31:33 This should be done on client.
75 title_ = base::UTF16ToUTF8(web_contents->GetTitle()); 75 if (WebContents* web_contents = WebContents::FromRenderViewHost(rvh)) {
76 url_ = web_contents->GetURL(); 76 description_ = GetViewDescription(web_contents);
77 last_activity_time_ = web_contents->GetLastActiveTime(); 77 title_ = base::UTF16ToUTF8(web_contents->GetTitle());
78 last_activity_time_ = web_contents->GetLastActiveTime();
79 }
80 }
78 } 81 }
79 82
80 // Delegate implementation for the devtools http handler for WebView. A new 83 // Delegate implementation for the devtools http handler for WebView. A new
81 // instance of this gets created each time web debugging is enabled. 84 // instance of this gets created each time web debugging is enabled.
82 class AwDevToolsServerDelegate : public content::DevToolsHttpHandlerDelegate { 85 class AwDevToolsServerDelegate : public content::DevToolsHttpHandlerDelegate {
83 public: 86 public:
84 AwDevToolsServerDelegate() {} 87 AwDevToolsServerDelegate() {}
85 virtual ~AwDevToolsServerDelegate() {} 88 virtual ~AwDevToolsServerDelegate() {}
86 89
87 // DevToolsHttpProtocolHandler::Delegate overrides. 90 // DevToolsHttpProtocolHandler::Delegate overrides.
88 virtual std::string GetDiscoveryPageHTML() OVERRIDE; 91 virtual std::string GetDiscoveryPageHTML() OVERRIDE;
89 92
90 virtual bool BundlesFrontendResources() OVERRIDE { 93 virtual bool BundlesFrontendResources() OVERRIDE {
91 return false; 94 return false;
92 } 95 }
93 96
94 virtual base::FilePath GetDebugFrontendDir() OVERRIDE { 97 virtual base::FilePath GetDebugFrontendDir() OVERRIDE {
95 return base::FilePath(); 98 return base::FilePath();
96 } 99 }
97 100
98 virtual std::string GetPageThumbnailData(const GURL&) OVERRIDE { 101 virtual std::string GetPageThumbnailData(const GURL&) OVERRIDE {
99 return ""; 102 return "";
100 } 103 }
101 104
102 virtual scoped_ptr<content::DevToolsTarget> CreateNewTarget( 105 virtual scoped_ptr<content::DevToolsTarget> CreateNewTarget(
103 const GURL&) OVERRIDE { 106 const GURL&) OVERRIDE {
104 return scoped_ptr<content::DevToolsTarget>(); 107 return scoped_ptr<content::DevToolsTarget>();
105 } 108 }
106 109
107 virtual void EnumerateTargets(TargetCallback callback) OVERRIDE { 110 virtual void EnumerateTargets(TargetCallback callback) OVERRIDE;
108 TargetList targets;
109 std::vector<RenderViewHost*> rvh_list =
110 DevToolsAgentHost::GetValidRenderViewHosts();
111 for (std::vector<RenderViewHost*>::iterator it = rvh_list.begin();
112 it != rvh_list.end(); ++it) {
113 WebContents* web_contents = WebContents::FromRenderViewHost(*it);
114 if (web_contents)
115 targets.push_back(new Target(web_contents));
116 }
117 callback.Run(targets);
118 }
119 111
120 virtual scoped_ptr<net::StreamListenSocket> CreateSocketForTethering( 112 virtual scoped_ptr<net::StreamListenSocket> CreateSocketForTethering(
121 net::StreamListenSocket::Delegate* delegate, 113 net::StreamListenSocket::Delegate* delegate,
122 std::string* name) OVERRIDE { 114 std::string* name) OVERRIDE {
123 return scoped_ptr<net::StreamListenSocket>(); 115 return scoped_ptr<net::StreamListenSocket>();
124 } 116 }
125 117
126 private: 118 private:
127 DISALLOW_COPY_AND_ASSIGN(AwDevToolsServerDelegate); 119 DISALLOW_COPY_AND_ASSIGN(AwDevToolsServerDelegate);
128 }; 120 };
129 121
122 static void CreateTargets(
123 const AwDevToolsServerDelegate::TargetCallback& callback,
124 const DevToolsAgentHost::List& agents) {
125 AwDevToolsServerDelegate::TargetList targets;
126 for (DevToolsAgentHost::List::const_iterator it = agents.begin();
127 it != agents.end(); ++it) {
128 targets.push_back(new Target(*it));
129 }
130 callback.Run(targets);
131 }
132
133 void AwDevToolsServerDelegate::EnumerateTargets(TargetCallback callback) {
134 DevToolsAgentHost::GetOrCreateAllHosts(base::Bind(&CreateTargets, callback));
135 }
130 136
131 std::string AwDevToolsServerDelegate::GetDiscoveryPageHTML() { 137 std::string AwDevToolsServerDelegate::GetDiscoveryPageHTML() {
132 const char html[] = 138 const char html[] =
133 "<html>" 139 "<html>"
134 "<head><title>WebView remote debugging</title></head>" 140 "<head><title>WebView remote debugging</title></head>"
135 "<body>Please use <a href=\'chrome://inspect\'>chrome://inspect</a>" 141 "<body>Please use <a href=\'chrome://inspect\'>chrome://inspect</a>"
136 "</body>" 142 "</body>"
137 "</html>"; 143 "</html>";
138 return html; 144 return html;
139 } 145 }
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 AwDevToolsServer* devtools_server = 225 AwDevToolsServer* devtools_server =
220 reinterpret_cast<AwDevToolsServer*>(server); 226 reinterpret_cast<AwDevToolsServer*>(server);
221 if (enabled) { 227 if (enabled) {
222 devtools_server->Start(); 228 devtools_server->Start();
223 } else { 229 } else {
224 devtools_server->Stop(); 230 devtools_server->Stop();
225 } 231 }
226 } 232 }
227 233
228 } // namespace android_webview 234 } // namespace android_webview
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/android/dev_tools_server.cc » ('j') | chrome/browser/devtools/devtools_target_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698