• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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// Use the <code>chrome.mediaGalleries</code> API to access media files (audio,
6// images, video) from the user's local disks (with the user's consent).
7namespace mediaGalleries {
8
9  [inline_doc] enum GetMediaFileSystemsInteractivity {
10    // Do not act interactively.
11    no,
12    // Ask the user to manage permitted media galleries.
13    yes,
14    // Ask the user to manage permitted galleries only if the return set would
15    // otherwise be empty.
16    if_needed
17  };
18
19  [inline_doc] enum GetMetadataType {
20    // Retrieve the mime type, metadata tags, and attached images.
21    all,
22    // Retrieve only the mime type and the metadata tags.
23    mimeTypeAndTags,
24    // Retrieve only the mime type.
25    mimeTypeOnly
26  };
27
28  [inline_doc] enum ScanProgressType {
29    // The scan started.
30    start,
31    // The scan was cancelled.
32    cancel,
33    // The scan finished but none of the result have been added,
34    // addScanResults() has to be called to ask the user for permission.
35    finish,
36    // The scan encountered an error and could not proceed.
37    error
38  };
39
40  [inline_doc] dictionary MediaFileSystemsDetails {
41    // Whether to prompt the user for permission to additional media galleries
42    // before returning the permitted set. Default is silent.  If the value
43    // 'yes' is passed, or if the application has not been granted access to
44    // any media galleries and the value 'if_needed' is passed, then the
45    // media gallery configuration dialog will be displayed.
46    GetMediaFileSystemsInteractivity? interactive;
47  };
48
49  [inline_doc] dictionary MediaMetadataOptions {
50    // Specifies which subset of the metadata to retrieve. Defaults to 'all'
51    // if the option is omitted.
52    GetMetadataType? metadataType;
53  };
54
55  callback MediaFileSystemsCallback =
56      void ([instanceOf=DOMFileSystem] object[] mediaFileSystems);
57
58  callback AddUserFolderCallback =
59      void ([instanceOf=DOMFileSystem] object[] mediaFileSystems,
60            DOMString selectedFileSystemName);
61
62  callback DropPermissionForMediaFileSystemCallback = void ();
63
64  [inline_doc] dictionary MediaFileSystemMetadata {
65    // The name of the file system.
66    DOMString name;
67
68    // A unique and persistent id for the media gallery.
69    DOMString galleryId;
70
71    // If the media gallery is on a removable device, a unique id for the
72    // device while the device is online.
73    DOMString? deviceId;
74
75    // True if the media gallery is on a removable device.
76    boolean isRemovable;
77
78    // True if the device the media gallery is on was detected as a media
79    // device.  i.e. a PTP or MTP device, or a DCIM directory is present.
80    boolean isMediaDevice;
81
82    // True if the device is currently available.
83    boolean isAvailable;
84  };
85
86  [inline_doc] dictionary ScanProgressDetails {
87    // The type of progress event, i.e. start, finish, etc.
88    ScanProgressType type;
89
90    // The number of Galleries found.
91    long? galleryCount;
92
93    // Appoximate number of media files found; some file types can be either
94    // audio or video and are included in both counts.
95    long? audioCount;
96    long? imageCount;
97    long? videoCount;
98  };
99
100  callback MediaFileSystemsMetadataCallback =
101      void (MediaFileSystemMetadata[] metadata);
102
103  dictionary StreamInfo {
104    // Describes format of container or codec of stream, i.e. "mp3", "h264".
105    DOMString type;
106
107    // An unfiltered string->string dictionary of tags for the stream.
108    object tags;
109  };
110
111  dictionary MediaMetadata {
112    // The browser sniffed mime type.
113    DOMString mimeType;
114
115    // Defined for images and video. In pixels.
116    long? height;
117    long? width;
118
119    // Defined for images only.
120    double? xResolution;
121    double? yResolution;
122
123    // Defined for audio and video. In seconds.
124    double? duration;
125
126    // Defined for images and video. In degrees.
127    long? rotation;
128
129    // Defined for images only.
130    DOMString? cameraMake;
131    DOMString? cameraModel;
132    double? exposureTimeSeconds;
133    boolean? flashFired;
134    double? fNumber;
135    double? focalLengthMm;
136    double? isoEquivalent;
137
138    // Defined for audio and video only.
139    DOMString? album;
140    DOMString? artist;
141    DOMString? comment;
142    DOMString? copyright;
143    long? disc;
144    DOMString? genre;
145    DOMString? language;
146    DOMString? title;
147    long? track;
148
149    // All the metadata in the media file. For formats with multiple streams,
150    // stream order will be preserved. Container metadata is the first element.
151    StreamInfo[] rawTags;
152
153    // The images embedded in the media file's metadata. This is most often
154    // used for album art or video thumbnails.
155    [instanceof=Blob] object[] attachedImages;
156  };
157
158  callback MediaMetadataCallback = void (MediaMetadata metadata);
159
160  interface Functions {
161    // Get the media galleries configured in this user agent. If none are
162    // configured or available, the callback will receive an empty array.
163    static void getMediaFileSystems(optional MediaFileSystemsDetails details,
164                                    MediaFileSystemsCallback callback);
165
166    // Present a directory picker to the user and add the selected directory
167    // as a gallery. If the user cancels the picker, selectedFileSystemName
168    // will be empty.
169    // A user gesture is required for the dialog to display. Without a user
170    // gesture, the callback will run as though the user canceled.
171    static void addUserSelectedFolder(AddUserFolderCallback callback);
172
173    // Give up access to a given media gallery.
174    static void dropPermissionForMediaFileSystem(
175        DOMString galleryId,
176        optional DropPermissionForMediaFileSystemCallback callback);
177
178    // Start a scan of the user's hard disks for directories containing media.
179    // The scan may take a long time so progress and completion is communicated
180    // by events. No permission is granted as a result of the scan, see
181    // addScanResults.
182    static void startMediaScan();
183
184    // Cancel any pending media scan.  Well behaved apps should provide a way
185    // for the user to cancel scans they start.
186    static void cancelMediaScan();
187
188    // Show the user the scan results and let them add any or all of them as
189    // galleries. This should be used after the 'finish' onScanProgress()
190    // event has happened. All galleries the app has access to are returned, not
191    // just the newly added galleries.
192    static void addScanResults(MediaFileSystemsCallback callback);
193
194    // Get metadata about a specific media file system.
195    [nocompile] static MediaFileSystemMetadata getMediaFileSystemMetadata(
196        [instanceOf=DOMFileSystem] object mediaFileSystem);
197
198    // Get metadata for all available media galleries.
199    static void getAllMediaFileSystemMetadata(
200        MediaFileSystemsMetadataCallback callback);
201
202    // Gets the media-specific metadata for a media file. This should work
203    // for files in media galleries as well as other DOM filesystems.
204    static void getMetadata([instanceOf=Blob] object mediaFile,
205                            optional MediaMetadataOptions options,
206                            MediaMetadataCallback callback);
207  };
208
209  interface Events {
210    // The pending media scan has changed state. See details for more
211    // information.
212    static void onScanProgress(ScanProgressDetails details);
213  };
214};
215