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

Side by Side Diff: chrome/common/extensions/docs/examples/api/fileSystemProvider/basic/background.js

Issue 2906283002: Take into account options.offset in onReadFileRequested. (Closed)
Patch Set: Fix nits. Created 3 years, 6 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 | « no previous file | no next file » | 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 'use strict'; 5 'use strict';
6 6
7 // Fake data similar to a file system structure. 7 // Fake data similar to a file system structure.
8 var MODIFICATION_DATE = new Date(); 8 var MODIFICATION_DATE = new Date();
9 var SHORT_CONTENTS = 'Just another example.'; 9 var SHORT_CONTENTS = 'Just another example.';
10 var LONGER_CONTENTS = 'It works!\nEverything gets displayed correctly.'; 10 var LONGER_CONTENTS = 'It works!\nEverything gets displayed correctly.';
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 82
83 function onReadFileRequested(options, onSuccess, onError) { 83 function onReadFileRequested(options, onSuccess, onError) {
84 if (!openedFiles[options.openRequestId]) { 84 if (!openedFiles[options.openRequestId]) {
85 onError('INVALID_OPERATION'); 85 onError('INVALID_OPERATION');
86 return; 86 return;
87 } 87 }
88 88
89 var contents = 89 var contents =
90 METADATA[openedFiles[options.openRequestId]].contents; 90 METADATA[openedFiles[options.openRequestId]].contents;
91 91
92 var remaining = Math.max(0, contents.length - options.offset);
93 var length = Math.min(remaining, options.length);
94
92 // Write the contents as ASCII text. 95 // Write the contents as ASCII text.
93 var buffer = new ArrayBuffer(options.length); 96 var buffer = new ArrayBuffer(length);
94 var bufferView = new Uint8Array(buffer); 97 var bufferView = new Uint8Array(buffer);
95 for (var i = 0; i < options.length; i++) { 98 for (var i = 0; i < length; i++) {
96 bufferView[i] = contents.charCodeAt(i); 99 bufferView[i] = contents.charCodeAt(i + options.offset);
97 } 100 }
98 101
99 onSuccess(buffer, false /* Last call. */); 102 onSuccess(buffer, false /* Last call. */);
100 } 103 }
101 104
102 function onMountRequested(onSuccess, onError) { 105 function onMountRequested(onSuccess, onError) {
103 chrome.fileSystemProvider.mount( 106 chrome.fileSystemProvider.mount(
104 {fileSystemId: 'sample-file-system', displayName: 'Sample File System'}, 107 {fileSystemId: 'sample-file-system', displayName: 'Sample File System'},
105 function() { 108 function() {
106 if (chrome.runtime.lastError) { 109 if (chrome.runtime.lastError) {
(...skipping 23 matching lines...) Expand all
130 chrome.fileSystemProvider.onGetMetadataRequested.addListener( 133 chrome.fileSystemProvider.onGetMetadataRequested.addListener(
131 onGetMetadataRequested); 134 onGetMetadataRequested);
132 chrome.fileSystemProvider.onReadDirectoryRequested.addListener( 135 chrome.fileSystemProvider.onReadDirectoryRequested.addListener(
133 onReadDirectoryRequested); 136 onReadDirectoryRequested);
134 chrome.fileSystemProvider.onOpenFileRequested.addListener(onOpenFileRequested); 137 chrome.fileSystemProvider.onOpenFileRequested.addListener(onOpenFileRequested);
135 chrome.fileSystemProvider.onCloseFileRequested.addListener( 138 chrome.fileSystemProvider.onCloseFileRequested.addListener(
136 onCloseFileRequested); 139 onCloseFileRequested);
137 chrome.fileSystemProvider.onReadFileRequested.addListener(onReadFileRequested); 140 chrome.fileSystemProvider.onReadFileRequested.addListener(onReadFileRequested);
138 chrome.fileSystemProvider.onMountRequested.addListener(onMountRequested); 141 chrome.fileSystemProvider.onMountRequested.addListener(onMountRequested);
139 chrome.fileSystemProvider.onUnmountRequested.addListener(onUnmountRequested); 142 chrome.fileSystemProvider.onUnmountRequested.addListener(onUnmountRequested);
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698