| 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 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_WALLPAPER_PRIVATE_API_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_WALLPAPER_PRIVATE_API_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_WALLPAPER_PRIVATE_API_H_ | 6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_WALLPAPER_PRIVATE_API_H_ |
| 7 | 7 |
| 8 #include "ash/desktop_background/desktop_background_controller.h" | 8 #include "ash/desktop_background/desktop_background_controller.h" |
| 9 #include "base/threading/sequenced_worker_pool.h" | 9 #include "base/threading/sequenced_worker_pool.h" |
| 10 #include "chrome/browser/extensions/extension_function.h" | 10 #include "chrome/browser/extensions/extension_function.h" |
| 11 #include "net/url_request/url_fetcher_delegate.h" | 11 #include "net/url_request/url_fetcher_delegate.h" |
| 12 #include "ui/gfx/image/image_skia.h" | 12 #include "ui/gfx/image/image_skia.h" |
| 13 | 13 |
| 14 // Wallpaper manager strings. | 14 // Wallpaper manager strings. |
| 15 class WallpaperStringsFunction : public SyncExtensionFunction { | 15 class WallpaperPrivateGetStringsFunction : public SyncExtensionFunction { |
| 16 public: | 16 public: |
| 17 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.getStrings", | 17 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.getStrings", |
| 18 WALLPAPERPRIVATE_GETSTRINGS) | 18 WALLPAPERPRIVATE_GETSTRINGS) |
| 19 | 19 |
| 20 protected: | 20 protected: |
| 21 virtual ~WallpaperStringsFunction() {} | 21 virtual ~WallpaperPrivateGetStringsFunction() {} |
| 22 | 22 |
| 23 // SyncExtensionFunction overrides. | 23 // SyncExtensionFunction overrides. |
| 24 virtual bool RunImpl() OVERRIDE; | 24 virtual bool RunImpl() OVERRIDE; |
| 25 }; | 25 }; |
| 26 | 26 |
| 27 // Wallpaper manager function base. It contains a JPEG decoder to decode | 27 // Wallpaper manager function base. It contains a JPEG decoder to decode |
| 28 // wallpaper data. | 28 // wallpaper data. |
| 29 class WallpaperFunctionBase : public AsyncExtensionFunction { | 29 class WallpaperFunctionBase : public AsyncExtensionFunction { |
| 30 public: | 30 public: |
| 31 WallpaperFunctionBase(); | 31 WallpaperFunctionBase(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 42 // Starts to decode |data|. Must run on UI thread. | 42 // Starts to decode |data|. Must run on UI thread. |
| 43 void StartDecode(const std::string& data); | 43 void StartDecode(const std::string& data); |
| 44 | 44 |
| 45 // Handles failure or cancel cases. Passes error message to Javascript side. | 45 // Handles failure or cancel cases. Passes error message to Javascript side. |
| 46 void OnFailureOrCancel(const std::string& error); | 46 void OnFailureOrCancel(const std::string& error); |
| 47 | 47 |
| 48 private: | 48 private: |
| 49 virtual void OnWallpaperDecoded(const gfx::ImageSkia& wallpaper) = 0; | 49 virtual void OnWallpaperDecoded(const gfx::ImageSkia& wallpaper) = 0; |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 class WallpaperSetWallpaperIfExistFunction : public WallpaperFunctionBase { | 52 class WallpaperPrivateSetWallpaperIfExistFunction |
| 53 : public WallpaperFunctionBase { |
| 53 public: | 54 public: |
| 54 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.setWallpaperIfExist", | 55 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.setWallpaperIfExist", |
| 55 WALLPAPERPRIVATE_SETWALLPAPERIFEXIST) | 56 WALLPAPERPRIVATE_SETWALLPAPERIFEXIST) |
| 56 | 57 |
| 57 WallpaperSetWallpaperIfExistFunction(); | 58 WallpaperPrivateSetWallpaperIfExistFunction(); |
| 58 | 59 |
| 59 protected: | 60 protected: |
| 60 virtual ~WallpaperSetWallpaperIfExistFunction(); | 61 virtual ~WallpaperPrivateSetWallpaperIfExistFunction(); |
| 61 | 62 |
| 62 // AsyncExtensionFunction overrides. | 63 // AsyncExtensionFunction overrides. |
| 63 virtual bool RunImpl() OVERRIDE; | 64 virtual bool RunImpl() OVERRIDE; |
| 64 | 65 |
| 65 private: | 66 private: |
| 66 virtual void OnWallpaperDecoded(const gfx::ImageSkia& wallpaper) OVERRIDE; | 67 virtual void OnWallpaperDecoded(const gfx::ImageSkia& wallpaper) OVERRIDE; |
| 67 | 68 |
| 68 // Reads file specified by |file_name|. If success, post a task to start | 69 // Reads file specified by |file_name|. If success, post a task to start |
| 69 // decoding the file. | 70 // decoding the file. |
| 70 void ReadFileAndInitiateStartDecode(const std::string& file_name); | 71 void ReadFileAndInitiateStartDecode(const std::string& file_name); |
| 71 | 72 |
| 72 // High resolution wallpaper URL. | 73 // High resolution wallpaper URL. |
| 73 std::string url_; | 74 std::string url_; |
| 74 | 75 |
| 75 // Layout of the downloaded wallpaper. | 76 // Layout of the downloaded wallpaper. |
| 76 ash::WallpaperLayout layout_; | 77 ash::WallpaperLayout layout_; |
| 77 | 78 |
| 78 // Sequence token associated with wallpaper operations. Shared with | 79 // Sequence token associated with wallpaper operations. Shared with |
| 79 // WallpaperManager. | 80 // WallpaperManager. |
| 80 base::SequencedWorkerPool::SequenceToken sequence_token_; | 81 base::SequencedWorkerPool::SequenceToken sequence_token_; |
| 81 | 82 |
| 82 }; | 83 }; |
| 83 | 84 |
| 84 class WallpaperSetWallpaperFunction : public WallpaperFunctionBase { | 85 class WallpaperPrivateSetWallpaperFunction : public WallpaperFunctionBase { |
| 85 public: | 86 public: |
| 86 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.setWallpaper", | 87 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.setWallpaper", |
| 87 WALLPAPERPRIVATE_SETWALLPAPER) | 88 WALLPAPERPRIVATE_SETWALLPAPER) |
| 88 | 89 |
| 89 WallpaperSetWallpaperFunction(); | 90 WallpaperPrivateSetWallpaperFunction(); |
| 90 | 91 |
| 91 protected: | 92 protected: |
| 92 virtual ~WallpaperSetWallpaperFunction(); | 93 virtual ~WallpaperPrivateSetWallpaperFunction(); |
| 93 | 94 |
| 94 // AsyncExtensionFunction overrides. | 95 // AsyncExtensionFunction overrides. |
| 95 virtual bool RunImpl() OVERRIDE; | 96 virtual bool RunImpl() OVERRIDE; |
| 96 | 97 |
| 97 private: | 98 private: |
| 98 virtual void OnWallpaperDecoded(const gfx::ImageSkia& wallpaper) OVERRIDE; | 99 virtual void OnWallpaperDecoded(const gfx::ImageSkia& wallpaper) OVERRIDE; |
| 99 | 100 |
| 100 // Saves the image data to a file. | 101 // Saves the image data to a file. |
| 101 void SaveToFile(); | 102 void SaveToFile(); |
| 102 | 103 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 117 std::string url_; | 118 std::string url_; |
| 118 | 119 |
| 119 // String representation of downloaded wallpaper. | 120 // String representation of downloaded wallpaper. |
| 120 std::string image_data_; | 121 std::string image_data_; |
| 121 | 122 |
| 122 // Sequence token associated with wallpaper operations. Shared with | 123 // Sequence token associated with wallpaper operations. Shared with |
| 123 // WallpaperManager. | 124 // WallpaperManager. |
| 124 base::SequencedWorkerPool::SequenceToken sequence_token_; | 125 base::SequencedWorkerPool::SequenceToken sequence_token_; |
| 125 }; | 126 }; |
| 126 | 127 |
| 127 class WallpaperSetCustomWallpaperFunction : public WallpaperFunctionBase { | 128 class WallpaperPrivateSetCustomWallpaperFunction |
| 129 : public WallpaperFunctionBase { |
| 128 public: | 130 public: |
| 129 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.setCustomWallpaper", | 131 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.setCustomWallpaper", |
| 130 WALLPAPERPRIVATE_SETCUSTOMWALLPAPER) | 132 WALLPAPERPRIVATE_SETCUSTOMWALLPAPER) |
| 131 | 133 |
| 132 WallpaperSetCustomWallpaperFunction(); | 134 WallpaperPrivateSetCustomWallpaperFunction(); |
| 133 | 135 |
| 134 protected: | 136 protected: |
| 135 virtual ~WallpaperSetCustomWallpaperFunction(); | 137 virtual ~WallpaperPrivateSetCustomWallpaperFunction(); |
| 136 | 138 |
| 137 // AsyncExtensionFunction overrides. | 139 // AsyncExtensionFunction overrides. |
| 138 virtual bool RunImpl() OVERRIDE; | 140 virtual bool RunImpl() OVERRIDE; |
| 139 | 141 |
| 140 private: | 142 private: |
| 141 virtual void OnWallpaperDecoded(const gfx::ImageSkia& wallpaper) OVERRIDE; | 143 virtual void OnWallpaperDecoded(const gfx::ImageSkia& wallpaper) OVERRIDE; |
| 142 | 144 |
| 143 // Layout of the downloaded wallpaper. | 145 // Layout of the downloaded wallpaper. |
| 144 ash::WallpaperLayout layout_; | 146 ash::WallpaperLayout layout_; |
| 145 | 147 |
| 146 // Email address of logged in user. | 148 // Email address of logged in user. |
| 147 std::string email_; | 149 std::string email_; |
| 148 | 150 |
| 149 // String representation of downloaded wallpaper. | 151 // String representation of downloaded wallpaper. |
| 150 std::string image_data_; | 152 std::string image_data_; |
| 151 }; | 153 }; |
| 152 | 154 |
| 153 class WallpaperMinimizeInactiveWindowsFunction : public AsyncExtensionFunction { | 155 class WallpaperPrivateMinimizeInactiveWindowsFunction |
| 156 : public AsyncExtensionFunction { |
| 154 public: | 157 public: |
| 155 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.minimizeInactiveWindows", | 158 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.minimizeInactiveWindows", |
| 156 WALLPAPERPRIVATE_MINIMIZEINACTIVEWINDOWS) | 159 WALLPAPERPRIVATE_MINIMIZEINACTIVEWINDOWS) |
| 157 | 160 |
| 158 WallpaperMinimizeInactiveWindowsFunction(); | 161 WallpaperPrivateMinimizeInactiveWindowsFunction(); |
| 159 | 162 |
| 160 protected: | 163 protected: |
| 161 virtual ~WallpaperMinimizeInactiveWindowsFunction(); | 164 virtual ~WallpaperPrivateMinimizeInactiveWindowsFunction(); |
| 162 | 165 |
| 163 // AsyncExtensionFunction overrides. | 166 // AsyncExtensionFunction overrides. |
| 164 virtual bool RunImpl() OVERRIDE; | 167 virtual bool RunImpl() OVERRIDE; |
| 165 }; | 168 }; |
| 166 | 169 |
| 167 class WallpaperRestoreMinimizedWindowsFunction : public AsyncExtensionFunction { | 170 class WallpaperPrivateRestoreMinimizedWindowsFunction |
| 171 : public AsyncExtensionFunction { |
| 168 public: | 172 public: |
| 169 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.restoreMinimizedWindows", | 173 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.restoreMinimizedWindows", |
| 170 WALLPAPERPRIVATE_RESTOREMINIMIZEDWINDOWS) | 174 WALLPAPERPRIVATE_RESTOREMINIMIZEDWINDOWS) |
| 171 | 175 |
| 172 WallpaperRestoreMinimizedWindowsFunction(); | 176 WallpaperPrivateRestoreMinimizedWindowsFunction(); |
| 173 | 177 |
| 174 protected: | 178 protected: |
| 175 virtual ~WallpaperRestoreMinimizedWindowsFunction(); | 179 virtual ~WallpaperPrivateRestoreMinimizedWindowsFunction(); |
| 176 | 180 |
| 177 // AsyncExtensionFunction overrides. | 181 // AsyncExtensionFunction overrides. |
| 178 virtual bool RunImpl() OVERRIDE; | 182 virtual bool RunImpl() OVERRIDE; |
| 179 }; | 183 }; |
| 180 | 184 |
| 181 class WallpaperGetThumbnailFunction : public AsyncExtensionFunction { | 185 class WallpaperPrivateGetThumbnailFunction : public AsyncExtensionFunction { |
| 182 public: | 186 public: |
| 183 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.getThumbnail", | 187 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.getThumbnail", |
| 184 WALLPAPERPRIVATE_GETTHUMBNAIL) | 188 WALLPAPERPRIVATE_GETTHUMBNAIL) |
| 185 | 189 |
| 186 WallpaperGetThumbnailFunction(); | 190 WallpaperPrivateGetThumbnailFunction(); |
| 187 | 191 |
| 188 protected: | 192 protected: |
| 189 virtual ~WallpaperGetThumbnailFunction(); | 193 virtual ~WallpaperPrivateGetThumbnailFunction(); |
| 190 | 194 |
| 191 // AsyncExtensionFunction overrides. | 195 // AsyncExtensionFunction overrides. |
| 192 virtual bool RunImpl() OVERRIDE; | 196 virtual bool RunImpl() OVERRIDE; |
| 193 | 197 |
| 194 private: | 198 private: |
| 195 // Failed to get thumbnail for |file_name|. | 199 // Failed to get thumbnail for |file_name|. |
| 196 void Failure(const std::string& file_name); | 200 void Failure(const std::string& file_name); |
| 197 | 201 |
| 198 // Returns true to suppress javascript console error. Called when the | 202 // Returns true to suppress javascript console error. Called when the |
| 199 // requested thumbnail is not found or corrupted in thumbnail directory. | 203 // requested thumbnail is not found or corrupted in thumbnail directory. |
| 200 void FileNotLoaded(); | 204 void FileNotLoaded(); |
| 201 | 205 |
| 202 // Sets data field to the loaded thumbnail binary data in the results. Called | 206 // Sets data field to the loaded thumbnail binary data in the results. Called |
| 203 // when requested wallpaper thumbnail loaded successfully. | 207 // when requested wallpaper thumbnail loaded successfully. |
| 204 void FileLoaded(const std::string& data); | 208 void FileLoaded(const std::string& data); |
| 205 | 209 |
| 206 // Gets thumbnail with |file_name| from thumbnail directory. If |file_name| | 210 // Gets thumbnail with |file_name| from thumbnail directory. If |file_name| |
| 207 // does not exist, call FileNotLoaded(). | 211 // does not exist, call FileNotLoaded(). |
| 208 void Get(const std::string& file_name); | 212 void Get(const std::string& file_name); |
| 209 | 213 |
| 210 // Sequence token associated with wallpaper operations. Shared with | 214 // Sequence token associated with wallpaper operations. Shared with |
| 211 // WallpaperManager. | 215 // WallpaperManager. |
| 212 base::SequencedWorkerPool::SequenceToken sequence_token_; | 216 base::SequencedWorkerPool::SequenceToken sequence_token_; |
| 213 }; | 217 }; |
| 214 | 218 |
| 215 class WallpaperSaveThumbnailFunction : public AsyncExtensionFunction { | 219 class WallpaperPrivateSaveThumbnailFunction : public AsyncExtensionFunction { |
| 216 public: | 220 public: |
| 217 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.saveThumbnail", | 221 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.saveThumbnail", |
| 218 WALLPAPERPRIVATE_SAVETHUMBNAIL) | 222 WALLPAPERPRIVATE_SAVETHUMBNAIL) |
| 219 | 223 |
| 220 WallpaperSaveThumbnailFunction(); | 224 WallpaperPrivateSaveThumbnailFunction(); |
| 221 | 225 |
| 222 protected: | 226 protected: |
| 223 virtual ~WallpaperSaveThumbnailFunction(); | 227 virtual ~WallpaperPrivateSaveThumbnailFunction(); |
| 224 | 228 |
| 225 // AsyncExtensionFunction overrides. | 229 // AsyncExtensionFunction overrides. |
| 226 virtual bool RunImpl() OVERRIDE; | 230 virtual bool RunImpl() OVERRIDE; |
| 227 | 231 |
| 228 private: | 232 private: |
| 229 // Failed to save thumbnail for |file_name|. | 233 // Failed to save thumbnail for |file_name|. |
| 230 void Failure(const std::string& file_name); | 234 void Failure(const std::string& file_name); |
| 231 | 235 |
| 232 // Saved thumbnail to thumbnail directory. | 236 // Saved thumbnail to thumbnail directory. |
| 233 void Success(); | 237 void Success(); |
| 234 | 238 |
| 235 // Saves thumbnail to thumbnail directory as |file_name|. | 239 // Saves thumbnail to thumbnail directory as |file_name|. |
| 236 void Save(const std::string& data, const std::string& file_name); | 240 void Save(const std::string& data, const std::string& file_name); |
| 237 | 241 |
| 238 // Sequence token associated with wallpaper operations. Shared with | 242 // Sequence token associated with wallpaper operations. Shared with |
| 239 // WallpaperManager. | 243 // WallpaperManager. |
| 240 base::SequencedWorkerPool::SequenceToken sequence_token_; | 244 base::SequencedWorkerPool::SequenceToken sequence_token_; |
| 241 }; | 245 }; |
| 242 | 246 |
| 243 class WallpaperGetOfflineWallpaperListFunction : public AsyncExtensionFunction { | 247 class WallpaperPrivateGetOfflineWallpaperListFunction |
| 248 : public AsyncExtensionFunction { |
| 244 public: | 249 public: |
| 245 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.getOfflineWallpaperList", | 250 DECLARE_EXTENSION_FUNCTION("wallpaperPrivate.getOfflineWallpaperList", |
| 246 WALLPAPERPRIVATE_GETOFFLINEWALLPAPERLIST) | 251 WALLPAPERPRIVATE_GETOFFLINEWALLPAPERLIST) |
| 247 WallpaperGetOfflineWallpaperListFunction(); | 252 WallpaperPrivateGetOfflineWallpaperListFunction(); |
| 248 | 253 |
| 249 protected: | 254 protected: |
| 250 virtual ~WallpaperGetOfflineWallpaperListFunction(); | 255 virtual ~WallpaperPrivateGetOfflineWallpaperListFunction(); |
| 251 | 256 |
| 252 // AsyncExtensionFunction overrides. | 257 // AsyncExtensionFunction overrides. |
| 253 virtual bool RunImpl() OVERRIDE; | 258 virtual bool RunImpl() OVERRIDE; |
| 254 | 259 |
| 255 private: | 260 private: |
| 256 // Enumerates the list of files in wallpaper directory. | 261 // Enumerates the list of files in wallpaper directory. |
| 257 void GetList(); | 262 void GetList(); |
| 258 | 263 |
| 259 // Sends the list of files to extension api caller. If no files or no | 264 // Sends the list of files to extension api caller. If no files or no |
| 260 // directory, sends empty list. | 265 // directory, sends empty list. |
| 261 void OnComplete(const std::vector<std::string>& file_list); | 266 void OnComplete(const std::vector<std::string>& file_list); |
| 262 | 267 |
| 263 // Sequence token associated with wallpaper operations. Shared with | 268 // Sequence token associated with wallpaper operations. Shared with |
| 264 // WallpaperManager. | 269 // WallpaperManager. |
| 265 base::SequencedWorkerPool::SequenceToken sequence_token_; | 270 base::SequencedWorkerPool::SequenceToken sequence_token_; |
| 266 }; | 271 }; |
| 267 | 272 |
| 268 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_WALLPAPER_PRIVATE_API_H_ | 273 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_WALLPAPER_PRIVATE_API_H_ |
| OLD | NEW |