| 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 14 matching lines...) Expand all Loading... |
| 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"; | 34 const char kTargetTypePage[] = "page"; |
| 35 const char kTargetTypeOther[] = "other"; |
| 35 | 36 |
| 36 std::string GetViewDescription(WebContents* web_contents); | 37 std::string GetViewDescription(WebContents* web_contents); |
| 37 | 38 |
| 38 class Target : public content::DevToolsTarget { | 39 class Target : public content::DevToolsTarget { |
| 39 public: | 40 public: |
| 40 explicit Target(WebContents* web_contents); | 41 explicit Target(scoped_refptr<DevToolsAgentHost> agent_host); |
| 41 | 42 |
| 42 virtual std::string GetId() const OVERRIDE { return id_; } | 43 virtual std::string GetId() const OVERRIDE { return id_; } |
| 43 virtual std::string GetParentId() const OVERRIDE { return std::string(); } | 44 virtual std::string GetParentId() const OVERRIDE { return std::string(); } |
| 44 virtual std::string GetType() const OVERRIDE { return kTargetTypePage; } | 45 virtual std::string GetType() const OVERRIDE { return type_; } |
| 45 virtual std::string GetTitle() const OVERRIDE { return title_; } | 46 virtual std::string GetTitle() const OVERRIDE { return title_; } |
| 46 virtual std::string GetDescription() const OVERRIDE { return description_; } | 47 virtual std::string GetDescription() const OVERRIDE { return description_; } |
| 47 virtual GURL GetURL() const OVERRIDE { return url_; } | 48 virtual GURL GetURL() const OVERRIDE { return url_; } |
| 48 virtual GURL GetFaviconURL() const OVERRIDE { return GURL(); } | 49 virtual GURL GetFaviconURL() const OVERRIDE { return GURL(); } |
| 49 virtual base::TimeTicks GetLastActivityTime() const OVERRIDE { | 50 virtual base::TimeTicks GetLastActivityTime() const OVERRIDE { |
| 50 return last_activity_time_; | 51 return last_activity_time_; |
| 51 } | 52 } |
| 52 virtual bool IsAttached() const OVERRIDE { | 53 virtual bool IsAttached() const OVERRIDE { |
| 53 return agent_host_->IsAttached(); | 54 return agent_host_->IsAttached(); |
| 54 } | 55 } |
| 55 virtual scoped_refptr<DevToolsAgentHost> GetAgentHost() const OVERRIDE { | 56 virtual scoped_refptr<DevToolsAgentHost> GetAgentHost() const OVERRIDE { |
| 56 return agent_host_; | 57 return agent_host_; |
| 57 } | 58 } |
| 58 virtual bool Activate() const OVERRIDE { return false; } | 59 virtual bool Activate() const OVERRIDE { return false; } |
| 59 virtual bool Close() const OVERRIDE { return false; } | 60 virtual bool Close() const OVERRIDE { return false; } |
| 60 | 61 |
| 61 private: | 62 private: |
| 62 scoped_refptr<DevToolsAgentHost> agent_host_; | 63 scoped_refptr<DevToolsAgentHost> agent_host_; |
| 63 std::string id_; | 64 std::string id_; |
| 65 std::string type_; |
| 64 std::string title_; | 66 std::string title_; |
| 65 std::string description_; | 67 std::string description_; |
| 66 GURL url_; | 68 GURL url_; |
| 67 base::TimeTicks last_activity_time_; | 69 base::TimeTicks last_activity_time_; |
| 68 }; | 70 }; |
| 69 | 71 |
| 70 Target::Target(WebContents* web_contents) { | 72 Target::Target(scoped_refptr<DevToolsAgentHost> agent_host) |
| 71 agent_host_ = | 73 : agent_host_(agent_host), |
| 72 DevToolsAgentHost::GetOrCreateFor(web_contents->GetRenderViewHost()); | 74 id_(agent_host_->GetId()), |
| 73 id_ = agent_host_->GetId(); | 75 url_(agent_host_->GetURL()) { |
| 74 description_ = GetViewDescription(web_contents); | 76 type_ = kTargetTypeOther; |
| 75 title_ = base::UTF16ToUTF8(web_contents->GetTitle()); | 77 if (RenderViewHost* rvh = agent_host_->GetRenderViewHost()) { |
| 76 url_ = web_contents->GetURL(); | 78 if (WebContents* web_contents = WebContents::FromRenderViewHost(rvh)) { |
| 77 last_activity_time_ = web_contents->GetLastActiveTime(); | 79 description_ = GetViewDescription(web_contents); |
| 80 title_ = base::UTF16ToUTF8(web_contents->GetTitle()); |
| 81 last_activity_time_ = web_contents->GetLastActiveTime(); |
| 82 type_ = kTargetTypePage; |
| 83 } |
| 84 } |
| 78 } | 85 } |
| 79 | 86 |
| 80 // Delegate implementation for the devtools http handler for WebView. A new | 87 // Delegate implementation for the devtools http handler for WebView. A new |
| 81 // instance of this gets created each time web debugging is enabled. | 88 // instance of this gets created each time web debugging is enabled. |
| 82 class AwDevToolsServerDelegate : public content::DevToolsHttpHandlerDelegate { | 89 class AwDevToolsServerDelegate : public content::DevToolsHttpHandlerDelegate { |
| 83 public: | 90 public: |
| 84 AwDevToolsServerDelegate() {} | 91 AwDevToolsServerDelegate() {} |
| 85 virtual ~AwDevToolsServerDelegate() {} | 92 virtual ~AwDevToolsServerDelegate() {} |
| 86 | 93 |
| 87 // DevToolsHttpProtocolHandler::Delegate overrides. | 94 // DevToolsHttpProtocolHandler::Delegate overrides. |
| 88 virtual std::string GetDiscoveryPageHTML() OVERRIDE; | 95 virtual std::string GetDiscoveryPageHTML() OVERRIDE; |
| 89 | 96 |
| 90 virtual bool BundlesFrontendResources() OVERRIDE { | 97 virtual bool BundlesFrontendResources() OVERRIDE { |
| 91 return false; | 98 return false; |
| 92 } | 99 } |
| 93 | 100 |
| 94 virtual base::FilePath GetDebugFrontendDir() OVERRIDE { | 101 virtual base::FilePath GetDebugFrontendDir() OVERRIDE { |
| 95 return base::FilePath(); | 102 return base::FilePath(); |
| 96 } | 103 } |
| 97 | 104 |
| 98 virtual std::string GetPageThumbnailData(const GURL&) OVERRIDE { | 105 virtual std::string GetPageThumbnailData(const GURL&) OVERRIDE { |
| 99 return ""; | 106 return ""; |
| 100 } | 107 } |
| 101 | 108 |
| 102 virtual scoped_ptr<content::DevToolsTarget> CreateNewTarget( | 109 virtual scoped_ptr<content::DevToolsTarget> CreateNewTarget( |
| 103 const GURL&) OVERRIDE { | 110 const GURL&) OVERRIDE { |
| 104 return scoped_ptr<content::DevToolsTarget>(); | 111 return scoped_ptr<content::DevToolsTarget>(); |
| 105 } | 112 } |
| 106 | 113 |
| 107 virtual void EnumerateTargets(TargetCallback callback) OVERRIDE { | 114 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 | 115 |
| 120 virtual scoped_ptr<net::StreamListenSocket> CreateSocketForTethering( | 116 virtual scoped_ptr<net::StreamListenSocket> CreateSocketForTethering( |
| 121 net::StreamListenSocket::Delegate* delegate, | 117 net::StreamListenSocket::Delegate* delegate, |
| 122 std::string* name) OVERRIDE { | 118 std::string* name) OVERRIDE { |
| 123 return scoped_ptr<net::StreamListenSocket>(); | 119 return scoped_ptr<net::StreamListenSocket>(); |
| 124 } | 120 } |
| 125 | 121 |
| 126 private: | 122 private: |
| 127 DISALLOW_COPY_AND_ASSIGN(AwDevToolsServerDelegate); | 123 DISALLOW_COPY_AND_ASSIGN(AwDevToolsServerDelegate); |
| 128 }; | 124 }; |
| 129 | 125 |
| 126 static void CreateTargets( |
| 127 const AwDevToolsServerDelegate::TargetCallback& callback, |
| 128 const DevToolsAgentHost::List& agents) { |
| 129 AwDevToolsServerDelegate::TargetList targets; |
| 130 for (DevToolsAgentHost::List::const_iterator it = agents.begin(); |
| 131 it != agents.end(); ++it) { |
| 132 targets.push_back(new Target(*it)); |
| 133 } |
| 134 callback.Run(targets); |
| 135 } |
| 136 |
| 137 void AwDevToolsServerDelegate::EnumerateTargets(TargetCallback callback) { |
| 138 DevToolsAgentHost::GetOrCreateAllHosts(base::Bind(&CreateTargets, callback)); |
| 139 } |
| 130 | 140 |
| 131 std::string AwDevToolsServerDelegate::GetDiscoveryPageHTML() { | 141 std::string AwDevToolsServerDelegate::GetDiscoveryPageHTML() { |
| 132 const char html[] = | 142 const char html[] = |
| 133 "<html>" | 143 "<html>" |
| 134 "<head><title>WebView remote debugging</title></head>" | 144 "<head><title>WebView remote debugging</title></head>" |
| 135 "<body>Please use <a href=\'chrome://inspect\'>chrome://inspect</a>" | 145 "<body>Please use <a href=\'chrome://inspect\'>chrome://inspect</a>" |
| 136 "</body>" | 146 "</body>" |
| 137 "</html>"; | 147 "</html>"; |
| 138 return html; | 148 return html; |
| 139 } | 149 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 AwDevToolsServer* devtools_server = | 229 AwDevToolsServer* devtools_server = |
| 220 reinterpret_cast<AwDevToolsServer*>(server); | 230 reinterpret_cast<AwDevToolsServer*>(server); |
| 221 if (enabled) { | 231 if (enabled) { |
| 222 devtools_server->Start(); | 232 devtools_server->Start(); |
| 223 } else { | 233 } else { |
| 224 devtools_server->Stop(); | 234 devtools_server->Stop(); |
| 225 } | 235 } |
| 226 } | 236 } |
| 227 | 237 |
| 228 } // namespace android_webview | 238 } // namespace android_webview |
| OLD | NEW |