summaryrefslogtreecommitdiffstats
path: root/chrome/browser/task_management/providers/web_contents/panel_task.cc
blob: ce07140ffd347f5ba660959d7698117d92e0a80f (plain)
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
// Copyright 2015 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_management/providers/web_contents/panel_task.h"

#include "base/i18n/rtl.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/panels/panel.h"
#include "content/public/browser/web_contents.h"
#include "extensions/browser/extension_registry.h"
#include "ui/gfx/image/image_skia.h"

namespace task_management {

namespace {

const gfx::ImageSkia* GetPanelIcon(Panel* panel) {
  const gfx::Image icon = panel->GetCurrentPageIcon();
  return !icon.IsEmpty() ? icon.ToImageSkia() : nullptr;
}

}  // namespace

PanelTask::PanelTask(Panel* panel, content::WebContents* web_contents)
    : RendererTask(GetCurrentPanelTitle(panel),
                   GetPanelIcon(panel),
                   web_contents,
                   web_contents->GetRenderProcessHost()),
      panel_(panel) {
}

PanelTask::~PanelTask() {
}

void PanelTask::OnTitleChanged(content::NavigationEntry* entry) {
  set_title(GetCurrentPanelTitle(panel_));
}

void PanelTask::OnFaviconChanged() {
  const gfx::ImageSkia* icon = GetPanelIcon(panel_);
  set_icon(icon ? *icon : gfx::ImageSkia());
}

Task::Type PanelTask::GetType() const {
  return Task::EXTENSION;
}

base::string16 PanelTask::GetCurrentPanelTitle(Panel* panel) const {
  base::string16 title = panel->GetWindowTitle();
  base::i18n::AdjustStringForLocaleDirection(&title);

  extensions::ExtensionRegistry* registry =
      extensions::ExtensionRegistry::Get(panel->profile());
  const extensions::Extension* extension =
      registry->enabled_extensions().GetByID(panel->extension_id());

  const bool is_app = extension && extension->is_app();
  const bool is_incognito = panel->profile()->IsOffTheRecord();

  return PrefixRendererTitle(title,
                             is_app,
                             true,  // is_extension.
                             is_incognito,
                             false);  // is_background.
}

}  // namespace task_management