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

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

Issue 675023002: Make extensions that desire to act pop out if in overflow (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Test fixes Created 6 years, 2 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
Index: chrome/browser/extensions/extension_toolbar_model.cc
diff --git a/chrome/browser/extensions/extension_toolbar_model.cc b/chrome/browser/extensions/extension_toolbar_model.cc
index c8e110d38d3fe44e95c7c2c3aacf7f3a3ea36b44..82f209e415a1182c94705ac3dd9635a4592a850e 100644
--- a/chrome/browser/extensions/extension_toolbar_model.cc
+++ b/chrome/browser/extensions/extension_toolbar_model.cc
@@ -153,11 +153,18 @@ void ExtensionToolbarModel::OnExtensionActionUpdated(
ExtensionRegistry::Get(profile_)->enabled_extensions().GetByID(
extension_action->extension_id());
// Notify observers if the extension exists and is in the model.
- if (extension &&
Finnur 2014/10/25 14:09:58 Is the extension check unnecessary now? Not saying
Devlin 2014/10/29 20:29:27 I think it actually always was - if extension is n
- std::find(toolbar_items_.begin(),
- toolbar_items_.end(),
- extension) != toolbar_items_.end()) {
- FOR_EACH_OBSERVER(Observer, observers_, ToolbarExtensionUpdated(extension));
+ ExtensionList::const_iterator iter =
+ std::find(toolbar_items_.begin(), toolbar_items_.end(), extension);
+ if (iter != toolbar_items_.end()) {
+ FOR_EACH_OBSERVER(
+ Observer, observers_, ToolbarExtensionUpdated(extension));
+ // If the action was in the overflow menu, we have to alert observers that
+ // the toolbar needs to be reordered (to show the action).
+ if (static_cast<size_t>(iter - toolbar_items_.begin()) >=
+ GetAbsoluteVisibleIconCount()) {
+ FOR_EACH_OBSERVER(
+ Observer, observers_, ToolbarReorderNecessary(web_contents));
+ }
}
}
@@ -568,6 +575,63 @@ void ExtensionToolbarModel::OnExtensionToolbarPrefChange() {
}
}
+int ExtensionToolbarModel::GetVisibleIconCountForTab(
+ content::WebContents* web_contents) const {
+ int base_visible = visible_icon_count_;
+ if (base_visible == -1)
+ return base_visible; // Already displaying all actions.
+
+ ExtensionActionAPI* extension_action_api = ExtensionActionAPI::Get(profile_);
+ size_t overflowed_actions_to_run = 0u;
Finnur 2014/10/25 14:09:58 nit: to run? Seems a bit weird to use that phrase
Devlin 2014/10/29 20:29:27 Done.
+ for (size_t i = base_visible; i < toolbar_items_.size(); ++i) {
+ if (extension_action_api->ExtensionWantsToRun(toolbar_items_[i].get(),
+ web_contents))
+ ++overflowed_actions_to_run;
+ }
+ return base_visible + overflowed_actions_to_run;
+}
+
+ExtensionList ExtensionToolbarModel::GetItemOrderForTab(
+ content::WebContents* web_contents) const {
+ // If we're highlighting, the items are always the same.
+ if (is_highlighting_)
+ return highlighted_items_;
+
+ // Start by initializing the array to be the same as toolbar items (this isn't
+ // any more expensive than initializing it to be of the same size with all
+ // nulls, and saves us time at the end).
+ ExtensionList result = toolbar_items_;
+ if (toolbar_items_.empty())
+ return result;
+
+ ExtensionList overflowed_actions_to_run;
+ ExtensionActionAPI* extension_action_api = ExtensionActionAPI::Get(profile_);
+ size_t base_visible = GetAbsoluteVisibleIconCount();
+ size_t index = toolbar_items_.size() - 1;
+
+ // We need to pop out any extensions that are overflowed, but want to act.
+ // Iterate over the overflowed extensions in reverse, and append those that
+ // don't want to act, while storing those that do separately.
+ for (size_t i = toolbar_items_.size() - 1; i >= base_visible; --i) {
+ if (extension_action_api->ExtensionWantsToRun(toolbar_items_[i].get(),
+ web_contents))
+ overflowed_actions_to_run.push_back(toolbar_items_[i]);
+ else
+ result[index--] = toolbar_items_[i];
+ }
+ // Now, append any that do want to act but were otherwise overflowed.
+ for (const scoped_refptr<const Extension>& extension :
+ overflowed_actions_to_run) {
+ result[index--] = extension;
+ }
+ // We should have appended all of (and only) those items that were in
+ // overflow.
+ DCHECK_EQ(base_visible, index + 1);
+ // The rest of the vector should be fine, since we don't need to reorder any
+ // of the already-visible extensions.
+ return result;
+}
+
bool ExtensionToolbarModel::ShowExtensionActionPopup(
const Extension* extension,
Browser* browser,
« no previous file with comments | « chrome/browser/extensions/extension_toolbar_model.h ('k') | chrome/browser/extensions/extension_toolbar_model_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698