summaryrefslogtreecommitdiffstats
path: root/chrome/common/extensions/api/image_writer_private.idl
blob: c4efd19bcad32b43a1b60714d98261464a95a6b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Use the <code>chrome.image_writer</code> API to write images to
// removable media.
//
// See the design doc for a detailed description of this API.
// https://goo.gl/KzMEFq
namespace imageWriterPrivate {
  // The different stages of a write call.
  //
  // <dl>
  //    <dt>confirmation</dt>
  //    <dd>The process starts by prompting the user for confirmation.</dd>
  //    <dt>download</dt>
  //    <dd>The image file is being download if a remote image was
  //    requested.</dd>
  //    <dt>verifyDownload</dt>
  //    <dd>The download is being verified to match the image hash, if
  //    provided</dd>
  //    <dt>unzip</dt>
  //    <dd>The image is being extracted from the downloaded zip file</dd>
  //    <dt>write</dt>
  //    <dd>The image is being written to disk.</dd>
  //    <dt>verifyWrite</dt>
  //    <dt>The system is verifying that the written image matches the
  //    downloaded image.</dd>
  // <dl>
  enum Stage {
    confirmation,
    download,
    verifyDownload,
    unzip,
    write,
    verifyWrite,
    unknown
  };

  // Options for writing an image.
  dictionary UrlWriteOptions {
    // If present, verify that the downloaded image matches this hash.
    DOMString? imageHash;
    // If true, save the downloaded image as a file using the user's downloads
    // preferences.
    boolean? saveAsDownload;
  };

  dictionary ProgressInfo {
    // The $(ref:Stage) that the write process is currently in.
    Stage stage;
    // Current progress within the stage.
    long percentComplete;
  };

  dictionary RemovableStorageDevice {
    DOMString storageUnitId;
    double capacity;
    DOMString vendor;
    DOMString model;
    boolean removable;
  };

  callback WriteImageCallback = void ();
  callback WriteCancelCallback = void ();
  callback ListRemovableStorageDevicesCallback = void (RemovableStorageDevice[] devices);
  callback DestroyPartitionsCallback = void ();

  interface Functions {
    // Write an image to the disk downloaded from the provided URL.  The
    // callback will be called when the entire operation completes, either
    // successfully or on error.
    //
    // |storageUnitId|: The identifier for the storage unit
    // |imageUrl|: The url of the image to download which will be written
    // to the storage unit identified by |storageUnitId|
    // |options|: Optional parameters if comparing the download with a given
    // hash or saving the download to the users Downloads folder instead of a
    // temporary directory is desired
    // |callback|: The callback which signifies that the write operation has
    // been started by the system and provides a unique ID for this operation.
    static void writeFromUrl(DOMString storageUnitId,
                             DOMString imageUrl,
                             optional UrlWriteOptions options,
                             WriteImageCallback callback);

    // Write an image to the disk, prompting the user to supply the image from
    // a local file.  The callback will be called when the entire operation
    // completes, either successfully or on error.
    //
    // |storageUnitId|: The identifier for the storage unit
    // |fileEntry|: The FileEntry object of the image to be burned.
    // |callback|: The callback which signifies that the write operation has
    // been started by the system and provides a unique ID for this operation.
    static void writeFromFile(DOMString storageUnitId,
                              [instanceOf=FileEntry] object fileEntry,
                              WriteImageCallback callback);

    // Cancel a current write operation.
    //
    // |callback|: The callback which is triggered with the write is
    // successfully cancelled, passing the $(ref:ProgressInfo) of the operation at
    // the time it was cancelled.
    static boolean cancelWrite(WriteCancelCallback callback);

    // Destroys the partition table of a disk, effectively erasing it.  This is
    // a fairly quick operation and so it does not have complex stages or
    // progress information, just a write phase.
    //
    // |storageUnitId|: The identifier of the storage unit to wipe
    // |callback|: A callback that triggers when the operation has been
    // successfully started.
    static void destroyPartitions(DOMString storageUnitId,
                                  DestroyPartitionsCallback callback);

    // List all the removable block devices currently attached to the system.
    // |callback|: A callback called with a list of removable storage devices
    static void listRemovableStorageDevices(
        ListRemovableStorageDevicesCallback callback);
  };

  interface Events {
    // Fires periodically throughout the writing operation and at least once per
    // stage.
    static void onWriteProgress(ProgressInfo info);

    // Fires when the write operation has completely finished, such as all
    // devices being finalized and resources released.
    static void onWriteComplete();

    // Fires when an error occured during writing, passing the $(ref:ProgressInfo)
    // of the operation at the time the error occured.
    static void onWriteError(ProgressInfo info, DOMString error);

    // Fires when a removable storage device is inserted.
    static void onDeviceInserted(RemovableStorageDevice device);

    // Fires when a removable storage device is removed.
    static void onDeviceRemoved(RemovableStorageDevice device);
  };

};