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" |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
391 switch (extension_action.action_type()) { | 391 switch (extension_action.action_type()) { |
392 case ActionInfo::TYPE_BROWSER: | 392 case ActionInfo::TYPE_BROWSER: |
393 event_name = "browserAction.onClicked"; | 393 event_name = "browserAction.onClicked"; |
394 break; | 394 break; |
395 case ActionInfo::TYPE_PAGE: | 395 case ActionInfo::TYPE_PAGE: |
396 event_name = "pageAction.onClicked"; | 396 event_name = "pageAction.onClicked"; |
397 break; | 397 break; |
398 case ActionInfo::TYPE_SYSTEM_INDICATOR: | 398 case ActionInfo::TYPE_SYSTEM_INDICATOR: |
399 // The System Indicator handles its own clicks. | 399 // The System Indicator handles its own clicks. |
400 break; | 400 break; |
401 case ActionInfo::TYPE_ACTIVE_SCRIPT: | |
402 NOTREACHED(); // We shouldn't get these calls (yet). | |
not at google - send to devlin
2014/05/08 20:47:09
even if we did I don't think we'll ever expose an
Devlin
2014/05/08 23:01:00
Actually, since PageActions and ActiveScriptAction
| |
403 return; | |
401 } | 404 } |
402 | 405 |
403 if (event_name) { | 406 if (event_name) { |
404 scoped_ptr<base::ListValue> args(new base::ListValue()); | 407 scoped_ptr<base::ListValue> args(new base::ListValue()); |
405 base::DictionaryValue* tab_value = | 408 base::DictionaryValue* tab_value = |
406 extensions::ExtensionTabUtil::CreateTabValue(web_contents); | 409 extensions::ExtensionTabUtil::CreateTabValue(web_contents); |
407 args->Append(tab_value); | 410 args->Append(tab_value); |
408 | 411 |
409 DispatchEventToExtension( | 412 DispatchEventToExtension( |
410 context, extension_action.extension_id(), event_name, args.Pass()); | 413 context, extension_action.extension_id(), event_name, args.Pass()); |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
613 ->GetBrowserAction(*extension_.get())) { | 616 ->GetBrowserAction(*extension_.get())) { |
614 NotifyBrowserActionChange(); | 617 NotifyBrowserActionChange(); |
615 } else if (ExtensionActionManager::Get(GetProfile()) | 618 } else if (ExtensionActionManager::Get(GetProfile()) |
616 ->GetPageAction(*extension_.get())) { | 619 ->GetPageAction(*extension_.get())) { |
617 NotifyLocationBarChange(); | 620 NotifyLocationBarChange(); |
618 } | 621 } |
619 return; | 622 return; |
620 case ActionInfo::TYPE_SYSTEM_INDICATOR: | 623 case ActionInfo::TYPE_SYSTEM_INDICATOR: |
621 NotifySystemIndicatorChange(); | 624 NotifySystemIndicatorChange(); |
622 return; | 625 return; |
626 case ActionInfo::TYPE_ACTIVE_SCRIPT: | |
627 NOTREACHED(); // We shouldn't get these calls (yet). | |
628 return; | |
623 } | 629 } |
624 NOTREACHED(); | 630 NOTREACHED(); |
625 } | 631 } |
626 | 632 |
627 void ExtensionActionFunction::NotifyBrowserActionChange() { | 633 void ExtensionActionFunction::NotifyBrowserActionChange() { |
628 content::NotificationService::current()->Notify( | 634 content::NotificationService::current()->Notify( |
629 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_UPDATED, | 635 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_UPDATED, |
630 content::Source<ExtensionAction>(extension_action_), | 636 content::Source<ExtensionAction>(extension_action_), |
631 content::Details<Profile>(GetProfile())); | 637 content::Details<Profile>(GetProfile())); |
632 } | 638 } |
633 | 639 |
634 void ExtensionActionFunction::NotifyLocationBarChange() { | 640 void ExtensionActionFunction::NotifyLocationBarChange() { |
635 TabHelper::FromWebContents(contents_)-> | 641 LocationBarController::NotifyChange(contents_); |
636 location_bar_controller()->NotifyChange(); | |
637 } | 642 } |
638 | 643 |
639 void ExtensionActionFunction::NotifySystemIndicatorChange() { | 644 void ExtensionActionFunction::NotifySystemIndicatorChange() { |
640 content::NotificationService::current()->Notify( | 645 content::NotificationService::current()->Notify( |
641 chrome::NOTIFICATION_EXTENSION_SYSTEM_INDICATOR_UPDATED, | 646 chrome::NOTIFICATION_EXTENSION_SYSTEM_INDICATOR_UPDATED, |
642 content::Source<Profile>(GetProfile()), | 647 content::Source<Profile>(GetProfile()), |
643 content::Details<ExtensionAction>(extension_action_)); | 648 content::Details<ExtensionAction>(extension_action_)); |
644 } | 649 } |
645 | 650 |
646 bool ExtensionActionFunction::SetVisible(bool visible) { | 651 bool ExtensionActionFunction::SetVisible(bool visible) { |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
902 content::NavigationEntry* entry = contents->GetController().GetVisibleEntry(); | 907 content::NavigationEntry* entry = contents->GetController().GetVisibleEntry(); |
903 if (!entry || url != entry->GetURL().spec()) { | 908 if (!entry || url != entry->GetURL().spec()) { |
904 error_ = extensions::ErrorUtils::FormatErrorMessage( | 909 error_ = extensions::ErrorUtils::FormatErrorMessage( |
905 extensions::kUrlNotActiveError, url); | 910 extensions::kUrlNotActiveError, url); |
906 return false; | 911 return false; |
907 } | 912 } |
908 | 913 |
909 // Set visibility and broadcast notifications that the UI should be updated. | 914 // Set visibility and broadcast notifications that the UI should be updated. |
910 page_action->SetIsVisible(tab_id, enable); | 915 page_action->SetIsVisible(tab_id, enable); |
911 page_action->SetTitle(tab_id, title); | 916 page_action->SetTitle(tab_id, title); |
912 extensions::TabHelper::FromWebContents(contents)-> | 917 extensions::LocationBarController::NotifyChange(contents); |
913 location_bar_controller()->NotifyChange(); | |
914 | 918 |
915 return true; | 919 return true; |
916 } | 920 } |
917 | 921 |
918 bool EnablePageActionsFunction::RunSync() { | 922 bool EnablePageActionsFunction::RunSync() { |
919 return SetPageActionEnabled(true); | 923 return SetPageActionEnabled(true); |
920 } | 924 } |
921 | 925 |
922 bool DisablePageActionsFunction::RunSync() { | 926 bool DisablePageActionsFunction::RunSync() { |
923 return SetPageActionEnabled(false); | 927 return SetPageActionEnabled(false); |
924 } | 928 } |
OLD | NEW |