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

Unified Diff: chrome/browser/resources/cryptotoken/cryptotokenapprovedorigins.js

Issue 799923007: Enable 3rd party support for Security Keys. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove duplicate line from merge Created 6 years 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/browser/resources/cryptotoken/cryptotokenapprovedorigins.js
diff --git a/chrome/browser/resources/cryptotoken/cryptotokenapprovedorigins.js b/chrome/browser/resources/cryptotoken/cryptotokenapprovedorigins.js
new file mode 100644
index 0000000000000000000000000000000000000000..35a0b62bc6b09da94e2cae6c7cda47797357bb87
--- /dev/null
+++ b/chrome/browser/resources/cryptotoken/cryptotokenapprovedorigins.js
@@ -0,0 +1,55 @@
+// 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.
+
+/**
+ * @fileoverview Provides an implementation of approved origins that relies
+ * on the chrome.cryptotokenPrivate.requestPermission API.
+ * (and only) allows google.com to use security keys.
+ *
+ */
+'use strict';
+
+/**
+ * Allows the caller to check whether the user has approved the use of
+ * security keys from an origin.
+ * @constructor
+ * @implements {ApprovedOrigins}
+ */
+function CryptoTokenApprovedOrigin() {}
+
+/**
+ * Checks whether the origin is approved to use security keys. (If not, an
+ * approval prompt may be shown.)
+ * @param {string} origin The origin to approve.
+ * @param {number=} opt_tabId A tab id to display approval prompt in.
+ * For this implementation, the tabId is always necessary, even though
+ * the type allows undefined.
+ * @return {Promise.<boolean>} A promise for the result of the check.
+ */
+CryptoTokenApprovedOrigin.prototype.isApprovedOrigin =
+ function(origin, opt_tabId) {
+ return new Promise(function(resolve, reject) {
+ if (!chrome.cryptotokenPrivate ||
+ !chrome.cryptotokenPrivate.requestPermission) {
+ resolve(false);
+ return;
+ }
+ if (!opt_tabId) {
+ resolve(false);
+ return;
+ }
+ var tabId = /** @type {number} */ (opt_tabId);
+ chrome.cryptotokenPrivate.requestPermission(tabId, origin,
+ function(result) {
+ if (result == 'ALLOWED') {
+ resolve(true);
+ return;
+ }
+ if (chrome.runtime.lastError) {
+ console.log(UTIL_fmt('lastError: ' + chrome.runtime.lastError));
+ }
+ resolve(false);
+ });
+ });
+};

Powered by Google App Engine
This is Rietveld 408576698