Home | History | Annotate | Download | only in intros
      1 <p class="caution">
      2 <b>Important:</b>
      3 This API works <b>only on Chrome OS</b>.
      4 </p>
      5 
      6 <p>
      7 The Chrome OS file browser comes up when
      8 the user either presses Ctrl+M
      9 or connects an external storage device,
     10 such as an SD card, USB key, external drive, or digital camera.
     11 Besides showing the files on external devices,
     12 the file browser can also display files
     13 that the user has previously saved to the system.
     14 </p>
     15 
     16 <p>
     17 When the user selects one or more files,
     18 the file browser adds buttons
     19 representing the valid handlers for those files.
     20 For example, in the following screenshot,
     21 selecting a file with a ".jpg" suffix
     22 results in an "Upload to Picasa" button that the user can click.
     23 </p>
     24 
     25 <p>
     26 <img src="{{static}}/images/filebrowserhandler.png"
     27   width="640" height="400" alt="file browser screenshot" />
     28 </p>
     29 
     30 
     31 <h2 id="manifest">Manifest</h2>
     32 
     33 <p>
     34 You must declare the "fileBrowserHandler" permission
     35 in the <a href="manifest.html">extension manifest</a>,
     36 and you must use the "file_browser_handlers" field
     37 to register the extension as a handler of at least one file type.
     38 You should also provide a 16x16 icon
     39 to be displayed on the button.
     40 For example:
     41 </p>
     42 
     43 <pre>
     44 {
     45   "name": "My extension",
     46   ...
     47   <b>"file_browser_handlers"</b>: [
     48     {
     49       <b>"id"</b>: "upload",
     50       <b>"default_title"</b>: "Save to Gallery", <em>// What the button will display</em>
     51       <b>"file_filters"</b>: [
     52         "filesystem:*.jpg", <em>// To match all files, use "filesystem:*.*"</em>
     53         "filesystem:*.jpeg",
     54         "filesystem:*.png"
     55       ]
     56     }
     57   ]</b>,
     58   "permissions" : [
     59     <b>"fileBrowserHandler"</b>
     60   ],
     61   "icons": { <b>"16"</b>: "icon16.png",
     62              "48": "icon48.png",
     63             "128": "icon128.png" },
     64   ...
     65 }</pre>
     66 
     67 <p class="note">
     68 <b>Note:</b>
     69 You can specify locale-specific strings for the value of "default_title".
     70 See <a href="i18n.html">Internationalization (i18n)</a> for details.
     71 </p>
     72 
     73 <h2 id="code">Implementing a file browser handler</h2>
     74 
     75 <p>
     76 To use this API,
     77 you must implement a function that handles the <code>onExecute</code> event
     78 of <code>chrome.fileBrowserHandler</code>.
     79 Your function will be called whenever the user clicks the button
     80 that represents your file browser handler.
     81 In your function, use the HTML5
     82 <a href="http://www.html5rocks.com/tutorials/file/filesystem/">FileSystem API</a>
     83 to get access to the file contents.
     84 Here is an example:
     85 </p>
     86 
     87 <pre>
     88 <em>//In background.html:</em>
     89 chrome.fileBrowserHandler.onExecute.addListener(function(id, details) {
     90   if (id == 'upload') {
     91     var fileEntries = details.entries;
     92     for (var i = 0, entry; entry = fileEntries[i]; ++i) {
     93       entry.file(function(file) {
     94         <em>// send file somewhere</em>
     95       });
     96     }
     97   }
     98 });
     99 </pre>
    100 
    101 <p>
    102 Your event handler is passed two arguments:
    103 </p>
    104 
    105 <dl>
    106   <dt> id </dt>
    107   <dd> The "id" value from the manifest file.
    108        If your extension implements multiple handlers,
    109        you can check the <code>id</code> value
    110        to see which handler has been triggered.
    111        </dd>
    112   <dt> details </dt>
    113   <dd> An object describing the event.
    114        You can get the file or files that the user has selected
    115        from the <code>entries</code> field of this object,
    116        which is an array of
    117        FileSystem <code>Entry</code> objects.
    118        </dd>
    119 </p>
    120 
    121 
    122 <!--
    123 <h2 id="manifest_details">Manifest details</h2>
    124 
    125 <p class="authornote">
    126 {PENDING: give details about "id" and "default_title".
    127 It should be unique within your extension -- don't worry about other extensions.
    128 "default_title" implies that you can change the title,
    129 but you can't aside from internationalizing it.
    130 </p>
    131 
    132 <p class="authornote">
    133 {PENDING: give details about the file_filters entry.
    134 File filters are currently case-sensitive, but we plan to change that.
    135 Mention <code>filesystem:*.*</code>.
    136 </p>
    137 -->
    138 
    139 <!--
    140 <h2 id="examples">Examples</h2>
    141 
    142 <p>
    143 For examples of using this API, see ...
    144 For other examples and for help in viewing the source code, see
    145 <a href="samples.html">Samples</a>.
    146 </p>
    147 -->
    148