From a6710f542a9e59eed22f72369bb98c6a7773e9cd Mon Sep 17 00:00:00 2001 From: Gary Kacmarcik Date: Tue, 9 Dec 2014 13:57:42 -0800 Subject: [PATCH] [Chromoting] Add GDrive capability support to the webapp. Add GDrive ClientSession.Capability to the webapp so that it can work with hosts that have enhanced GDrive support. Currently CRD hosts do not have this special GDrive support, so this Capability is not being enabled for the CRD application. NOTRY=True BUG= R=jamiewalch@chromium.org Review URL: https://codereview.chromium.org/792593002 Cr-Commit-Position: refs/heads/master@{#307562} --- remoting/webapp/crd/js/client_session.js | 53 ++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/remoting/webapp/crd/js/client_session.js b/remoting/webapp/crd/js/client_session.js index 69d5cbfdc105..c16e35ec55d5 100644 --- a/remoting/webapp/crd/js/client_session.js +++ b/remoting/webapp/crd/js/client_session.js @@ -23,6 +23,15 @@ var remoting = remoting || {}; /** + * Interval that determines how often the web-app should send a new access token + * to the host. + * + * @const + * @type {number} + */ +remoting.ACCESS_TOKEN_RESEND_INTERVAL_MS = 15 * 60 * 1000; + +/** * True if Cast capability is supported. * * @type {boolean} @@ -384,6 +393,11 @@ remoting.ClientSession.Capability = { // rate limits desktop-resize requests. RATE_LIMIT_RESIZE_REQUESTS: 'rateLimitResizeRequests', + // Indicates that host/client supports Google Drive integration, and that the + // client should send to the host the OAuth tokens to be used by Google Drive + // on the host. + GOOGLE_DRIVE: "googleDrive", + // Indicates that the client supports the video frame-recording extension. VIDEO_RECORDER: 'videoRecorder', @@ -1083,6 +1097,9 @@ remoting.ClientSession.prototype.onSetCapabilities_ = function(capabilities) { clientArea.height, window.devicePixelRatio); } + if (this.hasCapability_(remoting.ClientSession.Capability.GOOGLE_DRIVE)) { + this.sendGoogleDriveAccessToken_(); + } if (this.hasCapability_( remoting.ClientSession.Capability.VIDEO_RECORDER)) { this.videoFrameRecorder_ = new remoting.VideoFrameRecorder(this.plugin_); @@ -1514,6 +1531,18 @@ remoting.ClientSession.prototype.sendClipboardItem = function(mimeType, item) { }; /** + * Sends an extension message to the host. + * + * @param {string} type The message type. + * @param {string} message The message payload. + */ +remoting.ClientSession.prototype.sendClientMessage = function(type, message) { + if (!this.plugin_) + return; + this.plugin_.sendClientMessage(type, message); +}; + +/** * Send a gnubby-auth extension message to the host. * @param {Object} data The gnubby-auth message data. */ @@ -1555,6 +1584,30 @@ remoting.ClientSession.prototype.createGnubbyAuthHandler_ = function() { }; /** + * Timer callback to send the access token to the host. + * @private + */ +remoting.ClientSession.prototype.sendGoogleDriveAccessToken_ = function() { + if (this.state_ != remoting.ClientSession.State.CONNECTED) { + return; + } + /** @type {remoting.ClientSession} */ + var that = this; + + /** @param {string} token */ + var sendToken = function(token) { + remoting.clientSession.sendClientMessage('accessToken', token); + }; + /** @param {remoting.Error} error */ + var sendError = function(error) { + console.log('Failed to refresh access token: ' + error); + } + remoting.identity.callWithNewToken(sendToken, sendError); + window.setTimeout(this.sendGoogleDriveAccessToken_.bind(this), + remoting.ACCESS_TOKEN_RESEND_INTERVAL_MS); +}; + +/** * @return {{width: number, height: number}} The height of the window's client * area. This differs between apps v1 and apps v2 due to the custom window * borders used by the latter. -- 2.11.4.GIT