OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/devtools/render_view_devtools_agent_host.h" | 5 #include "content/browser/devtools/render_view_devtools_agent_host.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/utf_string_conversions.h" | |
10 #include "content/browser/child_process_security_policy_impl.h" | 11 #include "content/browser/child_process_security_policy_impl.h" |
11 #include "content/browser/devtools/devtools_manager_impl.h" | 12 #include "content/browser/devtools/devtools_manager_impl.h" |
12 #include "content/browser/devtools/devtools_protocol.h" | 13 #include "content/browser/devtools/devtools_protocol.h" |
13 #include "content/browser/devtools/renderer_overrides_handler.h" | 14 #include "content/browser/devtools/renderer_overrides_handler.h" |
14 #include "content/browser/renderer_host/render_process_host_impl.h" | 15 #include "content/browser/renderer_host/render_process_host_impl.h" |
15 #include "content/browser/renderer_host/render_view_host_impl.h" | 16 #include "content/browser/renderer_host/render_view_host_impl.h" |
16 #include "content/browser/site_instance_impl.h" | 17 #include "content/browser/site_instance_impl.h" |
17 #include "content/browser/web_contents/web_contents_impl.h" | 18 #include "content/browser/web_contents/web_contents_impl.h" |
18 #include "content/common/devtools_messages.h" | 19 #include "content/common/devtools_messages.h" |
19 #include "content/public/browser/content_browser_client.h" | 20 #include "content/public/browser/content_browser_client.h" |
21 #include "content/public/browser/favicon_status.h" | |
22 #include "content/public/browser/navigation_entry.h" | |
20 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
21 #include "content/public/browser/notification_types.h" | 24 #include "content/public/browser/notification_types.h" |
22 #include "content/public/browser/render_widget_host_view.h" | 25 #include "content/public/browser/render_widget_host_view.h" |
26 #include "net/base/escape.h" | |
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDevToolsAgent.h" | 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDevToolsAgent.h" |
24 #include "ui/gfx/image/image_skia.h" | 28 #include "ui/gfx/image/image_skia.h" |
25 #include "ui/gfx/native_widget_types.h" | 29 #include "ui/gfx/native_widget_types.h" |
26 #include "ui/snapshot/snapshot.h" | 30 #include "ui/snapshot/snapshot.h" |
27 | 31 |
28 | 32 |
29 namespace content { | 33 namespace content { |
30 | 34 |
31 typedef std::vector<RenderViewDevToolsAgentHost*> Instances; | 35 typedef std::vector<RenderViewDevToolsAgentHost*> Instances; |
32 | 36 |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
140 g_instances.Get().push_back(this); | 144 g_instances.Get().push_back(this); |
141 RenderViewHostDelegate* delegate = render_view_host_->GetDelegate(); | 145 RenderViewHostDelegate* delegate = render_view_host_->GetDelegate(); |
142 if (delegate && delegate->GetAsWebContents()) | 146 if (delegate && delegate->GetAsWebContents()) |
143 Observe(delegate->GetAsWebContents()); | 147 Observe(delegate->GetAsWebContents()); |
144 } | 148 } |
145 | 149 |
146 RenderViewHost* RenderViewDevToolsAgentHost::GetRenderViewHost() { | 150 RenderViewHost* RenderViewDevToolsAgentHost::GetRenderViewHost() { |
147 return render_view_host_; | 151 return render_view_host_; |
148 } | 152 } |
149 | 153 |
154 std::string RenderViewDevToolsAgentHost::title() { | |
155 WebContents* web_contents = | |
156 GetRenderViewHost()->GetDelegate()->GetAsWebContents(); | |
pfeldman
2013/03/01 14:28:17
Here and below: when RVH dies, this AgentHost is s
Vladislav Kaznacheev
2013/03/01 16:16:38
Done.
| |
157 if (!web_contents) | |
158 return ""; | |
159 | |
160 return UTF16ToUTF8(net::EscapeForHTML(web_contents->GetTitle())); | |
161 } | |
162 | |
163 GURL RenderViewDevToolsAgentHost::url() { | |
164 return GetRenderViewHost()->GetDelegate()->GetURL(); | |
165 } | |
166 | |
167 GURL RenderViewDevToolsAgentHost::thumbnail_url() { | |
168 NavigationEntry* entry = GetNavigationEntry(); | |
169 if (!entry) | |
170 return GURL(); | |
171 | |
172 return GURL("/thumb/" + entry->GetURL().spec()); | |
173 } | |
174 | |
175 GURL RenderViewDevToolsAgentHost::favicon_url() { | |
176 NavigationEntry* entry = GetNavigationEntry(); | |
177 if (!entry) | |
178 return GURL(); | |
179 | |
180 return entry->GetFavicon().url; | |
181 } | |
182 | |
150 void RenderViewDevToolsAgentHost::DispatchOnInspectorBackend( | 183 void RenderViewDevToolsAgentHost::DispatchOnInspectorBackend( |
151 const std::string& message) { | 184 const std::string& message) { |
152 std::string error_message; | 185 std::string error_message; |
153 scoped_ptr<DevToolsProtocol::Command> command( | 186 scoped_ptr<DevToolsProtocol::Command> command( |
154 DevToolsProtocol::ParseCommand(message, &error_message)); | 187 DevToolsProtocol::ParseCommand(message, &error_message)); |
155 if (!command) { | 188 if (!command) { |
156 OnDispatchOnInspectorFrontend(error_message); | 189 OnDispatchOnInspectorFrontend(error_message); |
157 return; | 190 return; |
158 } | 191 } |
159 | 192 |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
339 &png, | 372 &png, |
340 snapshot_bounds)) | 373 snapshot_bounds)) |
341 return false; | 374 return false; |
342 | 375 |
343 return base::Base64Encode(base::StringPiece( | 376 return base::Base64Encode(base::StringPiece( |
344 reinterpret_cast<char*>(&*png.begin()), | 377 reinterpret_cast<char*>(&*png.begin()), |
345 png.size()), | 378 png.size()), |
346 base_64_data); | 379 base_64_data); |
347 } | 380 } |
348 | 381 |
382 NavigationEntry* RenderViewDevToolsAgentHost::GetNavigationEntry() { | |
383 WebContents* web_contents = | |
384 GetRenderViewHost()->GetDelegate()->GetAsWebContents(); | |
385 if (!web_contents) | |
386 return NULL; | |
387 | |
388 NavigationController& controller = web_contents->GetController(); | |
389 NavigationEntry* entry = controller.GetActiveEntry(); | |
390 if (!entry || !entry->GetURL().is_valid()) | |
391 return NULL; | |
392 | |
393 return entry; | |
394 } | |
395 | |
349 } // namespace content | 396 } // namespace content |
OLD | NEW |