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

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

Issue 14607023: Add support for persistent file access in apps. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 7 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
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 binding for the fileSystem API. 5 // Custom binding for the fileSystem API.
6 6
7 var binding = require('binding').Binding.create('fileSystem'); 7 var binding = require('binding').Binding.create('fileSystem');
8 8
9 var fileSystemNatives = requireNative('file_system_natives'); 9 var fileSystemNatives = requireNative('file_system_natives');
10 var forEach = require('utils').forEach; 10 var forEach = require('utils').forEach;
11 var GetIsolatedFileSystem = fileSystemNatives.GetIsolatedFileSystem; 11 var GetIsolatedFileSystem = fileSystemNatives.GetIsolatedFileSystem;
12 var lastError = require('lastError'); 12 var lastError = require('lastError');
13 var sendRequest = require('sendRequest').sendRequest;
13 var GetModuleSystem = requireNative('v8_context').GetModuleSystem; 14 var GetModuleSystem = requireNative('v8_context').GetModuleSystem;
14 // TODO(sammc): Don't require extension. See http://crbug.com/235689. 15 // TODO(sammc): Don't require extension. See http://crbug.com/235689.
15 var GetExtensionViews = requireNative('extension').GetExtensionViews; 16 var GetExtensionViews = requireNative('extension').GetExtensionViews;
16 17
17 var backgroundPage = GetExtensionViews(-1, 'BACKGROUND')[0]; 18 var backgroundPage = GetExtensionViews(-1, 'BACKGROUND')[0];
18 var backgroundPageModuleSystem = GetModuleSystem(backgroundPage); 19 var backgroundPageModuleSystem = GetModuleSystem(backgroundPage);
19 var entryIdManager = backgroundPageModuleSystem.require('entryIdManager'); 20 var entryIdManager = backgroundPageModuleSystem.require('entryIdManager');
20 21
21 // All windows use the bindFileEntryCallback from the background page so their 22 // All windows use the bindFileEntryCallback from the background page so their
22 // FileEntry objects have the background page's context as their own. This 23 // FileEntry objects have the background page's context as their own. This
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 apiFunctions.setUpdateArgumentsPostValidate( 75 apiFunctions.setUpdateArgumentsPostValidate(
75 functionName, function(fileEntry, callback) { 76 functionName, function(fileEntry, callback) {
76 var fileSystemName = fileEntry.filesystem.name; 77 var fileSystemName = fileEntry.filesystem.name;
77 var relativePath = fileEntry.fullPath.slice(1); 78 var relativePath = fileEntry.fullPath.slice(1);
78 return [fileSystemName, relativePath, callback]; 79 return [fileSystemName, relativePath, callback];
79 }); 80 });
80 } 81 }
81 forEach(['getDisplayPath', 'getWritableEntry', 'isWritableEntry'], 82 forEach(['getDisplayPath', 'getWritableEntry', 'isWritableEntry'],
82 bindFileEntryFunction); 83 bindFileEntryFunction);
83 84
84 forEach(['getWritableEntry', 'chooseEntry'], function(i, functionName) { 85 forEach(['getWritableEntry', 'chooseEntry', 'restoreEntry'],
86 function(i, functionName) {
85 bindFileEntryCallback(functionName, apiFunctions); 87 bindFileEntryCallback(functionName, apiFunctions);
86 }); 88 });
87 89
88 apiFunctions.setHandleRequest('getEntryId', function(fileEntry) { 90 apiFunctions.setHandleRequest('retainEntry', function(fileEntry) {
89 return entryIdManager.getEntryId(fileEntry); 91 var id = entryIdManager.getEntryId(fileEntry);
92 if (!id)
93 return '';
94 var fileSystemName = fileEntry.filesystem.name;
95 var relativePath = fileEntry.fullPath.slice(1);
96
97 sendRequest(this.name, [id, fileSystemName, relativePath],
98 this.definition.parameters, {});
99 return id;
90 }); 100 });
91 101
92 apiFunctions.setHandleRequest('getEntryById', function(id) { 102 apiFunctions.setHandleRequest('isRestorable',
93 return entryIdManager.getEntryById(id); 103 function(id, callback) {
104 var savedEntry = entryIdManager.getEntryById(id);
105 if (savedEntry) {
106 callback(true);
107 } else {
108 sendRequest(this.name, [id, callback], this.definition.parameters, {});
109 }
110 });
111
112 apiFunctions.setUpdateArgumentsPostValidate('restoreEntry',
113 function(id, callback) {
114 var savedEntry = entryIdManager.getEntryById(id);
115 if (savedEntry) {
116 callback(savedEntry);
117 return [id, false, null];
118 } else {
119 return [id, true, callback];
120 }
94 }); 121 });
95 122
96 // TODO(benwells): Remove these deprecated versions of the functions. 123 // TODO(benwells): Remove these deprecated versions of the functions.
97 fileSystem.getWritableFileEntry = function() { 124 fileSystem.getWritableFileEntry = function() {
98 console.log("chrome.fileSystem.getWritableFileEntry is deprecated"); 125 console.log("chrome.fileSystem.getWritableFileEntry is deprecated");
99 console.log("Please use chrome.fileSystem.getWritableEntry instead"); 126 console.log("Please use chrome.fileSystem.getWritableEntry instead");
100 fileSystem.getWritableEntry.apply(this, arguments); 127 fileSystem.getWritableEntry.apply(this, arguments);
101 }; 128 };
102 129
103 fileSystem.isWritableFileEntry = function() { 130 fileSystem.isWritableFileEntry = function() {
104 console.log("chrome.fileSystem.isWritableFileEntry is deprecated"); 131 console.log("chrome.fileSystem.isWritableFileEntry is deprecated");
105 console.log("Please use chrome.fileSystem.isWritableEntry instead"); 132 console.log("Please use chrome.fileSystem.isWritableEntry instead");
106 fileSystem.isWritableEntry.apply(this, arguments); 133 fileSystem.isWritableEntry.apply(this, arguments);
107 }; 134 };
108 135
109 fileSystem.chooseFile = function() { 136 fileSystem.chooseFile = function() {
110 console.log("chrome.fileSystem.chooseFile is deprecated"); 137 console.log("chrome.fileSystem.chooseFile is deprecated");
111 console.log("Please use chrome.fileSystem.chooseEntry instead"); 138 console.log("Please use chrome.fileSystem.chooseEntry instead");
112 fileSystem.chooseEntry.apply(this, arguments); 139 fileSystem.chooseEntry.apply(this, arguments);
113 }; 140 };
114 }); 141 });
115 142
116 exports.bindFileEntryCallback = bindFileEntryCallback; 143 exports.bindFileEntryCallback = bindFileEntryCallback;
117 exports.binding = binding.generate(); 144 exports.binding = binding.generate();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698