| 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/api/extension_action/extension_action_api.h" | 5 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/extensions/active_script_controller.h" | 10 #include "chrome/browser/extensions/active_script_controller.h" |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 // enabled. | 223 // enabled. |
| 224 return browser->window()->GetLocationBar()->ShowPageActionPopup( | 224 return browser->window()->GetLocationBar()->ShowPageActionPopup( |
| 225 extension, grant_active_tab_permissions); | 225 extension, grant_active_tab_permissions); |
| 226 } else { | 226 } else { |
| 227 return ExtensionToolbarModel::Get(browser->profile())-> | 227 return ExtensionToolbarModel::Get(browser->profile())-> |
| 228 ShowExtensionActionPopup( | 228 ShowExtensionActionPopup( |
| 229 extension, browser, grant_active_tab_permissions); | 229 extension, browser, grant_active_tab_permissions); |
| 230 } | 230 } |
| 231 } | 231 } |
| 232 | 232 |
| 233 bool ExtensionActionAPI::ExtensionWantsToRun( |
| 234 const Extension* extension, content::WebContents* web_contents) { |
| 235 // An extension wants to act if it has a visible page action on the given |
| 236 // page... |
| 237 ExtensionAction* page_action = |
| 238 ExtensionActionManager::Get(browser_context_)->GetPageAction(*extension); |
| 239 if (page_action && |
| 240 page_action->GetIsVisible(SessionTabHelper::IdForTab(web_contents))) |
| 241 return true; |
| 242 |
| 243 // ... Or if it has pending scripts that need approval for execution. |
| 244 ActiveScriptController* active_script_controller = |
| 245 ActiveScriptController::GetForWebContents(web_contents); |
| 246 if (active_script_controller && |
| 247 active_script_controller->WantsToRun(extension)) |
| 248 return true; |
| 249 |
| 250 return false; |
| 251 } |
| 252 |
| 233 void ExtensionActionAPI::NotifyChange(ExtensionAction* extension_action, | 253 void ExtensionActionAPI::NotifyChange(ExtensionAction* extension_action, |
| 234 content::WebContents* web_contents, | 254 content::WebContents* web_contents, |
| 235 content::BrowserContext* context) { | 255 content::BrowserContext* context) { |
| 236 FOR_EACH_OBSERVER( | 256 FOR_EACH_OBSERVER( |
| 237 Observer, | 257 Observer, |
| 238 observers_, | 258 observers_, |
| 239 OnExtensionActionUpdated(extension_action, web_contents, context)); | 259 OnExtensionActionUpdated(extension_action, web_contents, context)); |
| 240 | 260 |
| 241 if (extension_action->action_type() == ActionInfo::TYPE_PAGE) | 261 if (extension_action->action_type() == ActionInfo::TYPE_PAGE) |
| 242 NotifyPageActionsChanged(web_contents); | 262 NotifyPageActionsChanged(web_contents); |
| 243 } | 263 } |
| 244 | 264 |
| 245 void ExtensionActionAPI::ClearAllValuesForTab( | 265 void ExtensionActionAPI::ClearAllValuesForTab( |
| 246 content::WebContents* web_contents) { | 266 content::WebContents* web_contents) { |
| 247 DCHECK(web_contents); | 267 DCHECK(web_contents); |
| 248 int tab_id = SessionTabHelper::IdForTab(web_contents); | 268 int tab_id = SessionTabHelper::IdForTab(web_contents); |
| 249 content::BrowserContext* browser_context = web_contents->GetBrowserContext(); | 269 content::BrowserContext* browser_context = web_contents->GetBrowserContext(); |
| 250 const ExtensionSet& enabled_extensions = | 270 const ExtensionSet& enabled_extensions = |
| 251 ExtensionRegistry::Get(browser_context_)->enabled_extensions(); | 271 ExtensionRegistry::Get(browser_context_)->enabled_extensions(); |
| 252 ExtensionActionManager* action_manager = | 272 ExtensionActionManager* action_manager = |
| 253 ExtensionActionManager::Get(browser_context_); | 273 ExtensionActionManager::Get(browser_context_); |
| 254 | 274 |
| 255 for (ExtensionSet::const_iterator iter = enabled_extensions.begin(); | 275 for (ExtensionSet::const_iterator iter = enabled_extensions.begin(); |
| 256 iter != enabled_extensions.end(); ++iter) { | 276 iter != enabled_extensions.end(); ++iter) { |
| 257 ExtensionAction* extension_action = | 277 ExtensionAction* extension_action = |
| 258 action_manager->GetBrowserAction(*iter->get()); | 278 action_manager->GetExtensionAction(**iter); |
| 259 if (!extension_action) | |
| 260 extension_action = action_manager->GetPageAction(*iter->get()); | |
| 261 if (extension_action) { | 279 if (extension_action) { |
| 262 extension_action->ClearAllValuesForTab(tab_id); | 280 extension_action->ClearAllValuesForTab(tab_id); |
| 263 NotifyChange(extension_action, web_contents, browser_context); | 281 NotifyChange(extension_action, web_contents, browser_context); |
| 264 } | 282 } |
| 265 } | 283 } |
| 266 } | 284 } |
| 267 | 285 |
| 268 void ExtensionActionAPI::DispatchEventToExtension( | 286 void ExtensionActionAPI::DispatchEventToExtension( |
| 269 content::BrowserContext* context, | 287 content::BrowserContext* context, |
| 270 const std::string& extension_id, | 288 const std::string& extension_id, |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 if (host->extension_host_type() != VIEW_TYPE_EXTENSION_POPUP || | 648 if (host->extension_host_type() != VIEW_TYPE_EXTENSION_POPUP || |
| 631 host->extension()->id() != extension_->id()) | 649 host->extension()->id() != extension_->id()) |
| 632 return; | 650 return; |
| 633 | 651 |
| 634 SendResponse(true); | 652 SendResponse(true); |
| 635 response_sent_ = true; | 653 response_sent_ = true; |
| 636 registrar_.RemoveAll(); | 654 registrar_.RemoveAll(); |
| 637 } | 655 } |
| 638 | 656 |
| 639 } // namespace extensions | 657 } // namespace extensions |
| OLD | NEW |