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

Side by Side Diff: remoting/webapp/crd/js/crd_init.js

Issue 742473002: [Chromoting] Break up the webapp's init function into smaller chunks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Upload Created 6 years, 1 month 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 // Copyright 2014 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.
4
5 'use strict';
6
7 /** @suppress {duplicate} */
8 var remoting = remoting || {};
9
10 /**
11 * Entry point for Chromoting webapp initialization.
12 */
13 remoting.init = function() {
14 remoting.initCommon();
Jamie 2014/11/19 19:31:24 Can we come up with a better name for this?
garykac 2014/11/20 03:18:50 Changed to initGlobalObjects(), which isn't much b
15 remoting.initIdentity();
16
17 if (base.isAppsV2()) {
18 remoting.windowFrame = new remoting.WindowFrame(
19 document.getElementById('title-bar'));
20 remoting.optionsMenu = remoting.windowFrame.createOptionsMenu();
21 } else {
22 remoting.toolbar = new remoting.Toolbar(
23 document.getElementById('session-toolbar'));
24 remoting.optionsMenu = remoting.toolbar.createOptionsMenu();
25 }
26
27 remoting.initHostlist_();
28
29 var homeFeedback = new remoting.MenuButton(
30 document.getElementById('help-feedback-main'));
31 var toolbarFeedback = new remoting.MenuButton(
32 document.getElementById('help-feedback-toolbar'));
33 remoting.manageHelpAndFeedback(
34 document.getElementById('title-bar'));
35 remoting.manageHelpAndFeedback(
36 document.getElementById('help-feedback-toolbar'));
37 remoting.manageHelpAndFeedback(
38 document.getElementById('help-feedback-main'));
39
40 remoting.windowShape.updateClientWindowShape();
41
42 remoting.showOrHideIT2MeUi();
43 remoting.showOrHideMe2MeUi();
44
45 // For Apps v1, check the tab type to warn the user if they are not getting
46 // the best keyboard experience.
47 if (!base.isAppsV2() && !remoting.platformIsMac()) {
48 /** @param {boolean} isWindowed */
49 var onIsWindowed = function(isWindowed) {
50 if (!isWindowed) {
51 document.getElementById('startup-mode-box-me2me').hidden = false;
52 document.getElementById('startup-mode-box-it2me').hidden = false;
53 }
54 };
55 isWindowed_(onIsWindowed);
56 }
57
58 remoting.ClientPlugin.factory.preloadPlugin();
59 };
60
61 /**
62 * Initialize the host list.
63 */
64 remoting.initHostlist_ = function() {
65 remoting.hostList = new remoting.HostList(
66 document.getElementById('host-list'),
67 document.getElementById('host-list-empty'),
68 document.getElementById('host-list-error-message'),
69 document.getElementById('host-list-refresh-failed-button'),
70 document.getElementById('host-list-loading-indicator'));
71
72 isHostModeSupported_().then(
73 /** @param {Boolean} supported */
74 function(supported){
75 if (supported) {
76 var noShare = document.getElementById('chrome-os-no-share');
77 noShare.parentNode.removeChild(noShare);
78 } else {
79 var button = document.getElementById('share-button');
80 button.disabled = true;
81 }
82 });
83
84 /**
85 * @return {Promise} A promise that resolves to the id of the current
86 * containing tab/window.
87 */
88 var getCurrentId = function () {
89 if (base.isAppsV2()) {
90 return Promise.resolve(chrome.app.window.current().id);
91 }
92
93 /**
94 * @param {function(*=):void} resolve
95 * @param {function(*=):void} reject
96 */
97 return new Promise(function(resolve, reject) {
98 /** @param {chrome.Tab} tab */
99 chrome.tabs.getCurrent(function(tab){
100 if (tab) {
101 resolve(String(tab.id));
102 }
103 reject('Cannot retrieve the current tab.');
104 });
105 });
106 };
107
108 var onLoad = function() {
109 // Parse URL parameters.
110 var urlParams = getUrlParameters_();
111 if ('mode' in urlParams) {
112 if (urlParams['mode'] === 'me2me') {
113 var hostId = urlParams['hostId'];
114 remoting.connectMe2Me(hostId);
115 return;
116 } else if (urlParams['mode'] === 'hangout') {
117 /** @param {*} id */
118 getCurrentId().then(function(id) {
119 /** @type {string} */
120 var accessCode = urlParams['accessCode'];
121 remoting.ensureSessionConnector_();
122 remoting.setMode(remoting.AppMode.CLIENT_CONNECTING);
123 remoting.connector.connectIT2Me(accessCode);
124
125 document.body.classList.add('hangout-remote-desktop');
126 var senderId = /** @type {string} */ String(id);
127 var hangoutSession = new remoting.HangoutSession(senderId);
128 hangoutSession.init();
129 });
130 return;
131 }
132 }
133 // No valid URL parameters, start up normally.
134 remoting.initHomeScreenUi();
135 }
136 remoting.hostList.load(onLoad);
137 }
138
139 /**
140 * initHomeScreenUi is called if the app is not starting up in session mode,
141 * and also if the user cancels pin entry or the connection in session mode.
142 */
143 remoting.initHomeScreenUi = function() {
144 remoting.hostController = new remoting.HostController();
145 remoting.setMode(remoting.AppMode.HOME);
146 remoting.hostSetupDialog =
147 new remoting.HostSetupDialog(remoting.hostController);
148 var dialog = document.getElementById('paired-clients-list');
149 var message = document.getElementById('paired-client-manager-message');
150 var deleteAll = document.getElementById('delete-all-paired-clients');
151 var close = document.getElementById('close-paired-client-manager-dialog');
152 var working = document.getElementById('paired-client-manager-dialog-working');
153 var error = document.getElementById('paired-client-manager-dialog-error');
154 var noPairedClients = document.getElementById('no-paired-clients');
155 remoting.pairedClientManager =
156 new remoting.PairedClientManager(remoting.hostController, dialog, message,
157 deleteAll, close, noPairedClients,
158 working, error);
159 // Display the cached host list, then asynchronously update and re-display it.
160 remoting.updateLocalHostState();
161 remoting.hostList.refresh(remoting.updateLocalHostState);
162 remoting.butterBar = new remoting.ButterBar();
163 };
164
165 /**
166 * Fetches local host state and updates the DOM accordingly.
167 */
168 remoting.updateLocalHostState = function() {
169 /**
170 * @param {remoting.HostController.State} state Host state.
171 */
172 var onHostState = function(state) {
173 if (state == remoting.HostController.State.STARTED) {
174 remoting.hostController.getLocalHostId(onHostId.bind(null, state));
175 } else {
176 onHostId(state, null);
177 }
178 };
179
180 /**
181 * @param {remoting.HostController.State} state Host state.
182 * @param {string?} hostId Host id.
183 */
184 var onHostId = function(state, hostId) {
185 remoting.hostList.setLocalHostStateAndId(state, hostId);
186 remoting.hostList.display();
187 };
188
189 /**
190 * @param {boolean} response True if the feature is present.
191 */
192 var onHasFeatureResponse = function(response) {
193 /**
194 * @param {remoting.Error} error
195 */
196 var onError = function(error) {
197 console.error('Failed to get pairing status: ' + error);
198 remoting.pairedClientManager.setPairedClients([]);
199 };
200
201 if (response) {
202 remoting.hostController.getPairedClients(
203 remoting.pairedClientManager.setPairedClients.bind(
204 remoting.pairedClientManager),
205 onError);
206 } else {
207 console.log('Pairing registry not supported by host.');
208 remoting.pairedClientManager.setPairedClients([]);
209 }
210 };
211
212 remoting.hostController.hasFeature(
213 remoting.HostController.Feature.PAIRING_REGISTRY, onHasFeatureResponse);
214 remoting.hostController.getLocalHostState(onHostState);
215 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698