1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/task_manager/panel_information.h"
#include "base/i18n/rtl.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/task_manager/renderer_resource.h"
#include "chrome/browser/task_manager/task_manager_util.h"
#include "chrome/browser/ui/panels/panel.h"
#include "chrome/browser/ui/panels/panel_manager.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/view_type_utils.h"
#include "extensions/common/extension.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/image/image_skia.h"
using content::RenderProcessHost;
using content::RenderViewHost;
using content::WebContents;
using extensions::Extension;
namespace task_manager {
class PanelResource : public RendererResource {
public:
explicit PanelResource(Panel* panel);
~PanelResource() override;
// Resource methods:
Type GetType() const override;
base::string16 GetTitle() const override;
gfx::ImageSkia GetIcon() const override;
content::WebContents* GetWebContents() const override;
private:
Panel* panel_;
// Determines prefix for title reflecting whether extensions are apps
// or in incognito mode.
int message_prefix_id_;
DISALLOW_COPY_AND_ASSIGN(PanelResource);
};
PanelResource::PanelResource(Panel* panel)
: RendererResource(
panel->GetWebContents()->GetRenderProcessHost()->GetHandle(),
panel->GetWebContents()->GetRenderViewHost()),
panel_(panel) {
extensions::ExtensionRegistry* registry =
extensions::ExtensionRegistry::Get(panel_->profile());
message_prefix_id_ = util::GetMessagePrefixID(
registry->enabled_extensions().GetByID(panel_->extension_id())->is_app(),
true, // is_extension
panel_->profile()->IsOffTheRecord(),
false, // is_prerender
false); // is_background
}
PanelResource::~PanelResource() {
}
Resource::Type PanelResource::GetType() const {
return EXTENSION;
}
base::string16 PanelResource::GetTitle() const {
base::string16 title = panel_->GetWindowTitle();
// Since the title will be concatenated with an IDS_TASK_MANAGER_* prefix
// we need to explicitly set the title to be LTR format if there is no
// strong RTL charater in it. Otherwise, if the task manager prefix is an
// RTL word, the concatenated result might be wrong. For example,
// a page whose title is "Yahoo! Mail: The best web-based Email!", without
// setting it explicitly as LTR format, the concatenated result will be
// "!Yahoo! Mail: The best web-based Email :PPA", in which the capital
// letters "PPA" stands for the Hebrew word for "app".
base::i18n::AdjustStringForLocaleDirection(&title);
return l10n_util::GetStringFUTF16(message_prefix_id_, title);
}
gfx::ImageSkia PanelResource::GetIcon() const {
gfx::Image icon = panel_->GetCurrentPageIcon();
return icon.IsEmpty() ? gfx::ImageSkia() : *icon.ToImageSkia();
}
WebContents* PanelResource::GetWebContents() const {
return panel_->GetWebContents();
}
////////////////////////////////////////////////////////////////////////////////
// PanelInformation class
////////////////////////////////////////////////////////////////////////////////
PanelInformation::PanelInformation() {}
PanelInformation::~PanelInformation() {}
bool PanelInformation::CheckOwnership(WebContents* web_contents) {
std::vector<Panel*> panels = PanelManager::GetInstance()->panels();
for (size_t i = 0; i < panels.size(); ++i) {
if (panels[i]->GetWebContents() == web_contents) {
return true;
}
}
return false;
}
void PanelInformation::GetAll(const NewWebContentsCallback& callback) {
// Add all the Panels.
std::vector<Panel*> panels = PanelManager::GetInstance()->panels();
for (size_t i = 0; i < panels.size(); ++i)
callback.Run(panels[i]->GetWebContents());
}
scoped_ptr<RendererResource> PanelInformation::MakeResource(
WebContents* web_contents) {
std::vector<Panel*> panels = PanelManager::GetInstance()->panels();
for (size_t i = 0; i < panels.size(); ++i) {
if (panels[i]->GetWebContents() == web_contents) {
return scoped_ptr<RendererResource>(new PanelResource(panels[i]));
}
}
NOTREACHED();
return scoped_ptr<RendererResource>();
}
} // namespace task_manager
|