Loosen up heuristics for detecting account creation forms.
[chromium-blink-merge.git] / remoting / webapp / host_session.js
blobd1f9a1460af83e2ea88662c65d0b5dfc6eb5d01b
1 // Copyright (c) 2012 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.
5 /**
6 * @fileoverview
7 * Class handling creation and teardown of a remoting host session.
9 * This abstracts a <embed> element and controls the plugin which does the
10 * actual remoting work. There should be no UI code inside this class. It
11 * should be purely thought of as a controller of sorts.
14 'use strict';
16 /** @suppress {duplicate} */
17 var remoting = remoting || {};
19 /**
20 * @constructor
22 remoting.HostSession = function() {
25 /** @type {remoting.HostPlugin} */
26 remoting.HostSession.prototype.plugin = null;
28 // Note that these values are copied directly from host_script_object.h and
29 // must be kept in sync.
30 /** @enum {number} */
31 remoting.HostSession.State = {
32 UNKNOWN: -1,
33 DISCONNECTED: 0,
34 STARTING: 1,
35 REQUESTED_ACCESS_CODE: 2,
36 RECEIVED_ACCESS_CODE: 3,
37 CONNECTED: 4,
38 DISCONNECTING: 5,
39 ERROR: 6
42 /**
43 * Create an instance of the host plugin.
44 * @return {remoting.HostPlugin} The new plugin instance.
46 remoting.HostSession.createPlugin = function() {
47 var plugin = document.createElement('embed');
48 plugin.type = remoting.PLUGIN_MIMETYPE;
49 // Hiding the plugin means it doesn't load, so make it size zero instead.
50 plugin.width = 0;
51 plugin.height = 0;
52 return /** @type {remoting.HostPlugin} */ (plugin);
55 /**
56 * Create the host plugin and initiate a connection.
57 * @param {Element} container The parent element to which to add the plugin.
58 * @param {string} email The user's email address.
59 * @param {string} accessToken A valid OAuth2 access token.
60 * @param {function(boolean):void} onNatTraversalPolicyChanged Callback
61 * for notification of changes to the NAT traversal policy.
62 * @param {function(remoting.HostSession.State):void} onStateChanged
63 * Callback for notifications of changes to the host plugin's state.
64 * @param {function(string):void} logDebugInfo Callback allowing the plugin
65 * to log messages to the debug log.
67 remoting.HostSession.prototype.createPluginAndConnect =
68 function(container, email, accessToken,
69 onNatTraversalPolicyChanged, onStateChanged, logDebugInfo) {
70 this.plugin = remoting.HostSession.createPlugin();
71 container.appendChild(this.plugin);
72 this.plugin.onNatTraversalPolicyChanged = onNatTraversalPolicyChanged;
73 this.plugin.onStateChanged = onStateChanged;
74 this.plugin.logDebugInfo = logDebugInfo;
75 this.plugin.localize(chrome.i18n.getMessage);
76 this.plugin.connect(email, 'oauth2:' + accessToken);
79 /**
80 * Get the access code generated by the host plugin. Valid only after the
81 * plugin state is RECEIVED_ACCESS_CODE.
82 * @return {string} The access code.
84 remoting.HostSession.prototype.getAccessCode = function() {
85 return this.plugin.accessCode;
88 /**
89 * Get the lifetime for the access code. Valid only after the plugin state is
90 * RECEIVED_ACCESS_CODE.
91 * @return {number} The access code lifetime, in seconds.
93 remoting.HostSession.prototype.getAccessCodeLifetime = function() {
94 return this.plugin.accessCodeLifetime;
97 /**
98 * Get the email address of the connected client. Valid only after the plugin
99 * state is CONNECTED.
100 * @return {string} The client's email address.
102 remoting.HostSession.prototype.getClient = function() {
103 return this.plugin.client;
107 * Disconnect the client.
108 * @return {void} Nothing.
110 remoting.HostSession.prototype.disconnect = function() {
111 this.plugin.disconnect();
116 * Remove the plugin element from the document.
117 * @return {void} Nothing.
119 remoting.HostSession.prototype.removePlugin = function() {
120 this.plugin.parentNode.removeChild(this.plugin);