| 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 return ExecuteBrowserAction(extension, browser, popup_url_out, true); |
| 140 } |
| 141 |
| 142 ExtensionToolbarModel::Action ExtensionToolbarModel::ExecuteBrowserAction( |
| 143 const Extension* extension, |
| 144 Browser* browser, |
| 145 GURL* popup_url_out, |
| 146 bool should_grant) { |
| 132 content::WebContents* web_contents = NULL; | 147 content::WebContents* web_contents = NULL; |
| 133 int tab_id = 0; | 148 int tab_id = 0; |
| 134 if (!ExtensionTabUtil::GetDefaultTab(browser, &web_contents, &tab_id)) | 149 if (!ExtensionTabUtil::GetDefaultTab(browser, &web_contents, &tab_id)) |
| 135 return ACTION_NONE; | 150 return ACTION_NONE; |
| 136 | 151 |
| 137 ExtensionAction* browser_action = | 152 ExtensionAction* browser_action = |
| 138 extensions::ExtensionActionManager::Get(service_->profile())-> | 153 extensions::ExtensionActionManager::Get(service_->profile())-> |
| 139 GetBrowserAction(*extension); | 154 GetBrowserAction(*extension); |
| 140 | 155 |
| 141 // For browser actions, visibility == enabledness. | 156 // For browser actions, visibility == enabledness. |
| 142 if (!browser_action->GetIsVisible(tab_id)) | 157 if (!browser_action->GetIsVisible(tab_id)) |
| 143 return ACTION_NONE; | 158 return ACTION_NONE; |
| 144 | 159 |
| 145 extensions::TabHelper::FromWebContents(web_contents)-> | 160 if (should_grant) { |
| 146 active_tab_permission_granter()->GrantIfRequested(extension); | 161 extensions::TabHelper::FromWebContents(web_contents)-> |
| 162 active_tab_permission_granter()->GrantIfRequested(extension); |
| 163 } |
| 147 | 164 |
| 148 if (browser_action->HasPopup(tab_id)) { | 165 if (browser_action->HasPopup(tab_id)) { |
| 149 if (popup_url_out) | 166 if (popup_url_out) |
| 150 *popup_url_out = browser_action->GetPopupUrl(tab_id); | 167 *popup_url_out = browser_action->GetPopupUrl(tab_id); |
| 151 return ACTION_SHOW_POPUP; | 168 return ACTION_SHOW_POPUP; |
| 152 } | 169 } |
| 153 | 170 |
| 154 extensions::ExtensionActionAPI::BrowserActionExecuted( | 171 extensions::ExtensionActionAPI::BrowserActionExecuted( |
| 155 service_->profile(), *browser_action, web_contents); | 172 service_->profile(), *browser_action, web_contents); |
| 156 return ACTION_NONE; | 173 return ACTION_NONE; |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 | 464 |
| 448 if (last_known_positions_.size() > pref_position_size) { | 465 if (last_known_positions_.size() > pref_position_size) { |
| 449 // Need to update pref because we have extra icons. But can't call | 466 // Need to update pref because we have extra icons. But can't call |
| 450 // UpdatePrefs() directly within observation closure. | 467 // UpdatePrefs() directly within observation closure. |
| 451 base::MessageLoop::current()->PostTask( | 468 base::MessageLoop::current()->PostTask( |
| 452 FROM_HERE, | 469 FROM_HERE, |
| 453 base::Bind(&ExtensionToolbarModel::UpdatePrefs, | 470 base::Bind(&ExtensionToolbarModel::UpdatePrefs, |
| 454 weak_ptr_factory_.GetWeakPtr())); | 471 weak_ptr_factory_.GetWeakPtr())); |
| 455 } | 472 } |
| 456 } | 473 } |
| 474 |
| 475 bool ExtensionToolbarModel::ShowBrowserActionPopup( |
| 476 const extensions::Extension* extension) { |
| 477 ObserverListBase<Observer>::Iterator it(observers_); |
| 478 Observer* obs = NULL; |
| 479 while ((obs = it.GetNext()) != NULL) { |
| 480 // Stop after first popup since it should only show in the active window. |
| 481 if (obs->BrowserActionShowPopup(extension)) |
| 482 return true; |
| 483 } |
| 484 return false; |
| 485 } |
| OLD | NEW |