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

Side by Side Diff: extensions/renderer/resources/file_entry_binding_util.js

Issue 2959583002: [Extensions Bindings] Don't load lastError module with native bindings (Closed)
Patch Set: rebase Created 3 years, 5 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
« no previous file with comments | « extensions/renderer/dispatcher.cc ('k') | extensions/renderer/resources/messaging.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 var fileSystemNatives = requireNative('file_system_natives'); 5 var fileSystemNatives = requireNative('file_system_natives');
6 var GetIsolatedFileSystem = fileSystemNatives.GetIsolatedFileSystem; 6 var GetIsolatedFileSystem = fileSystemNatives.GetIsolatedFileSystem;
7 var lastError = require('lastError');
8 var GetModuleSystem = requireNative('v8_context').GetModuleSystem; 7 var GetModuleSystem = requireNative('v8_context').GetModuleSystem;
9 // TODO(sammc): Don't require extension. See http://crbug.com/235689. 8 // TODO(sammc): Don't require extension. See http://crbug.com/235689.
10 var GetExtensionViews = requireNative('runtime').GetExtensionViews; 9 var GetExtensionViews = requireNative('runtime').GetExtensionViews;
11 var safeCallbackApply = require('uncaught_exception_handler').safeCallbackApply; 10 var safeCallbackApply = require('uncaught_exception_handler').safeCallbackApply;
12 11
12 var jsLastError = bindingUtil ? undefined : require('lastError');
13 function runCallbackWithLastError(name, message, stack, callback) {
14 if (bindingUtil)
15 bindingUtil.runCallbackWithLastError(message, callback);
16 else
17 jsLastError.run(name, message, stack, callback);
18 }
19
20
13 var WINDOW = {}; 21 var WINDOW = {};
14 try { 22 try {
15 WINDOW = window; 23 WINDOW = window;
16 } catch (e) { 24 } catch (e) {
17 // Running in SW context. 25 // Running in SW context.
18 // TODO(lazyboy): Synchronous access to background page is not possible from 26 // TODO(lazyboy): Synchronous access to background page is not possible from
19 // service worker context. Decide what we should do in this case for the class 27 // service worker context. Decide what we should do in this case for the class
20 // of APIs that require access to background page or window object 28 // of APIs that require access to background page or window object
21 } 29 }
22 30
(...skipping 21 matching lines...) Expand all
44 callback(); 52 callback();
45 return; 53 return;
46 } 54 }
47 55
48 var entries = []; 56 var entries = [];
49 var hasError = false; 57 var hasError = false;
50 58
51 var getEntryError = function(fileError) { 59 var getEntryError = function(fileError) {
52 if (!hasError) { 60 if (!hasError) {
53 hasError = true; 61 hasError = true;
54 lastError.run( 62 runCallbackWithLastError(
55 apiName + '.' + functionName, 63 apiName + '.' + functionName,
56 'Error getting fileEntry, code: ' + fileError.code, 64 'Error getting fileEntry, code: ' + fileError.code,
57 request.stack, 65 request.stack,
58 callback); 66 callback);
59 } 67 }
60 } 68 }
61 69
62 // Loop through the response entries and asynchronously get the 70 // Loop through the response entries and asynchronously get the
63 // FileEntry for each. We use hasError to ensure that only the first 71 // FileEntry for each. We use hasError to ensure that only the first
64 // error is reported. Note that an error can occur either during the 72 // error is reported. Note that an error can occur either during the
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 // WebDOMFileSystem::createV8Entry(). 104 // WebDOMFileSystem::createV8Entry().
97 if (entry.isDirectory) { 105 if (entry.isDirectory) {
98 fs.root.getDirectory(baseName, {}, getEntryCallback, 106 fs.root.getDirectory(baseName, {}, getEntryCallback,
99 getEntryError); 107 getEntryError);
100 } else { 108 } else {
101 fs.root.getFile(baseName, {}, getEntryCallback, getEntryError); 109 fs.root.getFile(baseName, {}, getEntryCallback, getEntryError);
102 } 110 }
103 } catch (e) { 111 } catch (e) {
104 if (!hasError) { 112 if (!hasError) {
105 hasError = true; 113 hasError = true;
106 lastError.run(apiName + '.' + functionName, 114 runCallbackWithLastError(apiName + '.' + functionName,
107 'Error getting fileEntry: ' + e.stack, 115 'Error getting fileEntry: ' + e.stack,
108 request.stack, 116 request.stack, callback);
109 callback);
110 } 117 }
111 } 118 }
112 }); 119 });
113 } 120 }
114 }); 121 });
115 }; 122 };
116 var entryIdManager = require('entryIdManager'); 123 var entryIdManager = require('entryIdManager');
117 } else { 124 } else {
118 // Force the fileSystem API to be loaded in the background page. Using 125 // Force the fileSystem API to be loaded in the background page. Using
119 // backgroundPageModuleSystem.require('fileSystem') is insufficient as 126 // backgroundPageModuleSystem.require('fileSystem') is insufficient as
(...skipping 23 matching lines...) Expand all
143 if (!response) { 150 if (!response) {
144 callback(); 151 callback();
145 return; 152 return;
146 } 153 }
147 var fileSystemId = response.fileSystemId; 154 var fileSystemId = response.fileSystemId;
148 var baseName = response.baseName; 155 var baseName = response.baseName;
149 var fs = GetIsolatedFileSystem(fileSystemId); 156 var fs = GetIsolatedFileSystem(fileSystemId);
150 157
151 try { 158 try {
152 fs.root.getDirectory(baseName, {}, callback, function(fileError) { 159 fs.root.getDirectory(baseName, {}, callback, function(fileError) {
153 lastError.run('runtime.' + functionName, 160 runCallbackWithLastError(
154 'Error getting Entry, code: ' + fileError.code, 161 'runtime.' + functionName,
155 request.stack, 162 'Error getting Entry, code: ' + fileError.code,
156 callback); 163 request.stack, callback);
157 }); 164 });
158 } catch (e) { 165 } catch (e) {
159 lastError.run('runtime.' + functionName, 166 runCallbackWithLastError('runtime.' + functionName,
160 'Error: ' + e.stack, 167 'Error: ' + e.stack,
161 request.stack, 168 request.stack, callback);
162 callback);
163 } 169 }
164 } 170 }
165 } 171 }
166 } else { 172 } else {
167 var backgroundPageModuleSystem = GetModuleSystem(backgroundPage); 173 var backgroundPageModuleSystem = GetModuleSystem(backgroundPage);
168 // Force the runtime API to be loaded in the background page. Using 174 // Force the runtime API to be loaded in the background page. Using
169 // backgroundPageModuleSystem.require('runtime') is insufficient as 175 // backgroundPageModuleSystem.require('runtime') is insufficient as
170 // requireNative is only allowed while lazily loading an API. 176 // requireNative is only allowed while lazily loading an API.
171 backgroundPage.chrome.runtime; 177 backgroundPage.chrome.runtime;
172 return backgroundPageModuleSystem.require('fileEntryBindingUtil') 178 return backgroundPageModuleSystem.require('fileEntryBindingUtil')
173 .getBindDirectoryEntryCallback(); 179 .getBindDirectoryEntryCallback();
174 } 180 }
175 } 181 }
176 182
177 exports.$set('getFileBindingsForApi', getFileBindingsForApi); 183 exports.$set('getFileBindingsForApi', getFileBindingsForApi);
178 exports.$set('getBindDirectoryEntryCallback', getBindDirectoryEntryCallback); 184 exports.$set('getBindDirectoryEntryCallback', getBindDirectoryEntryCallback);
OLDNEW
« no previous file with comments | « extensions/renderer/dispatcher.cc ('k') | extensions/renderer/resources/messaging.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698