Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / task_management / providers / web_contents / panel_task.cc
blobce07140ffd347f5ba660959d7698117d92e0a80f
1 // Copyright 2015 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_management/providers/web_contents/panel_task.h"
7 #include "base/i18n/rtl.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/panels/panel.h"
10 #include "content/public/browser/web_contents.h"
11 #include "extensions/browser/extension_registry.h"
12 #include "ui/gfx/image/image_skia.h"
14 namespace task_management {
16 namespace {
18 const gfx::ImageSkia* GetPanelIcon(Panel* panel) {
19 const gfx::Image icon = panel->GetCurrentPageIcon();
20 return !icon.IsEmpty() ? icon.ToImageSkia() : nullptr;
23 } // namespace
25 PanelTask::PanelTask(Panel* panel, content::WebContents* web_contents)
26 : RendererTask(GetCurrentPanelTitle(panel),
27 GetPanelIcon(panel),
28 web_contents,
29 web_contents->GetRenderProcessHost()),
30 panel_(panel) {
33 PanelTask::~PanelTask() {
36 void PanelTask::OnTitleChanged(content::NavigationEntry* entry) {
37 set_title(GetCurrentPanelTitle(panel_));
40 void PanelTask::OnFaviconChanged() {
41 const gfx::ImageSkia* icon = GetPanelIcon(panel_);
42 set_icon(icon ? *icon : gfx::ImageSkia());
45 Task::Type PanelTask::GetType() const {
46 return Task::EXTENSION;
49 base::string16 PanelTask::GetCurrentPanelTitle(Panel* panel) const {
50 base::string16 title = panel->GetWindowTitle();
51 base::i18n::AdjustStringForLocaleDirection(&title);
53 extensions::ExtensionRegistry* registry =
54 extensions::ExtensionRegistry::Get(panel->profile());
55 const extensions::Extension* extension =
56 registry->enabled_extensions().GetByID(panel->extension_id());
58 const bool is_app = extension && extension->is_app();
59 const bool is_incognito = panel->profile()->IsOffTheRecord();
61 return PrefixRendererTitle(title,
62 is_app,
63 true, // is_extension.
64 is_incognito,
65 false); // is_background.
68 } // namespace task_management