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

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

Issue 24995003: DevTools: Extract target discovery and manipulation from DevToolsHttpHandlerImpl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Extracted DevToolsTarget class Created 7 years, 2 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 | Annotate | Revision Log
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/browser/in_process_view_renderer.h" 7 #include "android_webview/browser/in_process_view_renderer.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
11 #include "base/strings/utf_string_conversions.h"
11 #include "base/values.h" 12 #include "base/values.h"
12 #include "content/public/browser/android/devtools_auth.h" 13 #include "content/public/browser/android/devtools_auth.h"
14 #include "content/public/browser/devtools_agent_host.h"
13 #include "content/public/browser/devtools_http_handler.h" 15 #include "content/public/browser/devtools_http_handler.h"
14 #include "content/public/browser/devtools_http_handler_delegate.h" 16 #include "content/public/browser/devtools_http_handler_delegate.h"
17 #include "content/public/browser/favicon_status.h"
18 #include "content/public/browser/navigation_entry.h"
15 #include "content/public/browser/web_contents.h" 19 #include "content/public/browser/web_contents.h"
16 #include "jni/AwDevToolsServer_jni.h" 20 #include "jni/AwDevToolsServer_jni.h"
21 #include "net/base/escape.h"
17 #include "net/socket/unix_domain_socket_posix.h" 22 #include "net/socket/unix_domain_socket_posix.h"
18 #include "webkit/common/user_agent/user_agent_util.h" 23 #include "webkit/common/user_agent/user_agent_util.h"
19 24
25 using content::DevToolsAgentHost;
26 using content::RenderViewHost;
27 using content::WebContents;
28
20 namespace { 29 namespace {
21 30
22 const char kFrontEndURL[] = 31 const char kFrontEndURL[] =
23 "http://chrome-devtools-frontend.appspot.com/serve_rev/%s/devtools.html"; 32 "http://chrome-devtools-frontend.appspot.com/serve_rev/%s/devtools.html";
24 const char kSocketNameFormat[] = "webview_devtools_remote_%d"; 33 const char kSocketNameFormat[] = "webview_devtools_remote_%d";
25 34
35 std::string GetViewDescription(WebContents* web_contents);
36
37 class Target : public content::DevToolsTarget {
38 public:
39 explicit Target(WebContents* web_contents);
40
41 virtual std::string GetId() const OVERRIDE { return id_; }
42 virtual std::string GetType() const OVERRIDE { return "page"; }
43 virtual std::string GetTitle() const OVERRIDE { return title_; }
44 virtual std::string GetDescription() const OVERRIDE { return description_; }
45 virtual GURL GetUrl() const OVERRIDE { return url_; }
46 virtual GURL GetFaviconUrl() const OVERRIDE { return GURL(); }
47 virtual base::TimeTicks GetLastActivityTime() const OVERRIDE {
48 return last_activity_time_;
49 }
50 virtual bool IsAttached() const OVERRIDE {
51 return agent_host_->IsAttached();
52 }
53 virtual scoped_refptr<DevToolsAgentHost> GetAgentHost() const OVERRIDE {
54 return agent_host_;
55 }
56 virtual bool Activate() const OVERRIDE { return false; }
57 virtual bool Close() const OVERRIDE { return false; }
58
59 private:
60 scoped_refptr<DevToolsAgentHost> agent_host_;
61 std::string id_;
62 std::string title_;
63 std::string description_;
64 GURL url_;
65 base::TimeTicks last_activity_time_;
66 };
67
68 Target::Target(WebContents* web_contents) {
69 agent_host_ =
70 DevToolsAgentHost::GetOrCreateFor(web_contents->GetRenderViewHost());
71 id_ = agent_host_->GetId();
72 description_ = GetViewDescription(web_contents);
73 title_ = UTF16ToUTF8(net::EscapeForHTML(web_contents->GetTitle()));
74 url_ = web_contents->GetURL();
75 last_activity_time_ = web_contents->GetLastSelectedTime();
76 }
77
26 // Delegate implementation for the devtools http handler for WebView. A new 78 // Delegate implementation for the devtools http handler for WebView. A new
27 // instance of this gets created each time web debugging is enabled. 79 // instance of this gets created each time web debugging is enabled.
28 class AwDevToolsServerDelegate : public content::DevToolsHttpHandlerDelegate { 80 class AwDevToolsServerDelegate : public content::DevToolsHttpHandlerDelegate {
29 public: 81 public:
30 AwDevToolsServerDelegate() {} 82 AwDevToolsServerDelegate() {}
31 virtual ~AwDevToolsServerDelegate() {} 83 virtual ~AwDevToolsServerDelegate() {}
32 84
33 // DevToolsHttpProtocolHandler::Delegate overrides. 85 // DevToolsHttpProtocolHandler::Delegate overrides.
34 virtual std::string GetDiscoveryPageHTML() OVERRIDE; 86 virtual std::string GetDiscoveryPageHTML() OVERRIDE;
35 87
36 virtual bool BundlesFrontendResources() OVERRIDE { 88 virtual bool BundlesFrontendResources() OVERRIDE {
37 return false; 89 return false;
38 } 90 }
39 91
40 virtual base::FilePath GetDebugFrontendDir() OVERRIDE { 92 virtual base::FilePath GetDebugFrontendDir() OVERRIDE {
41 return base::FilePath(); 93 return base::FilePath();
42 } 94 }
43 95
44 virtual std::string GetPageThumbnailData(const GURL&) OVERRIDE { 96 virtual std::string GetPageThumbnailData(const GURL&) OVERRIDE {
45 return ""; 97 return "";
46 } 98 }
47 99
48 virtual content::RenderViewHost* CreateNewTarget() OVERRIDE { 100 virtual scoped_refptr<content::DevToolsTarget> CreateNewTarget() OVERRIDE {
49 return NULL; 101 return NULL;
50 } 102 }
51 103
52 virtual TargetType GetTargetType(content::RenderViewHost*) OVERRIDE { 104 virtual void EnumerateTargets(TargetCallback callback) OVERRIDE {
53 return kTargetTypeTab; 105 TargetList targets;
106 std::vector<RenderViewHost*> rvh_list =
107 DevToolsAgentHost::GetValidRenderViewHosts();
108 for (std::vector<RenderViewHost*>::iterator it = rvh_list.begin();
109 it != rvh_list.end(); ++it) {
110 WebContents* web_contents = WebContents::FromRenderViewHost(*it);
111 if (web_contents)
112 targets.push_back(new Target(web_contents));
113 }
114 callback.Run(targets);
54 } 115 }
55 116
56 virtual std::string GetViewDescription(content::RenderViewHost*) OVERRIDE;
57
58 virtual scoped_ptr<net::StreamListenSocket> CreateSocketForTethering( 117 virtual scoped_ptr<net::StreamListenSocket> CreateSocketForTethering(
59 net::StreamListenSocket::Delegate* delegate, 118 net::StreamListenSocket::Delegate* delegate,
60 std::string* name) OVERRIDE { 119 std::string* name) OVERRIDE {
61 return scoped_ptr<net::StreamListenSocket>(); 120 return scoped_ptr<net::StreamListenSocket>();
62 } 121 }
63 122
64 private: 123 private:
65 DISALLOW_COPY_AND_ASSIGN(AwDevToolsServerDelegate); 124 DISALLOW_COPY_AND_ASSIGN(AwDevToolsServerDelegate);
66 }; 125 };
67 126
68 127
69 std::string AwDevToolsServerDelegate::GetDiscoveryPageHTML() { 128 std::string AwDevToolsServerDelegate::GetDiscoveryPageHTML() {
70 const char html[] = 129 const char html[] =
71 "<html>" 130 "<html>"
72 "<head><title>WebView remote debugging</title></head>" 131 "<head><title>WebView remote debugging</title></head>"
73 "<body>Please use <a href=\'chrome://inspect\'>chrome://inspect</a>" 132 "<body>Please use <a href=\'chrome://inspect\'>chrome://inspect</a>"
74 "</body>" 133 "</body>"
75 "</html>"; 134 "</html>";
76 return html; 135 return html;
77 } 136 }
78 137
79 std::string AwDevToolsServerDelegate::GetViewDescription( 138 std::string GetViewDescription(WebContents* web_contents) {
80 content::RenderViewHost* rvh) {
81 content::WebContents* web_contents =
82 content::WebContents::FromRenderViewHost(rvh);
83 if (!web_contents) return "";
84
85 android_webview::BrowserViewRenderer* bvr 139 android_webview::BrowserViewRenderer* bvr
86 = android_webview::InProcessViewRenderer::FromWebContents(web_contents); 140 = android_webview::InProcessViewRenderer::FromWebContents(web_contents);
87 if (!bvr) return ""; 141 if (!bvr) return "";
88 base::DictionaryValue description; 142 base::DictionaryValue description;
89 description.SetBoolean("attached", bvr->IsAttachedToWindow()); 143 description.SetBoolean("attached", bvr->IsAttachedToWindow());
90 description.SetBoolean("visible", bvr->IsVisible()); 144 description.SetBoolean("visible", bvr->IsVisible());
91 gfx::Rect screen_rect = bvr->GetScreenRect(); 145 gfx::Rect screen_rect = bvr->GetScreenRect();
92 description.SetInteger("screenX", screen_rect.x()); 146 description.SetInteger("screenX", screen_rect.x());
93 description.SetInteger("screenY", screen_rect.y()); 147 description.SetInteger("screenY", screen_rect.y());
94 description.SetBoolean("empty", screen_rect.size().IsEmpty()); 148 description.SetBoolean("empty", screen_rect.size().IsEmpty());
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 AwDevToolsServer* devtools_server = 215 AwDevToolsServer* devtools_server =
162 reinterpret_cast<AwDevToolsServer*>(server); 216 reinterpret_cast<AwDevToolsServer*>(server);
163 if (enabled) { 217 if (enabled) {
164 devtools_server->Start(); 218 devtools_server->Start();
165 } else { 219 } else {
166 devtools_server->Stop(); 220 devtools_server->Stop();
167 } 221 }
168 } 222 }
169 223
170 } // namespace android_webview 224 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698