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> |
| 8 |
7 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
8 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
9 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" | 11 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" |
10 #include "chrome/browser/extensions/extension_action.h" | 12 #include "chrome/browser/extensions/extension_action.h" |
11 #include "chrome/browser/extensions/extension_action_manager.h" | 13 #include "chrome/browser/extensions/extension_action_manager.h" |
12 #include "chrome/browser/extensions/extension_prefs.h" | 14 #include "chrome/browser/extensions/extension_prefs.h" |
13 #include "chrome/browser/extensions/extension_service.h" | 15 #include "chrome/browser/extensions/extension_service.h" |
14 #include "chrome/browser/extensions/extension_tab_util.h" | 16 #include "chrome/browser/extensions/extension_tab_util.h" |
15 #include "chrome/browser/extensions/tab_helper.h" | 17 #include "chrome/browser/extensions/tab_helper.h" |
16 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 | 124 |
123 FOR_EACH_OBSERVER(Observer, observers_, BrowserActionMoved(extension, index)); | 125 FOR_EACH_OBSERVER(Observer, observers_, BrowserActionMoved(extension, index)); |
124 | 126 |
125 UpdatePrefs(); | 127 UpdatePrefs(); |
126 } | 128 } |
127 | 129 |
128 ExtensionToolbarModel::Action ExtensionToolbarModel::ExecuteBrowserAction( | 130 ExtensionToolbarModel::Action ExtensionToolbarModel::ExecuteBrowserAction( |
129 const Extension* extension, | 131 const Extension* extension, |
130 Browser* browser, | 132 Browser* browser, |
131 GURL* popup_url_out) { | 133 GURL* popup_url_out) { |
| 134 return ExecuteBrowserAction(extension, browser, popup_url_out, true); |
| 135 } |
| 136 |
| 137 ExtensionToolbarModel::Action ExtensionToolbarModel::ExecuteBrowserAction( |
| 138 const Extension* extension, |
| 139 Browser* browser, |
| 140 GURL* popup_url_out, |
| 141 bool should_grant) { |
132 content::WebContents* web_contents = NULL; | 142 content::WebContents* web_contents = NULL; |
133 int tab_id = 0; | 143 int tab_id = 0; |
134 if (!ExtensionTabUtil::GetDefaultTab(browser, &web_contents, &tab_id)) | 144 if (!ExtensionTabUtil::GetDefaultTab(browser, &web_contents, &tab_id)) |
135 return ACTION_NONE; | 145 return ACTION_NONE; |
136 | 146 |
137 ExtensionAction* browser_action = | 147 ExtensionAction* browser_action = |
138 extensions::ExtensionActionManager::Get(service_->profile())-> | 148 extensions::ExtensionActionManager::Get(service_->profile())-> |
139 GetBrowserAction(*extension); | 149 GetBrowserAction(*extension); |
140 | 150 |
141 // For browser actions, visibility == enabledness. | 151 // For browser actions, visibility == enabledness. |
142 if (!browser_action->GetIsVisible(tab_id)) | 152 if (!browser_action->GetIsVisible(tab_id)) |
143 return ACTION_NONE; | 153 return ACTION_NONE; |
144 | 154 |
145 extensions::TabHelper::FromWebContents(web_contents)-> | 155 if (should_grant) { |
146 active_tab_permission_granter()->GrantIfRequested(extension); | 156 extensions::TabHelper::FromWebContents(web_contents)-> |
| 157 active_tab_permission_granter()->GrantIfRequested(extension); |
| 158 } |
147 | 159 |
148 if (browser_action->HasPopup(tab_id)) { | 160 if (browser_action->HasPopup(tab_id)) { |
149 if (popup_url_out) | 161 if (popup_url_out) |
150 *popup_url_out = browser_action->GetPopupUrl(tab_id); | 162 *popup_url_out = browser_action->GetPopupUrl(tab_id); |
151 return ACTION_SHOW_POPUP; | 163 return ACTION_SHOW_POPUP; |
152 } | 164 } |
153 | 165 |
154 extensions::ExtensionActionAPI::BrowserActionExecuted( | 166 extensions::ExtensionActionAPI::BrowserActionExecuted( |
155 service_->profile(), *browser_action, web_contents); | 167 service_->profile(), *browser_action, web_contents); |
156 return ACTION_NONE; | 168 return ACTION_NONE; |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 | 459 |
448 if (last_known_positions_.size() > pref_position_size) { | 460 if (last_known_positions_.size() > pref_position_size) { |
449 // Need to update pref because we have extra icons. But can't call | 461 // Need to update pref because we have extra icons. But can't call |
450 // UpdatePrefs() directly within observation closure. | 462 // UpdatePrefs() directly within observation closure. |
451 base::MessageLoop::current()->PostTask( | 463 base::MessageLoop::current()->PostTask( |
452 FROM_HERE, | 464 FROM_HERE, |
453 base::Bind(&ExtensionToolbarModel::UpdatePrefs, | 465 base::Bind(&ExtensionToolbarModel::UpdatePrefs, |
454 weak_ptr_factory_.GetWeakPtr())); | 466 weak_ptr_factory_.GetWeakPtr())); |
455 } | 467 } |
456 } | 468 } |
| 469 |
| 470 void ExtensionToolbarModel::ShowBrowserActionPopup( |
| 471 const extensions::Extension* extension) { |
| 472 FOR_EACH_OBSERVER(Observer, observers_, BrowserActionShowPopup(extension)); |
| 473 } |
OLD | NEW |