Give names to all utility processes.
[chromium-blink-merge.git] / chrome / browser / task_manager / panel_information.cc
blob189b9a649fef630ad506eef4bb28c930b09960e1
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/panel_information.h"
7 #include "base/i18n/rtl.h"
8 #include "chrome/browser/extensions/extension_service.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/task_manager/renderer_resource.h"
11 #include "chrome/browser/task_manager/task_manager_util.h"
12 #include "chrome/browser/ui/panels/panel.h"
13 #include "chrome/browser/ui/panels/panel_manager.h"
14 #include "content/public/browser/notification_service.h"
15 #include "content/public/browser/render_frame_host.h"
16 #include "content/public/browser/render_process_host.h"
17 #include "content/public/browser/render_view_host.h"
18 #include "content/public/browser/web_contents.h"
19 #include "extensions/browser/extension_registry.h"
20 #include "extensions/browser/view_type_utils.h"
21 #include "extensions/common/extension.h"
22 #include "ui/base/l10n/l10n_util.h"
23 #include "ui/gfx/image/image_skia.h"
25 using content::RenderProcessHost;
26 using content::RenderViewHost;
27 using content::WebContents;
28 using extensions::Extension;
30 namespace task_manager {
32 class PanelResource : public RendererResource {
33 public:
34 explicit PanelResource(Panel* panel);
35 ~PanelResource() override;
37 // Resource methods:
38 Type GetType() const override;
39 base::string16 GetTitle() const override;
40 gfx::ImageSkia GetIcon() const override;
41 content::WebContents* GetWebContents() const override;
43 private:
44 Panel* panel_;
45 // Determines prefix for title reflecting whether extensions are apps
46 // or in incognito mode.
47 int message_prefix_id_;
49 DISALLOW_COPY_AND_ASSIGN(PanelResource);
52 PanelResource::PanelResource(Panel* panel)
53 : RendererResource(
54 panel->GetWebContents()->GetRenderProcessHost()->GetHandle(),
55 panel->GetWebContents()->GetRenderViewHost()),
56 panel_(panel) {
57 extensions::ExtensionRegistry* registry =
58 extensions::ExtensionRegistry::Get(panel_->profile());
59 message_prefix_id_ = util::GetMessagePrefixID(
60 registry->enabled_extensions().GetByID(panel_->extension_id())->is_app(),
61 true, // is_extension
62 panel_->profile()->IsOffTheRecord(),
63 false, // is_prerender
64 false); // is_background
67 PanelResource::~PanelResource() {
70 Resource::Type PanelResource::GetType() const {
71 return EXTENSION;
74 base::string16 PanelResource::GetTitle() const {
75 base::string16 title = panel_->GetWindowTitle();
76 // Since the title will be concatenated with an IDS_TASK_MANAGER_* prefix
77 // we need to explicitly set the title to be LTR format if there is no
78 // strong RTL charater in it. Otherwise, if the task manager prefix is an
79 // RTL word, the concatenated result might be wrong. For example,
80 // a page whose title is "Yahoo! Mail: The best web-based Email!", without
81 // setting it explicitly as LTR format, the concatenated result will be
82 // "!Yahoo! Mail: The best web-based Email :PPA", in which the capital
83 // letters "PPA" stands for the Hebrew word for "app".
84 base::i18n::AdjustStringForLocaleDirection(&title);
86 return l10n_util::GetStringFUTF16(message_prefix_id_, title);
89 gfx::ImageSkia PanelResource::GetIcon() const {
90 gfx::Image icon = panel_->GetCurrentPageIcon();
91 return icon.IsEmpty() ? gfx::ImageSkia() : *icon.ToImageSkia();
94 WebContents* PanelResource::GetWebContents() const {
95 return panel_->GetWebContents();
98 ////////////////////////////////////////////////////////////////////////////////
99 // PanelInformation class
100 ////////////////////////////////////////////////////////////////////////////////
102 PanelInformation::PanelInformation() {}
104 PanelInformation::~PanelInformation() {}
106 bool PanelInformation::CheckOwnership(WebContents* web_contents) {
107 std::vector<Panel*> panels = PanelManager::GetInstance()->panels();
108 for (size_t i = 0; i < panels.size(); ++i) {
109 if (panels[i]->GetWebContents() == web_contents) {
110 return true;
113 return false;
116 void PanelInformation::GetAll(const NewWebContentsCallback& callback) {
117 // Add all the Panels.
118 std::vector<Panel*> panels = PanelManager::GetInstance()->panels();
119 for (size_t i = 0; i < panels.size(); ++i)
120 callback.Run(panels[i]->GetWebContents());
123 scoped_ptr<RendererResource> PanelInformation::MakeResource(
124 WebContents* web_contents) {
125 std::vector<Panel*> panels = PanelManager::GetInstance()->panels();
126 for (size_t i = 0; i < panels.size(); ++i) {
127 if (panels[i]->GetWebContents() == web_contents) {
128 return scoped_ptr<RendererResource>(new PanelResource(panels[i]));
131 NOTREACHED();
132 return scoped_ptr<RendererResource>();
135 } // namespace task_manager