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

Side by Side Diff: chrome/browser/extensions/extension_toolbar_model.cc

Issue 496863003: Consolidate ExtensionAction execution code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/extensions/extension_toolbar_model.h" 5 #include "chrome/browser/extensions/extension_toolbar_model.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 toolbar_items_.push_back(make_scoped_refptr(extension)); 115 toolbar_items_.push_back(make_scoped_refptr(extension));
116 last_known_positions_.push_back(extension->id()); 116 last_known_positions_.push_back(extension->id());
117 } 117 }
118 118
119 FOR_EACH_OBSERVER( 119 FOR_EACH_OBSERVER(
120 Observer, observers_, ToolbarExtensionMoved(extension, index)); 120 Observer, observers_, ToolbarExtensionMoved(extension, index));
121 MaybeUpdateVisibilityPref(extension, index); 121 MaybeUpdateVisibilityPref(extension, index);
122 UpdatePrefs(); 122 UpdatePrefs();
123 } 123 }
124 124
125 ExtensionAction::ShowAction ExtensionToolbarModel::ExecuteBrowserAction(
126 const Extension* extension,
127 Browser* browser,
128 GURL* popup_url_out,
129 bool should_grant) {
130 content::WebContents* web_contents = NULL;
131 int tab_id = 0;
132 if (!ExtensionTabUtil::GetDefaultTab(browser, &web_contents, &tab_id))
133 return ExtensionAction::ACTION_NONE;
134
135 ExtensionAction* browser_action =
136 ExtensionActionManager::Get(profile_)->GetBrowserAction(*extension);
137
138 // For browser actions, visibility == enabledness.
139 if (!browser_action->GetIsVisible(tab_id))
140 return ExtensionAction::ACTION_NONE;
141
142 if (should_grant) {
143 TabHelper::FromWebContents(web_contents)
144 ->active_tab_permission_granter()
145 ->GrantIfRequested(extension);
146 }
147
148 if (browser_action->HasPopup(tab_id)) {
149 if (popup_url_out)
150 *popup_url_out = browser_action->GetPopupUrl(tab_id);
151 return ExtensionAction::ACTION_SHOW_POPUP;
152 }
153
154 ExtensionActionAPI::BrowserActionExecuted(
155 browser->profile(), *browser_action, web_contents);
156 return ExtensionAction::ACTION_NONE;
157 }
158
159 void ExtensionToolbarModel::SetVisibleIconCount(int count) { 125 void ExtensionToolbarModel::SetVisibleIconCount(int count) {
160 visible_icon_count_ = 126 visible_icon_count_ =
161 count == static_cast<int>(toolbar_items_.size()) ? -1 : count; 127 count == static_cast<int>(toolbar_items_.size()) ? -1 : count;
162 128
163 // Only set the prefs if we're not in highlight mode. Highlight mode is 129 // Only set the prefs if we're not in highlight mode. Highlight mode is
164 // designed to be a transitory state, and should not persist across browser 130 // designed to be a transitory state, and should not persist across browser
165 // restarts (though it may be re-entered). 131 // restarts (though it may be re-entered).
166 if (!is_highlighting_) { 132 if (!is_highlighting_) {
167 // Additionally, if we are using the new toolbar, any icons which are in the 133 // Additionally, if we are using the new toolbar, any icons which are in the
168 // overflow menu are considered "hidden". But it so happens that the times 134 // overflow menu are considered "hidden". But it so happens that the times
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 FOR_EACH_OBSERVER(Observer, observers_, ToolbarHighlightModeChanged(false)); 657 FOR_EACH_OBSERVER(Observer, observers_, ToolbarHighlightModeChanged(false));
692 } 658 }
693 } 659 }
694 660
695 void ExtensionToolbarModel::SetVisibleIconCountForTest(size_t visible_icons) { 661 void ExtensionToolbarModel::SetVisibleIconCountForTest(size_t visible_icons) {
696 SetVisibleIconCount(visible_icons); 662 SetVisibleIconCount(visible_icons);
697 FOR_EACH_OBSERVER(Observer, observers_, ToolbarVisibleCountChanged()); 663 FOR_EACH_OBSERVER(Observer, observers_, ToolbarVisibleCountChanged());
698 } 664 }
699 665
700 } // namespace extensions 666 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_toolbar_model.h ('k') | chrome/browser/extensions/location_bar_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698