This source file includes following definitions.
- panel_
- GetType
- GetTitle
- GetIcon
- GetWebContents
- CheckOwnership
- GetAll
- MakeResource
#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/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);
virtual ~PanelResource();
virtual Type GetType() const OVERRIDE;
virtual base::string16 GetTitle() const OVERRIDE;
virtual gfx::ImageSkia GetIcon() const OVERRIDE;
virtual content::WebContents* GetWebContents() const OVERRIDE;
private:
Panel* panel_;
int message_prefix_id_;
DISALLOW_COPY_AND_ASSIGN(PanelResource);
};
PanelResource::PanelResource(Panel* panel)
: RendererResource(
panel->GetWebContents()->GetRenderProcessHost()->GetHandle(),
panel->GetWebContents()->GetRenderViewHost()),
panel_(panel) {
ExtensionService* service = panel_->profile()->GetExtensionService();
message_prefix_id_ = util::GetMessagePrefixID(
service->extensions()->GetByID(panel_->extension_id())->is_app(),
true,
panel_->profile()->IsOffTheRecord(),
false,
false);
}
PanelResource::~PanelResource() {
}
Resource::Type PanelResource::GetType() const {
return EXTENSION;
}
base::string16 PanelResource::GetTitle() const {
base::string16 title = panel_->GetWindowTitle();
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::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) {
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>();
}
}