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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/bindings/FileUtils.js

Issue 2493373002: DevTools: rename WebInspector into modules. (Closed)
Patch Set: for bots Created 4 years, 1 month 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 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 12 matching lines...) Expand all
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 /** 30 /**
31 * @interface 31 * @interface
32 */ 32 */
33 WebInspector.OutputStreamDelegate = function() {}; 33 Bindings.OutputStreamDelegate = function() {};
34 34
35 WebInspector.OutputStreamDelegate.prototype = { 35 Bindings.OutputStreamDelegate.prototype = {
36 onTransferStarted: function() {}, 36 onTransferStarted: function() {},
37 37
38 onTransferFinished: function() {}, 38 onTransferFinished: function() {},
39 39
40 /** 40 /**
41 * @param {!WebInspector.ChunkedReader} reader 41 * @param {!Bindings.ChunkedReader} reader
42 */ 42 */
43 onChunkTransferred: function(reader) {}, 43 onChunkTransferred: function(reader) {},
44 44
45 /** 45 /**
46 * @param {!WebInspector.ChunkedReader} reader 46 * @param {!Bindings.ChunkedReader} reader
47 * @param {!Event} event 47 * @param {!Event} event
48 */ 48 */
49 onError: function(reader, event) {}, 49 onError: function(reader, event) {},
50 }; 50 };
51 51
52 /** 52 /**
53 * @interface 53 * @interface
54 */ 54 */
55 WebInspector.ChunkedReader = function() {}; 55 Bindings.ChunkedReader = function() {};
56 56
57 WebInspector.ChunkedReader.prototype = { 57 Bindings.ChunkedReader.prototype = {
58 /** 58 /**
59 * @return {number} 59 * @return {number}
60 */ 60 */
61 fileSize: function() {}, 61 fileSize: function() {},
62 62
63 /** 63 /**
64 * @return {number} 64 * @return {number}
65 */ 65 */
66 loadedSize: function() {}, 66 loadedSize: function() {},
67 67
68 /** 68 /**
69 * @return {string} 69 * @return {string}
70 */ 70 */
71 fileName: function() {}, 71 fileName: function() {},
72 72
73 cancel: function() {} 73 cancel: function() {}
74 }; 74 };
75 75
76 /** 76 /**
77 * @implements {WebInspector.ChunkedReader} 77 * @implements {Bindings.ChunkedReader}
78 * @unrestricted 78 * @unrestricted
79 */ 79 */
80 WebInspector.ChunkedFileReader = class { 80 Bindings.ChunkedFileReader = class {
81 /** 81 /**
82 * @param {!File} file 82 * @param {!File} file
83 * @param {number} chunkSize 83 * @param {number} chunkSize
84 * @param {!WebInspector.OutputStreamDelegate} delegate 84 * @param {!Bindings.OutputStreamDelegate} delegate
85 */ 85 */
86 constructor(file, chunkSize, delegate) { 86 constructor(file, chunkSize, delegate) {
87 this._file = file; 87 this._file = file;
88 this._fileSize = file.size; 88 this._fileSize = file.size;
89 this._loadedSize = 0; 89 this._loadedSize = 0;
90 this._chunkSize = chunkSize; 90 this._chunkSize = chunkSize;
91 this._delegate = delegate; 91 this._delegate = delegate;
92 this._decoder = new TextDecoder(); 92 this._decoder = new TextDecoder();
93 this._isCanceled = false; 93 this._isCanceled = false;
94 } 94 }
95 95
96 /** 96 /**
97 * @param {!WebInspector.OutputStream} output 97 * @param {!Common.OutputStream} output
98 */ 98 */
99 start(output) { 99 start(output) {
100 this._output = output; 100 this._output = output;
101 101
102 this._reader = new FileReader(); 102 this._reader = new FileReader();
103 this._reader.onload = this._onChunkLoaded.bind(this); 103 this._reader.onload = this._onChunkLoaded.bind(this);
104 this._reader.onerror = this._delegate.onError.bind(this._delegate, this); 104 this._reader.onerror = this._delegate.onError.bind(this._delegate, this);
105 this._delegate.onTransferStarted(); 105 this._delegate.onTransferStarted();
106 this._loadChunk(); 106 this._loadChunk();
107 } 107 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 var chunkEnd = Math.min(this._fileSize, chunkStart + this._chunkSize); 172 var chunkEnd = Math.min(this._fileSize, chunkStart + this._chunkSize);
173 var nextPart = this._file.slice(chunkStart, chunkEnd); 173 var nextPart = this._file.slice(chunkStart, chunkEnd);
174 this._reader.readAsArrayBuffer(nextPart); 174 this._reader.readAsArrayBuffer(nextPart);
175 } 175 }
176 }; 176 };
177 177
178 /** 178 /**
179 * @param {function(!File)} callback 179 * @param {function(!File)} callback
180 * @return {!Node} 180 * @return {!Node}
181 */ 181 */
182 WebInspector.createFileSelectorElement = function(callback) { 182 Bindings.createFileSelectorElement = function(callback) {
183 var fileSelectorElement = createElement('input'); 183 var fileSelectorElement = createElement('input');
184 fileSelectorElement.type = 'file'; 184 fileSelectorElement.type = 'file';
185 fileSelectorElement.style.display = 'none'; 185 fileSelectorElement.style.display = 'none';
186 fileSelectorElement.setAttribute('tabindex', -1); 186 fileSelectorElement.setAttribute('tabindex', -1);
187 fileSelectorElement.onchange = onChange; 187 fileSelectorElement.onchange = onChange;
188 function onChange(event) { 188 function onChange(event) {
189 callback(fileSelectorElement.files[0]); 189 callback(fileSelectorElement.files[0]);
190 } 190 }
191 return fileSelectorElement; 191 return fileSelectorElement;
192 }; 192 };
193 193
194 /** 194 /**
195 * @implements {WebInspector.OutputStream} 195 * @implements {Common.OutputStream}
196 * @unrestricted 196 * @unrestricted
197 */ 197 */
198 WebInspector.FileOutputStream = class { 198 Bindings.FileOutputStream = class {
199 /** 199 /**
200 * @param {string} fileName 200 * @param {string} fileName
201 * @param {function(boolean)} callback 201 * @param {function(boolean)} callback
202 */ 202 */
203 open(fileName, callback) { 203 open(fileName, callback) {
204 this._closed = false; 204 this._closed = false;
205 this._writeCallbacks = []; 205 this._writeCallbacks = [];
206 this._fileName = fileName; 206 this._fileName = fileName;
207 207
208 /** 208 /**
209 * @param {boolean} accepted 209 * @param {boolean} accepted
210 * @this {WebInspector.FileOutputStream} 210 * @this {Bindings.FileOutputStream}
211 */ 211 */
212 function callbackWrapper(accepted) { 212 function callbackWrapper(accepted) {
213 if (accepted) 213 if (accepted)
214 WebInspector.fileManager.addEventListener( 214 Workspace.fileManager.addEventListener(
215 WebInspector.FileManager.Events.AppendedToURL, this._onAppendDone, t his); 215 Workspace.FileManager.Events.AppendedToURL, this._onAppendDone, this );
216 callback(accepted); 216 callback(accepted);
217 } 217 }
218 WebInspector.fileManager.save(this._fileName, '', true, callbackWrapper.bind (this)); 218 Workspace.fileManager.save(this._fileName, '', true, callbackWrapper.bind(th is));
219 } 219 }
220 220
221 /** 221 /**
222 * @override 222 * @override
223 * @param {string} data 223 * @param {string} data
224 * @param {function(!WebInspector.OutputStream)=} callback 224 * @param {function(!Common.OutputStream)=} callback
225 */ 225 */
226 write(data, callback) { 226 write(data, callback) {
227 this._writeCallbacks.push(callback); 227 this._writeCallbacks.push(callback);
228 WebInspector.fileManager.append(this._fileName, data); 228 Workspace.fileManager.append(this._fileName, data);
229 } 229 }
230 230
231 /** 231 /**
232 * @override 232 * @override
233 */ 233 */
234 close() { 234 close() {
235 this._closed = true; 235 this._closed = true;
236 if (this._writeCallbacks.length) 236 if (this._writeCallbacks.length)
237 return; 237 return;
238 WebInspector.fileManager.removeEventListener( 238 Workspace.fileManager.removeEventListener(
239 WebInspector.FileManager.Events.AppendedToURL, this._onAppendDone, this) ; 239 Workspace.FileManager.Events.AppendedToURL, this._onAppendDone, this);
240 WebInspector.fileManager.close(this._fileName); 240 Workspace.fileManager.close(this._fileName);
241 } 241 }
242 242
243 /** 243 /**
244 * @param {!WebInspector.Event} event 244 * @param {!Common.Event} event
245 */ 245 */
246 _onAppendDone(event) { 246 _onAppendDone(event) {
247 if (event.data !== this._fileName) 247 if (event.data !== this._fileName)
248 return; 248 return;
249 var callback = this._writeCallbacks.shift(); 249 var callback = this._writeCallbacks.shift();
250 if (callback) 250 if (callback)
251 callback(this); 251 callback(this);
252 if (!this._writeCallbacks.length) { 252 if (!this._writeCallbacks.length) {
253 if (this._closed) { 253 if (this._closed) {
254 WebInspector.fileManager.removeEventListener( 254 Workspace.fileManager.removeEventListener(
255 WebInspector.FileManager.Events.AppendedToURL, this._onAppendDone, t his); 255 Workspace.FileManager.Events.AppendedToURL, this._onAppendDone, this );
256 WebInspector.fileManager.close(this._fileName); 256 Workspace.fileManager.close(this._fileName);
257 } 257 }
258 } 258 }
259 } 259 }
260 }; 260 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698