Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(230)

Side by Side Diff: chrome/browser/task_manager/panel_information.cc

Issue 2197483003: Move the Mac Task Manager to the new backend code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: mark Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "chrome/browser/task_manager/panel_information.h"
6
7 #include <stddef.h>
8
9 #include "base/i18n/rtl.h"
10 #include "base/macros.h"
11 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/task_manager/renderer_resource.h"
14 #include "chrome/browser/task_manager/task_manager_util.h"
15 #include "chrome/browser/ui/panels/panel.h"
16 #include "chrome/browser/ui/panels/panel_manager.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/web_contents.h"
22 #include "extensions/browser/extension_registry.h"
23 #include "extensions/browser/view_type_utils.h"
24 #include "extensions/common/extension.h"
25 #include "ui/base/l10n/l10n_util.h"
26 #include "ui/gfx/image/image_skia.h"
27
28 using content::RenderProcessHost;
29 using content::RenderViewHost;
30 using content::WebContents;
31 using extensions::Extension;
32
33 namespace task_manager {
34
35 class PanelResource : public RendererResource {
36 public:
37 explicit PanelResource(Panel* panel);
38 ~PanelResource() override;
39
40 // Resource methods:
41 Type GetType() const override;
42 base::string16 GetTitle() const override;
43 gfx::ImageSkia GetIcon() const override;
44 content::WebContents* GetWebContents() const override;
45
46 private:
47 Panel* panel_;
48 // Determines prefix for title reflecting whether extensions are apps
49 // or in incognito mode.
50 int message_prefix_id_;
51
52 DISALLOW_COPY_AND_ASSIGN(PanelResource);
53 };
54
55 PanelResource::PanelResource(Panel* panel)
56 : RendererResource(
57 panel->GetWebContents()->GetRenderProcessHost()->GetHandle(),
58 panel->GetWebContents()->GetRenderViewHost()),
59 panel_(panel) {
60 extensions::ExtensionRegistry* registry =
61 extensions::ExtensionRegistry::Get(panel_->profile());
62 message_prefix_id_ = util::GetMessagePrefixID(
63 registry->enabled_extensions().GetByID(panel_->extension_id())->is_app(),
64 true, // is_extension
65 panel_->profile()->IsOffTheRecord(),
66 false, // is_prerender
67 false); // is_background
68 }
69
70 PanelResource::~PanelResource() {
71 }
72
73 Resource::Type PanelResource::GetType() const {
74 return EXTENSION;
75 }
76
77 base::string16 PanelResource::GetTitle() const {
78 base::string16 title = panel_->GetWindowTitle();
79 // Since the title will be concatenated with an IDS_TASK_MANAGER_* prefix
80 // we need to explicitly set the title to be LTR format if there is no
81 // strong RTL charater in it. Otherwise, if the task manager prefix is an
82 // RTL word, the concatenated result might be wrong. For example,
83 // a page whose title is "Yahoo! Mail: The best web-based Email!", without
84 // setting it explicitly as LTR format, the concatenated result will be
85 // "!Yahoo! Mail: The best web-based Email :PPA", in which the capital
86 // letters "PPA" stands for the Hebrew word for "app".
87 base::i18n::AdjustStringForLocaleDirection(&title);
88
89 return l10n_util::GetStringFUTF16(message_prefix_id_, title);
90 }
91
92 gfx::ImageSkia PanelResource::GetIcon() const {
93 gfx::Image icon = panel_->GetCurrentPageIcon();
94 return icon.IsEmpty() ? gfx::ImageSkia() : *icon.ToImageSkia();
95 }
96
97 WebContents* PanelResource::GetWebContents() const {
98 return panel_->GetWebContents();
99 }
100
101 ////////////////////////////////////////////////////////////////////////////////
102 // PanelInformation class
103 ////////////////////////////////////////////////////////////////////////////////
104
105 PanelInformation::PanelInformation() {}
106
107 PanelInformation::~PanelInformation() {}
108
109 bool PanelInformation::CheckOwnership(WebContents* web_contents) {
110 std::vector<Panel*> panels = PanelManager::GetInstance()->panels();
111 for (size_t i = 0; i < panels.size(); ++i) {
112 if (panels[i]->GetWebContents() == web_contents) {
113 return true;
114 }
115 }
116 return false;
117 }
118
119 void PanelInformation::GetAll(const NewWebContentsCallback& callback) {
120 // Add all the Panels.
121 std::vector<Panel*> panels = PanelManager::GetInstance()->panels();
122 for (size_t i = 0; i < panels.size(); ++i)
123 callback.Run(panels[i]->GetWebContents());
124 }
125
126 std::unique_ptr<RendererResource> PanelInformation::MakeResource(
127 WebContents* web_contents) {
128 std::vector<Panel*> panels = PanelManager::GetInstance()->panels();
129 for (size_t i = 0; i < panels.size(); ++i) {
130 if (panels[i]->GetWebContents() == web_contents) {
131 return std::unique_ptr<RendererResource>(new PanelResource(panels[i]));
132 }
133 }
134 NOTREACHED();
135 return std::unique_ptr<RendererResource>();
136 }
137
138 } // namespace task_manager
OLDNEW
« no previous file with comments | « chrome/browser/task_manager/panel_information.h ('k') | chrome/browser/task_manager/printing_information.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698