BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / task_management / providers / web_contents / extension_task.cc
blob9e6da132398dc92de57dfc0a6d46ab3a8f4b768e
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 {
20 namespace {
22 gfx::ImageSkia* g_default_icon = nullptr;
24 gfx::ImageSkia* GetDefaultIcon() {
25 if (!ResourceBundle::HasSharedInstance())
26 return nullptr;
28 if (!g_default_icon) {
29 g_default_icon = ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
30 IDR_EXTENSIONS_FAVICON);
33 return g_default_icon;
36 } // namespace
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),
42 GetDefaultIcon(),
43 web_contents,
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
58 // extension.
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 {
76 DCHECK(web_contents);
78 base::string16 title = extension ?
79 base::UTF8ToUTF16(extension->name()) :
80 RendererTask::GetTitleFromWebContents(web_contents);
82 bool is_background =
83 view_type == extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE;
85 return RendererTask::PrefixRendererTitle(
86 title,
87 extension && extension->is_app(),
88 true, // is_extension
89 web_contents->GetBrowserContext()->IsOffTheRecord(),
90 is_background);
93 void ExtensionTask::LoadExtensionIcon(const extensions::Extension* extension) {
94 if (!extension)
95 return;
97 extension_icon_.reset(
98 new extensions::IconImage(web_contents()->GetBrowserContext(),
99 extension,
100 extensions::IconsInfo::GetIcons(extension),
101 extension_misc::EXTENSION_ICON_SMALL,
102 icon(),
103 this));
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