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

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: Added Android implementations 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/values.h" 11 #include "base/values.h"
12 #include "content/public/browser/android/devtools_auth.h" 12 #include "content/public/browser/android/devtools_auth.h"
13 #include "content/public/browser/devtools_agent_host.h"
13 #include "content/public/browser/devtools_http_handler.h" 14 #include "content/public/browser/devtools_http_handler.h"
14 #include "content/public/browser/devtools_http_handler_delegate.h" 15 #include "content/public/browser/devtools_http_handler_delegate.h"
16 #include "content/public/browser/devtools_target_descriptor.h"
15 #include "content/public/browser/web_contents.h" 17 #include "content/public/browser/web_contents.h"
16 #include "jni/AwDevToolsServer_jni.h" 18 #include "jni/AwDevToolsServer_jni.h"
17 #include "net/socket/unix_domain_socket_posix.h" 19 #include "net/socket/unix_domain_socket_posix.h"
18 #include "webkit/common/user_agent/user_agent_util.h" 20 #include "webkit/common/user_agent/user_agent_util.h"
19 21
22 using content::DevToolsAgentHost;
23 using content::RenderViewHost;
24 using content::WebContents;
25
20 namespace { 26 namespace {
21 27
22 const char kFrontEndURL[] = 28 const char kFrontEndURL[] =
23 "http://chrome-devtools-frontend.appspot.com/serve_rev/%s/devtools.html"; 29 "http://chrome-devtools-frontend.appspot.com/serve_rev/%s/devtools.html";
24 const char kSocketNameFormat[] = "webview_devtools_remote_%d"; 30 const char kSocketNameFormat[] = "webview_devtools_remote_%d";
25 31
26 // Delegate implementation for the devtools http handler for WebView. A new 32 // Delegate implementation for the devtools http handler for WebView. A new
27 // instance of this gets created each time web debugging is enabled. 33 // instance of this gets created each time web debugging is enabled.
28 class AwDevToolsServerDelegate : public content::DevToolsHttpHandlerDelegate { 34 class AwDevToolsServerDelegate : public content::DevToolsHttpHandlerDelegate {
29 public: 35 public:
30 AwDevToolsServerDelegate() {} 36 AwDevToolsServerDelegate() {}
31 virtual ~AwDevToolsServerDelegate() {} 37 virtual ~AwDevToolsServerDelegate() {}
32 38
33 // DevToolsHttpProtocolHandler::Delegate overrides. 39 // DevToolsHttpProtocolHandler::Delegate overrides.
34 virtual std::string GetDiscoveryPageHTML() OVERRIDE; 40 virtual std::string GetDiscoveryPageHTML() OVERRIDE;
35 41
36 virtual bool BundlesFrontendResources() OVERRIDE { 42 virtual bool BundlesFrontendResources() OVERRIDE {
37 return false; 43 return false;
38 } 44 }
39 45
40 virtual base::FilePath GetDebugFrontendDir() OVERRIDE { 46 virtual base::FilePath GetDebugFrontendDir() OVERRIDE {
41 return base::FilePath(); 47 return base::FilePath();
42 } 48 }
43 49
44 virtual std::string GetPageThumbnailData(const GURL&) OVERRIDE { 50 virtual bool SupportsPageThumbnails() OVERRIDE {
51 return false;
52 }
53
54 virtual std::string GetPageThumbnailData(const std::string&) OVERRIDE {
45 return ""; 55 return "";
46 } 56 }
47 57
48 virtual content::RenderViewHost* CreateNewTarget() OVERRIDE { 58 virtual Target* CreateNewTarget() OVERRIDE {
49 return NULL; 59 return NULL;
50 } 60 }
51 61
52 virtual TargetType GetTargetType(content::RenderViewHost*) OVERRIDE { 62 std::string GetViewDescription(WebContents* web_contents);
53 return kTargetTypeTab; 63
64 virtual bool ActivateTarget(const std::string& id) OVERRIDE {
65 return false;
54 } 66 }
55 67
56 virtual std::string GetViewDescription(content::RenderViewHost*) OVERRIDE; 68 virtual bool CloseTarget(const std::string& id) OVERRIDE {
69 return false;
70 }
71
72 virtual scoped_refptr<DevToolsAgentHost> GetAgentHost(
73 const std::string& id) OVERRIDE {
74 return DevToolsAgentHost::GetForId(id);
75 }
76
77 virtual void RequestTargets(TargetCallback callback) OVERRIDE {
78 TargetList targets;
79 std::vector<RenderViewHost*> rvh_list =
80 DevToolsAgentHost::GetValidRenderViewHosts();
81 for (std::vector<RenderViewHost*>::iterator it = rvh_list.begin();
82 it != rvh_list.end(); ++it) {
83 WebContents* web_contents = WebContents::FromRenderViewHost(*it);
84 if (!web_contents)
85 continue;
86 Target* target = Target::FromWebContents(web_contents);
87 target->OverrideDescription(GetViewDescription(web_contents));
88 targets.push_back(target);
89 }
90 callback.Run(targets);
91 }
57 92
58 virtual scoped_ptr<net::StreamListenSocket> CreateSocketForTethering( 93 virtual scoped_ptr<net::StreamListenSocket> CreateSocketForTethering(
59 net::StreamListenSocket::Delegate* delegate, 94 net::StreamListenSocket::Delegate* delegate,
60 std::string* name) OVERRIDE { 95 std::string* name) OVERRIDE {
61 return scoped_ptr<net::StreamListenSocket>(); 96 return scoped_ptr<net::StreamListenSocket>();
62 } 97 }
63 98
64 private: 99 private:
65 DISALLOW_COPY_AND_ASSIGN(AwDevToolsServerDelegate); 100 DISALLOW_COPY_AND_ASSIGN(AwDevToolsServerDelegate);
66 }; 101 };
67 102
68 103
69 std::string AwDevToolsServerDelegate::GetDiscoveryPageHTML() { 104 std::string AwDevToolsServerDelegate::GetDiscoveryPageHTML() {
70 const char html[] = 105 const char html[] =
71 "<html>" 106 "<html>"
72 "<head><title>WebView remote debugging</title></head>" 107 "<head><title>WebView remote debugging</title></head>"
73 "<body>Please use <a href=\'chrome://inspect\'>chrome://inspect</a>" 108 "<body>Please use <a href=\'chrome://inspect\'>chrome://inspect</a>"
74 "</body>" 109 "</body>"
75 "</html>"; 110 "</html>";
76 return html; 111 return html;
77 } 112 }
78 113
79 std::string AwDevToolsServerDelegate::GetViewDescription( 114 std::string AwDevToolsServerDelegate::GetViewDescription(
80 content::RenderViewHost* rvh) { 115 WebContents* web_contents) {
81 content::WebContents* web_contents =
82 content::WebContents::FromRenderViewHost(rvh);
83 if (!web_contents) return "";
84
85 android_webview::BrowserViewRenderer* bvr 116 android_webview::BrowserViewRenderer* bvr
86 = android_webview::InProcessViewRenderer::FromWebContents(web_contents); 117 = android_webview::InProcessViewRenderer::FromWebContents(web_contents);
87 if (!bvr) return ""; 118 if (!bvr) return "";
88 base::DictionaryValue description; 119 base::DictionaryValue description;
89 description.SetBoolean("attached", bvr->IsAttachedToWindow()); 120 description.SetBoolean("attached", bvr->IsAttachedToWindow());
90 description.SetBoolean("visible", bvr->IsVisible()); 121 description.SetBoolean("visible", bvr->IsVisible());
91 gfx::Rect screen_rect = bvr->GetScreenRect(); 122 gfx::Rect screen_rect = bvr->GetScreenRect();
92 description.SetInteger("screenX", screen_rect.x()); 123 description.SetInteger("screenX", screen_rect.x());
93 description.SetInteger("screenY", screen_rect.y()); 124 description.SetInteger("screenY", screen_rect.y());
94 description.SetBoolean("empty", screen_rect.size().IsEmpty()); 125 description.SetBoolean("empty", screen_rect.size().IsEmpty());
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 AwDevToolsServer* devtools_server = 192 AwDevToolsServer* devtools_server =
162 reinterpret_cast<AwDevToolsServer*>(server); 193 reinterpret_cast<AwDevToolsServer*>(server);
163 if (enabled) { 194 if (enabled) {
164 devtools_server->Start(); 195 devtools_server->Start();
165 } else { 196 } else {
166 devtools_server->Stop(); 197 devtools_server->Stop();
167 } 198 }
168 } 199 }
169 200
170 } // namespace android_webview 201 } // 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