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

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: Fixed clang compile and a minor bug 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"
mnaganov (inactive) 2013/10/01 16:15:02 Do we really need these two includes? I can't see
Vladislav Kaznacheev 2013/10/02 10:28:29 We do not. That was copypasta. On 2013/10/01 16:1
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 const char kTargetTypePage[] = "page";
36
37 std::string GetViewDescription(WebContents* web_contents);
38
39 class Target : public content::DevToolsTarget {
40 public:
41 explicit Target(WebContents* web_contents);
42
43 virtual std::string GetId() const OVERRIDE { return id_; }
44 virtual std::string GetType() const OVERRIDE { return kTargetTypePage; }
45 virtual std::string GetTitle() const OVERRIDE { return title_; }
46 virtual std::string GetDescription() const OVERRIDE { return description_; }
47 virtual GURL GetUrl() const OVERRIDE { return url_; }
48 virtual GURL GetFaviconUrl() const OVERRIDE { return GURL(); }
49 virtual base::TimeTicks GetLastActivityTime() const OVERRIDE {
50 return last_activity_time_;
51 }
52 virtual bool IsAttached() const OVERRIDE {
53 return agent_host_->IsAttached();
54 }
55 virtual scoped_refptr<DevToolsAgentHost> GetAgentHost() const OVERRIDE {
56 return agent_host_;
57 }
58 virtual bool Activate() const OVERRIDE { return false; }
59 virtual bool Close() const OVERRIDE { return false; }
60
61 private:
62 virtual ~Target() {}
63
64 scoped_refptr<DevToolsAgentHost> agent_host_;
65 std::string id_;
66 std::string title_;
67 std::string description_;
68 GURL url_;
69 base::TimeTicks last_activity_time_;
70 };
71
72 Target::Target(WebContents* web_contents) {
73 agent_host_ =
74 DevToolsAgentHost::GetOrCreateFor(web_contents->GetRenderViewHost());
75 id_ = agent_host_->GetId();
76 description_ = GetViewDescription(web_contents);
77 title_ = UTF16ToUTF8(net::EscapeForHTML(web_contents->GetTitle()));
78 url_ = web_contents->GetURL();
79 last_activity_time_ = web_contents->GetLastSelectedTime();
80 }
81
26 // Delegate implementation for the devtools http handler for WebView. A new 82 // Delegate implementation for the devtools http handler for WebView. A new
27 // instance of this gets created each time web debugging is enabled. 83 // instance of this gets created each time web debugging is enabled.
28 class AwDevToolsServerDelegate : public content::DevToolsHttpHandlerDelegate { 84 class AwDevToolsServerDelegate : public content::DevToolsHttpHandlerDelegate {
29 public: 85 public:
30 AwDevToolsServerDelegate() {} 86 AwDevToolsServerDelegate() {}
31 virtual ~AwDevToolsServerDelegate() {} 87 virtual ~AwDevToolsServerDelegate() {}
32 88
33 // DevToolsHttpProtocolHandler::Delegate overrides. 89 // DevToolsHttpProtocolHandler::Delegate overrides.
34 virtual std::string GetDiscoveryPageHTML() OVERRIDE; 90 virtual std::string GetDiscoveryPageHTML() OVERRIDE;
35 91
36 virtual bool BundlesFrontendResources() OVERRIDE { 92 virtual bool BundlesFrontendResources() OVERRIDE {
37 return false; 93 return false;
38 } 94 }
39 95
40 virtual base::FilePath GetDebugFrontendDir() OVERRIDE { 96 virtual base::FilePath GetDebugFrontendDir() OVERRIDE {
41 return base::FilePath(); 97 return base::FilePath();
42 } 98 }
43 99
44 virtual std::string GetPageThumbnailData(const GURL&) OVERRIDE { 100 virtual std::string GetPageThumbnailData(const GURL&) OVERRIDE {
45 return ""; 101 return "";
46 } 102 }
47 103
48 virtual content::RenderViewHost* CreateNewTarget() OVERRIDE { 104 virtual scoped_refptr<content::DevToolsTarget> CreateNewTarget() OVERRIDE {
49 return NULL; 105 return NULL;
50 } 106 }
51 107
52 virtual TargetType GetTargetType(content::RenderViewHost*) OVERRIDE { 108 virtual void EnumerateTargets(TargetCallback callback) OVERRIDE {
53 return kTargetTypeTab; 109 TargetList targets;
110 std::vector<RenderViewHost*> rvh_list =
111 DevToolsAgentHost::GetValidRenderViewHosts();
112 for (std::vector<RenderViewHost*>::iterator it = rvh_list.begin();
113 it != rvh_list.end(); ++it) {
114 WebContents* web_contents = WebContents::FromRenderViewHost(*it);
115 if (web_contents)
116 targets.push_back(new Target(web_contents));
117 }
118 callback.Run(targets);
54 } 119 }
55 120
56 virtual std::string GetViewDescription(content::RenderViewHost*) OVERRIDE;
57
58 virtual scoped_ptr<net::StreamListenSocket> CreateSocketForTethering( 121 virtual scoped_ptr<net::StreamListenSocket> CreateSocketForTethering(
59 net::StreamListenSocket::Delegate* delegate, 122 net::StreamListenSocket::Delegate* delegate,
60 std::string* name) OVERRIDE { 123 std::string* name) OVERRIDE {
61 return scoped_ptr<net::StreamListenSocket>(); 124 return scoped_ptr<net::StreamListenSocket>();
62 } 125 }
63 126
64 private: 127 private:
65 DISALLOW_COPY_AND_ASSIGN(AwDevToolsServerDelegate); 128 DISALLOW_COPY_AND_ASSIGN(AwDevToolsServerDelegate);
66 }; 129 };
67 130
68 131
69 std::string AwDevToolsServerDelegate::GetDiscoveryPageHTML() { 132 std::string AwDevToolsServerDelegate::GetDiscoveryPageHTML() {
70 const char html[] = 133 const char html[] =
71 "<html>" 134 "<html>"
72 "<head><title>WebView remote debugging</title></head>" 135 "<head><title>WebView remote debugging</title></head>"
73 "<body>Please use <a href=\'chrome://inspect\'>chrome://inspect</a>" 136 "<body>Please use <a href=\'chrome://inspect\'>chrome://inspect</a>"
74 "</body>" 137 "</body>"
75 "</html>"; 138 "</html>";
76 return html; 139 return html;
77 } 140 }
78 141
79 std::string AwDevToolsServerDelegate::GetViewDescription( 142 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 143 android_webview::BrowserViewRenderer* bvr
86 = android_webview::InProcessViewRenderer::FromWebContents(web_contents); 144 = android_webview::InProcessViewRenderer::FromWebContents(web_contents);
87 if (!bvr) return ""; 145 if (!bvr) return "";
88 base::DictionaryValue description; 146 base::DictionaryValue description;
89 description.SetBoolean("attached", bvr->IsAttachedToWindow()); 147 description.SetBoolean("attached", bvr->IsAttachedToWindow());
90 description.SetBoolean("visible", bvr->IsVisible()); 148 description.SetBoolean("visible", bvr->IsVisible());
91 gfx::Rect screen_rect = bvr->GetScreenRect(); 149 gfx::Rect screen_rect = bvr->GetScreenRect();
92 description.SetInteger("screenX", screen_rect.x()); 150 description.SetInteger("screenX", screen_rect.x());
93 description.SetInteger("screenY", screen_rect.y()); 151 description.SetInteger("screenY", screen_rect.y());
94 description.SetBoolean("empty", screen_rect.size().IsEmpty()); 152 description.SetBoolean("empty", screen_rect.size().IsEmpty());
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 AwDevToolsServer* devtools_server = 219 AwDevToolsServer* devtools_server =
162 reinterpret_cast<AwDevToolsServer*>(server); 220 reinterpret_cast<AwDevToolsServer*>(server);
163 if (enabled) { 221 if (enabled) {
164 devtools_server->Start(); 222 devtools_server->Start();
165 } else { 223 } else {
166 devtools_server->Stop(); 224 devtools_server->Stop();
167 } 225 }
168 } 226 }
169 227
170 } // namespace android_webview 228 } // namespace android_webview
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/android/dev_tools_server.cc » ('j') | content/public/browser/devtools_http_handler_delegate.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698