Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chromecast/shell/browser/devtools/cast_dev_tools_delegate.h" | |
| 6 | |
| 7 #include "base/files/file_path.h" | |
| 8 #include "base/strings/utf_string_conversions.h" | |
| 9 #include "content/public/browser/devtools_agent_host.h" | |
| 10 #include "content/public/browser/devtools_target.h" | |
| 11 #include "content/public/browser/favicon_status.h" | |
| 12 #include "content/public/browser/navigation_entry.h" | |
| 13 #include "content/public/browser/render_view_host.h" | |
| 14 #include "content/public/browser/web_contents.h" | |
| 15 #include "content/public/browser/web_contents_delegate.h" | |
| 16 #include "grit/shell_resources.h" | |
| 17 #include "ui/base/resource/resource_bundle.h" | |
| 18 | |
| 19 namespace chromecast { | |
| 20 namespace shell { | |
| 21 | |
| 22 namespace { | |
| 23 | |
| 24 const char kTargetTypePage[] = "page"; | |
| 25 | |
| 26 class Target : public content::DevToolsTarget { | |
| 27 public: | |
| 28 explicit Target(content::WebContents* web_contents); | |
| 29 | |
| 30 virtual std::string GetId() const OVERRIDE { return id_; } | |
| 31 virtual std::string GetParentId() const OVERRIDE { return std::string(); } | |
| 32 virtual std::string GetType() const OVERRIDE { return kTargetTypePage; } | |
| 33 virtual std::string GetTitle() const OVERRIDE { return title_; } | |
| 34 virtual std::string GetDescription() const OVERRIDE { return std::string(); } | |
| 35 virtual GURL GetURL() const OVERRIDE { return url_; } | |
| 36 virtual GURL GetFaviconURL() const OVERRIDE { return favicon_url_; } | |
| 37 virtual base::TimeTicks GetLastActivityTime() const OVERRIDE { | |
| 38 return last_activity_time_; | |
| 39 } | |
| 40 virtual bool IsAttached() const OVERRIDE { | |
| 41 return agent_host_->IsAttached(); | |
| 42 } | |
| 43 virtual scoped_refptr<content::DevToolsAgentHost> GetAgentHost() | |
| 44 const OVERRIDE { | |
| 45 return agent_host_; | |
| 46 } | |
| 47 virtual bool Activate() const OVERRIDE; | |
| 48 virtual bool Close() const OVERRIDE; | |
| 49 | |
| 50 private: | |
| 51 scoped_refptr<content::DevToolsAgentHost> agent_host_; | |
| 52 std::string id_; | |
| 53 std::string title_; | |
| 54 GURL url_; | |
| 55 GURL favicon_url_; | |
| 56 base::TimeTicks last_activity_time_; | |
|
damienv1
2014/08/14 15:57:19
DISALLOW_COPY_AND_ASSIGN missing ? (I didn't check
gunsch
2014/08/14 16:26:43
Done.
| |
| 57 }; | |
| 58 | |
| 59 Target::Target(content::WebContents* web_contents) { | |
| 60 agent_host_ = content::DevToolsAgentHost::GetOrCreateFor(web_contents); | |
| 61 id_ = agent_host_->GetId(); | |
| 62 title_ = base::UTF16ToUTF8(web_contents->GetTitle()); | |
| 63 url_ = web_contents->GetURL(); | |
| 64 content::NavigationController& controller = web_contents->GetController(); | |
| 65 content::NavigationEntry* entry = controller.GetActiveEntry(); | |
| 66 if (entry != NULL && entry->GetURL().is_valid()) | |
| 67 favicon_url_ = entry->GetFavicon().url; | |
| 68 last_activity_time_ = web_contents->GetLastActiveTime(); | |
| 69 } | |
| 70 | |
| 71 bool Target::Activate() const { | |
| 72 content::WebContents* web_contents = agent_host_->GetWebContents(); | |
| 73 if (!web_contents) | |
| 74 return false; | |
| 75 web_contents->GetDelegate()->ActivateContents(web_contents); | |
| 76 return true; | |
| 77 } | |
| 78 | |
| 79 bool Target::Close() const { | |
| 80 content::WebContents* web_contents = agent_host_->GetWebContents(); | |
| 81 if (!web_contents) | |
| 82 return false; | |
| 83 web_contents->GetRenderViewHost()->ClosePage(); | |
| 84 return true; | |
| 85 } | |
| 86 | |
| 87 } // namespace | |
| 88 | |
| 89 CastDevToolsDelegate::CastDevToolsDelegate() { | |
| 90 } | |
| 91 | |
| 92 CastDevToolsDelegate::~CastDevToolsDelegate() { | |
| 93 } | |
| 94 | |
| 95 std::string CastDevToolsDelegate::GetDiscoveryPageHTML() { | |
| 96 #if defined(OS_ANDROID) | |
| 97 return std::string(); | |
|
damienv1
2014/08/14 15:57:19
Why is it done differently for Android ? (might de
gunsch
2014/08/14 16:26:43
Done.
| |
| 98 #else | |
| 99 return ResourceBundle::GetSharedInstance().GetRawDataResource( | |
| 100 IDR_CAST_SHELL_DEVTOOLS_DISCOVERY_PAGE).as_string(); | |
| 101 #endif // defined(OS_ANDROID) | |
| 102 } | |
| 103 | |
| 104 bool CastDevToolsDelegate::BundlesFrontendResources() { | |
| 105 #if defined(OS_ANDROID) | |
| 106 return false; | |
|
damienv1
2014/08/14 16:00:37
Same question: why is the underlying reason for th
gunsch
2014/08/14 16:26:43
Left a comment. See also:
https://code.google.com/
| |
| 107 #else | |
| 108 return true; | |
| 109 #endif // defined(OS_ANDROID) | |
| 110 } | |
| 111 | |
| 112 base::FilePath CastDevToolsDelegate::GetDebugFrontendDir() { | |
| 113 return base::FilePath(); | |
| 114 } | |
| 115 | |
| 116 std::string CastDevToolsDelegate::GetPageThumbnailData(const GURL& url) { | |
| 117 return ""; | |
| 118 } | |
| 119 | |
| 120 scoped_ptr<content::DevToolsTarget> CastDevToolsDelegate::CreateNewTarget( | |
| 121 const GURL& url) { | |
| 122 return scoped_ptr<content::DevToolsTarget>(); | |
| 123 } | |
| 124 | |
| 125 void CastDevToolsDelegate::EnumerateTargets(TargetCallback callback) { | |
| 126 TargetList targets; | |
| 127 std::vector<content::WebContents*> wc_list = | |
| 128 content::DevToolsAgentHost::GetInspectableWebContents(); | |
| 129 for (std::vector<content::WebContents*>::iterator it = wc_list.begin(); | |
| 130 it != wc_list.end(); | |
| 131 ++it) { | |
| 132 targets.push_back(new Target(*it)); | |
| 133 } | |
| 134 callback.Run(targets); | |
| 135 } | |
| 136 | |
| 137 scoped_ptr<net::StreamListenSocket> | |
| 138 CastDevToolsDelegate::CreateSocketForTethering( | |
| 139 net::StreamListenSocket::Delegate* delegate, | |
| 140 std::string* name) { | |
| 141 return scoped_ptr<net::StreamListenSocket>(); | |
| 142 } | |
| 143 | |
| 144 } // namespace shell | |
| 145 } // namespace chromecast | |
| OLD | NEW |