| 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 visible_icon_count_ = | 162 visible_icon_count_ = |
| 162 count == static_cast<int>(toolbar_items_.size()) ? -1 : count; | 163 count == static_cast<int>(toolbar_items_.size()) ? -1 : count; |
| 164 LOG(ERROR) << "SetVisibleIconCount " |
| 165 << count << " == " << toolbar_items_.size() << " -> " |
| 166 << visible_icon_count_ << " " |
| 167 << "is_highlighting: " << is_highlighting_; |
| 163 // 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 |
| 164 // 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 |
| 165 // restarts (though it may be re-entered). | 170 // restarts (though it may be re-entered). |
| 166 if (!is_highlighting_) { | 171 if (!is_highlighting_) { |
| 167 prefs_->SetInteger(pref_names::kToolbarSize, visible_icon_count_); | 172 prefs_->SetInteger(pref_names::kToolbarSize, visible_icon_count_); |
| 168 } | 173 } |
| 169 } | 174 } |
| 170 | 175 |
| 171 void ExtensionToolbarModel::OnExtensionLoaded( | 176 void ExtensionToolbarModel::OnExtensionLoaded( |
| 172 content::BrowserContext* browser_context, | 177 content::BrowserContext* browser_context, |
| 173 const Extension* extension) { | 178 const Extension* extension) { |
| 179 LOG(ERROR) << "Loading extension"; |
| 180 |
| 174 // 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 |
| 175 // added by EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED below, if the user | 182 // added by EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED below, if the user |
| 176 // hides the browser action and then disables and enables the extension. | 183 // hides the browser action and then disables and enables the extension. |
| 177 for (size_t i = 0; i < toolbar_items_.size(); i++) { | 184 for (size_t i = 0; i < toolbar_items_.size(); i++) { |
| 178 if (toolbar_items_[i].get() == extension) | 185 if (toolbar_items_[i].get() == extension) { |
| 186 LOG(ERROR) << "... but returning early"; |
| 179 return; | 187 return; |
| 188 } |
| 180 } | 189 } |
| 181 if (ExtensionActionAPI::GetBrowserActionVisibility(extension_prefs_, | 190 if (ExtensionActionAPI::GetBrowserActionVisibility(extension_prefs_, |
| 182 extension->id())) { | 191 extension->id())) { |
| 192 LOG(ERROR) << "Adding extensions"; |
| 183 AddExtension(extension); | 193 AddExtension(extension); |
| 194 } else { |
| 195 LOG(ERROR) << "NOT visible"; |
| 184 } | 196 } |
| 185 } | 197 } |
| 186 | 198 |
| 187 void ExtensionToolbarModel::OnExtensionUnloaded( | 199 void ExtensionToolbarModel::OnExtensionUnloaded( |
| 188 content::BrowserContext* browser_context, | 200 content::BrowserContext* browser_context, |
| 189 const Extension* extension, | 201 const Extension* extension, |
| 190 UnloadedExtensionInfo::Reason reason) { | 202 UnloadedExtensionInfo::Reason reason) { |
| 191 RemoveExtension(extension); | 203 RemoveExtension(extension); |
| 192 } | 204 } |
| 193 | 205 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 211 const content::NotificationSource& source, | 223 const content::NotificationSource& source, |
| 212 const content::NotificationDetails& details) { | 224 const content::NotificationDetails& details) { |
| 213 DCHECK_EQ(chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, | 225 DCHECK_EQ(chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, |
| 214 type); | 226 type); |
| 215 const Extension* extension = | 227 const Extension* extension = |
| 216 ExtensionRegistry::Get(profile_)->GetExtensionById( | 228 ExtensionRegistry::Get(profile_)->GetExtensionById( |
| 217 *content::Details<const std::string>(details).ptr(), | 229 *content::Details<const std::string>(details).ptr(), |
| 218 ExtensionRegistry::EVERYTHING); | 230 ExtensionRegistry::EVERYTHING); |
| 219 if (ExtensionActionAPI::GetBrowserActionVisibility(extension_prefs_, | 231 if (ExtensionActionAPI::GetBrowserActionVisibility(extension_prefs_, |
| 220 extension->id())) { | 232 extension->id())) { |
| 233 LOG(ERROR) << "Adding extension"; |
| 221 AddExtension(extension); | 234 AddExtension(extension); |
| 222 } else { | 235 } else { |
| 236 LOG(ERROR) << "Removing extension"; |
| 223 RemoveExtension(extension); | 237 RemoveExtension(extension); |
| 224 } | 238 } |
| 225 } | 239 } |
| 226 | 240 |
| 227 void ExtensionToolbarModel::OnReady() { | 241 void ExtensionToolbarModel::OnReady() { |
| 228 ExtensionRegistry* registry = ExtensionRegistry::Get(profile_); | 242 ExtensionRegistry* registry = ExtensionRegistry::Get(profile_); |
| 229 InitializeExtensionList(registry->enabled_extensions()); | 243 InitializeExtensionList(registry->enabled_extensions()); |
| 230 // Wait until the extension system is ready before observing any further | 244 // Wait until the extension system is ready before observing any further |
| 231 // changes so that the toolbar buttons can be shown in their stable ordering | 245 // changes so that the toolbar buttons can be shown in their stable ordering |
| 232 // taken from prefs. | 246 // taken from prefs. |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 is_highlighting_ = false; | 598 is_highlighting_ = false; |
| 585 if (old_visible_icon_count_ != visible_icon_count_) { | 599 if (old_visible_icon_count_ != visible_icon_count_) { |
| 586 SetVisibleIconCount(old_visible_icon_count_); | 600 SetVisibleIconCount(old_visible_icon_count_); |
| 587 FOR_EACH_OBSERVER(Observer, observers_, VisibleCountChanged()); | 601 FOR_EACH_OBSERVER(Observer, observers_, VisibleCountChanged()); |
| 588 } | 602 } |
| 589 FOR_EACH_OBSERVER(Observer, observers_, HighlightModeChanged(false)); | 603 FOR_EACH_OBSERVER(Observer, observers_, HighlightModeChanged(false)); |
| 590 } | 604 } |
| 591 } | 605 } |
| 592 | 606 |
| 593 } // namespace extensions | 607 } // namespace extensions |
| OLD | NEW |