QUIC - cleanup changes to sync chromium tree with internal source.
[chromium-blink-merge.git] / chrome / browser / task_manager / guest_information.cc
blob192b3e346baeeb703e86feda118a3c4b7dceca36
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.
5 #include "chrome/browser/task_manager/guest_information.h"
7 #include "base/strings/string16.h"
8 #include "chrome/browser/chrome_notification_types.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/task_manager/renderer_resource.h"
11 #include "chrome/browser/task_manager/resource_provider.h"
12 #include "chrome/browser/task_manager/task_manager.h"
13 #include "chrome/browser/task_manager/task_manager_util.h"
14 #include "chrome/grit/generated_resources.h"
15 #include "components/favicon/content/content_favicon_driver.h"
16 #include "components/guest_view/browser/guest_view_base.h"
17 #include "content/public/browser/notification_service.h"
18 #include "content/public/browser/render_frame_host.h"
19 #include "content/public/browser/render_process_host.h"
20 #include "content/public/browser/render_view_host.h"
21 #include "content/public/browser/render_widget_host_iterator.h"
22 #include "content/public/browser/site_instance.h"
23 #include "content/public/browser/web_contents.h"
24 #include "extensions/strings/grit/extensions_strings.h"
25 #include "ui/base/l10n/l10n_util.h"
26 #include "ui/gfx/image/image.h"
27 #include "ui/gfx/image/image_skia.h"
29 using content::RenderProcessHost;
30 using content::RenderViewHost;
31 using content::RenderWidgetHost;
32 using content::WebContents;
33 using extensions::Extension;
34 using guest_view::GuestViewBase;
36 namespace task_manager {
38 class GuestResource : public RendererResource {
39 public:
40 explicit GuestResource(content::RenderViewHost* render_view_host);
41 ~GuestResource() override;
43 // Resource methods:
44 Type GetType() const override;
45 base::string16 GetTitle() const override;
46 gfx::ImageSkia GetIcon() const override;
47 content::WebContents* GetWebContents() const override;
49 private:
50 DISALLOW_COPY_AND_ASSIGN(GuestResource);
53 GuestResource::GuestResource(RenderViewHost* render_view_host)
54 : RendererResource(
55 render_view_host->GetSiteInstance()->GetProcess()->GetHandle(),
56 render_view_host) {
59 GuestResource::~GuestResource() {
62 Resource::Type GuestResource::GetType() const {
63 return GUEST;
66 base::string16 GuestResource::GetTitle() const {
67 WebContents* web_contents = GetWebContents();
68 if (!web_contents) {
69 const int message_id = IDS_EXTENSION_TASK_MANAGER_WEBVIEW_TAG_PREFIX;
70 return l10n_util::GetStringFUTF16(message_id, base::string16());
72 GuestViewBase* guest = GuestViewBase::FromWebContents(web_contents);
73 return l10n_util::GetStringFUTF16(
74 guest->GetTaskPrefix(),
75 util::GetTitleFromWebContents(web_contents));
78 gfx::ImageSkia GuestResource::GetIcon() const {
79 WebContents* web_contents = GetWebContents();
80 if (web_contents) {
81 favicon::FaviconDriver* favicon_driver =
82 favicon::ContentFaviconDriver::FromWebContents(web_contents);
83 if (favicon_driver)
84 return favicon_driver->GetFavicon().AsImageSkia();
86 return gfx::ImageSkia();
89 WebContents* GuestResource::GetWebContents() const {
90 return WebContents::FromRenderViewHost(render_view_host());
93 ////////////////////////////////////////////////////////////////////////////////
94 // GuestInformation class
95 ////////////////////////////////////////////////////////////////////////////////
97 GuestInformation::GuestInformation() {}
99 GuestInformation::~GuestInformation() {}
101 bool GuestInformation::CheckOwnership(WebContents* web_contents) {
102 // Guest WebContentses are created and owned internally by the content layer.
103 return GuestViewBase::IsGuest(web_contents);
106 void GuestInformation::GetAll(const NewWebContentsCallback& callback) {
107 scoped_ptr<content::RenderWidgetHostIterator> widgets(
108 content::RenderWidgetHost::GetRenderWidgetHosts());
109 while (content::RenderWidgetHost* widget = widgets->GetNextHost()) {
110 if (widget->IsRenderView()) {
111 content::RenderViewHost* rvh = content::RenderViewHost::From(widget);
112 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
113 if (web_contents && GuestViewBase::IsGuest(web_contents))
114 callback.Run(web_contents);
119 scoped_ptr<RendererResource> GuestInformation::MakeResource(
120 WebContents* web_contents) {
121 return scoped_ptr<RendererResource>(
122 new GuestResource(web_contents->GetRenderViewHost()));
125 } // namespace task_manager