OLD | NEW |
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 <string> | 7 #include <string> |
8 | 8 |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/metrics/histogram_base.h" | 10 #include "base/metrics/histogram_base.h" |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 *popup_url_out = browser_action->GetPopupUrl(tab_id); | 151 *popup_url_out = browser_action->GetPopupUrl(tab_id); |
152 return ACTION_SHOW_POPUP; | 152 return ACTION_SHOW_POPUP; |
153 } | 153 } |
154 | 154 |
155 ExtensionActionAPI::BrowserActionExecuted( | 155 ExtensionActionAPI::BrowserActionExecuted( |
156 browser->profile(), *browser_action, web_contents); | 156 browser->profile(), *browser_action, web_contents); |
157 return ACTION_NONE; | 157 return ACTION_NONE; |
158 } | 158 } |
159 | 159 |
160 void ExtensionToolbarModel::SetVisibleIconCount(int count) { | 160 void ExtensionToolbarModel::SetVisibleIconCount(int count) { |
161 VLOG(4) << "visible_icon_count_ before: " << visible_icon_count_; | |
162 visible_icon_count_ = | 161 visible_icon_count_ = |
163 count == static_cast<int>(toolbar_items_.size()) ? -1 : count; | 162 count == static_cast<int>(toolbar_items_.size()) ? -1 : count; |
164 VLOG(4) << "SetVisibleIconCount " | |
165 << count << " == " << toolbar_items_.size() << " -> " | |
166 << visible_icon_count_ << " " | |
167 << "is_highlighting: " << is_highlighting_; | |
168 // Only set the prefs if we're not in highlight mode. Highlight mode is | 163 // Only set the prefs if we're not in highlight mode. Highlight mode is |
169 // designed to be a transitory state, and should not persist across browser | 164 // designed to be a transitory state, and should not persist across browser |
170 // restarts (though it may be re-entered). | 165 // restarts (though it may be re-entered). |
171 if (!is_highlighting_) { | 166 if (!is_highlighting_) |
172 prefs_->SetInteger(pref_names::kToolbarSize, visible_icon_count_); | 167 prefs_->SetInteger(pref_names::kToolbarSize, visible_icon_count_); |
173 } | |
174 } | 168 } |
175 | 169 |
176 void ExtensionToolbarModel::OnExtensionLoaded( | 170 void ExtensionToolbarModel::OnExtensionLoaded( |
177 content::BrowserContext* browser_context, | 171 content::BrowserContext* browser_context, |
178 const Extension* extension) { | 172 const Extension* extension) { |
179 VLOG(4) << "Loading extension"; | |
180 | |
181 // We don't want to add the same extension twice. It may have already been | 173 // We don't want to add the same extension twice. It may have already been |
182 // added by EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED below, if the user | 174 // added by EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED below, if the user |
183 // hides the browser action and then disables and enables the extension. | 175 // hides the browser action and then disables and enables the extension. |
184 for (size_t i = 0; i < toolbar_items_.size(); i++) { | 176 for (size_t i = 0; i < toolbar_items_.size(); i++) { |
185 if (toolbar_items_[i].get() == extension) { | 177 if (toolbar_items_[i].get() == extension) |
186 VLOG(4) << "... but returning early"; | |
187 return; | 178 return; |
188 } | |
189 } | 179 } |
190 if (ExtensionActionAPI::GetBrowserActionVisibility(extension_prefs_, | 180 if (ExtensionActionAPI::GetBrowserActionVisibility(extension_prefs_, |
191 extension->id())) { | 181 extension->id())) { |
192 VLOG(4) << "Adding extensions"; | |
193 AddExtension(extension); | 182 AddExtension(extension); |
194 } else { | |
195 VLOG(4) << "NOT visible"; | |
196 } | 183 } |
197 } | 184 } |
198 | 185 |
199 void ExtensionToolbarModel::OnExtensionUnloaded( | 186 void ExtensionToolbarModel::OnExtensionUnloaded( |
200 content::BrowserContext* browser_context, | 187 content::BrowserContext* browser_context, |
201 const Extension* extension, | 188 const Extension* extension, |
202 UnloadedExtensionInfo::Reason reason) { | 189 UnloadedExtensionInfo::Reason reason) { |
203 RemoveExtension(extension); | 190 RemoveExtension(extension); |
204 } | 191 } |
205 | 192 |
(...skipping 16 matching lines...) Expand all Loading... |
222 int type, | 209 int type, |
223 const content::NotificationSource& source, | 210 const content::NotificationSource& source, |
224 const content::NotificationDetails& details) { | 211 const content::NotificationDetails& details) { |
225 DCHECK_EQ(chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, | 212 DCHECK_EQ(chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, |
226 type); | 213 type); |
227 const Extension* extension = | 214 const Extension* extension = |
228 ExtensionRegistry::Get(profile_)->GetExtensionById( | 215 ExtensionRegistry::Get(profile_)->GetExtensionById( |
229 *content::Details<const std::string>(details).ptr(), | 216 *content::Details<const std::string>(details).ptr(), |
230 ExtensionRegistry::EVERYTHING); | 217 ExtensionRegistry::EVERYTHING); |
231 if (ExtensionActionAPI::GetBrowserActionVisibility(extension_prefs_, | 218 if (ExtensionActionAPI::GetBrowserActionVisibility(extension_prefs_, |
232 extension->id())) { | 219 extension->id())) |
233 VLOG(4) << "Adding extension"; | |
234 AddExtension(extension); | 220 AddExtension(extension); |
235 } else { | 221 else |
236 VLOG(4) << "Removing extension"; | |
237 RemoveExtension(extension); | 222 RemoveExtension(extension); |
238 } | |
239 } | 223 } |
240 | 224 |
241 void ExtensionToolbarModel::OnReady() { | 225 void ExtensionToolbarModel::OnReady() { |
242 VLOG(4) << "OnReady called"; | |
243 ExtensionRegistry* registry = ExtensionRegistry::Get(profile_); | 226 ExtensionRegistry* registry = ExtensionRegistry::Get(profile_); |
244 InitializeExtensionList(registry->enabled_extensions()); | 227 InitializeExtensionList(registry->enabled_extensions()); |
245 // Wait until the extension system is ready before observing any further | 228 // Wait until the extension system is ready before observing any further |
246 // changes so that the toolbar buttons can be shown in their stable ordering | 229 // changes so that the toolbar buttons can be shown in their stable ordering |
247 // taken from prefs. | 230 // taken from prefs. |
248 extension_registry_observer_.Add(registry); | 231 extension_registry_observer_.Add(registry); |
249 registrar_.Add( | 232 registrar_.Add( |
250 this, | 233 this, |
251 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, | 234 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, |
252 content::Source<ExtensionPrefs>(extension_prefs_)); | 235 content::Source<ExtensionPrefs>(extension_prefs_)); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 // pref service. For robustness we use a somewhat inefficient process: | 329 // pref service. For robustness we use a somewhat inefficient process: |
347 // 1. Create a vector of extensions sorted by their pref values. This vector may | 330 // 1. Create a vector of extensions sorted by their pref values. This vector may |
348 // have holes. | 331 // have holes. |
349 // 2. Create a vector of extensions that did not have a pref value. | 332 // 2. Create a vector of extensions that did not have a pref value. |
350 // 3. Remove holes from the sorted vector and append the unsorted vector. | 333 // 3. Remove holes from the sorted vector and append the unsorted vector. |
351 void ExtensionToolbarModel::InitializeExtensionList( | 334 void ExtensionToolbarModel::InitializeExtensionList( |
352 const ExtensionSet& extensions) { | 335 const ExtensionSet& extensions) { |
353 last_known_positions_ = extension_prefs_->GetToolbarOrder(); | 336 last_known_positions_ = extension_prefs_->GetToolbarOrder(); |
354 Populate(last_known_positions_, extensions); | 337 Populate(last_known_positions_, extensions); |
355 | 338 |
356 VLOG(4) << "extensions_initialized!"; | |
357 extensions_initialized_ = true; | 339 extensions_initialized_ = true; |
358 FOR_EACH_OBSERVER(Observer, observers_, VisibleCountChanged()); | 340 FOR_EACH_OBSERVER(Observer, observers_, VisibleCountChanged()); |
359 } | 341 } |
360 | 342 |
361 void ExtensionToolbarModel::Populate(const ExtensionIdList& positions, | 343 void ExtensionToolbarModel::Populate(const ExtensionIdList& positions, |
362 const ExtensionSet& extensions) { | 344 const ExtensionSet& extensions) { |
363 // Items that have explicit positions. | 345 // Items that have explicit positions. |
364 ExtensionList sorted; | 346 ExtensionList sorted; |
365 sorted.resize(positions.size(), NULL); | 347 sorted.resize(positions.size(), NULL); |
366 // The items that don't have explicit positions. | 348 // The items that don't have explicit positions. |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
600 is_highlighting_ = false; | 582 is_highlighting_ = false; |
601 if (old_visible_icon_count_ != visible_icon_count_) { | 583 if (old_visible_icon_count_ != visible_icon_count_) { |
602 SetVisibleIconCount(old_visible_icon_count_); | 584 SetVisibleIconCount(old_visible_icon_count_); |
603 FOR_EACH_OBSERVER(Observer, observers_, VisibleCountChanged()); | 585 FOR_EACH_OBSERVER(Observer, observers_, VisibleCountChanged()); |
604 } | 586 } |
605 FOR_EACH_OBSERVER(Observer, observers_, HighlightModeChanged(false)); | 587 FOR_EACH_OBSERVER(Observer, observers_, HighlightModeChanged(false)); |
606 } | 588 } |
607 } | 589 } |
608 | 590 |
609 } // namespace extensions | 591 } // namespace extensions |
OLD | NEW |