Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/task_manager/guest_information.h" | 5 #include "chrome/browser/task_manager/guest_information.h" |
| 6 | 6 |
| 7 #include "base/strings/string16.h" | 7 #include "base/strings/string16.h" |
| 8 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
| 9 #include "chrome/browser/favicon/favicon_tab_helper.h" | 9 #include "chrome/browser/favicon/favicon_tab_helper.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/task_manager/renderer_resource.h" | 11 #include "chrome/browser/task_manager/renderer_resource.h" |
| 12 #include "chrome/browser/task_manager/resource_provider.h" | 12 #include "chrome/browser/task_manager/resource_provider.h" |
| 13 #include "chrome/browser/task_manager/task_manager.h" | 13 #include "chrome/browser/task_manager/task_manager.h" |
| 14 #include "chrome/browser/task_manager/task_manager_util.h" | 14 #include "chrome/browser/task_manager/task_manager_util.h" |
| 15 #include "chrome/grit/generated_resources.h" | 15 #include "chrome/grit/generated_resources.h" |
| 16 #include "content/public/browser/notification_service.h" | 16 #include "content/public/browser/notification_service.h" |
| 17 #include "content/public/browser/render_frame_host.h" | 17 #include "content/public/browser/render_frame_host.h" |
| 18 #include "content/public/browser/render_process_host.h" | 18 #include "content/public/browser/render_process_host.h" |
| 19 #include "content/public/browser/render_view_host.h" | 19 #include "content/public/browser/render_view_host.h" |
| 20 #include "content/public/browser/render_widget_host_iterator.h" | 20 #include "content/public/browser/render_widget_host_iterator.h" |
| 21 #include "content/public/browser/site_instance.h" | 21 #include "content/public/browser/site_instance.h" |
| 22 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
| 23 #include "extensions/browser/guest_view/guest_view_base.h" | |
| 23 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
| 24 #include "ui/gfx/image/image.h" | 25 #include "ui/gfx/image/image.h" |
| 25 #include "ui/gfx/image/image_skia.h" | 26 #include "ui/gfx/image/image_skia.h" |
| 26 | 27 |
| 27 using content::RenderProcessHost; | 28 using content::RenderProcessHost; |
| 28 using content::RenderViewHost; | 29 using content::RenderViewHost; |
| 29 using content::RenderWidgetHost; | 30 using content::RenderWidgetHost; |
| 30 using content::WebContents; | 31 using content::WebContents; |
| 31 using extensions::Extension; | 32 using extensions::Extension; |
| 32 | 33 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 55 | 56 |
| 56 GuestResource::~GuestResource() { | 57 GuestResource::~GuestResource() { |
| 57 } | 58 } |
| 58 | 59 |
| 59 Resource::Type GuestResource::GetType() const { | 60 Resource::Type GuestResource::GetType() const { |
| 60 return GUEST; | 61 return GUEST; |
| 61 } | 62 } |
| 62 | 63 |
| 63 base::string16 GuestResource::GetTitle() const { | 64 base::string16 GuestResource::GetTitle() const { |
| 64 WebContents* web_contents = GetWebContents(); | 65 WebContents* web_contents = GetWebContents(); |
| 65 const int message_id = IDS_TASK_MANAGER_WEBVIEW_TAG_PREFIX; | 66 if (!web_contents) { |
| 66 if (web_contents) { | 67 const int message_id = IDS_TASK_MANAGER_WEBVIEW_TAG_PREFIX; |
| 67 base::string16 title = util::GetTitleFromWebContents(web_contents); | 68 return l10n_util::GetStringFUTF16(message_id, base::string16()); |
| 68 return l10n_util::GetStringFUTF16(message_id, title); | |
| 69 } | 69 } |
| 70 return l10n_util::GetStringFUTF16(message_id, base::string16()); | 70 extensions::GuestViewBase* guest = |
| 71 extensions::GuestViewBase::FromWebContents(web_contents); | |
| 72 int message_id = guest->GetTaskPrefix() ? guest->GetTaskPrefix() : | |
| 73 IDS_TASK_MANAGER_WEBVIEW_TAG_PREFIX; | |
| 74 return l10n_util::GetStringFUTF16(message_id, | |
| 75 guest->GetTaskTitle()); | |
|
Charlie Reis
2014/08/25 20:25:41
Why do we need GetTaskTitle? It looks like that's
Fady Samuel
2014/08/25 23:05:52
That code lives in chrome, this code lives in exte
Charlie Reis
2014/08/25 23:47:22
But the only caller of this is in chrome, right?
| |
| 71 } | 76 } |
| 72 | 77 |
| 73 gfx::ImageSkia GuestResource::GetIcon() const { | 78 gfx::ImageSkia GuestResource::GetIcon() const { |
| 74 WebContents* web_contents = GetWebContents(); | 79 WebContents* web_contents = GetWebContents(); |
| 75 if (web_contents && FaviconTabHelper::FromWebContents(web_contents)) { | 80 if (web_contents && FaviconTabHelper::FromWebContents(web_contents)) { |
| 76 return FaviconTabHelper::FromWebContents(web_contents)-> | 81 return FaviconTabHelper::FromWebContents(web_contents)-> |
| 77 GetFavicon().AsImageSkia(); | 82 GetFavicon().AsImageSkia(); |
| 78 } | 83 } |
| 79 return gfx::ImageSkia(); | 84 return gfx::ImageSkia(); |
| 80 } | 85 } |
| 81 | 86 |
| 82 WebContents* GuestResource::GetWebContents() const { | 87 WebContents* GuestResource::GetWebContents() const { |
| 83 return WebContents::FromRenderViewHost(render_view_host()); | 88 return WebContents::FromRenderViewHost(render_view_host()); |
| 84 } | 89 } |
| 85 | 90 |
| 86 //////////////////////////////////////////////////////////////////////////////// | 91 //////////////////////////////////////////////////////////////////////////////// |
| 87 // GuestInformation class | 92 // GuestInformation class |
| 88 //////////////////////////////////////////////////////////////////////////////// | 93 //////////////////////////////////////////////////////////////////////////////// |
| 89 | 94 |
| 90 GuestInformation::GuestInformation() {} | 95 GuestInformation::GuestInformation() {} |
| 91 | 96 |
| 92 GuestInformation::~GuestInformation() {} | 97 GuestInformation::~GuestInformation() {} |
| 93 | 98 |
| 94 bool GuestInformation::CheckOwnership(WebContents* web_contents) { | 99 bool GuestInformation::CheckOwnership(WebContents* web_contents) { |
| 95 // Guest WebContentses are created and owned internally by the content layer. | 100 // Guest WebContentses are created and owned internally by the content layer. |
| 96 return web_contents->IsSubframe(); | 101 return extensions::GuestViewBase::IsGuest(web_contents); |
| 97 } | 102 } |
| 98 | 103 |
| 99 void GuestInformation::GetAll(const NewWebContentsCallback& callback) { | 104 void GuestInformation::GetAll(const NewWebContentsCallback& callback) { |
| 100 scoped_ptr<content::RenderWidgetHostIterator> widgets( | 105 scoped_ptr<content::RenderWidgetHostIterator> widgets( |
| 101 content::RenderWidgetHost::GetRenderWidgetHosts()); | 106 content::RenderWidgetHost::GetRenderWidgetHosts()); |
| 102 while (content::RenderWidgetHost* widget = widgets->GetNextHost()) { | 107 while (content::RenderWidgetHost* widget = widgets->GetNextHost()) { |
| 103 if (widget->IsRenderView()) { | 108 if (widget->IsRenderView()) { |
| 104 content::RenderViewHost* rvh = content::RenderViewHost::From(widget); | 109 content::RenderViewHost* rvh = content::RenderViewHost::From(widget); |
| 105 WebContents* web_contents = WebContents::FromRenderViewHost(rvh); | 110 WebContents* web_contents = WebContents::FromRenderViewHost(rvh); |
| 106 if (web_contents && web_contents->IsSubframe()) | 111 if (web_contents && extensions::GuestViewBase::IsGuest(web_contents)) |
| 107 callback.Run(web_contents); | 112 callback.Run(web_contents); |
| 108 } | 113 } |
| 109 } | 114 } |
| 110 } | 115 } |
| 111 | 116 |
| 112 scoped_ptr<RendererResource> GuestInformation::MakeResource( | 117 scoped_ptr<RendererResource> GuestInformation::MakeResource( |
| 113 WebContents* web_contents) { | 118 WebContents* web_contents) { |
| 114 return scoped_ptr<RendererResource>( | 119 return scoped_ptr<RendererResource>( |
| 115 new GuestResource(web_contents->GetRenderViewHost())); | 120 new GuestResource(web_contents->GetRenderViewHost())); |
| 116 } | 121 } |
| 117 | 122 |
| 118 } // namespace task_manager | 123 } // namespace task_manager |
| OLD | NEW |