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> | |
8 | |
9 #include "base/base64.h" | 7 #include "base/base64.h" |
10 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
11 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
13 #include "base/values.h" | 11 #include "base/values.h" |
14 #include "chrome/browser/chrome_notification_types.h" | 12 #include "chrome/browser/chrome_notification_types.h" |
15 #include "chrome/browser/extensions/api/extension_action/extension_page_actions_ api_constants.h" | 13 #include "chrome/browser/extensions/api/extension_action/extension_page_actions_ api_constants.h" |
16 #include "chrome/browser/extensions/event_router.h" | 14 #include "chrome/browser/extensions/event_router.h" |
17 #include "chrome/browser/extensions/extension_action.h" | 15 #include "chrome/browser/extensions/extension_action.h" |
18 #include "chrome/browser/extensions/extension_action_manager.h" | 16 #include "chrome/browser/extensions/extension_action_manager.h" |
19 #include "chrome/browser/extensions/extension_function_registry.h" | 17 #include "chrome/browser/extensions/extension_function_registry.h" |
18 #include "chrome/browser/extensions/extension_host.h" | |
20 #include "chrome/browser/extensions/extension_service.h" | 19 #include "chrome/browser/extensions/extension_service.h" |
21 #include "chrome/browser/extensions/extension_system.h" | 20 #include "chrome/browser/extensions/extension_system.h" |
22 #include "chrome/browser/extensions/extension_tab_util.h" | 21 #include "chrome/browser/extensions/extension_tab_util.h" |
23 #include "chrome/browser/extensions/location_bar_controller.h" | 22 #include "chrome/browser/extensions/location_bar_controller.h" |
24 #include "chrome/browser/extensions/state_store.h" | 23 #include "chrome/browser/extensions/state_store.h" |
25 #include "chrome/browser/extensions/tab_helper.h" | 24 #include "chrome/browser/extensions/tab_helper.h" |
26 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
27 #include "chrome/common/extensions/api/extension_action/action_info.h" | 26 #include "chrome/common/extensions/api/extension_action/action_info.h" |
28 #include "chrome/common/render_messages.h" | 27 #include "chrome/common/render_messages.h" |
29 #include "content/public/browser/navigation_entry.h" | 28 #include "content/public/browser/navigation_entry.h" |
(...skipping 22 matching lines...) Expand all Loading... | |
52 // Whether the browser action is visible in the toolbar. | 51 // Whether the browser action is visible in the toolbar. |
53 const char kBrowserActionVisible[] = "browser_action_visible"; | 52 const char kBrowserActionVisible[] = "browser_action_visible"; |
54 | 53 |
55 // Errors. | 54 // Errors. |
56 const char kNoExtensionActionError[] = | 55 const char kNoExtensionActionError[] = |
57 "This extension has no action specified."; | 56 "This extension has no action specified."; |
58 const char kNoTabError[] = "No tab with id: *."; | 57 const char kNoTabError[] = "No tab with id: *."; |
59 const char kNoPageActionError[] = | 58 const char kNoPageActionError[] = |
60 "This extension has no page action specified."; | 59 "This extension has no page action specified."; |
61 const char kUrlNotActiveError[] = "This url is no longer active: *."; | 60 const char kUrlNotActiveError[] = "This url is no longer active: *."; |
61 const char kInternalError[] = "Internal error."; | |
62 | 62 |
63 struct IconRepresentationInfo { | 63 struct IconRepresentationInfo { |
64 // Size as a string that will be used to retrieve representation value from | 64 // Size as a string that will be used to retrieve representation value from |
65 // SetIcon function arguments. | 65 // SetIcon function arguments. |
66 const char* size_string; | 66 const char* size_string; |
67 // Scale factor for which the represantion should be used. | 67 // Scale factor for which the represantion should be used. |
68 ui::ScaleFactor scale; | 68 ui::ScaleFactor scale; |
69 }; | 69 }; |
70 | 70 |
71 const IconRepresentationInfo kIconSizes[] = { | 71 const IconRepresentationInfo kIconSizes[] = { |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
202 registry->RegisterFunction<BrowserActionSetTitleFunction>(); | 202 registry->RegisterFunction<BrowserActionSetTitleFunction>(); |
203 registry->RegisterFunction<BrowserActionSetBadgeTextFunction>(); | 203 registry->RegisterFunction<BrowserActionSetBadgeTextFunction>(); |
204 registry->RegisterFunction<BrowserActionSetBadgeBackgroundColorFunction>(); | 204 registry->RegisterFunction<BrowserActionSetBadgeBackgroundColorFunction>(); |
205 registry->RegisterFunction<BrowserActionSetPopupFunction>(); | 205 registry->RegisterFunction<BrowserActionSetPopupFunction>(); |
206 registry->RegisterFunction<BrowserActionGetTitleFunction>(); | 206 registry->RegisterFunction<BrowserActionGetTitleFunction>(); |
207 registry->RegisterFunction<BrowserActionGetBadgeTextFunction>(); | 207 registry->RegisterFunction<BrowserActionGetBadgeTextFunction>(); |
208 registry->RegisterFunction<BrowserActionGetBadgeBackgroundColorFunction>(); | 208 registry->RegisterFunction<BrowserActionGetBadgeBackgroundColorFunction>(); |
209 registry->RegisterFunction<BrowserActionGetPopupFunction>(); | 209 registry->RegisterFunction<BrowserActionGetPopupFunction>(); |
210 registry->RegisterFunction<BrowserActionEnableFunction>(); | 210 registry->RegisterFunction<BrowserActionEnableFunction>(); |
211 registry->RegisterFunction<BrowserActionDisableFunction>(); | 211 registry->RegisterFunction<BrowserActionDisableFunction>(); |
212 registry->RegisterFunction<BrowserActionOpenPopupFunction>(); | |
212 | 213 |
213 // Page Actions | 214 // Page Actions |
214 registry->RegisterFunction<EnablePageActionsFunction>(); | 215 registry->RegisterFunction<EnablePageActionsFunction>(); |
215 registry->RegisterFunction<DisablePageActionsFunction>(); | 216 registry->RegisterFunction<DisablePageActionsFunction>(); |
216 registry->RegisterFunction<PageActionShowFunction>(); | 217 registry->RegisterFunction<PageActionShowFunction>(); |
217 registry->RegisterFunction<PageActionHideFunction>(); | 218 registry->RegisterFunction<PageActionHideFunction>(); |
218 registry->RegisterFunction<PageActionSetIconFunction>(); | 219 registry->RegisterFunction<PageActionSetIconFunction>(); |
219 registry->RegisterFunction<PageActionSetTitleFunction>(); | 220 registry->RegisterFunction<PageActionSetTitleFunction>(); |
220 registry->RegisterFunction<PageActionSetPopupFunction>(); | 221 registry->RegisterFunction<PageActionSetPopupFunction>(); |
221 registry->RegisterFunction<PageActionGetTitleFunction>(); | 222 registry->RegisterFunction<PageActionGetTitleFunction>(); |
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
798 list->Append( | 799 list->Append( |
799 new base::FundamentalValue(static_cast<int>(SkColorGetG(color)))); | 800 new base::FundamentalValue(static_cast<int>(SkColorGetG(color)))); |
800 list->Append( | 801 list->Append( |
801 new base::FundamentalValue(static_cast<int>(SkColorGetB(color)))); | 802 new base::FundamentalValue(static_cast<int>(SkColorGetB(color)))); |
802 list->Append( | 803 list->Append( |
803 new base::FundamentalValue(static_cast<int>(SkColorGetA(color)))); | 804 new base::FundamentalValue(static_cast<int>(SkColorGetA(color)))); |
804 SetResult(list); | 805 SetResult(list); |
805 return true; | 806 return true; |
806 } | 807 } |
807 | 808 |
809 BrowserActionOpenPopupFunction::BrowserActionOpenPopupFunction() | |
810 : response_sent_(false) { | |
811 } | |
812 | |
813 bool BrowserActionOpenPopupFunction::RunImpl() { | |
814 ExtensionToolbarModel* model = extensions::ExtensionSystem::Get(profile_)-> | |
815 extension_service()->toolbar_model(); | |
816 if (!model) { | |
817 error_ = kInternalError; | |
818 return false; | |
819 } | |
820 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, | |
821 content::Source<Profile>(profile_)); | |
822 model->ShowBrowserActionPopup(extension_); | |
823 | |
824 // Set a timeout for waiting for the notification that the popup is loaded. | |
825 // Waiting is required so that the popup view can be retrieved by the custom | |
826 // bindings for response callback. | |
827 base::MessageLoopForUI::current()->PostDelayedTask( | |
828 FROM_HERE, | |
829 base::Bind(&BrowserActionOpenPopupFunction::OpenPopupTimedOut, this), | |
830 base::TimeDelta::FromSeconds(1)); | |
831 return true; | |
832 } | |
833 | |
834 void BrowserActionOpenPopupFunction::OpenPopupTimedOut() { | |
835 if (response_sent_) | |
836 return; | |
837 | |
838 DVLOG(1) << "chrome.browserAction.openPopup did not show a popup."; | |
839 // Custom binding will still try to get the popup, but may fail. | |
840 SendResponse(new base::ListValue()); | |
841 response_sent_ = true; | |
842 } | |
843 | |
844 void BrowserActionOpenPopupFunction::Observe( | |
845 int type, | |
846 const content::NotificationSource& source, | |
847 const content::NotificationDetails& details) { | |
848 DCHECK_EQ(type, chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING); | |
849 if (response_sent_) | |
850 return; | |
851 | |
852 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); | |
853 if (host->extension()->id() != extension_->id()) | |
854 return; | |
855 | |
856 SendResponse(new base::ListValue()); | |
mark a. foltz
2013/10/16 19:00:53
Is this what you intended? The signature for Exte
justinlin
2013/10/16 19:31:29
Oh good catch. So, apparently base::Value* can be
| |
857 response_sent_ = true; | |
mark a. foltz
2013/10/16 19:00:53
You could also check for NULL-ness of results_, bu
justinlin
2013/10/16 19:31:29
I think it's okay not to set result here since we
| |
858 // Don't need to de-register notification listener since the last ref for this | |
mark a. foltz
2013/10/16 19:00:53
Would it hurt to de-register it anyway?
justinlin
2013/10/16 19:31:29
Done.
| |
859 // object will go away after OpenPopupTimedOut is called. | |
860 } | |
861 | |
808 // | 862 // |
809 // ScriptBadgeGetAttentionFunction | 863 // ScriptBadgeGetAttentionFunction |
810 // | 864 // |
811 | 865 |
812 ScriptBadgeGetAttentionFunction::~ScriptBadgeGetAttentionFunction() {} | 866 ScriptBadgeGetAttentionFunction::~ScriptBadgeGetAttentionFunction() {} |
813 | 867 |
814 bool ScriptBadgeGetAttentionFunction::RunExtensionAction() { | 868 bool ScriptBadgeGetAttentionFunction::RunExtensionAction() { |
815 tab_helper().location_bar_controller()->GetAttentionFor(extension_id()); | 869 tab_helper().location_bar_controller()->GetAttentionFor(extension_id()); |
816 return true; | 870 return true; |
817 } | 871 } |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
884 return true; | 938 return true; |
885 } | 939 } |
886 | 940 |
887 bool EnablePageActionsFunction::RunImpl() { | 941 bool EnablePageActionsFunction::RunImpl() { |
888 return SetPageActionEnabled(true); | 942 return SetPageActionEnabled(true); |
889 } | 943 } |
890 | 944 |
891 bool DisablePageActionsFunction::RunImpl() { | 945 bool DisablePageActionsFunction::RunImpl() { |
892 return SetPageActionEnabled(false); | 946 return SetPageActionEnabled(false); |
893 } | 947 } |
OLD | NEW |