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

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: 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 7c91f4b8ae2fdf9d62c4c80316d0ff75b3dfdd66..bf15d401f80ebb1475f03a2d69f1a075e31ecc9a 100644
--- a/chrome/browser/extensions/extension_toolbar_model.cc
+++ b/chrome/browser/extensions/extension_toolbar_model.cc
@@ -152,11 +152,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 &&
- 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));
+ }
}
}
@@ -567,6 +574,63 @@ void ExtensionToolbarModel::OnExtensionToolbarPrefChange() {
}
}
+int ExtensionToolbarModel::GetVisibleIconCountForTab(
+ content::WebContents* web_contents) const {
+ int base_visible = visible_icon_count_;
Peter Kasting 2014/10/30 22:05:59 Why do we need this temp? Does visible_icon_count
Devlin 2014/10/31 17:44:09 Whoops, leftover from old implementation. Fixed.
+ if (base_visible == -1)
+ return base_visible; // Already displaying all actions.
+
+ ExtensionActionAPI* extension_action_api = ExtensionActionAPI::Get(profile_);
+ size_t overflowed_actions_wanting_to_run = 0u;
+ for (size_t i = base_visible; i < toolbar_items_.size(); ++i) {
+ if (extension_action_api->ExtensionWantsToRun(toolbar_items_[i].get(),
+ web_contents))
+ ++overflowed_actions_wanting_to_run;
+ }
+ return base_visible + overflowed_actions_wanting_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_wanting_to_run;
+ ExtensionActionAPI* extension_action_api = ExtensionActionAPI::Get(profile_);
+ int base_visible = GetAbsoluteVisibleIconCount();
+ int 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 (int i = toolbar_items_.size() - 1; i >= base_visible; --i) {
Peter Kasting 2014/10/30 22:05:59 This is a very complicated way of doing what I thi
Devlin 2014/10/31 17:44:09 Ah, yes, that is quite a bit simpler. Done.
+ if (extension_action_api->ExtensionWantsToRun(toolbar_items_[i].get(),
+ web_contents))
+ overflowed_actions_wanting_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_wanting_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,

Powered by Google App Engine
This is Rietveld 408576698