• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (c) 2011 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/**
6 * Global fileManager reference useful for poking at from the console.
7 */
8var fileManager;
9
10/**
11 * Kick off the file manager dialog.
12 *
13 * Called by main.html after the dom has been parsed.
14 */
15function init() {
16  var params;
17
18  var rootPaths = ['Downloads', 'media'];
19
20  if (document.location.search) {
21    var json = decodeURIComponent(document.location.search.substr(1));
22    var params = JSON.parse(json);
23    console.log('params: ' + JSON.stringify(params));
24  }
25
26  function onEntriesFound(entries) {
27    FileManager.initStrings(function () {
28      fileManager = new FileManager(document.body, entries, params);
29    });
30  }
31
32  function onFileSystemFound(filesystem) {
33    console.log('Found filesystem: ' + filesystem.name, filesystem);
34
35    var entries = [];
36
37    function onPathError(path, err) {
38      console.error('Error locating root path: ' + path + ': ' + err);
39    }
40
41    function onEntryFound(entry) {
42      if (entry) {
43        entries.push(entry);
44      } else {
45        onEntriesFound(entries);
46      }
47    }
48
49    if (filesystem.name.match(/^chrome-extension_\S+:external/i)) {
50      // We've been handed the local filesystem, whose root directory
51      // cannot be enumerated.
52      util.getDirectories(filesystem.root, {create: false}, rootPaths,
53                          onEntryFound, onPathError);
54    } else {
55      util.forEachDirEntry(filesystem.root, onEntryFound);
56    }
57  };
58
59  util.installFileErrorToString();
60
61  console.log('Requesting filesystem.');
62  chrome.fileBrowserPrivate.requestLocalFileSystem(onFileSystemFound);
63}
64