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/extension_util.h" | 17 #include "chrome/browser/extensions/extension_util.h" |
16 #include "chrome/browser/extensions/tab_helper.h" | 18 #include "chrome/browser/extensions/tab_helper.h" |
(...skipping 18 matching lines...) Expand all Loading... |
35 const extensions::ExtensionList& extension_list) { | 37 const extensions::ExtensionList& extension_list) { |
36 for (size_t i = 0; i < extension_list.size(); i++) { | 38 for (size_t i = 0; i < extension_list.size(); i++) { |
37 if (extension_list[i].get() == extension) | 39 if (extension_list[i].get() == extension) |
38 return true; | 40 return true; |
39 } | 41 } |
40 return false; | 42 return false; |
41 } | 43 } |
42 | 44 |
43 } // namespace | 45 } // namespace |
44 | 46 |
| 47 bool ExtensionToolbarModel::Observer::BrowserActionShowPopup( |
| 48 const extensions::Extension* extension) { |
| 49 return false; |
| 50 } |
| 51 |
45 ExtensionToolbarModel::ExtensionToolbarModel(ExtensionService* service) | 52 ExtensionToolbarModel::ExtensionToolbarModel(ExtensionService* service) |
46 : service_(service), | 53 : service_(service), |
47 prefs_(service->profile()->GetPrefs()), | 54 prefs_(service->profile()->GetPrefs()), |
48 extensions_initialized_(false), | 55 extensions_initialized_(false), |
49 weak_ptr_factory_(this) { | 56 weak_ptr_factory_(this) { |
50 DCHECK(service_); | 57 DCHECK(service_); |
51 | 58 |
52 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 59 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
53 content::Source<Profile>(service_->profile())); | 60 content::Source<Profile>(service_->profile())); |
54 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 61 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 } | 129 } |
123 | 130 |
124 FOR_EACH_OBSERVER(Observer, observers_, BrowserActionMoved(extension, index)); | 131 FOR_EACH_OBSERVER(Observer, observers_, BrowserActionMoved(extension, index)); |
125 | 132 |
126 UpdatePrefs(); | 133 UpdatePrefs(); |
127 } | 134 } |
128 | 135 |
129 ExtensionToolbarModel::Action ExtensionToolbarModel::ExecuteBrowserAction( | 136 ExtensionToolbarModel::Action ExtensionToolbarModel::ExecuteBrowserAction( |
130 const Extension* extension, | 137 const Extension* extension, |
131 Browser* browser, | 138 Browser* browser, |
132 GURL* popup_url_out) { | 139 GURL* popup_url_out, |
| 140 bool should_grant) { |
133 content::WebContents* web_contents = NULL; | 141 content::WebContents* web_contents = NULL; |
134 int tab_id = 0; | 142 int tab_id = 0; |
135 if (!ExtensionTabUtil::GetDefaultTab(browser, &web_contents, &tab_id)) | 143 if (!ExtensionTabUtil::GetDefaultTab(browser, &web_contents, &tab_id)) |
136 return ACTION_NONE; | 144 return ACTION_NONE; |
137 | 145 |
138 ExtensionAction* browser_action = | 146 ExtensionAction* browser_action = |
139 extensions::ExtensionActionManager::Get(service_->profile())-> | 147 extensions::ExtensionActionManager::Get(service_->profile())-> |
140 GetBrowserAction(*extension); | 148 GetBrowserAction(*extension); |
141 | 149 |
142 // For browser actions, visibility == enabledness. | 150 // For browser actions, visibility == enabledness. |
143 if (!browser_action->GetIsVisible(tab_id)) | 151 if (!browser_action->GetIsVisible(tab_id)) |
144 return ACTION_NONE; | 152 return ACTION_NONE; |
145 | 153 |
146 extensions::TabHelper::FromWebContents(web_contents)-> | 154 if (should_grant) { |
147 active_tab_permission_granter()->GrantIfRequested(extension); | 155 extensions::TabHelper::FromWebContents(web_contents)-> |
| 156 active_tab_permission_granter()->GrantIfRequested(extension); |
| 157 } |
148 | 158 |
149 if (browser_action->HasPopup(tab_id)) { | 159 if (browser_action->HasPopup(tab_id)) { |
150 if (popup_url_out) | 160 if (popup_url_out) |
151 *popup_url_out = browser_action->GetPopupUrl(tab_id); | 161 *popup_url_out = browser_action->GetPopupUrl(tab_id); |
152 return ACTION_SHOW_POPUP; | 162 return ACTION_SHOW_POPUP; |
153 } | 163 } |
154 | 164 |
155 extensions::ExtensionActionAPI::BrowserActionExecuted( | 165 extensions::ExtensionActionAPI::BrowserActionExecuted( |
156 service_->profile(), *browser_action, web_contents); | 166 service_->profile(), *browser_action, web_contents); |
157 return ACTION_NONE; | 167 return ACTION_NONE; |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 | 458 |
449 if (last_known_positions_.size() > pref_position_size) { | 459 if (last_known_positions_.size() > pref_position_size) { |
450 // Need to update pref because we have extra icons. But can't call | 460 // Need to update pref because we have extra icons. But can't call |
451 // UpdatePrefs() directly within observation closure. | 461 // UpdatePrefs() directly within observation closure. |
452 base::MessageLoop::current()->PostTask( | 462 base::MessageLoop::current()->PostTask( |
453 FROM_HERE, | 463 FROM_HERE, |
454 base::Bind(&ExtensionToolbarModel::UpdatePrefs, | 464 base::Bind(&ExtensionToolbarModel::UpdatePrefs, |
455 weak_ptr_factory_.GetWeakPtr())); | 465 weak_ptr_factory_.GetWeakPtr())); |
456 } | 466 } |
457 } | 467 } |
| 468 |
| 469 bool ExtensionToolbarModel::ShowBrowserActionPopup( |
| 470 const extensions::Extension* extension) { |
| 471 ObserverListBase<Observer>::Iterator it(observers_); |
| 472 Observer* obs = NULL; |
| 473 while ((obs = it.GetNext()) != NULL) { |
| 474 // Stop after first popup since it should only show in the active window. |
| 475 if (obs->BrowserActionShowPopup(extension)) |
| 476 return true; |
| 477 } |
| 478 return false; |
| 479 } |
OLD | NEW |