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