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 // Defines the Chrome Extensions Media Galleries API functions for accessing | 5 // Defines the Chrome Extensions Media Galleries API functions for accessing |
6 // user's media files, as specified in the extension API IDL. | 6 // user's media files, as specified in the extension API IDL. |
7 | 7 |
8 #ifndef CHROME_BROWSER_EXTENSIONS_API_MEDIA_GALLERIES_MEDIA_GALLERIES_API_H_ | 8 #ifndef CHROME_BROWSER_EXTENSIONS_API_MEDIA_GALLERIES_MEDIA_GALLERIES_API_H_ |
9 #define CHROME_BROWSER_EXTENSIONS_API_MEDIA_GALLERIES_MEDIA_GALLERIES_API_H_ | 9 #define CHROME_BROWSER_EXTENSIONS_API_MEDIA_GALLERIES_MEDIA_GALLERIES_API_H_ |
10 | 10 |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "chrome/browser/extensions/chrome_extension_function.h" | 13 #include "chrome/browser/extensions/chrome_extension_function.h" |
14 #include "chrome/browser/media_galleries/media_file_system_registry.h" | 14 #include "chrome/browser/media_galleries/media_file_system_registry.h" |
15 #include "chrome/browser/storage_monitor/media_storage_util.h" | 15 #include "chrome/browser/storage_monitor/media_storage_util.h" |
16 #include "chrome/common/extensions/api/media_galleries.h" | 16 #include "chrome/common/extensions/api/media_galleries.h" |
17 | 17 |
18 namespace MediaGalleries = extensions::api::media_galleries; | 18 namespace MediaGalleries = extensions::api::media_galleries; |
19 | 19 |
| 20 namespace base { |
| 21 class FilePath; |
| 22 } |
| 23 |
20 namespace extensions { | 24 namespace extensions { |
21 | 25 |
| 26 // Common class for media gallery functions that create DOMFileSystems. |
| 27 // Abstract due to the lack of a RunImpl() implementation. |
| 28 class MediaGalleriesGetMediaFileSystemsBase |
| 29 : public ChromeAsyncExtensionFunction { |
| 30 protected: |
| 31 virtual ~MediaGalleriesGetMediaFileSystemsBase(); |
| 32 |
| 33 // Always show the dialog. Forces MediaFileSystemRegistry to read its |
| 34 // preferences. |
| 35 void ReadPrefsAndShowDialog(); |
| 36 |
| 37 // Simply shows the configuration dialog to edit gallery preferences. |
| 38 // Does not force MediaFileSystemRegistry to read its preferences. |
| 39 void ShowDialog(); |
| 40 |
| 41 // Grabs galleries from the media file system registry and passes them to |
| 42 // |ReturnGalleries|. |
| 43 void GetAndReturnGalleries(); |
| 44 |
| 45 // Returns galleries to the caller. |
| 46 void ReturnGalleries(const std::vector<MediaFileSystemInfo>& filesystems); |
| 47 |
| 48 // Take an array of MediaFileSystemInfo and turn it into a ListValue |
| 49 // suitable for use with JS. |
| 50 // Returns NULL on failure. Callers owns the returned value. |
| 51 // The custom JS binding can use this list to create DOMFileSystem objects. |
| 52 base::ListValue* ConstructFileSystemList( |
| 53 const std::vector<MediaFileSystemInfo>& filesystems); |
| 54 |
| 55 // A helper method that calls |
| 56 // MediaFileSystemRegistry::GetMediaFileSystemsForExtension(). |
| 57 void GetMediaFileSystemsForExtension(const MediaFileSystemsCallback& cb); |
| 58 |
| 59 // Helper function to get the appropriate WebContents. |
| 60 content::WebContents* GetWebContents(); |
| 61 |
| 62 // Helper function to get the MediaGalleriesPreferences. |
| 63 MediaGalleriesPreferences* GetMediaGalleriesPreferences(); |
| 64 |
| 65 private: |
| 66 // Callback adaptor that just shows the dialog. |
| 67 void AlwaysShowDialog(const std::vector<MediaFileSystemInfo>& filesystems); |
| 68 }; |
| 69 |
22 class MediaGalleriesGetMediaFileSystemsFunction | 70 class MediaGalleriesGetMediaFileSystemsFunction |
23 : public ChromeAsyncExtensionFunction { | 71 : public MediaGalleriesGetMediaFileSystemsBase { |
24 public: | 72 public: |
25 DECLARE_EXTENSION_FUNCTION("mediaGalleries.getMediaFileSystems", | 73 DECLARE_EXTENSION_FUNCTION("mediaGalleries.getMediaFileSystems", |
26 MEDIAGALLERIES_GETMEDIAFILESYSTEMS) | 74 MEDIAGALLERIES_GETMEDIAFILESYSTEMS) |
27 | 75 |
28 protected: | 76 protected: |
29 virtual ~MediaGalleriesGetMediaFileSystemsFunction(); | 77 virtual ~MediaGalleriesGetMediaFileSystemsFunction(); |
30 virtual bool RunImpl() OVERRIDE; | 78 virtual bool RunImpl() OVERRIDE; |
31 | 79 |
32 private: | 80 private: |
33 // Bottom half for RunImpl, invoked after the preferences is initialized. | 81 // Bottom half for RunImpl, invoked after the preferences is initialized. |
34 void OnPreferencesInit( | 82 void OnPreferencesInit( |
35 MediaGalleries::GetMediaFileSystemsInteractivity interactive); | 83 MediaGalleries::GetMediaFileSystemsInteractivity interactive); |
36 | 84 |
37 // Always show the dialog. | |
38 void AlwaysShowDialog(const std::vector<MediaFileSystemInfo>& filesystems); | |
39 | |
40 // If no galleries are found, show the dialog, otherwise return them. | 85 // If no galleries are found, show the dialog, otherwise return them. |
41 void ShowDialogIfNoGalleries( | 86 void ShowDialogIfNoGalleries( |
42 const std::vector<MediaFileSystemInfo>& filesystems); | 87 const std::vector<MediaFileSystemInfo>& filesystems); |
43 | |
44 // Grabs galleries from the media file system registry and passes them to | |
45 // |ReturnGalleries|. | |
46 void GetAndReturnGalleries(); | |
47 | |
48 // Returns galleries to the caller. | |
49 void ReturnGalleries(const std::vector<MediaFileSystemInfo>& filesystems); | |
50 | |
51 // Shows the configuration dialog to edit gallery preferences. | |
52 void ShowDialog(); | |
53 | |
54 // A helper method that calls | |
55 // MediaFileSystemRegistry::GetMediaFileSystemsForExtension(). | |
56 void GetMediaFileSystemsForExtension(const MediaFileSystemsCallback& cb); | |
57 }; | 88 }; |
58 | 89 |
59 class MediaGalleriesGetAllMediaFileSystemMetadataFunction | 90 class MediaGalleriesGetAllMediaFileSystemMetadataFunction |
60 : public ChromeAsyncExtensionFunction { | 91 : public ChromeAsyncExtensionFunction { |
61 public: | 92 public: |
62 DECLARE_EXTENSION_FUNCTION("mediaGalleries.getAllMediaFileSystemMetadata", | 93 DECLARE_EXTENSION_FUNCTION("mediaGalleries.getAllMediaFileSystemMetadata", |
63 MEDIAGALLERIES_GETALLMEDIAFILESYSTEMMETADATA) | 94 MEDIAGALLERIES_GETALLMEDIAFILESYSTEMMETADATA) |
64 | 95 |
65 protected: | 96 protected: |
66 virtual ~MediaGalleriesGetAllMediaFileSystemMetadataFunction(); | 97 virtual ~MediaGalleriesGetAllMediaFileSystemMetadataFunction(); |
67 virtual bool RunImpl() OVERRIDE; | 98 virtual bool RunImpl() OVERRIDE; |
68 | 99 |
69 private: | 100 private: |
70 // Bottom half for RunImpl, invoked after the preferences is initialized. | 101 // Bottom half for RunImpl, invoked after the preferences is initialized. |
71 // Gets the list of permitted galleries and checks if they are available. | 102 // Gets the list of permitted galleries and checks if they are available. |
72 void OnPreferencesInit(); | 103 void OnPreferencesInit(); |
73 | 104 |
74 // Callback to run upon getting the list of available devices. | 105 // Callback to run upon getting the list of available devices. |
75 // Sends the list of media filesystem metadata back to the extension. | 106 // Sends the list of media filesystem metadata back to the extension. |
76 void OnGetGalleries(const MediaGalleryPrefIdSet& permitted_gallery_ids, | 107 void OnGetGalleries(const MediaGalleryPrefIdSet& permitted_gallery_ids, |
77 const MediaStorageUtil::DeviceIdSet* available_devices); | 108 const MediaStorageUtil::DeviceIdSet* available_devices); |
78 }; | 109 }; |
79 | 110 |
| 111 class MediaGalleriesManageMediaLocationsFunction |
| 112 : public MediaGalleriesGetMediaFileSystemsBase { |
| 113 public: |
| 114 DECLARE_EXTENSION_FUNCTION("mediaGalleries.manageMediaLocations", |
| 115 MEDIAGALLERIES_MANAGEMEDIALOCATIONS) |
| 116 |
| 117 protected: |
| 118 virtual ~MediaGalleriesManageMediaLocationsFunction(); |
| 119 virtual bool RunImpl() OVERRIDE; |
| 120 |
| 121 private: |
| 122 // Bottom half for RunImpl, invoked after the preferences is initialized. |
| 123 // Handle the |request_type| appropriately. |
| 124 void OnPreferencesInit(MediaGalleries::ManageRequestType request_type); |
| 125 |
| 126 // Callback for the directory prompt request, with the input from the user. |
| 127 // If |selected_directory| is empty, then the user canceled. |
| 128 // Either handle the user canceled case or check to see if |
| 129 // |selected_directory| exists. |
| 130 void OnDirectorySelected(const base::FilePath& selected_directory); |
| 131 |
| 132 // Callback for the directory prompt request from OnDirectorySelected(). |
| 133 // If |selected_directory| exists, add it as a gallery. |
| 134 void OnDirectoryChecked(const base::FilePath& selected_directory, |
| 135 bool exists); |
| 136 |
| 137 // Callback for the directory prompt request. Find the file system in |
| 138 // |filesystems| with a pref id of |pref_id| and return that file system to |
| 139 // the caller. |
| 140 void FindGalleryWithPrefId( |
| 141 MediaGalleryPrefId pref_id, |
| 142 const std::vector<MediaFileSystemInfo>& filesystems); |
| 143 }; |
| 144 |
80 } // namespace extensions | 145 } // namespace extensions |
81 | 146 |
82 #endif // CHROME_BROWSER_EXTENSIONS_API_MEDIA_GALLERIES_MEDIA_GALLERIES_API_H_ | 147 #endif // CHROME_BROWSER_EXTENSIONS_API_MEDIA_GALLERIES_MEDIA_GALLERIES_API_H_ |
OLD | NEW |