| 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" |
| 11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
| 12 #include "chrome/browser/chrome_notification_types.h" | 12 #include "chrome/browser/chrome_notification_types.h" |
| 13 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" | 13 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" |
| 14 #include "chrome/browser/extensions/extension_action.h" | |
| 15 #include "chrome/browser/extensions/extension_action_manager.h" | 14 #include "chrome/browser/extensions/extension_action_manager.h" |
| 16 #include "chrome/browser/extensions/extension_tab_util.h" | 15 #include "chrome/browser/extensions/extension_tab_util.h" |
| 17 #include "chrome/browser/extensions/extension_toolbar_model_factory.h" | 16 #include "chrome/browser/extensions/extension_toolbar_model_factory.h" |
| 18 #include "chrome/browser/extensions/extension_util.h" | 17 #include "chrome/browser/extensions/extension_util.h" |
| 19 #include "chrome/browser/extensions/tab_helper.h" | 18 #include "chrome/browser/extensions/tab_helper.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/ui/browser.h" | 20 #include "chrome/browser/ui/browser.h" |
| 22 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 23 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 24 #include "content/public/browser/notification_details.h" | 23 #include "content/public/browser/notification_details.h" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 | 114 |
| 116 toolbar_items_.push_back(make_scoped_refptr(extension)); | 115 toolbar_items_.push_back(make_scoped_refptr(extension)); |
| 117 last_known_positions_.push_back(extension->id()); | 116 last_known_positions_.push_back(extension->id()); |
| 118 } | 117 } |
| 119 | 118 |
| 120 FOR_EACH_OBSERVER(Observer, observers_, BrowserActionMoved(extension, index)); | 119 FOR_EACH_OBSERVER(Observer, observers_, BrowserActionMoved(extension, index)); |
| 121 | 120 |
| 122 UpdatePrefs(); | 121 UpdatePrefs(); |
| 123 } | 122 } |
| 124 | 123 |
| 125 ExtensionToolbarModel::Action ExtensionToolbarModel::ExecuteBrowserAction( | 124 ExtensionAction::ShowAction ExtensionToolbarModel::ExecuteBrowserAction( |
| 126 const Extension* extension, | 125 const Extension* extension, |
| 127 Browser* browser, | 126 Browser* browser, |
| 128 GURL* popup_url_out, | 127 GURL* popup_url_out, |
| 129 bool should_grant) { | 128 bool should_grant) { |
| 130 content::WebContents* web_contents = NULL; | 129 content::WebContents* web_contents = NULL; |
| 131 int tab_id = 0; | 130 int tab_id = 0; |
| 132 if (!ExtensionTabUtil::GetDefaultTab(browser, &web_contents, &tab_id)) { | 131 if (!ExtensionTabUtil::GetDefaultTab(browser, &web_contents, &tab_id)) |
| 133 return ACTION_NONE; | 132 return ExtensionAction::ACTION_NONE; |
| 134 } | |
| 135 | 133 |
| 136 ExtensionAction* browser_action = | 134 ExtensionAction* browser_action = |
| 137 ExtensionActionManager::Get(profile_)->GetBrowserAction(*extension); | 135 ExtensionActionManager::Get(profile_)->GetBrowserAction(*extension); |
| 138 | 136 |
| 139 // For browser actions, visibility == enabledness. | 137 // For browser actions, visibility == enabledness. |
| 140 if (!browser_action->GetIsVisible(tab_id)) | 138 if (!browser_action->GetIsVisible(tab_id)) |
| 141 return ACTION_NONE; | 139 return ExtensionAction::ACTION_NONE; |
| 142 | 140 |
| 143 if (should_grant) { | 141 if (should_grant) { |
| 144 TabHelper::FromWebContents(web_contents) | 142 TabHelper::FromWebContents(web_contents) |
| 145 ->active_tab_permission_granter() | 143 ->active_tab_permission_granter() |
| 146 ->GrantIfRequested(extension); | 144 ->GrantIfRequested(extension); |
| 147 } | 145 } |
| 148 | 146 |
| 149 if (browser_action->HasPopup(tab_id)) { | 147 if (browser_action->HasPopup(tab_id)) { |
| 150 if (popup_url_out) | 148 if (popup_url_out) |
| 151 *popup_url_out = browser_action->GetPopupUrl(tab_id); | 149 *popup_url_out = browser_action->GetPopupUrl(tab_id); |
| 152 return ACTION_SHOW_POPUP; | 150 return ExtensionAction::ACTION_SHOW_POPUP; |
| 153 } | 151 } |
| 154 | 152 |
| 155 ExtensionActionAPI::BrowserActionExecuted( | 153 ExtensionActionAPI::BrowserActionExecuted( |
| 156 browser->profile(), *browser_action, web_contents); | 154 browser->profile(), *browser_action, web_contents); |
| 157 return ACTION_NONE; | 155 return ExtensionAction::ACTION_NONE; |
| 158 } | 156 } |
| 159 | 157 |
| 160 void ExtensionToolbarModel::SetVisibleIconCount(int count) { | 158 void ExtensionToolbarModel::SetVisibleIconCount(int count) { |
| 161 visible_icon_count_ = | 159 visible_icon_count_ = |
| 162 count == static_cast<int>(toolbar_items_.size()) ? -1 : count; | 160 count == static_cast<int>(toolbar_items_.size()) ? -1 : count; |
| 163 // Only set the prefs if we're not in highlight mode. Highlight mode is | 161 // 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 | 162 // designed to be a transitory state, and should not persist across browser |
| 165 // restarts (though it may be re-entered). | 163 // restarts (though it may be re-entered). |
| 166 if (!is_highlighting_) | 164 if (!is_highlighting_) |
| 167 prefs_->SetInteger(pref_names::kToolbarSize, visible_icon_count_); | 165 prefs_->SetInteger(pref_names::kToolbarSize, visible_icon_count_); |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 is_highlighting_ = false; | 582 is_highlighting_ = false; |
| 585 if (old_visible_icon_count_ != visible_icon_count_) { | 583 if (old_visible_icon_count_ != visible_icon_count_) { |
| 586 SetVisibleIconCount(old_visible_icon_count_); | 584 SetVisibleIconCount(old_visible_icon_count_); |
| 587 FOR_EACH_OBSERVER(Observer, observers_, VisibleCountChanged()); | 585 FOR_EACH_OBSERVER(Observer, observers_, VisibleCountChanged()); |
| 588 } | 586 } |
| 589 FOR_EACH_OBSERVER(Observer, observers_, HighlightModeChanged(false)); | 587 FOR_EACH_OBSERVER(Observer, observers_, HighlightModeChanged(false)); |
| 590 } | 588 } |
| 591 } | 589 } |
| 592 | 590 |
| 593 } // namespace extensions | 591 } // namespace extensions |
| OLD | NEW |