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 <string> | 7 #include <set> |
|
mark a. foltz
2013/10/11 20:25:30
Did you mean to remove #include <string>?
justinlin
2013/10/16 07:06:48
Yea, it's already in the .h, actually we don't nee
| |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chrome/browser/chrome_notification_types.h" | 14 #include "chrome/browser/chrome_notification_types.h" |
| 15 #include "chrome/browser/extensions/api/extension_action/extension_page_actions_ api_constants.h" | 15 #include "chrome/browser/extensions/api/extension_action/extension_page_actions_ api_constants.h" |
| 16 #include "chrome/browser/extensions/event_router.h" | 16 #include "chrome/browser/extensions/event_router.h" |
| 17 #include "chrome/browser/extensions/extension_action.h" | 17 #include "chrome/browser/extensions/extension_action.h" |
| 18 #include "chrome/browser/extensions/extension_action_manager.h" | 18 #include "chrome/browser/extensions/extension_action_manager.h" |
| 19 #include "chrome/browser/extensions/extension_function_registry.h" | 19 #include "chrome/browser/extensions/extension_function_registry.h" |
| 20 #include "chrome/browser/extensions/extension_service.h" | 20 #include "chrome/browser/extensions/extension_service.h" |
| 21 #include "chrome/browser/extensions/extension_system.h" | 21 #include "chrome/browser/extensions/extension_system.h" |
| 22 #include "chrome/browser/extensions/extension_tab_util.h" | 22 #include "chrome/browser/extensions/extension_tab_util.h" |
| 23 #include "chrome/browser/extensions/location_bar_controller.h" | 23 #include "chrome/browser/extensions/location_bar_controller.h" |
| 24 #include "chrome/browser/extensions/state_store.h" | 24 #include "chrome/browser/extensions/state_store.h" |
| 25 #include "chrome/browser/extensions/tab_helper.h" | 25 #include "chrome/browser/extensions/tab_helper.h" |
| 26 #include "chrome/browser/profiles/profile.h" | 26 #include "chrome/browser/profiles/profile.h" |
| 27 #include "chrome/common/extensions/api/extension_action/action_info.h" | 27 #include "chrome/common/extensions/api/extension_action/action_info.h" |
| 28 #include "chrome/common/extensions/features/simple_feature.h" | |
| 28 #include "chrome/common/render_messages.h" | 29 #include "chrome/common/render_messages.h" |
| 29 #include "content/public/browser/navigation_entry.h" | 30 #include "content/public/browser/navigation_entry.h" |
| 30 #include "content/public/browser/notification_service.h" | 31 #include "content/public/browser/notification_service.h" |
| 31 #include "extensions/common/error_utils.h" | 32 #include "extensions/common/error_utils.h" |
| 32 #include "ui/gfx/image/image.h" | 33 #include "ui/gfx/image/image.h" |
| 33 #include "ui/gfx/image/image_skia.h" | 34 #include "ui/gfx/image/image_skia.h" |
| 34 | 35 |
| 36 using chrome::VersionInfo; | |
| 35 using content::WebContents; | 37 using content::WebContents; |
| 36 | 38 |
| 37 namespace page_actions_keys = extension_page_actions_api_constants; | 39 namespace page_actions_keys = extension_page_actions_api_constants; |
| 38 | 40 |
| 39 namespace extensions { | 41 namespace extensions { |
| 40 | 42 |
| 41 namespace { | 43 namespace { |
| 42 | 44 |
| 43 const char kBrowserActionStorageKey[] = "browser_action"; | 45 const char kBrowserActionStorageKey[] = "browser_action"; |
| 44 const char kPopupUrlStorageKey[] = "poupup_url"; | 46 const char kPopupUrlStorageKey[] = "poupup_url"; |
| 45 const char kTitleStorageKey[] = "title"; | 47 const char kTitleStorageKey[] = "title"; |
| 46 const char kIconStorageKey[] = "icon"; | 48 const char kIconStorageKey[] = "icon"; |
| 47 const char kBadgeTextStorageKey[] = "badge_text"; | 49 const char kBadgeTextStorageKey[] = "badge_text"; |
| 48 const char kBadgeBackgroundColorStorageKey[] = "badge_background_color"; | 50 const char kBadgeBackgroundColorStorageKey[] = "badge_background_color"; |
| 49 const char kBadgeTextColorStorageKey[] = "badge_text_color"; | 51 const char kBadgeTextColorStorageKey[] = "badge_text_color"; |
| 50 const char kAppearanceStorageKey[] = "appearance"; | 52 const char kAppearanceStorageKey[] = "appearance"; |
| 51 | 53 |
| 52 // Whether the browser action is visible in the toolbar. | 54 // Whether the browser action is visible in the toolbar. |
| 53 const char kBrowserActionVisible[] = "browser_action_visible"; | 55 const char kBrowserActionVisible[] = "browser_action_visible"; |
| 54 | 56 |
| 55 // Errors. | 57 // Errors. |
| 56 const char kNoExtensionActionError[] = | 58 const char kNoExtensionActionError[] = |
| 57 "This extension has no action specified."; | 59 "This extension has no action specified."; |
| 58 const char kNoTabError[] = "No tab with id: *."; | 60 const char kNoTabError[] = "No tab with id: *."; |
| 59 const char kNoPageActionError[] = | 61 const char kNoPageActionError[] = |
| 60 "This extension has no page action specified."; | 62 "This extension has no page action specified."; |
| 61 const char kUrlNotActiveError[] = "This url is no longer active: *."; | 63 const char kUrlNotActiveError[] = "This url is no longer active: *."; |
| 62 | 64 |
| 65 // Whitelisted extensions for the openPopup API. | |
| 66 const char* whitelisted_extensions[] = { | |
|
mark a. foltz
2013/10/11 20:25:30
kOpenPopupWhitelistedExtensions
justinlin
2013/10/16 07:06:48
moved to _api_features.json
| |
| 67 "enhhojjnijigcajfphajepfemndkmdlo", // Dev | |
| 68 "pkedcjkdefgpdelpbcmbmeomcjbeemfm", // Trusted Tester | |
| 69 "fmfcbgogabcbclcofgocippekhfcmgfj", // Staging | |
| 70 "hfaagokkkhdbgiakmmlclaapfelnkoah", // Canary | |
| 71 "F155646B5D1CA545F7E1E4E20D573DFDD44C2540", // Trusted Tester (public) | |
| 72 "16CA7A47AAE4BE49B1E75A6B960C3875E945B264" // Release | |
| 73 }; | |
| 74 | |
| 63 struct IconRepresentationInfo { | 75 struct IconRepresentationInfo { |
| 64 // Size as a string that will be used to retrieve representation value from | 76 // Size as a string that will be used to retrieve representation value from |
| 65 // SetIcon function arguments. | 77 // SetIcon function arguments. |
| 66 const char* size_string; | 78 const char* size_string; |
| 67 // Scale factor for which the represantion should be used. | 79 // Scale factor for which the represantion should be used. |
| 68 ui::ScaleFactor scale; | 80 ui::ScaleFactor scale; |
| 69 }; | 81 }; |
| 70 | 82 |
| 71 const IconRepresentationInfo kIconSizes[] = { | 83 const IconRepresentationInfo kIconSizes[] = { |
| 72 { "19", ui::SCALE_FACTOR_100P }, | 84 { "19", ui::SCALE_FACTOR_100P }, |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 registry->RegisterFunction<BrowserActionSetTitleFunction>(); | 214 registry->RegisterFunction<BrowserActionSetTitleFunction>(); |
| 203 registry->RegisterFunction<BrowserActionSetBadgeTextFunction>(); | 215 registry->RegisterFunction<BrowserActionSetBadgeTextFunction>(); |
| 204 registry->RegisterFunction<BrowserActionSetBadgeBackgroundColorFunction>(); | 216 registry->RegisterFunction<BrowserActionSetBadgeBackgroundColorFunction>(); |
| 205 registry->RegisterFunction<BrowserActionSetPopupFunction>(); | 217 registry->RegisterFunction<BrowserActionSetPopupFunction>(); |
| 206 registry->RegisterFunction<BrowserActionGetTitleFunction>(); | 218 registry->RegisterFunction<BrowserActionGetTitleFunction>(); |
| 207 registry->RegisterFunction<BrowserActionGetBadgeTextFunction>(); | 219 registry->RegisterFunction<BrowserActionGetBadgeTextFunction>(); |
| 208 registry->RegisterFunction<BrowserActionGetBadgeBackgroundColorFunction>(); | 220 registry->RegisterFunction<BrowserActionGetBadgeBackgroundColorFunction>(); |
| 209 registry->RegisterFunction<BrowserActionGetPopupFunction>(); | 221 registry->RegisterFunction<BrowserActionGetPopupFunction>(); |
| 210 registry->RegisterFunction<BrowserActionEnableFunction>(); | 222 registry->RegisterFunction<BrowserActionEnableFunction>(); |
| 211 registry->RegisterFunction<BrowserActionDisableFunction>(); | 223 registry->RegisterFunction<BrowserActionDisableFunction>(); |
| 224 registry->RegisterFunction<BrowserActionOpenPopupFunction>(); | |
| 212 | 225 |
| 213 // Page Actions | 226 // Page Actions |
| 214 registry->RegisterFunction<EnablePageActionsFunction>(); | 227 registry->RegisterFunction<EnablePageActionsFunction>(); |
| 215 registry->RegisterFunction<DisablePageActionsFunction>(); | 228 registry->RegisterFunction<DisablePageActionsFunction>(); |
| 216 registry->RegisterFunction<PageActionShowFunction>(); | 229 registry->RegisterFunction<PageActionShowFunction>(); |
| 217 registry->RegisterFunction<PageActionHideFunction>(); | 230 registry->RegisterFunction<PageActionHideFunction>(); |
| 218 registry->RegisterFunction<PageActionSetIconFunction>(); | 231 registry->RegisterFunction<PageActionSetIconFunction>(); |
| 219 registry->RegisterFunction<PageActionSetTitleFunction>(); | 232 registry->RegisterFunction<PageActionSetTitleFunction>(); |
| 220 registry->RegisterFunction<PageActionSetPopupFunction>(); | 233 registry->RegisterFunction<PageActionSetPopupFunction>(); |
| 221 registry->RegisterFunction<PageActionGetTitleFunction>(); | 234 registry->RegisterFunction<PageActionGetTitleFunction>(); |
| (...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 798 list->Append( | 811 list->Append( |
| 799 new base::FundamentalValue(static_cast<int>(SkColorGetG(color)))); | 812 new base::FundamentalValue(static_cast<int>(SkColorGetG(color)))); |
| 800 list->Append( | 813 list->Append( |
| 801 new base::FundamentalValue(static_cast<int>(SkColorGetB(color)))); | 814 new base::FundamentalValue(static_cast<int>(SkColorGetB(color)))); |
| 802 list->Append( | 815 list->Append( |
| 803 new base::FundamentalValue(static_cast<int>(SkColorGetA(color)))); | 816 new base::FundamentalValue(static_cast<int>(SkColorGetA(color)))); |
| 804 SetResult(list); | 817 SetResult(list); |
| 805 return true; | 818 return true; |
| 806 } | 819 } |
| 807 | 820 |
| 821 bool BrowserActionOpenPopupFunction::RunImpl() { | |
| 822 if (VersionInfo::GetChannel() != VersionInfo::CHANNEL_UNKNOWN && | |
|
mark a. foltz
2013/10/11 20:25:30
For clarity, suggest adding a private boolean meth
Matt Perry
2013/10/11 22:22:53
We actually have a standard mechanism for this. Ad
justinlin
2013/10/16 07:06:48
Done.
justinlin
2013/10/16 07:06:48
Just using _api_features.json now.
| |
| 823 VersionInfo::GetChannel() != VersionInfo::CHANNEL_DEV && | |
| 824 !SimpleFeature::IsIdInWhitelist( | |
| 825 extension_->id(), | |
| 826 std::set<std::string>( | |
|
mark a. foltz
2013/10/11 20:25:30
Is this an overloaded ctor for std::set that takes
| |
| 827 whitelisted_extensions, | |
| 828 whitelisted_extensions + arraysize(whitelisted_extensions)))) { | |
| 829 SetResult(new base::DictionaryValue()); | |
| 830 return false; | |
| 831 } | |
| 832 | |
| 833 ExtensionService* service = | |
| 834 extensions::ExtensionSystem::Get(profile_)->extension_service(); | |
| 835 if (!service) { | |
| 836 SetResult(new base::DictionaryValue()); | |
|
Matt Perry
2013/10/11 22:22:53
Don't set result on errors. Use SetError instead,
justinlin
2013/10/16 07:06:48
Done.
| |
| 837 return false; | |
| 838 } | |
| 839 | |
| 840 ExtensionToolbarModel *model = service->toolbar_model(); | |
| 841 if (!model) { | |
| 842 SetResult(new base::DictionaryValue()); | |
| 843 return false; | |
| 844 } | |
| 845 | |
| 846 model->ShowBrowserActionPopup(extension_); | |
| 847 | |
| 848 SetResult(new base::DictionaryValue()); | |
|
mark a. foltz
2013/10/11 20:25:30
Just call this at the top of RunImpl?
justinlin
2013/10/16 07:06:48
no longer needed.
| |
| 849 return true; | |
| 850 } | |
| 851 | |
| 808 // | 852 // |
| 809 // ScriptBadgeGetAttentionFunction | 853 // ScriptBadgeGetAttentionFunction |
| 810 // | 854 // |
| 811 | 855 |
| 812 ScriptBadgeGetAttentionFunction::~ScriptBadgeGetAttentionFunction() {} | 856 ScriptBadgeGetAttentionFunction::~ScriptBadgeGetAttentionFunction() {} |
| 813 | 857 |
| 814 bool ScriptBadgeGetAttentionFunction::RunExtensionAction() { | 858 bool ScriptBadgeGetAttentionFunction::RunExtensionAction() { |
| 815 tab_helper().location_bar_controller()->GetAttentionFor(extension_id()); | 859 tab_helper().location_bar_controller()->GetAttentionFor(extension_id()); |
| 816 return true; | 860 return true; |
| 817 } | 861 } |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 884 return true; | 928 return true; |
| 885 } | 929 } |
| 886 | 930 |
| 887 bool EnablePageActionsFunction::RunImpl() { | 931 bool EnablePageActionsFunction::RunImpl() { |
| 888 return SetPageActionEnabled(true); | 932 return SetPageActionEnabled(true); |
| 889 } | 933 } |
| 890 | 934 |
| 891 bool DisablePageActionsFunction::RunImpl() { | 935 bool DisablePageActionsFunction::RunImpl() { |
| 892 return SetPageActionEnabled(false); | 936 return SetPageActionEnabled(false); |
| 893 } | 937 } |
| OLD | NEW |