Give names to all utility processes.
[chromium-blink-merge.git] / chrome / browser / task_manager / guest_information.cc
blob0c7f7e1f667c6bfcad4a3bf3f8ad4d5dfb789296
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/favicon/favicon_tab_helper.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/task_manager/renderer_resource.h"
12 #include "chrome/browser/task_manager/resource_provider.h"
13 #include "chrome/browser/task_manager/task_manager.h"
14 #include "chrome/browser/task_manager/task_manager_util.h"
15 #include "chrome/grit/generated_resources.h"
16 #include "content/public/browser/notification_service.h"
17 #include "content/public/browser/render_frame_host.h"
18 #include "content/public/browser/render_process_host.h"
19 #include "content/public/browser/render_view_host.h"
20 #include "content/public/browser/render_widget_host_iterator.h"
21 #include "content/public/browser/site_instance.h"
22 #include "content/public/browser/web_contents.h"
23 #include "extensions/browser/guest_view/guest_view_base.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;
35 namespace task_manager {
37 class GuestResource : public RendererResource {
38 public:
39 explicit GuestResource(content::RenderViewHost* render_view_host);
40 ~GuestResource() override;
42 // Resource methods:
43 Type GetType() const override;
44 base::string16 GetTitle() const override;
45 gfx::ImageSkia GetIcon() const override;
46 content::WebContents* GetWebContents() const override;
48 private:
49 DISALLOW_COPY_AND_ASSIGN(GuestResource);
52 GuestResource::GuestResource(RenderViewHost* render_view_host)
53 : RendererResource(
54 render_view_host->GetSiteInstance()->GetProcess()->GetHandle(),
55 render_view_host) {
58 GuestResource::~GuestResource() {
61 Resource::Type GuestResource::GetType() const {
62 return GUEST;
65 base::string16 GuestResource::GetTitle() const {
66 WebContents* web_contents = GetWebContents();
67 if (!web_contents) {
68 const int message_id = IDS_EXTENSION_TASK_MANAGER_WEBVIEW_TAG_PREFIX;
69 return l10n_util::GetStringFUTF16(message_id, base::string16());
71 extensions::GuestViewBase* guest =
72 extensions::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 && FaviconTabHelper::FromWebContents(web_contents)) {
81 return FaviconTabHelper::FromWebContents(web_contents)->
82 GetFavicon().AsImageSkia();
84 return gfx::ImageSkia();
87 WebContents* GuestResource::GetWebContents() const {
88 return WebContents::FromRenderViewHost(render_view_host());
91 ////////////////////////////////////////////////////////////////////////////////
92 // GuestInformation class
93 ////////////////////////////////////////////////////////////////////////////////
95 GuestInformation::GuestInformation() {}
97 GuestInformation::~GuestInformation() {}
99 bool GuestInformation::CheckOwnership(WebContents* web_contents) {
100 // Guest WebContentses are created and owned internally by the content layer.
101 return extensions::GuestViewBase::IsGuest(web_contents);
104 void GuestInformation::GetAll(const NewWebContentsCallback& callback) {
105 scoped_ptr<content::RenderWidgetHostIterator> widgets(
106 content::RenderWidgetHost::GetRenderWidgetHosts());
107 while (content::RenderWidgetHost* widget = widgets->GetNextHost()) {
108 if (widget->IsRenderView()) {
109 content::RenderViewHost* rvh = content::RenderViewHost::From(widget);
110 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
111 if (web_contents && extensions::GuestViewBase::IsGuest(web_contents))
112 callback.Run(web_contents);
117 scoped_ptr<RendererResource> GuestInformation::MakeResource(
118 WebContents* web_contents) {
119 return scoped_ptr<RendererResource>(
120 new GuestResource(web_contents->GetRenderViewHost()));
123 } // namespace task_manager