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
|
// 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/extension_task.h"
#include "base/strings/utf_string_conversions.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/web_contents.h"
#include "extensions/browser/view_type_utils.h"
#include "extensions/common/extension.h"
#include "extensions/common/view_type.h"
#include "grit/theme_resources.h"
#include "ui/base/resource/resource_bundle.h"
namespace task_management {
namespace {
gfx::ImageSkia* g_default_icon = nullptr;
gfx::ImageSkia* GetDefaultIcon() {
if (!ResourceBundle::HasSharedInstance())
return nullptr;
if (!g_default_icon) {
g_default_icon = ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
IDR_EXTENSIONS_FAVICON);
}
return g_default_icon;
}
} // namespace
ExtensionTask::ExtensionTask(content::WebContents* web_contents,
const extensions::Extension* extension,
extensions::ViewType view_type)
: RendererTask(GetExtensionTitle(web_contents, extension, view_type),
GetDefaultIcon(),
web_contents,
web_contents->GetRenderProcessHost()) {
}
ExtensionTask::~ExtensionTask() {
}
void ExtensionTask::OnTitleChanged(content::NavigationEntry* entry) {
// The title of the extension should not change as a result of title change
// in its WebContents, so we ignore this.
}
void ExtensionTask::OnFaviconChanged() {
// For now we never change the favicon of the extension, we always use the
// default one.
// TODO(afakhry): In the future use the extensions' favicons.
}
Task::Type ExtensionTask::GetType() const {
return Task::EXTENSION;
}
base::string16 ExtensionTask::GetExtensionTitle(
content::WebContents* web_contents,
const extensions::Extension* extension,
extensions::ViewType view_type) const {
DCHECK(web_contents);
base::string16 title = extension ?
base::UTF8ToUTF16(extension->name()) :
RendererTask::GetTitleFromWebContents(web_contents);
bool is_background =
view_type == extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE;
return RendererTask::PrefixRendererTitle(
title,
extension->is_app(),
true, // is_extension
web_contents->GetBrowserContext()->IsOffTheRecord(),
is_background);
}
} // namespace task_management
|