| Index: chrome/common/extensions/docs/examples/api/document_scan/scan.js
|
| diff --git a/chrome/common/extensions/docs/examples/api/document_scan/scan.js b/chrome/common/extensions/docs/examples/api/document_scan/scan.js
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..b43d4226d68dcb0b49b5e65447a17363af1ec0cc
|
| --- /dev/null
|
| +++ b/chrome/common/extensions/docs/examples/api/document_scan/scan.js
|
| @@ -0,0 +1,65 @@
|
| +var requestButton = document.getElementById("requestButton");
|
| +var scanButton = document.getElementById('scanButton');
|
| +var scannedImages = document.getElementById('scannedImages');
|
| +var waitAnimation = document.getElementById('waitAnimation');
|
| +var imageMimeType;
|
| +
|
| +function setOnlyChild(parent, child) {
|
| + while (parent.firstChild) {
|
| + parent.removeChild(parent.firstChild);
|
| + }
|
| + parent.appendChild(child);
|
| +}
|
| +
|
| +var gotPermission = function(result) {
|
| + waitAnimation.style.display = 'block';
|
| + requestButton.style.display = 'none';
|
| + scanButton.style.display = 'block';
|
| + console.log('App was granted the "documentScan" permission.');
|
| + waitAnimation.style.display = 'none';
|
| +};
|
| +
|
| +var permissionObj = {permissions: ['documentScan']};
|
| +
|
| +requestButton.addEventListener('click', function() {
|
| + waitAnimation.style.display = 'block';
|
| + chrome.permissions.request( permissionObj, function(result) {
|
| + if (result) {
|
| + gotPermission();
|
| + } else {
|
| + console.log('App was not granted the "documentScan" permission.');
|
| + console.log(chrome.runtime.lastError);
|
| + }
|
| + });
|
| +});
|
| +
|
| +var onScanCompleted = function(buffers, datatype) {
|
| + waitAnimation.style.display = 'none';
|
| + if (chrome.runtime.lastError) {
|
| + console.log('Scan failed: ' + chrome.runtime.lastError.message);
|
| + return;
|
| + }
|
| + numImages = buffers.length;
|
| + console.log('Scan completed with ' + numImages + ' images.');
|
| + for (var i = 0; i < numImages; i++) {
|
| + urlData = buffers[i]
|
| + console.log('Scan ' + i + ' data length ' +
|
| + urlData.length + '.');
|
| + console.log('URL is ' + urlData);
|
| + var scannedImage = document.createElement('img');
|
| + scannedImage.src = urlData;
|
| + scannedImages.insertBefore(scannedImage, scannedImages.firstChild);
|
| + }
|
| +};
|
| +
|
| +scanButton.addEventListener('click', function() {
|
| + var scanProperties = {};
|
| + waitAnimation.style.display = 'block';
|
| + chrome.documentScan.scan(scanProperties, onScanCompleted);
|
| +});
|
| +
|
| +chrome.permissions.contains(permissionObj, function(result) {
|
| + if (result) {
|
| + gotPermission();
|
| + }
|
| +});
|
|
|