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

Side by Side Diff: chrome/common/extensions/docs/examples/api/document_scan/scan.js

Issue 286933006: Implement a JavaScript API for document scanning (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address kalman@'s comments. Still need tests. Created 6 years, 2 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
(Empty)
1 var requestButton = document.getElementById("requestButton");
2 var scanButton = document.getElementById('scanButton');
3 var scannedImages = document.getElementById('scannedImages');
4 var waitAnimation = document.getElementById('waitAnimation');
5 var imageMimeType;
6
7 function setOnlyChild(parent, child) {
8 while (parent.firstChild) {
9 parent.removeChild(parent.firstChild);
10 }
11 parent.appendChild(child);
12 }
13
14 var gotPermission = function(result) {
15 waitAnimation.style.display = 'block';
16 requestButton.style.display = 'none';
17 scanButton.style.display = 'block';
18 console.log('App was granted the "documentScan" permission.');
19 waitAnimation.style.display = 'none';
20 };
21
22 var permissionObj = {permissions: ['documentScan']};
23
24 requestButton.addEventListener('click', function() {
25 waitAnimation.style.display = 'block';
26 chrome.permissions.request( permissionObj, function(result) {
27 if (result) {
28 gotPermission();
29 } else {
30 console.log('App was not granted the "documentScan" permission.');
31 console.log(chrome.runtime.lastError);
32 }
33 });
34 });
35
36 var onScanCompleted = function(scan_results) {
37 waitAnimation.style.display = 'none';
38 if (chrome.runtime.lastError) {
39 console.log('Scan failed: ' + chrome.runtime.lastError.message);
40 return;
41 }
42 numImages = scan_results.dataUrls.length;
43 console.log('Scan completed with ' + numImages + ' images.');
44 for (var i = 0; i < numImages; i++) {
45 urlData = scan_results.dataUrls[i]
46 console.log('Scan ' + i + ' data length ' +
47 urlData.length + '.');
48 console.log('URL is ' + urlData);
49 var scannedImage = document.createElement('img');
50 scannedImage.src = urlData;
51 scannedImages.insertBefore(scannedImage, scannedImages.firstChild);
52 }
53 };
54
55 scanButton.addEventListener('click', function() {
56 var scanProperties = {};
57 waitAnimation.style.display = 'block';
58 chrome.documentScan.scan(scanProperties, onScanCompleted);
59 });
60
61 chrome.permissions.contains(permissionObj, function(result) {
62 if (result) {
63 gotPermission();
64 }
65 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698