Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Unified Diff: chrome/browser/extensions/extension_action_manager.cc

Issue 415813003: Improve extension icon prediction (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Minor changes Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/extensions/extension_action_manager.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/extension_action_manager.cc
diff --git a/chrome/browser/extensions/extension_action_manager.cc b/chrome/browser/extensions/extension_action_manager.cc
index b4799741373788db69ca8511c2a4e6cd1c9bd681..8587a8ba8d4c49f6328900c47cb9edade6a815c1 100644
--- a/chrome/browser/extensions/extension_action_manager.cc
+++ b/chrome/browser/extensions/extension_action_manager.cc
@@ -12,6 +12,8 @@
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/extensions_browser_client.h"
+#include "extensions/common/constants.h"
+#include "extensions/common/manifest_handlers/icons_handler.h"
namespace extensions {
@@ -82,6 +84,40 @@ void ExtensionActionManager::OnExtensionUnloaded(
namespace {
+// Loads resources missing from |action| (ie title, icons) from "icons" key of
Devlin 2014/07/25 16:46:55 "i.e." "the "icons" key"
gpdavis 2014/07/28 21:40:36 Done.
+// |extension|'s manifest.
+void PopulateMissingValues(const Extension& extension,
+ ExtensionAction* action) {
+ if (!action)
Devlin 2014/07/25 16:46:55 Why are we passing in NULL actions in the first pl
gpdavis 2014/07/28 21:40:36 You're right; we shouldn't need to check for this.
+ return;
+
+ // If the title is missing from |action|, set it to |extension|'s name.
+ if (!action->HasTitle(ExtensionAction::kDefaultTabId))
+ action->SetTitle(ExtensionAction::kDefaultTabId, extension.name());
+
+ // Get largest available icon for |extension|. If no icon is found, there
+ // is nothing available to replace missing action icons with, so we return.
+ std::string icon_path = extensions::IconsInfo::GetIcons(&extension).Get(
+ extension_misc::EXTENSION_ICON_GIGANTOR,
+ ExtensionIconSet::MATCH_SMALLER);
+ if (icon_path.empty())
+ return;
+
+ scoped_ptr<ExtensionIconSet> default_icon(new ExtensionIconSet());
+ if (action->default_icon())
+ *default_icon = *action->default_icon();
+
+ // Replace any missing extension action icons with the largest icon
+ // retrieved from |extension|'s manifest.
+ for (size_t i = 0; i < extension_misc::kNumExtensionActionIconSizes; ++i) {
+ int size = extension_misc::kExtensionActionIconSizes[i];
+ if (default_icon->Get(size, ExtensionIconSet::MATCH_EXACTLY).empty())
+ default_icon->Add(size, icon_path);
+ }
+
+ action->set_default_icon(default_icon.Pass());
+}
+
// Returns map[extension_id] if that entry exists. Otherwise, if
// action_info!=NULL, creates an ExtensionAction from it, fills in the map, and
// returns that. Otherwise (action_info==NULL), returns NULL.
@@ -109,13 +145,15 @@ ExtensionAction* GetOrCreateOrNull(
linked_ptr<ExtensionAction> action(new ExtensionAction(
extension_id, action_type, *action_info));
(*map)[extension_id] = action;
+ PopulateMissingValues(*service->GetExtensionById(extension_id, false),
Devlin 2014/07/25 16:46:55 this is deprecated. Use ExtensionRegistry::enabled
gpdavis 2014/07/28 21:40:36 Any idea why this deprecation isn't documented? D
not at google - send to devlin 2014/07/28 21:55:36 good point: https://codereview.chromium.org/426553
+ action.get());
return action.get();
}
} // namespace
ExtensionAction* ExtensionActionManager::GetPageAction(
- const extensions::Extension& extension) const {
+ const Extension& extension) const {
return GetOrCreateOrNull(&page_actions_, extension.id(),
ActionInfo::TYPE_PAGE,
ActionInfo::GetPageActionInfo(&extension),
@@ -123,15 +161,22 @@ ExtensionAction* ExtensionActionManager::GetPageAction(
}
ExtensionAction* ExtensionActionManager::GetBrowserAction(
- const extensions::Extension& extension) const {
+ const Extension& extension) const {
return GetOrCreateOrNull(&browser_actions_, extension.id(),
ActionInfo::TYPE_BROWSER,
ActionInfo::GetBrowserActionInfo(&extension),
profile_);
}
+ExtensionAction* ExtensionActionManager::GetBestFitAction(
Devlin 2014/07/25 16:46:55 I'm a bit confused. I thought part of the purpose
gpdavis 2014/07/28 21:40:36 I'm actually a bit confused about the purpose of t
not at google - send to devlin 2014/07/28 21:55:36 Yes exactly. one could imagine super-cool functio
gpdavis 2014/07/29 00:18:01 Can do. A couple of design questions: Script inj
+ const Extension& extension) const {
+ if (ActionInfo::GetBrowserActionInfo(&extension))
+ return GetBrowserAction(extension);
+ return GetPageAction(extension);
+}
+
ExtensionAction* ExtensionActionManager::GetSystemIndicator(
- const extensions::Extension& extension) const {
+ const Extension& extension) const {
// If it does not already exist, create the SystemIndicatorManager for the
// given profile. This could return NULL if the system indicator area is
// unavailable on the current system. If so, return NULL to signal that
« no previous file with comments | « chrome/browser/extensions/extension_action_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698