| 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 "chrome/browser/devtools/devtools_target_impl.h" | 5 #include "chrome/browser/devtools/devtools_target_impl.h" |
| 6 | 6 |
| 7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/devtools/devtools_window.h" | 9 #include "chrome/browser/devtools/devtools_window.h" |
| 10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
| 11 #include "chrome/browser/extensions/extension_tab_util.h" | 11 #include "chrome/browser/extensions/extension_tab_util.h" |
| 12 #include "chrome/browser/guest_view/guest_view_base.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" | 14 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" |
| 14 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" | 15 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" |
| 15 #include "chrome/common/extensions/extension_constants.h" | 16 #include "chrome/common/extensions/extension_constants.h" |
| 16 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/browser/favicon_status.h" | 18 #include "content/public/browser/favicon_status.h" |
| 18 #include "content/public/browser/navigation_entry.h" | 19 #include "content/public/browser/navigation_entry.h" |
| 19 #include "content/public/browser/render_frame_host.h" | 20 #include "content/public/browser/render_frame_host.h" |
| 20 #include "content/public/browser/render_view_host.h" | 21 #include "content/public/browser/render_view_host.h" |
| 21 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
| 22 #include "extensions/browser/extension_host.h" | 23 #include "extensions/browser/extension_host.h" |
| 23 #include "extensions/browser/extension_system.h" | 24 #include "extensions/browser/extension_system.h" |
| 24 #include "extensions/common/constants.h" | 25 #include "extensions/common/constants.h" |
| 25 | 26 |
| 26 using content::BrowserThread; | 27 using content::BrowserThread; |
| 27 using content::DevToolsAgentHost; | 28 using content::DevToolsAgentHost; |
| 28 using content::RenderViewHost; | 29 using content::RenderViewHost; |
| 29 using content::WebContents; | 30 using content::WebContents; |
| 30 using content::WorkerService; | 31 using content::WorkerService; |
| 31 | 32 |
| 32 namespace { | 33 namespace { |
| 33 | 34 |
| 34 const char kTargetTypeApp[] = "app"; | 35 const char kTargetTypeApp[] = "app"; |
| 35 const char kTargetTypeBackgroundPage[] = "background_page"; | 36 const char kTargetTypeBackgroundPage[] = "background_page"; |
| 36 const char kTargetTypePage[] = "page"; | 37 const char kTargetTypePage[] = "page"; |
| 37 const char kTargetTypeWorker[] = "worker"; | 38 const char kTargetTypeWorker[] = "worker"; |
| 39 const char kTargetTypeWebView[] = "webview"; |
| 40 const char kTargetTypeIFrame[] = "iframe"; |
| 38 const char kTargetTypeOther[] = "other"; | 41 const char kTargetTypeOther[] = "other"; |
| 39 | 42 |
| 40 // RenderViewHostTarget -------------------------------------------------------- | 43 // RenderViewHostTarget -------------------------------------------------------- |
| 41 | 44 |
| 42 class RenderViewHostTarget : public DevToolsTargetImpl { | 45 class RenderViewHostTarget : public DevToolsTargetImpl { |
| 43 public: | 46 public: |
| 44 explicit RenderViewHostTarget(RenderViewHost* rvh, bool is_tab); | 47 explicit RenderViewHostTarget(RenderViewHost* rvh, bool is_tab); |
| 45 | 48 |
| 46 // DevToolsTargetImpl overrides: | 49 // DevToolsTargetImpl overrides: |
| 47 virtual bool Activate() const OVERRIDE; | 50 virtual bool Activate() const OVERRIDE; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 60 : DevToolsTargetImpl(DevToolsAgentHost::GetOrCreateFor(rvh)), | 63 : DevToolsTargetImpl(DevToolsAgentHost::GetOrCreateFor(rvh)), |
| 61 tab_id_(-1) { | 64 tab_id_(-1) { |
| 62 set_type(kTargetTypeOther); | 65 set_type(kTargetTypeOther); |
| 63 WebContents* web_contents = WebContents::FromRenderViewHost(rvh); | 66 WebContents* web_contents = WebContents::FromRenderViewHost(rvh); |
| 64 if (!web_contents) | 67 if (!web_contents) |
| 65 return; // Orphan RVH will show up with no title/url/icon in clients. | 68 return; // Orphan RVH will show up with no title/url/icon in clients. |
| 66 | 69 |
| 67 content::RenderFrameHost* rfh = rvh->GetMainFrame(); | 70 content::RenderFrameHost* rfh = rvh->GetMainFrame(); |
| 68 if (rfh->IsCrossProcessSubframe()) { | 71 if (rfh->IsCrossProcessSubframe()) { |
| 69 set_url(rfh->GetLastCommittedURL()); | 72 set_url(rfh->GetLastCommittedURL()); |
| 70 set_type(kTargetTypeOther); | 73 set_type(kTargetTypeIFrame); |
| 71 // TODO(kaznacheev) Try setting the title when the frame navigation | 74 // TODO(kaznacheev) Try setting the title when the frame navigation |
| 72 // refactoring is done. | 75 // refactoring is done. |
| 76 RenderViewHost* parent_rvh = rfh->GetParent()->GetRenderViewHost(); |
| 77 set_parent_id(DevToolsAgentHost::GetOrCreateFor(parent_rvh)->GetId()); |
| 73 return; | 78 return; |
| 74 } | 79 } |
| 75 | 80 |
| 76 set_title(base::UTF16ToUTF8(web_contents->GetTitle())); | 81 set_title(base::UTF16ToUTF8(web_contents->GetTitle())); |
| 77 set_url(web_contents->GetURL()); | 82 set_url(web_contents->GetURL()); |
| 78 content::NavigationController& controller = web_contents->GetController(); | 83 content::NavigationController& controller = web_contents->GetController(); |
| 79 content::NavigationEntry* entry = controller.GetActiveEntry(); | 84 content::NavigationEntry* entry = controller.GetActiveEntry(); |
| 80 if (entry != NULL && entry->GetURL().is_valid()) | 85 if (entry != NULL && entry->GetURL().is_valid()) |
| 81 set_favicon_url(entry->GetFavicon().url); | 86 set_favicon_url(entry->GetFavicon().url); |
| 82 set_last_activity_time(web_contents->GetLastActiveTime()); | 87 set_last_activity_time(web_contents->GetLastActiveTime()); |
| 83 | 88 |
| 89 GuestViewBase* guest = GuestViewBase::FromWebContents(web_contents); |
| 90 if (guest) { |
| 91 set_type(kTargetTypeWebView); |
| 92 RenderViewHost* parent_rvh = |
| 93 guest->embedder_web_contents()->GetRenderViewHost(); |
| 94 set_parent_id(DevToolsAgentHost::GetOrCreateFor(parent_rvh)->GetId()); |
| 95 return; |
| 96 } |
| 97 |
| 84 if (is_tab) { | 98 if (is_tab) { |
| 85 set_type(kTargetTypePage); | 99 set_type(kTargetTypePage); |
| 86 tab_id_ = extensions::ExtensionTabUtil::GetTabId(web_contents); | 100 tab_id_ = extensions::ExtensionTabUtil::GetTabId(web_contents); |
| 87 } else { | 101 } else { |
| 88 Profile* profile = | 102 Profile* profile = |
| 89 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 103 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 90 if (profile) { | 104 if (profile) { |
| 91 ExtensionService* extension_service = profile->GetExtensionService(); | 105 ExtensionService* extension_service = profile->GetExtensionService(); |
| 92 const extensions::Extension* extension = extension_service-> | 106 const extensions::Extension* extension = extension_service-> |
| 93 extensions()->GetByID(GetURL().host()); | 107 extensions()->GetByID(GetURL().host()); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 | 213 |
| 200 // DevToolsTargetImpl ---------------------------------------------------------- | 214 // DevToolsTargetImpl ---------------------------------------------------------- |
| 201 | 215 |
| 202 DevToolsTargetImpl::~DevToolsTargetImpl() { | 216 DevToolsTargetImpl::~DevToolsTargetImpl() { |
| 203 } | 217 } |
| 204 | 218 |
| 205 DevToolsTargetImpl::DevToolsTargetImpl(DevToolsAgentHost* agent_host) | 219 DevToolsTargetImpl::DevToolsTargetImpl(DevToolsAgentHost* agent_host) |
| 206 : agent_host_(agent_host) { | 220 : agent_host_(agent_host) { |
| 207 } | 221 } |
| 208 | 222 |
| 223 std::string DevToolsTargetImpl::GetParentId() const { |
| 224 return parent_id_; |
| 225 } |
| 226 |
| 209 std::string DevToolsTargetImpl::GetId() const { | 227 std::string DevToolsTargetImpl::GetId() const { |
| 210 return agent_host_->GetId(); | 228 return agent_host_->GetId(); |
| 211 } | 229 } |
| 212 | 230 |
| 213 std::string DevToolsTargetImpl::GetType() const { | 231 std::string DevToolsTargetImpl::GetType() const { |
| 214 return type_; | 232 return type_; |
| 215 } | 233 } |
| 216 | 234 |
| 217 std::string DevToolsTargetImpl::GetTitle() const { | 235 std::string DevToolsTargetImpl::GetTitle() const { |
| 218 return title_; | 236 return title_; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 | 345 |
| 328 // static | 346 // static |
| 329 void DevToolsTargetImpl::EnumerateAllTargets(Callback callback) { | 347 void DevToolsTargetImpl::EnumerateAllTargets(Callback callback) { |
| 330 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 348 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 331 content::BrowserThread::PostTask( | 349 content::BrowserThread::PostTask( |
| 332 content::BrowserThread::IO, | 350 content::BrowserThread::IO, |
| 333 FROM_HERE, | 351 FROM_HERE, |
| 334 base::Bind(&DevToolsTargetImpl::EnumerateWorkerTargets, | 352 base::Bind(&DevToolsTargetImpl::EnumerateWorkerTargets, |
| 335 base::Bind(&CollectAllTargets, callback))); | 353 base::Bind(&CollectAllTargets, callback))); |
| 336 } | 354 } |
| OLD | NEW |