1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 * Responsible for interfacing with the native component of the WebUI to make
7 * CryptAuth API requests and handling the responses.
11 * A list of observers of CryptAuth events.
18 addObserver: function(observer) {
19 CryptAuthInterface.observers_.push(observer);
23 * Removes an observer.
25 removeObserver: function(observer) {
26 var index = CryptAuthInterface.observers_.indexOf(observer);
28 CryptAuthInterface.observers_.splice(index, 1);
32 * Starts the findEligibleUnlockDevices API call.
33 * The onGotEligibleDevices() function will be called upon success.
35 findEligibleUnlockDevices: function() {
36 chrome.send('findEligibleUnlockDevices');
40 * Starts the flow to find reachable devices. Reachable devices are those that
41 * respond to a CryptAuth ping.
42 * The onGotReachableDevices() function will be called upon success.
44 findReachableDevices: function() {
45 chrome.send('findReachableDevices');
49 * Makes the device with |publicKey| an unlock key if |makeUnlockKey| is true.
50 * Otherwise, the device will be removed as an unlock key.
52 toggleUnlockKey: function(publicKey, makeUnlockKey) {
53 chrome.send('toggleUnlockKey', [publicKey, makeUnlockKey]);
57 * Called by the browser when the API request fails.
59 onError: function(errorMessage) {
60 CryptAuthInterface.observers_.forEach(function(observer) {
61 if (observer.onCryptAuthError != null)
62 observer.onCryptAuthError(errorMessage);
67 * Called by the browser when a findEligibleUnlockDevices completes
69 * @param {Array<DeviceInfo>} eligibleDevices
70 * @param {Array<DeviceInfo>} ineligibleDevices
72 onGotEligibleDevices: function(eligibleDevices, ineligibleDevices) {
73 CryptAuthInterface.observers_.forEach(function(observer) {
74 if (observer.onGotEligibleDevices != null)
75 observer.onGotEligibleDevices(eligibleDevices, ineligibleDevices);
80 * Called by the browser when the reachable devices flow completes
82 * @param {Array<DeviceInfo>} reachableDevices
84 onGotReachableDevices: function(reachableDevices) {
85 CryptAuthInterface.observers_.forEach(function(observer) {
86 if (observer.onGotReachableDevices != null)
87 observer.onGotReachableDevices(reachableDevices);
92 * Called by the browser when an unlock key is toggled.
94 onUnlockKeyToggled: function() {
95 CryptAuthInterface.observers_.forEach(function(observer) {
96 if (observer.onUnlockKeyToggled != null)
97 observer.onUnlockKeyToggled();
102 // This message tells the native WebUI handler that the WebContents backing the
103 // WebUI has been iniitalized. This signal allows the native handler to execute
104 // JavaScript inside the page.
105 chrome.send('onWebContentsInitialized');