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