Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/task_management/providers/web_contents/extension_task.h " | 5 #include "chrome/browser/task_management/providers/web_contents/extension_task.h " |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "content/public/browser/browser_context.h" | 8 #include "content/public/browser/browser_context.h" |
| 9 #include "content/public/browser/web_contents.h" | 9 #include "content/public/browser/web_contents.h" |
| 10 #include "extensions/browser/view_type_utils.h" | 10 #include "extensions/browser/view_type_utils.h" |
| 11 #include "extensions/common/constants.h" | |
| 11 #include "extensions/common/extension.h" | 12 #include "extensions/common/extension.h" |
| 13 #include "extensions/common/manifest_handlers/icons_handler.h" | |
| 12 #include "extensions/common/view_type.h" | 14 #include "extensions/common/view_type.h" |
| 13 #include "grit/theme_resources.h" | 15 #include "grit/theme_resources.h" |
| 14 #include "ui/base/resource/resource_bundle.h" | 16 #include "ui/base/resource/resource_bundle.h" |
| 15 | 17 |
| 16 namespace task_management { | 18 namespace task_management { |
| 17 | 19 |
| 18 namespace { | 20 namespace { |
| 19 | 21 |
| 20 gfx::ImageSkia* g_default_icon = nullptr; | 22 gfx::ImageSkia* g_default_icon = nullptr; |
| 21 | 23 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 33 | 35 |
| 34 } // namespace | 36 } // namespace |
| 35 | 37 |
| 36 ExtensionTask::ExtensionTask(content::WebContents* web_contents, | 38 ExtensionTask::ExtensionTask(content::WebContents* web_contents, |
| 37 const extensions::Extension* extension, | 39 const extensions::Extension* extension, |
| 38 extensions::ViewType view_type) | 40 extensions::ViewType view_type) |
| 39 : RendererTask(GetExtensionTitle(web_contents, extension, view_type), | 41 : RendererTask(GetExtensionTitle(web_contents, extension, view_type), |
| 40 GetDefaultIcon(), | 42 GetDefaultIcon(), |
| 41 web_contents, | 43 web_contents, |
| 42 web_contents->GetRenderProcessHost()) { | 44 web_contents->GetRenderProcessHost()) { |
| 45 LoadExtensionIcon(web_contents, extension); | |
| 43 } | 46 } |
| 44 | 47 |
| 45 ExtensionTask::~ExtensionTask() { | 48 ExtensionTask::~ExtensionTask() { |
| 46 } | 49 } |
| 47 | 50 |
| 48 void ExtensionTask::OnTitleChanged(content::NavigationEntry* entry) { | 51 void ExtensionTask::OnTitleChanged(content::NavigationEntry* entry) { |
| 49 // The title of the extension should not change as a result of title change | 52 // The title of the extension should not change as a result of title change |
| 50 // in its WebContents, so we ignore this. | 53 // in its WebContents, so we ignore this. |
| 51 } | 54 } |
| 52 | 55 |
| 53 void ExtensionTask::OnFaviconChanged() { | 56 void ExtensionTask::OnFaviconChanged() { |
| 54 // For now we never change the favicon of the extension, we always use the | 57 // We don't care about the favicon of the WebContents but rather of the |
| 55 // default one. | 58 // extension. |
| 56 // TODO(afakhry): In the future use the extensions' favicons. | |
| 57 } | 59 } |
| 58 | 60 |
| 59 Task::Type ExtensionTask::GetType() const { | 61 Task::Type ExtensionTask::GetType() const { |
| 60 return Task::EXTENSION; | 62 return Task::EXTENSION; |
| 61 } | 63 } |
| 62 | 64 |
| 65 void ExtensionTask::OnExtensionIconImageChanged(extensions::IconImage* image) { | |
| 66 DCHECK_EQ(extension_icon_.get(), image); | |
| 67 | |
| 68 if (image->image_skia().isNull()) | |
| 69 return; | |
|
Devlin
2015/08/27 16:08:55
nit: it'll depend on who you ask, but I generally
afakhry
2015/08/27 21:48:15
Done.
| |
| 70 | |
| 71 set_icon(image->image_skia()); | |
| 72 } | |
| 73 | |
| 63 base::string16 ExtensionTask::GetExtensionTitle( | 74 base::string16 ExtensionTask::GetExtensionTitle( |
| 64 content::WebContents* web_contents, | 75 content::WebContents* web_contents, |
| 65 const extensions::Extension* extension, | 76 const extensions::Extension* extension, |
| 66 extensions::ViewType view_type) const { | 77 extensions::ViewType view_type) const { |
| 67 DCHECK(web_contents); | 78 DCHECK(web_contents); |
| 68 | 79 |
| 69 base::string16 title = extension ? | 80 base::string16 title = extension ? |
|
Devlin
2015/08/27 16:08:55
I don't know why I didn't see this before, but if
afakhry
2015/08/27 21:48:15
Yes it can, in some tests if you remember, which t
| |
| 70 base::UTF8ToUTF16(extension->name()) : | 81 base::UTF8ToUTF16(extension->name()) : |
| 71 RendererTask::GetTitleFromWebContents(web_contents); | 82 RendererTask::GetTitleFromWebContents(web_contents); |
| 72 | 83 |
| 73 bool is_background = | 84 bool is_background = |
| 74 view_type == extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE; | 85 view_type == extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE; |
| 75 | 86 |
| 76 return RendererTask::PrefixRendererTitle( | 87 return RendererTask::PrefixRendererTitle( |
| 77 title, | 88 title, |
| 78 extension->is_app(), | 89 extension->is_app(), |
| 79 true, // is_extension | 90 true, // is_extension |
| 80 web_contents->GetBrowserContext()->IsOffTheRecord(), | 91 web_contents->GetBrowserContext()->IsOffTheRecord(), |
| 81 is_background); | 92 is_background); |
| 82 } | 93 } |
| 83 | 94 |
| 95 void ExtensionTask::LoadExtensionIcon(content::WebContents* web_contents, | |
|
Devlin
2015/08/27 16:08:55
instead of passing in web_contents, just use web_c
afakhry
2015/08/27 21:48:15
Done.
| |
| 96 const extensions::Extension* extension) { | |
| 97 DCHECK(web_contents); | |
| 98 | |
| 99 if (!extension) | |
| 100 return; | |
| 101 | |
| 102 extension_icon_.reset( | |
| 103 new extensions::IconImage(web_contents->GetBrowserContext(), | |
| 104 extension, | |
| 105 extensions::IconsInfo::GetIcons(extension), | |
| 106 extension_misc::EXTENSION_ICON_SMALL, | |
| 107 icon(), | |
| 108 this)); | |
| 109 | |
| 110 // Triggers actual image loading with 1x resources. | |
| 111 extension_icon_->image_skia().GetRepresentation(1.0f); | |
| 112 set_icon(extension_icon_->image_skia()); | |
| 113 } | |
| 114 | |
| 84 } // namespace task_management | 115 } // namespace task_management |
| OLD | NEW |