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

Side by Side Diff: remoting/webapp/wcs_sandbox_container.js

Issue 17449017: Delete and recreate the client plugin if WCS is reloaded. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reviewer feedback. Created 7 years, 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « remoting/webapp/session_connector.js ('k') | remoting/webapp/wcs_sandbox_content.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Copyright 2013 The Chromium Authors. All rights reserved. 1 /* Copyright 2013 The Chromium Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be 2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file. 3 * found in the LICENSE file.
4 */ 4 */
5 5
6 /** 6 /**
7 * @fileoverview 7 * @fileoverview
8 * The application side of the application/sandbox WCS interface, used by the 8 * The application side of the application/sandbox WCS interface, used by the
9 * application to exchange messages with the sandbox. 9 * application to exchange messages with the sandbox.
10 */ 10 */
11 11
12 'use strict'; 12 'use strict';
13 13
14 /** @suppress {duplicate} */ 14 /** @suppress {duplicate} */
15 var remoting = remoting || {}; 15 var remoting = remoting || {};
16 16
17 /** 17 /**
18 * @param {Window} sandbox The Javascript Window object representing the 18 * @param {Window} sandbox The Javascript Window object representing the
19 * sandboxed WCS driver. 19 * sandboxed WCS driver.
20 * @constructor 20 * @constructor
21 */ 21 */
22 remoting.WcsSandboxContainer = function(sandbox) { 22 remoting.WcsSandboxContainer = function(sandbox) {
23 this.sandbox_ = sandbox; 23 this.sandbox_ = sandbox;
24 /** @type {?function(string):void} */ 24 /** @type {?function(string):void} */
25 this.onReady_ = null; 25 this.onLocalJid_ = null;
26 /** @type {?function(remoting.Error):void} */ 26 /** @type {?function(remoting.Error):void} */
27 this.onError_ = null; 27 this.onError_ = null;
28 /** @type {?function(string):void} */ 28 /** @type {?function(string):void} */
29 this.onIq_ = null; 29 this.onIq_ = null;
30 /** @type {Object.<number, XMLHttpRequest>} */ 30 /** @type {Object.<number, XMLHttpRequest>} */
31 this.pendingXhrs_ = {}; 31 this.pendingXhrs_ = {};
32 32
33 window.addEventListener('message', this.onMessage_.bind(this), false); 33 window.addEventListener('message', this.onMessage_.bind(this), false);
34 }; 34 };
35 35
36 /** 36 /**
37 * @param {?function(string):void} onReady Callback invoked with the client JID 37 * @param {?function(string):void} onLocalJid Callback invoked with the client
38 * when the WCS code has loaded. 38 * JID when the WCS code has loaded. Note that this may be called more than
39 * once (potentially with a different JID) if the WCS node is reloaded for
40 * any reason.
39 * @return {void} Nothing. 41 * @return {void} Nothing.
40 */ 42 */
41 remoting.WcsSandboxContainer.prototype.setOnReady = function(onReady) { 43 remoting.WcsSandboxContainer.prototype.setOnLocalJid = function(onLocalJid) {
42 this.onReady_ = onReady; 44 this.onLocalJid_ = onLocalJid;
43 }; 45 };
44 46
45 /** 47 /**
46 * @param {?function(remoting.Error):void} onError Callback invoked if the WCS 48 * @param {?function(remoting.Error):void} onError Callback invoked if the WCS
47 * code cannot be loaded. 49 * code cannot be loaded.
48 * @return {void} Nothing. 50 * @return {void} Nothing.
49 */ 51 */
50 remoting.WcsSandboxContainer.prototype.setOnError = function(onError) { 52 remoting.WcsSandboxContainer.prototype.setOnError = function(onError) {
51 this.onError_ = onError; 53 this.onError_ = onError;
52 }; 54 };
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 }; 87 };
86 88
87 /** 89 /**
88 * Event handler to process messages from the sandbox. 90 * Event handler to process messages from the sandbox.
89 * 91 *
90 * @param {Event} event 92 * @param {Event} event
91 */ 93 */
92 remoting.WcsSandboxContainer.prototype.onMessage_ = function(event) { 94 remoting.WcsSandboxContainer.prototype.onMessage_ = function(event) {
93 switch (event.data['command']) { 95 switch (event.data['command']) {
94 96
95 case 'onReady': 97 case 'onLocalJid':
96 /** @type {string} */ 98 /** @type {string} */
97 var clientJid = event.data['clientJid']; 99 var clientJid = event.data['clientJid'];
98 if (clientJid === undefined) { 100 if (clientJid === undefined) {
99 console.error('onReady: missing client JID'); 101 console.error('onReady: missing client JID');
100 break; 102 break;
101 } 103 }
102 if (this.onReady_) { 104 if (this.onLocalJid_) {
103 this.onReady_(clientJid); 105 this.onLocalJid_(clientJid);
104 } 106 }
105 break; 107 break;
106 108
107 case 'onError': 109 case 'onError':
108 /** @type {remoting.Error} */ 110 /** @type {remoting.Error} */
109 var error = event.data['error']; 111 var error = event.data['error'];
110 if (error === undefined) { 112 if (error === undefined) {
111 console.error('onError: missing error code'); 113 console.error('onError: missing error code');
112 break; 114 break;
113 } 115 }
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 'xhr': sanitizeXhr_(xhr) 237 'xhr': sanitizeXhr_(xhr)
236 }; 238 };
237 this.sandbox_.postMessage(message, '*'); 239 this.sandbox_.postMessage(message, '*');
238 if (xhr.readyState == 4) { 240 if (xhr.readyState == 4) {
239 delete this.pendingXhrs_[id]; 241 delete this.pendingXhrs_[id];
240 } 242 }
241 } 243 }
242 244
243 /** @type {remoting.WcsSandboxContainer} */ 245 /** @type {remoting.WcsSandboxContainer} */
244 remoting.wcsSandbox = null; 246 remoting.wcsSandbox = null;
OLDNEW
« no previous file with comments | « remoting/webapp/session_connector.js ('k') | remoting/webapp/wcs_sandbox_content.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698