Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(580)

Side by Side Diff: chrome/renderer/resources/extensions/file_system_custom_bindings.js

Issue 11571014: Lazy load chrome.* APIs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: android compilation Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 // Custom bindings for the fileSystem API. 5 // Custom binding for the fileSystem API.
6 6
7 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); 7 var binding = require('binding').Binding.create('fileSystem');
8
8 var fileSystemNatives = requireNative('file_system_natives'); 9 var fileSystemNatives = requireNative('file_system_natives');
9 var GetIsolatedFileSystem = fileSystemNatives.GetIsolatedFileSystem; 10 var GetIsolatedFileSystem = fileSystemNatives.GetIsolatedFileSystem;
10 var lastError = require('lastError'); 11 var lastError = require('lastError');
11 var entryIdManager = require('entryIdManager'); 12 var entryIdManager = require('entryIdManager');
12 13
13 chromeHidden.registerCustomHook('fileSystem', function(bindingsAPI) { 14 binding.registerCustomHook(function(bindingsAPI) {
14 var apiFunctions = bindingsAPI.apiFunctions; 15 var apiFunctions = bindingsAPI.apiFunctions;
16 var fileSystem = bindingsAPI.compiledApi;
17
15 function bindFileEntryFunction(functionName) { 18 function bindFileEntryFunction(functionName) {
16 apiFunctions.setUpdateArgumentsPostValidate( 19 apiFunctions.setUpdateArgumentsPostValidate(
17 functionName, function(fileEntry, callback) { 20 functionName, function(fileEntry, callback) {
18 var fileSystemName = fileEntry.filesystem.name; 21 var fileSystemName = fileEntry.filesystem.name;
19 var relativePath = fileEntry.fullPath.slice(1); 22 var relativePath = fileEntry.fullPath.slice(1);
20 return [fileSystemName, relativePath, callback]; 23 return [fileSystemName, relativePath, callback];
21 }); 24 });
22 } 25 }
23 ['getDisplayPath', 'getWritableEntry', 'isWritableEntry'] 26 ['getDisplayPath', 'getWritableEntry', 'isWritableEntry']
24 .forEach(bindFileEntryFunction); 27 .forEach(bindFileEntryFunction);
(...skipping 12 matching lines...) Expand all
37 var fs = GetIsolatedFileSystem(fileSystemId); 40 var fs = GetIsolatedFileSystem(fileSystemId);
38 41
39 try { 42 try {
40 // TODO(koz): fs.root.getFile() makes a trip to the browser process, 43 // TODO(koz): fs.root.getFile() makes a trip to the browser process,
41 // but it might be possible avoid that by calling 44 // but it might be possible avoid that by calling
42 // WebFrame::createFileEntry(). 45 // WebFrame::createFileEntry().
43 fs.root.getFile(baseName, {}, function(fileEntry) { 46 fs.root.getFile(baseName, {}, function(fileEntry) {
44 entryIdManager.registerEntry(id, fileEntry); 47 entryIdManager.registerEntry(id, fileEntry);
45 callback(fileEntry); 48 callback(fileEntry);
46 }, function(fileError) { 49 }, function(fileError) {
47 lastError.set('Error getting fileEntry, code: ' + fileError.code); 50 lastError.run('Error getting fileEntry, code: ' + fileError.code,
48 callback(); 51 callback);
49 }); 52 });
50 } catch (e) { 53 } catch (e) {
51 lastError.set('Error in event handler for onLaunched: ' + e.stack); 54 lastError.run('Error in event handler for onLaunched: ' + e.stack,
52 callback(); 55 callback);
53 } 56 }
54 } 57 }
55 }); 58 });
56 } 59 }
57 ['getWritableEntry', 'chooseEntry'].forEach(bindFileEntryCallback); 60 ['getWritableEntry', 'chooseEntry'].forEach(bindFileEntryCallback);
58 61
59 apiFunctions.setHandleRequest('getEntryId', function(fileEntry) { 62 apiFunctions.setHandleRequest('getEntryId', function(fileEntry) {
60 return entryIdManager.getEntryId(fileEntry); 63 return entryIdManager.getEntryId(fileEntry);
61 }); 64 });
62 65
63 apiFunctions.setHandleRequest('getEntryById', function(id) { 66 apiFunctions.setHandleRequest('getEntryById', function(id) {
64 return entryIdManager.getEntryById(id); 67 return entryIdManager.getEntryById(id);
65 }); 68 });
66 69
67 // TODO(benwells): Remove these deprecated versions of the functions. 70 // TODO(benwells): Remove these deprecated versions of the functions.
68 chrome.fileSystem.getWritableFileEntry = function() { 71 fileSystem.getWritableFileEntry = function() {
69 console.log("chrome.fileSystem.getWritableFileEntry is deprecated"); 72 console.log("chrome.fileSystem.getWritableFileEntry is deprecated");
70 console.log("Please use chrome.fileSystem.getWritableEntry instead"); 73 console.log("Please use chrome.fileSystem.getWritableEntry instead");
71 chrome.fileSystem.getWritableEntry.apply(this, arguments); 74 fileSystem.getWritableEntry.apply(this, arguments);
72 }; 75 };
73 76
74 chrome.fileSystem.isWritableFileEntry = function() { 77 fileSystem.isWritableFileEntry = function() {
75 console.log("chrome.fileSystem.isWritableFileEntry is deprecated"); 78 console.log("chrome.fileSystem.isWritableFileEntry is deprecated");
76 console.log("Please use chrome.fileSystem.isWritableEntry instead"); 79 console.log("Please use chrome.fileSystem.isWritableEntry instead");
77 chrome.fileSystem.isWritableEntry.apply(this, arguments); 80 fileSystem.isWritableEntry.apply(this, arguments);
78 }; 81 };
79 82
80 chrome.fileSystem.chooseFile = function() { 83 fileSystem.chooseFile = function() {
81 console.log("chrome.fileSystem.chooseFile is deprecated"); 84 console.log("chrome.fileSystem.chooseFile is deprecated");
82 console.log("Please use chrome.fileSystem.chooseEntry instead"); 85 console.log("Please use chrome.fileSystem.chooseEntry instead");
83 chrome.fileSystem.chooseEntry.apply(this, arguments); 86 fileSystem.chooseEntry.apply(this, arguments);
84 }; 87 };
85 }); 88 });
89
90 exports.binding = binding.generate();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698