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/extension_task.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "content/public/browser/browser_context.h"
9 #include "content/public/browser/web_contents.h"
10 #include "extensions/browser/view_type_utils.h"
11 #include "extensions/common/constants.h"
12 #include "extensions/common/extension.h"
13 #include "extensions/common/manifest_handlers/icons_handler.h"
14 #include "extensions/common/view_type.h"
15 #include "grit/theme_resources.h"
16 #include "ui/base/resource/resource_bundle.h"
18 namespace task_management
{
22 gfx::ImageSkia
* g_default_icon
= nullptr;
24 gfx::ImageSkia
* GetDefaultIcon() {
25 if (!ResourceBundle::HasSharedInstance())
28 if (!g_default_icon
) {
29 g_default_icon
= ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
30 IDR_EXTENSIONS_FAVICON
);
33 return g_default_icon
;
38 ExtensionTask::ExtensionTask(content::WebContents
* web_contents
,
39 const extensions::Extension
* extension
,
40 extensions::ViewType view_type
)
41 : RendererTask(GetExtensionTitle(web_contents
, extension
, view_type
),
44 web_contents
->GetRenderProcessHost()) {
45 LoadExtensionIcon(extension
);
48 ExtensionTask::~ExtensionTask() {
51 void ExtensionTask::UpdateTitle() {
52 // The title of the extension should not change as a result of title change
53 // in its WebContents, so we ignore this.
56 void ExtensionTask::UpdateFavicon() {
57 // We don't care about the favicon of the WebContents but rather of the
61 Task::Type
ExtensionTask::GetType() const {
62 return Task::EXTENSION
;
65 void ExtensionTask::OnExtensionIconImageChanged(extensions::IconImage
* image
) {
66 DCHECK_EQ(extension_icon_
.get(), image
);
68 if (!image
->image_skia().isNull())
69 set_icon(image
->image_skia());
72 base::string16
ExtensionTask::GetExtensionTitle(
73 content::WebContents
* web_contents
,
74 const extensions::Extension
* extension
,
75 extensions::ViewType view_type
) const {
78 base::string16 title
= extension
?
79 base::UTF8ToUTF16(extension
->name()) :
80 RendererTask::GetTitleFromWebContents(web_contents
);
83 view_type
== extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE
;
85 return RendererTask::PrefixRendererTitle(
87 extension
&& extension
->is_app(),
89 web_contents
->GetBrowserContext()->IsOffTheRecord(),
93 void ExtensionTask::LoadExtensionIcon(const extensions::Extension
* extension
) {
97 extension_icon_
.reset(
98 new extensions::IconImage(web_contents()->GetBrowserContext(),
100 extensions::IconsInfo::GetIcons(extension
),
101 extension_misc::EXTENSION_ICON_SMALL
,
105 // Triggers actual image loading with 1x resources.
106 extension_icon_
->image_skia().GetRepresentation(1.0f
);
107 set_icon(extension_icon_
->image_skia());
110 } // namespace task_management