Chromium Code Reviews| 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/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/browser/extensions/api/extension_action/extension_page_actions_ api_constants.h" | 12 #include "chrome/browser/extensions/api/extension_action/extension_page_actions_ api_constants.h" |
| 13 #include "chrome/browser/extensions/extension_action.h" | 13 #include "chrome/browser/extensions/extension_action.h" |
| 14 #include "chrome/browser/extensions/extension_action_manager.h" | 14 #include "chrome/browser/extensions/extension_action_manager.h" |
| 15 #include "chrome/browser/extensions/extension_service.h" | 15 #include "chrome/browser/extensions/extension_service.h" |
| 16 #include "chrome/browser/extensions/extension_tab_util.h" | 16 #include "chrome/browser/extensions/extension_tab_util.h" |
| 17 #include "chrome/browser/extensions/extension_toolbar_model.h" | 17 #include "chrome/browser/extensions/extension_toolbar_model.h" |
| 18 #include "chrome/browser/extensions/location_bar_controller.h" | 18 #include "chrome/browser/extensions/location_bar_controller.h" |
| 19 #include "chrome/browser/extensions/tab_helper.h" | 19 #include "chrome/browser/extensions/tab_helper.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/sessions/session_tab_helper.h" | 21 #include "chrome/browser/sessions/session_tab_helper.h" |
| 22 #include "chrome/browser/ui/browser_finder.h" | |
| 23 #include "chrome/browser/ui/browser_window.h" | |
| 24 #include "chrome/browser/ui/location_bar/location_bar.h" | |
| 22 #include "chrome/common/extensions/api/extension_action/action_info.h" | 25 #include "chrome/common/extensions/api/extension_action/action_info.h" |
| 23 #include "chrome/common/render_messages.h" | 26 #include "chrome/common/render_messages.h" |
| 24 #include "content/public/browser/navigation_entry.h" | 27 #include "content/public/browser/navigation_entry.h" |
| 25 #include "content/public/browser/notification_service.h" | 28 #include "content/public/browser/notification_service.h" |
| 26 #include "extensions/browser/event_router.h" | 29 #include "extensions/browser/event_router.h" |
| 27 #include "extensions/browser/extension_function_registry.h" | 30 #include "extensions/browser/extension_function_registry.h" |
| 28 #include "extensions/browser/extension_host.h" | 31 #include "extensions/browser/extension_host.h" |
| 29 #include "extensions/browser/extension_registry.h" | 32 #include "extensions/browser/extension_registry.h" |
| 30 #include "extensions/browser/extension_system.h" | 33 #include "extensions/browser/extension_system.h" |
| 31 #include "extensions/browser/image_util.h" | 34 #include "extensions/browser/image_util.h" |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 391 observers_.RemoveObserver(observer); | 394 observers_.RemoveObserver(observer); |
| 392 } | 395 } |
| 393 | 396 |
| 394 void ExtensionActionAPI::NotifyChange(ExtensionAction* extension_action, | 397 void ExtensionActionAPI::NotifyChange(ExtensionAction* extension_action, |
| 395 content::WebContents* web_contents, | 398 content::WebContents* web_contents, |
| 396 content::BrowserContext* context) { | 399 content::BrowserContext* context) { |
| 397 FOR_EACH_OBSERVER( | 400 FOR_EACH_OBSERVER( |
| 398 Observer, | 401 Observer, |
| 399 observers_, | 402 observers_, |
| 400 OnExtensionActionUpdated(extension_action, web_contents, context)); | 403 OnExtensionActionUpdated(extension_action, web_contents, context)); |
| 404 | |
| 405 if (extension_action->action_type() == ActionInfo::TYPE_PAGE) | |
| 406 NotifyPageActionsChanged(web_contents); | |
| 401 } | 407 } |
| 402 | 408 |
| 403 void ExtensionActionAPI::ClearAllValuesForTab( | 409 void ExtensionActionAPI::ClearAllValuesForTab( |
| 404 content::WebContents* web_contents) { | 410 content::WebContents* web_contents) { |
| 405 DCHECK(web_contents); | 411 DCHECK(web_contents); |
| 406 int tab_id = SessionTabHelper::IdForTab(web_contents); | 412 int tab_id = SessionTabHelper::IdForTab(web_contents); |
| 407 content::BrowserContext* browser_context = web_contents->GetBrowserContext(); | 413 content::BrowserContext* browser_context = web_contents->GetBrowserContext(); |
| 408 const ExtensionSet& enabled_extensions = | 414 const ExtensionSet& enabled_extensions = |
| 409 ExtensionRegistry::Get(browser_context_)->enabled_extensions(); | 415 ExtensionRegistry::Get(browser_context_)->enabled_extensions(); |
| 410 ExtensionActionManager* action_manager = | 416 ExtensionActionManager* action_manager = |
| 411 ExtensionActionManager::Get(browser_context_); | 417 ExtensionActionManager::Get(browser_context_); |
| 412 | 418 |
| 413 for (ExtensionSet::const_iterator iter = enabled_extensions.begin(); | 419 for (ExtensionSet::const_iterator iter = enabled_extensions.begin(); |
| 414 iter != enabled_extensions.end(); ++iter) { | 420 iter != enabled_extensions.end(); ++iter) { |
| 415 ExtensionAction* extension_action = | 421 ExtensionAction* extension_action = |
| 416 action_manager->GetBrowserAction(*iter->get()); | 422 action_manager->GetBrowserAction(*iter->get()); |
| 417 if (!extension_action) | 423 if (!extension_action) |
|
Finnur
2014/08/25 13:47:56
If extension_action is non-null here, why call Not
Devlin
2014/08/25 16:57:36
Whoops! Rebasing mistake (too many patches touchi
| |
| 418 extension_action = action_manager->GetPageAction(*iter->get()); | 424 extension_action = action_manager->GetPageAction(*iter->get()); |
| 419 if (extension_action) { | 425 if (extension_action) { |
| 420 extension_action->ClearAllValuesForTab(tab_id); | 426 extension_action->ClearAllValuesForTab(tab_id); |
| 421 NotifyChange(extension_action, web_contents, browser_context); | 427 NotifyChange(extension_action, web_contents, browser_context); |
| 422 } | 428 } |
| 423 } | 429 } |
| 430 | |
| 431 NotifyPageActionsChanged(web_contents); | |
| 432 } | |
| 433 | |
| 434 void ExtensionActionAPI::NotifyPageActionsChanged( | |
| 435 content::WebContents* web_contents) { | |
| 436 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); | |
| 437 if (!browser) | |
| 438 return; | |
| 439 LocationBar* location_bar = | |
| 440 browser->window() ? browser->window()->GetLocationBar() : NULL; | |
| 441 if (!location_bar) | |
| 442 return; | |
| 443 location_bar->UpdatePageActions(); | |
| 444 | |
| 445 FOR_EACH_OBSERVER(Observer, observers_, OnPageActionsUpdated(web_contents)); | |
| 424 } | 446 } |
| 425 | 447 |
| 426 void ExtensionActionAPI::Shutdown() { | 448 void ExtensionActionAPI::Shutdown() { |
| 427 FOR_EACH_OBSERVER(Observer, observers_, OnExtensionActionAPIShuttingDown()); | 449 FOR_EACH_OBSERVER(Observer, observers_, OnExtensionActionAPIShuttingDown()); |
| 428 } | 450 } |
| 429 | 451 |
| 430 // | 452 // |
| 431 // ExtensionActionStorageManager | 453 // ExtensionActionStorageManager |
| 432 // | 454 // |
| 433 | 455 |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 824 if (host->extension_host_type() != VIEW_TYPE_EXTENSION_POPUP || | 846 if (host->extension_host_type() != VIEW_TYPE_EXTENSION_POPUP || |
| 825 host->extension()->id() != extension_->id()) | 847 host->extension()->id() != extension_->id()) |
| 826 return; | 848 return; |
| 827 | 849 |
| 828 SendResponse(true); | 850 SendResponse(true); |
| 829 response_sent_ = true; | 851 response_sent_ = true; |
| 830 registrar_.RemoveAll(); | 852 registrar_.RemoveAll(); |
| 831 } | 853 } |
| 832 | 854 |
| 833 } // namespace extensions | 855 } // namespace extensions |
| OLD | NEW |