| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_EXTENSION_ACTION_EXTENSION_ACTIONS_API_H_ | |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_EXTENSION_ACTION_EXTENSION_ACTIONS_API_H_ | |
| 7 | |
| 8 #include "base/memory/weak_ptr.h" | |
| 9 #include "chrome/browser/extensions/extension_action.h" | |
| 10 #include "chrome/browser/extensions/extension_function.h" | |
| 11 #include "content/public/browser/notification_observer.h" | |
| 12 #include "content/public/browser/notification_registrar.h" | |
| 13 | |
| 14 namespace base { | |
| 15 class DictionaryValue; | |
| 16 } | |
| 17 | |
| 18 namespace content { | |
| 19 class WebContents; | |
| 20 } | |
| 21 | |
| 22 namespace extensions { | |
| 23 class TabHelper; | |
| 24 } | |
| 25 | |
| 26 namespace extensions { | |
| 27 | |
| 28 // This class manages reading and writing browser action values from storage. | |
| 29 class ExtensionActionStorageManager | |
| 30 : public content::NotificationObserver, | |
| 31 public base::SupportsWeakPtr<ExtensionActionStorageManager> { | |
| 32 public: | |
| 33 explicit ExtensionActionStorageManager(Profile* profile); | |
| 34 virtual ~ExtensionActionStorageManager(); | |
| 35 | |
| 36 private: | |
| 37 // NotificationObserver: | |
| 38 virtual void Observe(int type, | |
| 39 const content::NotificationSource& source, | |
| 40 const content::NotificationDetails& details) OVERRIDE; | |
| 41 | |
| 42 // Reads/Writes the ExtensionAction's default values to/from storage. | |
| 43 void WriteToStorage(ExtensionAction* extension_action); | |
| 44 void ReadFromStorage( | |
| 45 const std::string& extension_id, scoped_ptr<base::Value> value); | |
| 46 | |
| 47 Profile* profile_; | |
| 48 content::NotificationRegistrar registrar_; | |
| 49 }; | |
| 50 | |
| 51 } // namespace extensions | |
| 52 | |
| 53 | |
| 54 // Implementation of the browserAction, pageAction, and scriptBadge APIs. | |
| 55 // | |
| 56 // Divergent behaviour between the three is minimal (pageAction and scriptBadge | |
| 57 // have required tabIds while browserAction's are optional, they have different | |
| 58 // internal browser notification requirements, and not all functions are defined | |
| 59 // for all APIs). | |
| 60 class ExtensionActionFunction : public SyncExtensionFunction { | |
| 61 public: | |
| 62 static bool ParseCSSColorString(const std::string& color_string, | |
| 63 SkColor* result); | |
| 64 | |
| 65 protected: | |
| 66 ExtensionActionFunction(); | |
| 67 virtual ~ExtensionActionFunction(); | |
| 68 virtual bool RunImpl() OVERRIDE; | |
| 69 virtual bool RunExtensionAction() = 0; | |
| 70 | |
| 71 bool ExtractDataFromArguments(); | |
| 72 void NotifyChange(); | |
| 73 void NotifyBrowserActionChange(); | |
| 74 void NotifyLocationBarChange(); | |
| 75 void NotifySystemIndicatorChange(); | |
| 76 bool SetVisible(bool visible); | |
| 77 | |
| 78 // Extension-related information for |tab_id_|. | |
| 79 // CHECK-fails if there is no tab. | |
| 80 extensions::TabHelper& tab_helper() const; | |
| 81 | |
| 82 // All the extension action APIs take a single argument called details that | |
| 83 // is a dictionary. | |
| 84 base::DictionaryValue* details_; | |
| 85 | |
| 86 // The tab id the extension action function should apply to, if any, or | |
| 87 // kDefaultTabId if none was specified. | |
| 88 int tab_id_; | |
| 89 | |
| 90 // WebContents for |tab_id_| if one exists. | |
| 91 content::WebContents* contents_; | |
| 92 | |
| 93 // The extension action for the current extension. | |
| 94 ExtensionAction* extension_action_; | |
| 95 }; | |
| 96 | |
| 97 // | |
| 98 // Implementations of each extension action API. | |
| 99 // | |
| 100 // pageAction and browserAction bindings are created for these by extending them | |
| 101 // then declaring an EXTENSION_FUNCTION_NAME. | |
| 102 // | |
| 103 | |
| 104 // show | |
| 105 class ExtensionActionShowFunction : public ExtensionActionFunction { | |
| 106 protected: | |
| 107 virtual ~ExtensionActionShowFunction() {} | |
| 108 virtual bool RunExtensionAction() OVERRIDE; | |
| 109 }; | |
| 110 | |
| 111 // hide | |
| 112 class ExtensionActionHideFunction : public ExtensionActionFunction { | |
| 113 protected: | |
| 114 virtual ~ExtensionActionHideFunction() {} | |
| 115 virtual bool RunExtensionAction() OVERRIDE; | |
| 116 }; | |
| 117 | |
| 118 // setIcon | |
| 119 class ExtensionActionSetIconFunction : public ExtensionActionFunction { | |
| 120 protected: | |
| 121 virtual ~ExtensionActionSetIconFunction() {} | |
| 122 virtual bool RunExtensionAction() OVERRIDE; | |
| 123 }; | |
| 124 | |
| 125 // setTitle | |
| 126 class ExtensionActionSetTitleFunction : public ExtensionActionFunction { | |
| 127 protected: | |
| 128 virtual ~ExtensionActionSetTitleFunction() {} | |
| 129 virtual bool RunExtensionAction() OVERRIDE; | |
| 130 }; | |
| 131 | |
| 132 // setPopup | |
| 133 class ExtensionActionSetPopupFunction : public ExtensionActionFunction { | |
| 134 protected: | |
| 135 virtual ~ExtensionActionSetPopupFunction() {} | |
| 136 virtual bool RunExtensionAction() OVERRIDE; | |
| 137 }; | |
| 138 | |
| 139 // setBadgeText | |
| 140 class ExtensionActionSetBadgeTextFunction : public ExtensionActionFunction { | |
| 141 protected: | |
| 142 virtual ~ExtensionActionSetBadgeTextFunction() {} | |
| 143 virtual bool RunExtensionAction() OVERRIDE; | |
| 144 }; | |
| 145 | |
| 146 // setBadgeBackgroundColor | |
| 147 class ExtensionActionSetBadgeBackgroundColorFunction | |
| 148 : public ExtensionActionFunction { | |
| 149 protected: | |
| 150 virtual ~ExtensionActionSetBadgeBackgroundColorFunction() {} | |
| 151 virtual bool RunExtensionAction() OVERRIDE; | |
| 152 }; | |
| 153 | |
| 154 // getTitle | |
| 155 class ExtensionActionGetTitleFunction : public ExtensionActionFunction { | |
| 156 protected: | |
| 157 virtual ~ExtensionActionGetTitleFunction() {} | |
| 158 virtual bool RunExtensionAction() OVERRIDE; | |
| 159 }; | |
| 160 | |
| 161 // getPopup | |
| 162 class ExtensionActionGetPopupFunction : public ExtensionActionFunction { | |
| 163 protected: | |
| 164 virtual ~ExtensionActionGetPopupFunction() {} | |
| 165 virtual bool RunExtensionAction() OVERRIDE; | |
| 166 }; | |
| 167 | |
| 168 // getBadgeText | |
| 169 class ExtensionActionGetBadgeTextFunction : public ExtensionActionFunction { | |
| 170 protected: | |
| 171 virtual ~ExtensionActionGetBadgeTextFunction() {} | |
| 172 virtual bool RunExtensionAction() OVERRIDE; | |
| 173 }; | |
| 174 | |
| 175 // getBadgeBackgroundColor | |
| 176 class ExtensionActionGetBadgeBackgroundColorFunction | |
| 177 : public ExtensionActionFunction { | |
| 178 protected: | |
| 179 virtual ~ExtensionActionGetBadgeBackgroundColorFunction() {} | |
| 180 virtual bool RunExtensionAction() OVERRIDE; | |
| 181 }; | |
| 182 | |
| 183 #endif // CHROME_BROWSER_EXTENSIONS_API_EXTENSION_ACTION_EXTENSION_ACTIONS_API_
H_ | |
| OLD | NEW |