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

Side by Side Diff: chromecast/shell/browser/devtools/cast_dev_tools_delegate.cc

Issue 454063004: Adds remote devtools support to cast_shell. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 4 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
OLDNEW
(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/macros.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "content/public/browser/devtools_agent_host.h"
11 #include "content/public/browser/devtools_target.h"
12 #include "content/public/browser/favicon_status.h"
13 #include "content/public/browser/navigation_entry.h"
14 #include "content/public/browser/render_view_host.h"
15 #include "content/public/browser/web_contents.h"
16 #include "content/public/browser/web_contents_delegate.h"
17 #include "grit/shell_resources.h"
18 #include "ui/base/resource/resource_bundle.h"
19
20 namespace chromecast {
21 namespace shell {
22
23 namespace {
24
25 const char kTargetTypePage[] = "page";
26
27 class Target : public content::DevToolsTarget {
28 public:
29 explicit Target(content::WebContents* web_contents);
30
31 virtual std::string GetId() const OVERRIDE { return id_; }
32 virtual std::string GetParentId() const OVERRIDE { return std::string(); }
33 virtual std::string GetType() const OVERRIDE { return kTargetTypePage; }
34 virtual std::string GetTitle() const OVERRIDE { return title_; }
35 virtual std::string GetDescription() const OVERRIDE { return std::string(); }
36 virtual GURL GetURL() const OVERRIDE { return url_; }
37 virtual GURL GetFaviconURL() const OVERRIDE { return favicon_url_; }
38 virtual base::TimeTicks GetLastActivityTime() const OVERRIDE {
39 return last_activity_time_;
40 }
41 virtual bool IsAttached() const OVERRIDE {
42 return agent_host_->IsAttached();
43 }
44 virtual scoped_refptr<content::DevToolsAgentHost> GetAgentHost()
45 const OVERRIDE {
46 return agent_host_;
47 }
48 virtual bool Activate() const OVERRIDE;
49 virtual bool Close() const OVERRIDE;
50
51 private:
52 scoped_refptr<content::DevToolsAgentHost> agent_host_;
53 std::string id_;
54 std::string title_;
55 GURL url_;
56 GURL favicon_url_;
57 base::TimeTicks last_activity_time_;
58
59 DISALLOW_COPY_AND_ASSIGN(Target);
60 };
61
62 Target::Target(content::WebContents* web_contents) {
63 agent_host_ = content::DevToolsAgentHost::GetOrCreateFor(web_contents);
64 id_ = agent_host_->GetId();
65 title_ = base::UTF16ToUTF8(web_contents->GetTitle());
66 url_ = web_contents->GetURL();
67 content::NavigationController& controller = web_contents->GetController();
68 content::NavigationEntry* entry = controller.GetActiveEntry();
69 if (entry != NULL && entry->GetURL().is_valid())
70 favicon_url_ = entry->GetFavicon().url;
71 last_activity_time_ = web_contents->GetLastActiveTime();
72 }
73
74 bool Target::Activate() const {
75 content::WebContents* web_contents = agent_host_->GetWebContents();
76 if (!web_contents)
77 return false;
78 web_contents->GetDelegate()->ActivateContents(web_contents);
79 return true;
80 }
81
82 bool Target::Close() const {
83 content::WebContents* web_contents = agent_host_->GetWebContents();
84 if (!web_contents)
85 return false;
86 web_contents->GetRenderViewHost()->ClosePage();
87 return true;
88 }
89
90 } // namespace
91
92 CastDevToolsDelegate::CastDevToolsDelegate() {
93 }
94
95 CastDevToolsDelegate::~CastDevToolsDelegate() {
96 }
97
98 std::string CastDevToolsDelegate::GetDiscoveryPageHTML() {
99 #if defined(OS_ANDROID)
100 return std::string();
101 #else
102 return ResourceBundle::GetSharedInstance().GetRawDataResource(
103 IDR_CAST_SHELL_DEVTOOLS_DISCOVERY_PAGE).as_string();
104 #endif // defined(OS_ANDROID)
105 }
106
107 bool CastDevToolsDelegate::BundlesFrontendResources() {
108 #if defined(OS_ANDROID)
109 // Since Android remote debugging connects over a Unix domain socket, Chrome
110 // will not load the same homepage.
111 return false;
112 #else
113 return true;
114 #endif // defined(OS_ANDROID)
115 }
116
117 base::FilePath CastDevToolsDelegate::GetDebugFrontendDir() {
118 return base::FilePath();
119 }
120
121 std::string CastDevToolsDelegate::GetPageThumbnailData(const GURL& url) {
122 return "";
123 }
124
125 scoped_ptr<content::DevToolsTarget> CastDevToolsDelegate::CreateNewTarget(
126 const GURL& url) {
127 return scoped_ptr<content::DevToolsTarget>();
128 }
129
130 void CastDevToolsDelegate::EnumerateTargets(TargetCallback callback) {
131 TargetList targets;
132 std::vector<content::WebContents*> wc_list =
133 content::DevToolsAgentHost::GetInspectableWebContents();
134 for (std::vector<content::WebContents*>::iterator it = wc_list.begin();
135 it != wc_list.end();
136 ++it) {
137 targets.push_back(new Target(*it));
138 }
139 callback.Run(targets);
140 }
141
142 scoped_ptr<net::StreamListenSocket>
143 CastDevToolsDelegate::CreateSocketForTethering(
144 net::StreamListenSocket::Delegate* delegate,
145 std::string* name) {
146 return scoped_ptr<net::StreamListenSocket>();
147 }
148
149 } // namespace shell
150 } // namespace chromecast
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698