| OLD | NEW |
| 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 13 matching lines...) Expand all Loading... |
| 24 using content::DevToolsAgentHost; | 24 using content::DevToolsAgentHost; |
| 25 using content::RenderViewHost; | 25 using content::RenderViewHost; |
| 26 using content::WebContents; | 26 using content::WebContents; |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 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"; | |
| 35 const char kTargetTypeServiceWorker[] = "service_worker"; | |
| 36 const char kTargetTypeOther[] = "other"; | |
| 37 | |
| 38 std::string GetViewDescription(WebContents* web_contents); | |
| 39 | |
| 40 class Target : public content::DevToolsTarget { | |
| 41 public: | |
| 42 explicit Target(scoped_refptr<DevToolsAgentHost> agent_host); | |
| 43 | |
| 44 virtual std::string GetId() const OVERRIDE { return agent_host_->GetId(); } | |
| 45 virtual std::string GetParentId() const OVERRIDE { return std::string(); } | |
| 46 virtual std::string GetType() const OVERRIDE { | |
| 47 switch (agent_host_->GetType()) { | |
| 48 case DevToolsAgentHost::TYPE_WEB_CONTENTS: | |
| 49 return kTargetTypePage; | |
| 50 case DevToolsAgentHost::TYPE_SERVICE_WORKER: | |
| 51 return kTargetTypeServiceWorker; | |
| 52 default: | |
| 53 break; | |
| 54 } | |
| 55 return kTargetTypeOther; | |
| 56 } | |
| 57 virtual std::string GetTitle() const OVERRIDE { | |
| 58 return agent_host_->GetTitle(); | |
| 59 } | |
| 60 virtual std::string GetDescription() const OVERRIDE { return description_; } | |
| 61 virtual GURL GetURL() const OVERRIDE { return agent_host_->GetURL(); } | |
| 62 virtual GURL GetFaviconURL() const OVERRIDE { return GURL(); } | |
| 63 virtual base::TimeTicks GetLastActivityTime() const OVERRIDE { | |
| 64 return last_activity_time_; | |
| 65 } | |
| 66 virtual bool IsAttached() const OVERRIDE { | |
| 67 return agent_host_->IsAttached(); | |
| 68 } | |
| 69 virtual scoped_refptr<DevToolsAgentHost> GetAgentHost() const OVERRIDE { | |
| 70 return agent_host_; | |
| 71 } | |
| 72 virtual bool Activate() const OVERRIDE { return agent_host_->Activate(); } | |
| 73 virtual bool Close() const OVERRIDE { return agent_host_->Close(); } | |
| 74 | |
| 75 private: | |
| 76 scoped_refptr<DevToolsAgentHost> agent_host_; | |
| 77 std::string description_; | |
| 78 base::TimeTicks last_activity_time_; | |
| 79 }; | |
| 80 | |
| 81 Target::Target(scoped_refptr<DevToolsAgentHost> agent_host) | |
| 82 : agent_host_(agent_host) { | |
| 83 if (WebContents* web_contents = agent_host->GetWebContents()) { | |
| 84 description_ = GetViewDescription(web_contents); | |
| 85 last_activity_time_ = web_contents->GetLastActiveTime(); | |
| 86 } | |
| 87 } | |
| 88 | |
| 89 // Delegate implementation for the devtools http handler for WebView. A new | 34 // Delegate implementation for the devtools http handler for WebView. A new |
| 90 // instance of this gets created each time web debugging is enabled. | 35 // instance of this gets created each time web debugging is enabled. |
| 91 class AwDevToolsServerDelegate : public content::DevToolsHttpHandlerDelegate { | 36 class AwDevToolsServerDelegate : public content::DevToolsHttpHandlerDelegate { |
| 92 public: | 37 public: |
| 93 AwDevToolsServerDelegate() {} | 38 AwDevToolsServerDelegate() {} |
| 94 virtual ~AwDevToolsServerDelegate() {} | 39 virtual ~AwDevToolsServerDelegate() {} |
| 95 | 40 |
| 96 // DevToolsHttpProtocolHandler::Delegate overrides. | 41 // DevToolsHttpProtocolHandler::Delegate overrides. |
| 97 virtual std::string GetDiscoveryPageHTML() OVERRIDE; | 42 virtual std::string GetDiscoveryPageHTML() OVERRIDE; |
| 98 | 43 |
| 99 virtual bool BundlesFrontendResources() OVERRIDE { | 44 virtual bool BundlesFrontendResources() OVERRIDE { |
| 100 return false; | 45 return false; |
| 101 } | 46 } |
| 102 | 47 |
| 103 virtual base::FilePath GetDebugFrontendDir() OVERRIDE { | 48 virtual base::FilePath GetDebugFrontendDir() OVERRIDE { |
| 104 return base::FilePath(); | 49 return base::FilePath(); |
| 105 } | 50 } |
| 106 | 51 |
| 107 virtual std::string GetPageThumbnailData(const GURL&) OVERRIDE { | |
| 108 return ""; | |
| 109 } | |
| 110 | |
| 111 virtual scoped_ptr<content::DevToolsTarget> CreateNewTarget( | |
| 112 const GURL&) OVERRIDE { | |
| 113 return scoped_ptr<content::DevToolsTarget>(); | |
| 114 } | |
| 115 | |
| 116 virtual void EnumerateTargets(TargetCallback callback) OVERRIDE { | |
| 117 TargetList targets; | |
| 118 DevToolsAgentHost::List agents = DevToolsAgentHost::GetOrCreateAll(); | |
| 119 for (DevToolsAgentHost::List::iterator it = agents.begin(); | |
| 120 it != agents.end(); ++it) { | |
| 121 targets.push_back(new Target(*it)); | |
| 122 } | |
| 123 callback.Run(targets); | |
| 124 } | |
| 125 | |
| 126 virtual scoped_ptr<net::StreamListenSocket> CreateSocketForTethering( | 52 virtual scoped_ptr<net::StreamListenSocket> CreateSocketForTethering( |
| 127 net::StreamListenSocket::Delegate* delegate, | 53 net::StreamListenSocket::Delegate* delegate, |
| 128 std::string* name) OVERRIDE { | 54 std::string* name) OVERRIDE { |
| 129 return scoped_ptr<net::StreamListenSocket>(); | 55 return scoped_ptr<net::StreamListenSocket>(); |
| 130 } | 56 } |
| 131 | 57 |
| 132 private: | 58 private: |
| 133 DISALLOW_COPY_AND_ASSIGN(AwDevToolsServerDelegate); | 59 DISALLOW_COPY_AND_ASSIGN(AwDevToolsServerDelegate); |
| 134 }; | 60 }; |
| 135 | 61 |
| 136 | 62 |
| 137 std::string AwDevToolsServerDelegate::GetDiscoveryPageHTML() { | 63 std::string AwDevToolsServerDelegate::GetDiscoveryPageHTML() { |
| 138 const char html[] = | 64 const char html[] = |
| 139 "<html>" | 65 "<html>" |
| 140 "<head><title>WebView remote debugging</title></head>" | 66 "<head><title>WebView remote debugging</title></head>" |
| 141 "<body>Please use <a href=\'chrome://inspect\'>chrome://inspect</a>" | 67 "<body>Please use <a href=\'chrome://inspect\'>chrome://inspect</a>" |
| 142 "</body>" | 68 "</body>" |
| 143 "</html>"; | 69 "</html>"; |
| 144 return html; | 70 return html; |
| 145 } | 71 } |
| 146 | 72 |
| 147 std::string GetViewDescription(WebContents* web_contents) { | |
| 148 const android_webview::BrowserViewRenderer* bvr = | |
| 149 android_webview::AwContents::FromWebContents(web_contents) | |
| 150 ->GetBrowserViewRenderer(); | |
| 151 if (!bvr) return ""; | |
| 152 base::DictionaryValue description; | |
| 153 description.SetBoolean("attached", bvr->attached_to_window()); | |
| 154 description.SetBoolean("visible", bvr->IsVisible()); | |
| 155 gfx::Rect screen_rect = bvr->GetScreenRect(); | |
| 156 description.SetInteger("screenX", screen_rect.x()); | |
| 157 description.SetInteger("screenY", screen_rect.y()); | |
| 158 description.SetBoolean("empty", screen_rect.size().IsEmpty()); | |
| 159 if (!screen_rect.size().IsEmpty()) { | |
| 160 description.SetInteger("width", screen_rect.width()); | |
| 161 description.SetInteger("height", screen_rect.height()); | |
| 162 } | |
| 163 std::string json; | |
| 164 base::JSONWriter::Write(&description, &json); | |
| 165 return json; | |
| 166 } | |
| 167 | |
| 168 // Factory for UnixDomainServerSocket. | 73 // Factory for UnixDomainServerSocket. |
| 169 class UnixDomainServerSocketFactory | 74 class UnixDomainServerSocketFactory |
| 170 : public content::DevToolsHttpHandler::ServerSocketFactory { | 75 : public content::DevToolsHttpHandler::ServerSocketFactory { |
| 171 public: | 76 public: |
| 172 explicit UnixDomainServerSocketFactory(const std::string& socket_name) | 77 explicit UnixDomainServerSocketFactory(const std::string& socket_name) |
| 173 : content::DevToolsHttpHandler::ServerSocketFactory(socket_name, 0, 1) {} | 78 : content::DevToolsHttpHandler::ServerSocketFactory(socket_name, 0, 1) {} |
| 174 | 79 |
| 175 private: | 80 private: |
| 176 // content::DevToolsHttpHandler::ServerSocketFactory. | 81 // content::DevToolsHttpHandler::ServerSocketFactory. |
| 177 virtual scoped_ptr<net::ServerSocket> Create() const OVERRIDE { | 82 virtual scoped_ptr<net::ServerSocket> Create() const OVERRIDE { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 AwDevToolsServer* devtools_server = | 149 AwDevToolsServer* devtools_server = |
| 245 reinterpret_cast<AwDevToolsServer*>(server); | 150 reinterpret_cast<AwDevToolsServer*>(server); |
| 246 if (enabled) { | 151 if (enabled) { |
| 247 devtools_server->Start(); | 152 devtools_server->Start(); |
| 248 } else { | 153 } else { |
| 249 devtools_server->Stop(); | 154 devtools_server->Stop(); |
| 250 } | 155 } |
| 251 } | 156 } |
| 252 | 157 |
| 253 } // namespace android_webview | 158 } // namespace android_webview |
| OLD | NEW |