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/chrome_notification_types.h" | |
13 #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" |
14 #include "chrome/browser/extensions/extension_action.h" | 13 #include "chrome/browser/extensions/extension_action.h" |
15 #include "chrome/browser/extensions/extension_action_manager.h" | 14 #include "chrome/browser/extensions/extension_action_manager.h" |
16 #include "chrome/browser/extensions/extension_service.h" | 15 #include "chrome/browser/extensions/extension_service.h" |
17 #include "chrome/browser/extensions/extension_tab_util.h" | 16 #include "chrome/browser/extensions/extension_tab_util.h" |
18 #include "chrome/browser/extensions/extension_toolbar_model.h" | 17 #include "chrome/browser/extensions/extension_toolbar_model.h" |
19 #include "chrome/browser/extensions/location_bar_controller.h" | 18 #include "chrome/browser/extensions/location_bar_controller.h" |
20 #include "chrome/browser/extensions/tab_helper.h" | 19 #include "chrome/browser/extensions/tab_helper.h" |
21 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
22 #include "chrome/common/extensions/api/extension_action/action_info.h" | 21 #include "chrome/common/extensions/api/extension_action/action_info.h" |
23 #include "chrome/common/render_messages.h" | 22 #include "chrome/common/render_messages.h" |
24 #include "content/public/browser/navigation_entry.h" | 23 #include "content/public/browser/navigation_entry.h" |
25 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
26 #include "extensions/browser/event_router.h" | 25 #include "extensions/browser/event_router.h" |
27 #include "extensions/browser/extension_function_registry.h" | 26 #include "extensions/browser/extension_function_registry.h" |
28 #include "extensions/browser/extension_host.h" | 27 #include "extensions/browser/extension_host.h" |
29 #include "extensions/browser/extension_registry.h" | 28 #include "extensions/browser/extension_registry.h" |
30 #include "extensions/browser/extension_system.h" | 29 #include "extensions/browser/extension_system.h" |
31 #include "extensions/browser/image_util.h" | 30 #include "extensions/browser/image_util.h" |
| 31 #include "extensions/browser/notification_types.h" |
32 #include "extensions/browser/state_store.h" | 32 #include "extensions/browser/state_store.h" |
33 #include "extensions/common/error_utils.h" | 33 #include "extensions/common/error_utils.h" |
34 #include "ui/gfx/codec/png_codec.h" | 34 #include "ui/gfx/codec/png_codec.h" |
35 #include "ui/gfx/image/image.h" | 35 #include "ui/gfx/image/image.h" |
36 #include "ui/gfx/image/image_skia.h" | 36 #include "ui/gfx/image/image_skia.h" |
37 | 37 |
38 using content::WebContents; | 38 using content::WebContents; |
39 | 39 |
40 namespace page_actions_keys = extension_page_actions_api_constants; | 40 namespace page_actions_keys = extension_page_actions_api_constants; |
41 | 41 |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 ExtensionPrefs* prefs, | 301 ExtensionPrefs* prefs, |
302 const std::string& extension_id, | 302 const std::string& extension_id, |
303 bool visible) { | 303 bool visible) { |
304 if (GetBrowserActionVisibility(prefs, extension_id) == visible) | 304 if (GetBrowserActionVisibility(prefs, extension_id) == visible) |
305 return; | 305 return; |
306 | 306 |
307 prefs->UpdateExtensionPref(extension_id, | 307 prefs->UpdateExtensionPref(extension_id, |
308 kBrowserActionVisible, | 308 kBrowserActionVisible, |
309 new base::FundamentalValue(visible)); | 309 new base::FundamentalValue(visible)); |
310 content::NotificationService::current()->Notify( | 310 content::NotificationService::current()->Notify( |
311 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, | 311 extensions::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, |
312 content::Source<ExtensionPrefs>(prefs), | 312 content::Source<ExtensionPrefs>(prefs), |
313 content::Details<const std::string>(&extension_id)); | 313 content::Details<const std::string>(&extension_id)); |
314 } | 314 } |
315 | 315 |
316 // static | 316 // static |
317 void ExtensionActionAPI::BrowserActionExecuted( | 317 void ExtensionActionAPI::BrowserActionExecuted( |
318 content::BrowserContext* context, | 318 content::BrowserContext* context, |
319 const ExtensionAction& browser_action, | 319 const ExtensionAction& browser_action, |
320 WebContents* web_contents) { | 320 WebContents* web_contents) { |
321 ExtensionActionExecuted(context, browser_action, web_contents); | 321 ExtensionActionExecuted(context, browser_action, web_contents); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 } | 413 } |
414 } | 414 } |
415 | 415 |
416 // | 416 // |
417 // ExtensionActionStorageManager | 417 // ExtensionActionStorageManager |
418 // | 418 // |
419 | 419 |
420 ExtensionActionStorageManager::ExtensionActionStorageManager(Profile* profile) | 420 ExtensionActionStorageManager::ExtensionActionStorageManager(Profile* profile) |
421 : profile_(profile), extension_registry_observer_(this) { | 421 : profile_(profile), extension_registry_observer_(this) { |
422 extension_registry_observer_.Add(ExtensionRegistry::Get(profile_)); | 422 extension_registry_observer_.Add(ExtensionRegistry::Get(profile_)); |
423 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_UPDATED, | 423 registrar_.Add(this, |
| 424 extensions::NOTIFICATION_EXTENSION_BROWSER_ACTION_UPDATED, |
424 content::NotificationService::AllBrowserContextsAndSources()); | 425 content::NotificationService::AllBrowserContextsAndSources()); |
425 | 426 |
426 StateStore* storage = ExtensionSystem::Get(profile_)->state_store(); | 427 StateStore* storage = ExtensionSystem::Get(profile_)->state_store(); |
427 if (storage) | 428 if (storage) |
428 storage->RegisterKey(kBrowserActionStorageKey); | 429 storage->RegisterKey(kBrowserActionStorageKey); |
429 } | 430 } |
430 | 431 |
431 ExtensionActionStorageManager::~ExtensionActionStorageManager() { | 432 ExtensionActionStorageManager::~ExtensionActionStorageManager() { |
432 } | 433 } |
433 | 434 |
(...skipping 12 matching lines...) Expand all Loading... |
446 base::Bind(&ExtensionActionStorageManager::ReadFromStorage, | 447 base::Bind(&ExtensionActionStorageManager::ReadFromStorage, |
447 AsWeakPtr(), | 448 AsWeakPtr(), |
448 extension->id())); | 449 extension->id())); |
449 } | 450 } |
450 } | 451 } |
451 | 452 |
452 void ExtensionActionStorageManager::Observe( | 453 void ExtensionActionStorageManager::Observe( |
453 int type, | 454 int type, |
454 const content::NotificationSource& source, | 455 const content::NotificationSource& source, |
455 const content::NotificationDetails& details) { | 456 const content::NotificationDetails& details) { |
456 DCHECK_EQ(type, chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_UPDATED); | 457 DCHECK_EQ(type, extensions::NOTIFICATION_EXTENSION_BROWSER_ACTION_UPDATED); |
457 ExtensionAction* extension_action = | 458 ExtensionAction* extension_action = |
458 content::Source<ExtensionAction>(source).ptr(); | 459 content::Source<ExtensionAction>(source).ptr(); |
459 Profile* profile = content::Details<Profile>(details).ptr(); | 460 Profile* profile = content::Details<Profile>(details).ptr(); |
460 if (profile != profile_) | 461 if (profile != profile_) |
461 return; | 462 return; |
462 | 463 |
463 WriteToStorage(extension_action); | 464 WriteToStorage(extension_action); |
464 } | 465 } |
465 | 466 |
466 void ExtensionActionStorageManager::WriteToStorage( | 467 void ExtensionActionStorageManager::WriteToStorage( |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
620 return; | 621 return; |
621 case ActionInfo::TYPE_SYSTEM_INDICATOR: | 622 case ActionInfo::TYPE_SYSTEM_INDICATOR: |
622 NotifySystemIndicatorChange(); | 623 NotifySystemIndicatorChange(); |
623 return; | 624 return; |
624 } | 625 } |
625 NOTREACHED(); | 626 NOTREACHED(); |
626 } | 627 } |
627 | 628 |
628 void ExtensionActionFunction::NotifyBrowserActionChange() { | 629 void ExtensionActionFunction::NotifyBrowserActionChange() { |
629 content::NotificationService::current()->Notify( | 630 content::NotificationService::current()->Notify( |
630 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_UPDATED, | 631 extensions::NOTIFICATION_EXTENSION_BROWSER_ACTION_UPDATED, |
631 content::Source<ExtensionAction>(extension_action_), | 632 content::Source<ExtensionAction>(extension_action_), |
632 content::Details<Profile>(GetProfile())); | 633 content::Details<Profile>(GetProfile())); |
633 } | 634 } |
634 | 635 |
635 void ExtensionActionFunction::NotifyLocationBarChange() { | 636 void ExtensionActionFunction::NotifyLocationBarChange() { |
636 LocationBarController::NotifyChange(contents_); | 637 LocationBarController::NotifyChange(contents_); |
637 } | 638 } |
638 | 639 |
639 void ExtensionActionFunction::NotifySystemIndicatorChange() { | 640 void ExtensionActionFunction::NotifySystemIndicatorChange() { |
640 content::NotificationService::current()->Notify( | 641 content::NotificationService::current()->Notify( |
641 chrome::NOTIFICATION_EXTENSION_SYSTEM_INDICATOR_UPDATED, | 642 extensions::NOTIFICATION_EXTENSION_SYSTEM_INDICATOR_UPDATED, |
642 content::Source<Profile>(GetProfile()), | 643 content::Source<Profile>(GetProfile()), |
643 content::Details<ExtensionAction>(extension_action_)); | 644 content::Details<ExtensionAction>(extension_action_)); |
644 } | 645 } |
645 | 646 |
646 bool ExtensionActionFunction::SetVisible(bool visible) { | 647 bool ExtensionActionFunction::SetVisible(bool visible) { |
647 if (extension_action_->GetIsVisible(tab_id_) == visible) | 648 if (extension_action_->GetIsVisible(tab_id_) == visible) |
648 return true; | 649 return true; |
649 extension_action_->SetIsVisible(tab_id_, visible); | 650 extension_action_->SetIsVisible(tab_id_, visible); |
650 NotifyChange(); | 651 NotifyChange(); |
651 return true; | 652 return true; |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
800 error_ = kInternalError; | 801 error_ = kInternalError; |
801 return false; | 802 return false; |
802 } | 803 } |
803 | 804 |
804 if (!model->ShowBrowserActionPopup(extension_)) { | 805 if (!model->ShowBrowserActionPopup(extension_)) { |
805 error_ = kOpenPopupError; | 806 error_ = kOpenPopupError; |
806 return false; | 807 return false; |
807 } | 808 } |
808 | 809 |
809 registrar_.Add(this, | 810 registrar_.Add(this, |
810 chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, | 811 extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, |
811 content::Source<Profile>(GetProfile())); | 812 content::Source<Profile>(GetProfile())); |
812 | 813 |
813 // Set a timeout for waiting for the notification that the popup is loaded. | 814 // Set a timeout for waiting for the notification that the popup is loaded. |
814 // Waiting is required so that the popup view can be retrieved by the custom | 815 // Waiting is required so that the popup view can be retrieved by the custom |
815 // bindings for the response callback. It's also needed to keep this function | 816 // bindings for the response callback. It's also needed to keep this function |
816 // instance around until a notification is observed. | 817 // instance around until a notification is observed. |
817 base::MessageLoopForUI::current()->PostDelayedTask( | 818 base::MessageLoopForUI::current()->PostDelayedTask( |
818 FROM_HERE, | 819 FROM_HERE, |
819 base::Bind(&BrowserActionOpenPopupFunction::OpenPopupTimedOut, this), | 820 base::Bind(&BrowserActionOpenPopupFunction::OpenPopupTimedOut, this), |
820 base::TimeDelta::FromSeconds(10)); | 821 base::TimeDelta::FromSeconds(10)); |
821 return true; | 822 return true; |
822 } | 823 } |
823 | 824 |
824 void BrowserActionOpenPopupFunction::OpenPopupTimedOut() { | 825 void BrowserActionOpenPopupFunction::OpenPopupTimedOut() { |
825 if (response_sent_) | 826 if (response_sent_) |
826 return; | 827 return; |
827 | 828 |
828 DVLOG(1) << "chrome.browserAction.openPopup did not show a popup."; | 829 DVLOG(1) << "chrome.browserAction.openPopup did not show a popup."; |
829 error_ = kOpenPopupError; | 830 error_ = kOpenPopupError; |
830 SendResponse(false); | 831 SendResponse(false); |
831 response_sent_ = true; | 832 response_sent_ = true; |
832 } | 833 } |
833 | 834 |
834 void BrowserActionOpenPopupFunction::Observe( | 835 void BrowserActionOpenPopupFunction::Observe( |
835 int type, | 836 int type, |
836 const content::NotificationSource& source, | 837 const content::NotificationSource& source, |
837 const content::NotificationDetails& details) { | 838 const content::NotificationDetails& details) { |
838 DCHECK_EQ(chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, type); | 839 DCHECK_EQ(extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, type); |
839 if (response_sent_) | 840 if (response_sent_) |
840 return; | 841 return; |
841 | 842 |
842 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); | 843 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); |
843 if (host->extension_host_type() != VIEW_TYPE_EXTENSION_POPUP || | 844 if (host->extension_host_type() != VIEW_TYPE_EXTENSION_POPUP || |
844 host->extension()->id() != extension_->id()) | 845 host->extension()->id() != extension_->id()) |
845 return; | 846 return; |
846 | 847 |
847 SendResponse(true); | 848 SendResponse(true); |
848 response_sent_ = true; | 849 response_sent_ = true; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
914 return true; | 915 return true; |
915 } | 916 } |
916 | 917 |
917 bool EnablePageActionsFunction::RunSync() { | 918 bool EnablePageActionsFunction::RunSync() { |
918 return SetPageActionEnabled(true); | 919 return SetPageActionEnabled(true); |
919 } | 920 } |
920 | 921 |
921 bool DisablePageActionsFunction::RunSync() { | 922 bool DisablePageActionsFunction::RunSync() { |
922 return SetPageActionEnabled(false); | 923 return SetPageActionEnabled(false); |
923 } | 924 } |
OLD | NEW |