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

Unified 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: Starting over. This used to be 286933006 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 side-by-side diff with in-line comments
Download patch
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..23d849578c407f976598ca5a0838e1eff2cf251c
--- /dev/null
+++ b/chrome/common/extensions/docs/examples/api/document_scan/scan.js
@@ -0,0 +1,69 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+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(scan_results) {
+ waitAnimation.style.display = 'none';
+ if (chrome.runtime.lastError) {
+ console.log('Scan failed: ' + chrome.runtime.lastError.message);
+ return;
+ }
+ numImages = scan_results.dataUrls.length;
+ console.log('Scan completed with ' + numImages + ' images.');
+ for (var i = 0; i < numImages; i++) {
+ urlData = scan_results.dataUrls[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();
+ }
+});

Powered by Google App Engine
This is Rietveld 408576698