diff options
author | jamiewalch <jamiewalch@chromium.org> | 2015-09-25 12:30:44 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-09-25 19:32:17 +0000 |
commit | 5816f58abd0d2b08d118924ed9240195a0a23716 (patch) | |
tree | a0014422e98b29759bc368c7ebfdeef3ca6f1b17 /remoting | |
parent | 2338784958b986a1280d7aa67e34dc0766b746d2 (diff) | |
download | chromium_src-5816f58abd0d2b08d118924ed9240195a0a23716.zip chromium_src-5816f58abd0d2b08d118924ed9240195a0a23716.tar.gz chromium_src-5816f58abd0d2b08d118924ed9240195a0a23716.tar.bz2 |
Refactor HostSettings class.
There are four main changes:
* Rename HostSettings to HostOptions (since the functionality it provides was previously provided by Host.Options).
* Make all fields optional. This was in response to a comment on https://codereview.chromium.org/1343503002/ that using an empty set of remappings to represent the default doesn't make much sense. I extended it to apply to all settings.
* Move the default key remapping logic into getRemapKeys().
* Move the string->dictionary key remapping logic into setRemapKeys().
Review URL: https://codereview.chromium.org/1358173005
Cr-Commit-Position: refs/heads/master@{#350886}
Diffstat (limited to 'remoting')
-rw-r--r-- | remoting/remoting_webapp_files.gypi | 3 | ||||
-rw-r--r-- | remoting/webapp/base/js/base.js | 22 | ||||
-rw-r--r-- | remoting/webapp/base/js/base_unittest.js | 20 | ||||
-rw-r--r-- | remoting/webapp/base/js/host.js | 88 | ||||
-rw-r--r-- | remoting/webapp/base/js/host_options.js | 223 | ||||
-rw-r--r-- | remoting/webapp/base/js/host_options_unittest.js | 106 | ||||
-rw-r--r-- | remoting/webapp/base/js/host_settings.js | 105 | ||||
-rw-r--r-- | remoting/webapp/crd/js/crd_experimental.js | 3 | ||||
-rw-r--r-- | remoting/webapp/crd/js/desktop_connected_view.js | 18 | ||||
-rw-r--r-- | remoting/webapp/crd/js/desktop_remoting_activity.js | 8 | ||||
-rw-r--r-- | remoting/webapp/crd/js/desktop_viewport.js | 33 | ||||
-rw-r--r-- | remoting/webapp/crd/js/me2me_activity.js | 7 | ||||
-rw-r--r-- | remoting/webapp/crd/js/remoting_activity_test_driver.js | 4 | ||||
-rw-r--r-- | remoting/webapp/files.gni | 3 |
14 files changed, 406 insertions, 237 deletions
diff --git a/remoting/remoting_webapp_files.gypi b/remoting/remoting_webapp_files.gypi index f15f196..5e90ca7 100644 --- a/remoting/remoting_webapp_files.gypi +++ b/remoting/remoting_webapp_files.gypi @@ -93,6 +93,7 @@ 'webapp/base/js/dns_blackhole_checker_unittest.js', 'webapp/base/js/error_unittest.js', 'webapp/base/js/fallback_signal_strategy_unittest.js', + 'webapp/base/js/host_options_unittest.js', 'webapp/base/js/identity_unittest.js', 'webapp/base/js/ipc_unittest.js', 'webapp/base/js/l10n_unittest.js', @@ -207,7 +208,7 @@ # Host JavaScript files. 'remoting_webapp_shared_js_host_files': [ 'webapp/base/js/host.js', - 'webapp/base/js/host_settings.js', + 'webapp/base/js/host_options.js', ], # Logging and stats JavaScript files. 'remoting_webapp_shared_js_logging_files': [ diff --git a/remoting/webapp/base/js/base.js b/remoting/webapp/base/js/base.js index 602d129..f8c7cc7 100644 --- a/remoting/webapp/base/js/base.js +++ b/remoting/webapp/base/js/base.js @@ -188,17 +188,27 @@ base.deepCopy = function(value) { * @template T */ base.copyWithoutNullFields = function(input) { - /** @const {!Object} */ var result = {}; - if (input) { - for (var field in input) { - var value = /** @type {*} */ (input[field]); + base.mergeWithoutNullFields(result, input); + return result; +}; + +/** + * Merge non-null fields of |src| into |dest|. + * + * @param {!Object<T>} dest + * @param {Object<?T>|undefined} src + * @template T + */ +base.mergeWithoutNullFields = function(dest, src) { + if (src) { + for (var field in src) { + var value = /** @type {*} */ (src[field]); if (value != null) { - result[field] = value; + dest[field] = base.deepCopy(value); } } } - return result; }; /** diff --git a/remoting/webapp/base/js/base_unittest.js b/remoting/webapp/base/js/base_unittest.js index 7fd746f..cecfc8a 100644 --- a/remoting/webapp/base/js/base_unittest.js +++ b/remoting/webapp/base/js/base_unittest.js @@ -110,6 +110,26 @@ QUnit.test('copyWithoutNullFields(null) returns a new empty object', base.copyWithoutNullFields(undefined)); }); +QUnit.test('copyWithoutNullFields does a deep copy', + function(assert) { + var obj = { + a: 'foo', + b: { c: 'bar' } + }; + var copy = base.copyWithoutNullFields(obj); + assert.notEqual(obj.b, copy['b']); +}); + +QUnit.test('mergeWithoutNullFields(null) leaves the destination unchanged', + function(assert) { + var obj = { 'a': 1 }; + var reference = base.deepCopy(obj); + base.mergeWithoutNullFields(obj, null); + assert.deepEqual(obj, reference); + base.mergeWithoutNullFields(obj, undefined); + assert.deepEqual(obj, reference); +}); + QUnit.test('isEmptyObject works', function(assert) { assert.ok(base.isEmptyObject({})); diff --git a/remoting/webapp/base/js/host.js b/remoting/webapp/base/js/host.js index aed63da..1a93bec 100644 --- a/remoting/webapp/base/js/host.js +++ b/remoting/webapp/base/js/host.js @@ -44,92 +44,8 @@ remoting.Host = function(hostId) { this.updatedTime = ''; /** @type {string} */ this.hostOfflineReason = ''; - /** @type {remoting.Host.Options} */ - this.options = new remoting.Host.Options(hostId); -}; - -/** - * @constructor - * @param {!string} hostId - * @struct - */ -remoting.Host.Options = function(hostId) { - /** @private @const */ - this.hostId_ = hostId; - /** @type {boolean} */ - this.shrinkToFit = true; - /** @type {boolean} */ - this.resizeToClient = true; - /** @type {!Object} */ - this.remapKeys = {}; - /** @type {number} */ - this.desktopScale = 1; - /** @type {remoting.PairingInfo} */ - this.pairingInfo = {clientId: '', sharedSecret: ''}; -}; - -remoting.Host.Options.prototype.save = function() { - // TODO(kelvinp): Migrate pairingInfo to use this class as well and get rid of - // remoting.HostSettings. - remoting.HostSettings.save(this.hostId_, this); -}; - - -/** @return {Promise} A promise that resolves when the settings are loaded. */ -remoting.Host.Options.prototype.load = function() { - var that = this; - return base.Promise.as(remoting.HostSettings.load, [this.hostId_]).then( - /** - * @param {Object<string|boolean|number|!Object>} options - */ - function(options) { - // Must be defaulted to true so that app-remoting can resize the host - // upon launching. - // TODO(kelvinp): Uses a separate host options for app-remoting that - // hardcodes resizeToClient to true. - that.resizeToClient = - base.getBooleanAttr(options, 'resizeToClient', true); - that.shrinkToFit = base.getBooleanAttr(options, 'shrinkToFit', true); - that.desktopScale = base.getNumberAttr(options, 'desktopScale', 1); - that.pairingInfo = - /** @type {remoting.PairingInfo} */ ( - base.getObjectAttr(options, 'pairingInfo', that.pairingInfo)); - - // Load the key remappings, allowing for either old or new formats. - var remappings = /** string|!Object */ (options['remapKeys']); - if (typeof(remappings) === 'string') { - remappings = remoting.Host.Options.convertRemapKeys(remappings); - } else if (typeof(remappings) !== 'object') { - remappings = {}; - } - that.remapKeys = /** @type {!Object} */ (base.deepCopy(remappings)); - }); -}; - -/** - * Convert an old-style string key remapping into a new-style dictionary one. - * - * @param {string} remappings - * @return {!Object} The same remapping expressed as a dictionary. - */ -remoting.Host.Options.convertRemapKeys = function(remappings) { - var remappingsArr = remappings.split(','); - var result = {}; - for (var i = 0; i < remappingsArr.length; ++i) { - var keyCodes = remappingsArr[i].split('>'); - if (keyCodes.length != 2) { - console.log('bad remapKey: ' + remappingsArr[i]); - continue; - } - var fromKey = parseInt(keyCodes[0], 0); - var toKey = parseInt(keyCodes[1], 0); - if (!fromKey || !toKey) { - console.log('bad remapKey code: ' + remappingsArr[i]); - continue; - } - result[fromKey] = toKey; - } - return result; + /** @type {remoting.HostOptions} */ + this.options = new remoting.HostOptions(hostId); }; /** diff --git a/remoting/webapp/base/js/host_options.js b/remoting/webapp/base/js/host_options.js new file mode 100644 index 0000000..e70e460 --- /dev/null +++ b/remoting/webapp/base/js/host_options.js @@ -0,0 +1,223 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/** + * @fileoverview + * Class handling saving and restoring of per-host options. + */ + +/** @suppress {duplicate} */ +var remoting = remoting || {}; + +(function(){ + +'use strict'; + +/** + * @param {string} hostId + * @constructor + */ +remoting.HostOptions = function (hostId) { + /** @private @const */ + this.hostId_ = hostId; + + // This class violates the convention that private variables end with an + // underscore because it simplifies the load/save code. + + /** @private {?boolean} */ + this.shrinkToFit = null; + /** @private {?boolean} */ + this.resizeToClient = null; + /** @private {?number} */ + this.desktopScale = null; + /** @private {?remoting.PairingInfo} */ + this.pairingInfo = null; + /** @private {Object} */ + this.remapKeys = null; +}; + +/** @return {boolean} True if the remote desktop should be reduced in size to + * fit a smaller client window; false if scroll-bars or bump-scrolling + * should be used instead. + */ +remoting.HostOptions.prototype.getShrinkToFit = function() { + return (this.shrinkToFit == null) ? true : this.shrinkToFit; +}; + +/** @param {boolean} shrinkToFit */ +remoting.HostOptions.prototype.setShrinkToFit = function(shrinkToFit) { + this.shrinkToFit = shrinkToFit; +}; + +/** @return {boolean} True if the remote desktop should be resized to fit the + * client window size. + */ +remoting.HostOptions.prototype.getResizeToClient = function() { + return (this.resizeToClient == null) ? true : this.resizeToClient; +}; + +/** @param {boolean} resizeToClient */ +remoting.HostOptions.prototype.setResizeToClient = function(resizeToClient) { + this.resizeToClient = resizeToClient; +}; + +/** @return {number} The scaling factor applied when rendering or resizing the + * remote desktop. + */ +remoting.HostOptions.prototype.getDesktopScale = function() { + return (this.desktopScale == null) ? 1 : this.desktopScale; +}; + +/** @param {number} desktopScale */ +remoting.HostOptions.prototype.setDesktopScale = function(desktopScale) { + this.desktopScale = desktopScale; +}; + +/** + * @return {!remoting.PairingInfo} The pairing info for this client/host pair. + */ +remoting.HostOptions.prototype.getPairingInfo = function() { + return (this.pairingInfo == null) + ? {clientId: '', sharedSecret: ''} + : /** @type {remoting.PairingInfo} */ (base.deepCopy(this.pairingInfo)); +}; + +/** + * @param {!remoting.PairingInfo} pairingInfo + */ +remoting.HostOptions.prototype.setPairingInfo = function(pairingInfo) { + this.pairingInfo = + /** @type {remoting.PairingInfo} */ (base.deepCopy(pairingInfo)); +}; + +/** + * @return {!Object} The key remapping to apply to connections to this host. + */ +remoting.HostOptions.prototype.getRemapKeys = function() { + if (this.remapKeys == null) { + return (remoting.platformIsChromeOS()) ? {0x0700e4: 0x0700e7} : {}; + } else { + return /** @type {!Object} */ (base.deepCopy(this.remapKeys)); + } +}; + +/** + * @param {string|!Object} remapKeys The new key remapping, either in the new- + * style dictionary format, or the old-style "from>to,..." string encoding. + */ +remoting.HostOptions.prototype.setRemapKeys = function(remapKeys) { + this.remapKeys = (typeof remapKeys == 'string') + ? remapKeysFromString_(/** @type {string} */(remapKeys)) + : /** @type {!Object} */ (base.deepCopy(remapKeys)) +}; + +/** + * Save the settings for this host. Only settings that have been set using one + * of the setter methods are saved. + * + * @return {Promise} Promise resolved when the save is complete. + */ +remoting.HostOptions.prototype.save = function() { + var settings = base.copyWithoutNullFields(this); + delete settings['hostId_']; // No need to save the hostId + + var hostId = this.hostId_; + return remoting.HostOptions.loadInternal_().then( + function(/** Object */ allHosts) { + allHosts[hostId] = settings; + var newSettings = {}; + newSettings[remoting.HostOptions.KEY_] = JSON.stringify(allHosts); + var deferred = new base.Deferred(); + chrome.storage.local.set(newSettings, + function() { deferred.resolve(); }); + return deferred.promise(); + }); +}; + +/** + * Load the settings for this host. + * + * @return {Promise} Promise resolved when the load is complete. + */ +remoting.HostOptions.prototype.load = function() { + var that = this; + return remoting.HostOptions.loadInternal_().then( + function(/** Object */ allHosts) { + if (allHosts.hasOwnProperty(that.hostId_) && + typeof(allHosts[that.hostId_]) == 'object') { + /** @type {!Object} */ + var host = allHosts[that.hostId_]; + base.mergeWithoutNullFields(that, host); + // Older clients stored remapKeys as a string, which will be decoded + // in setRemapKeys(). + if (typeof that.remapKeys == 'string') { + that.setRemapKeys(/** @type {string} */ (host['remapKeys'])); + } + } + }); +}; + +/** + * Helper function for both load and save. + * + * @return {Promise<Object>} Promise resolved with the current settings for + * all hosts. + * @private + */ +remoting.HostOptions.loadInternal_ = function() { + var deferred = new base.Deferred(); + /** + * @param {Object} storageResult The current options for all hosts. + */ + var onDone = function(storageResult) { + var result = {}; + try { + /** @type {string} */ + var allHosts = storageResult[remoting.HostOptions.KEY_]; + if (allHosts && typeof allHosts == 'string') { + result = base.jsonParseSafe(allHosts); + if (typeof(result) != 'object') { + console.error('Error loading host settings: Not an object'); + result = {}; + } + } + } catch (/** @type {*} */ err) { + console.error('Error loading host settings:', err); + } + deferred.resolve(result); + }; + chrome.storage.local.get(remoting.HostOptions.KEY_, onDone); + return deferred.promise(); +}; + +/** + * Convert an old-style string key remapping into a new-style dictionary one. + * + * @param {string} remappings + * @return {!Object} The same remapping expressed as a dictionary. + */ +function remapKeysFromString_(remappings) { + var remappingsArr = remappings.split(','); + var result = {}; + for (var i = 0; i < remappingsArr.length; ++i) { + var keyCodes = remappingsArr[i].split('>'); + if (keyCodes.length != 2) { + console.log('bad remapKey: ' + remappingsArr[i]); + continue; + } + var fromKey = parseInt(keyCodes[0], 0); + var toKey = parseInt(keyCodes[1], 0); + if (!fromKey || !toKey) { + console.log('bad remapKey code: ' + remappingsArr[i]); + continue; + } + result[fromKey] = toKey; + } + return result; +}; + +/** @type {string} @private */ +remoting.HostOptions.KEY_ = 'remoting-host-options'; + +})(); diff --git a/remoting/webapp/base/js/host_options_unittest.js b/remoting/webapp/base/js/host_options_unittest.js new file mode 100644 index 0000000..a6b1d46 --- /dev/null +++ b/remoting/webapp/base/js/host_options_unittest.js @@ -0,0 +1,106 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +'use strict'; + +QUnit.module('HostOptions', { + beforeEach: function() { + sinon.stub(remoting, 'platformIsChromeOS'); + }, + afterEach: function() { + $testStub(remoting.platformIsChromeOS).restore(); + chrome.storage.local.clear(); + }, +}); + +/** + * @param {!QUnit.Assert} assert + * @param {remoting.HostOptions} options + * @param {boolean} isChromeOS +*/ +function assertDefaults(assert, options, isChromeOS) { + var pairingInfo = {clientId: '', sharedSecret: ''}; + var chromeOsMap = {0x0700e4: 0x0700e7}; + var nonChromeOsMap = {}; + assert.equal(options.getShrinkToFit(), true); + assert.equal(options.getResizeToClient(), true); + assert.equal(options.getDesktopScale(), 1); + assert.deepEqual(options.getPairingInfo(), pairingInfo); + assert.deepEqual(options.getRemapKeys(), + isChromeOS ? chromeOsMap : nonChromeOsMap); +} + +QUnit.test('Per-platform defaults are set correctly', + function(assert) { + + $testStub(remoting.platformIsChromeOS).returns(false); + var options = new remoting.HostOptions('host-id'); + assertDefaults(assert, options, false); + + $testStub(remoting.platformIsChromeOS).returns(true); + options = new remoting.HostOptions('host-id'); + assertDefaults(assert, options, true); +}); + +QUnit.test('Loading a non-existent host yields default values', + function(assert) { + $testStub(remoting.platformIsChromeOS).returns(true); + var options = new remoting.HostOptions('host-id'); + return options.load().then( + function() { + assertDefaults(assert, options, true); + }); +}); + +QUnit.test('Saving and loading a host preserves the saved values', + function(assert) { + var options = new remoting.HostOptions('host-id'); + options.setShrinkToFit(false); + options.setResizeToClient(false); + options.setDesktopScale(2); + options.setRemapKeys({2: 1, 1: 2}); + options.setPairingInfo({ + clientId: 'client-id', + sharedSecret: 'shared-secret' + }); + var optionsCopy = base.deepCopy(options); + + return options.save().then(function() { + return options.load(); + }).then(function() { + assert.deepEqual(optionsCopy, base.deepCopy(options)); + }); +}); + +QUnit.test('Saving a host ignores unset values', + function(assert) { + var options = new remoting.HostOptions('host-id'); + var optionsCopy = base.deepCopy(options); + + return options.save().then(function() { + return options.load(); + }).then(function() { + assert.deepEqual(optionsCopy, base.deepCopy(options)); + }); +}); + +QUnit.test('Old-style (string-formatted) key remappings are parsed correctly', + function(assert) { + var options1 = new remoting.HostOptions('host-id'); + options1.setRemapKeys({2: 1, 1: 2}); + var savedHostOptions = { + 'host-id': { + 'remapKeys': '2>1,1>2' + } + }; + var savedAllOptions = { + 'remoting-host-options': JSON.stringify(savedHostOptions) + }; + chrome.storage.local.set(savedAllOptions); // Mock storage is synchronous + var options2 = new remoting.HostOptions('host-id'); + return options2.load().then( + function() { + assert.deepEqual(options1, options2); + }); +}); diff --git a/remoting/webapp/base/js/host_settings.js b/remoting/webapp/base/js/host_settings.js deleted file mode 100644 index 9257f19..0000000 --- a/remoting/webapp/base/js/host_settings.js +++ /dev/null @@ -1,105 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -/** - * @fileoverview - * Class handling saving and restoring of per-host options. - */ - -'use strict'; - -/** @suppress {duplicate} */ -var remoting = remoting || {}; - -/** @type {Object} */ -remoting.HostSettings = {}; - -/** - * Load the settings for the specified host. Settings are returned as a - * dictionary of (name, value) pairs. - * - * @param {string} hostId The host identifer for which to load options. - * @param {function(Object):void} callback Callback to which the - * current settings for the host are passed. If there are no settings, - * then an empty dictionary is passed. - * @return {void} Nothing. - */ -remoting.HostSettings.load = function(hostId, callback) { - /** - * @param {Object} requestedHost - * @param {Object} allHosts - * @return {void} Nothing. - */ - var onDone = function(requestedHost, allHosts) { - callback(requestedHost); - }; - remoting.HostSettings.loadInternal_(hostId, onDone); -}; - -/** - * Save the settings for the specified hosts. Existing settings with the same - * names will be overwritten; settings not currently saved will be created. - * - * @param {string} hostId The host identifer for which to save options. - * @param {Object} options The options to save, expressed as a dictionary of - * (name, value) pairs. - * @param {function():void=} opt_callback Optional completion callback. - * @return {void} Nothing. - */ -remoting.HostSettings.save = function(hostId, options, opt_callback) { - /** - * @param {Object} requestedHost - * @param {Object} allHosts - * @return {void} Nothing. - */ - var onDone = function(requestedHost, allHosts) { - for (var option in options) { - requestedHost[option] = options[option]; - } - allHosts[hostId] = requestedHost; - var newSettings = {}; - newSettings[remoting.HostSettings.KEY_] = JSON.stringify(allHosts); - chrome.storage.local.set(newSettings, opt_callback); - }; - remoting.HostSettings.loadInternal_(hostId, onDone); -}; - -/** - * Helper function for both load and save. - * - * @param {string} hostId The host identifer for which to load options. - * @param {function(Object, Object):void} callback Callback to which the - * current settings for the specified host and for all hosts are passed. - * @return {void} Nothing. - */ -remoting.HostSettings.loadInternal_ = function(hostId, callback) { - /** - * @param {Object<string>} allHosts The current options for all hosts. - * @return {void} Nothing. - */ - var onDone = function(allHosts) { - var result = {}; - try { - var hosts = allHosts[remoting.HostSettings.KEY_]; - if (hosts) { - result = base.jsonParseSafe(hosts); - if (typeof(result) != 'object') { - console.error("Error loading host settings: Not an object"); - result = {}; - } else if (/** @type {Object} */ (result).hasOwnProperty(hostId) && - typeof(result[hostId]) == 'object') { - callback(result[hostId], result); - return; - } - } - } catch (/** @type {*} */ err) { - console.error('Error loading host settings:', err); - } - callback({}, /** @type {Object} */ (result)); - }; - chrome.storage.local.get(remoting.HostSettings.KEY_, onDone); -}; - -/** @type {string} @private */ -remoting.HostSettings.KEY_ = 'remoting-host-options'; diff --git a/remoting/webapp/crd/js/crd_experimental.js b/remoting/webapp/crd/js/crd_experimental.js index 7586ff7..36019a1 100644 --- a/remoting/webapp/crd/js/crd_experimental.js +++ b/remoting/webapp/crd/js/crd_experimental.js @@ -53,7 +53,6 @@ remoting.experimental.setRemapKeys = function(remappings) { var drApp = /** @type {remoting.DesktopRemoting} */ (remoting.app); if (drApp instanceof remoting.DesktopRemoting) { var connectedView = drApp.getConnectedViewForTesting(); - connectedView.setRemapKeys( - remoting.Host.Options.convertRemapKeys(remappings)); + connectedView.setRemapKeys(remappings); } }; diff --git a/remoting/webapp/crd/js/desktop_connected_view.js b/remoting/webapp/crd/js/desktop_connected_view.js index 1f528d3..22cbf4b 100644 --- a/remoting/webapp/crd/js/desktop_connected_view.js +++ b/remoting/webapp/crd/js/desktop_connected_view.js @@ -111,7 +111,7 @@ remoting.DesktopConnectedView.prototype.getResizeToClient = function() { * (Windows, Command) key. */ remoting.DesktopConnectedView.prototype.getMapRightCtrl = function() { - return this.host_.options.remapKeys[0x0700e4] === 0x0700e7; + return this.host_.options.getRemapKeys()[0x0700e4] === 0x0700e7; }; remoting.DesktopConnectedView.prototype.toggleStats = function() { @@ -255,12 +255,13 @@ remoting.DesktopConnectedView.prototype.setMapRightCtrl = function(enable) { return; // In case right Ctrl is mapped, but not to right Meta. } + var remapKeys = this.host_.options.getRemapKeys(); if (enable) { - this.host_.options.remapKeys[0x0700e4] = 0x0700e7; + remapKeys[0x0700e4] = 0x0700e7; } else { - delete this.host_.options.remapKeys[0x0700e4] + delete remapKeys[0x0700e4] } - this.setRemapKeys(this.host_.options.remapKeys); + this.setRemapKeys(remapKeys); }; /** @@ -287,14 +288,13 @@ remoting.DesktopConnectedView.prototype.sendPrintScreen = function() { * Sets and stores the key remapping setting for the current host. If set, * these mappings override the defaults for the client platform. * - * @param {!Object} remappings + * @param {string|!Object} remappings */ remoting.DesktopConnectedView.prototype.setRemapKeys = function(remappings) { - this.plugin_.setRemapKeys(remappings); // Save the new remapping setting. - this.host_.options.remapKeys = - /** @type {!Object} */ (base.deepCopy(remappings)); + this.host_.options.setRemapKeys(remappings); this.host_.options.save(); + this.plugin_.setRemapKeys(this.host_.options.getRemapKeys()); }; /** @param {remoting.VideoFrameRecorder} recorder */ @@ -341,4 +341,4 @@ remoting.DesktopConnectedView.prototype.startStopRecording = function() { */ remoting.DesktopConnectedView.create = function(container, connectionInfo) { return new remoting.DesktopConnectedView(container, connectionInfo); -};
\ No newline at end of file +}; diff --git a/remoting/webapp/crd/js/desktop_remoting_activity.js b/remoting/webapp/crd/js/desktop_remoting_activity.js index 5b48b1e..b4c3a079 100644 --- a/remoting/webapp/crd/js/desktop_remoting_activity.js +++ b/remoting/webapp/crd/js/desktop_remoting_activity.js @@ -94,12 +94,8 @@ remoting.DesktopRemotingActivity.prototype.onConnected = document.getElementById('client-container'), connectionInfo); // Apply the default or previously-specified keyboard remapping. - var remapping = connectionInfo.host().options.remapKeys; - if (base.isEmptyObject(remapping) && remoting.platformIsChromeOS()) { - // Under ChromeOS, remap the right Control key to the right Win/Cmd key. - remapping = {0x0700e4: 0x0700e7}; - } - connectionInfo.plugin().setRemapKeys(remapping); + var remapping = connectionInfo.host().options.getRemapKeys(); + this.connectedView_.setRemapKeys(remapping); if (connectionInfo.plugin().hasCapability( remoting.ClientSession.Capability.VIDEO_RECORDER)) { diff --git a/remoting/webapp/crd/js/desktop_viewport.js b/remoting/webapp/crd/js/desktop_viewport.js index 0eae605..12b6b9b 100644 --- a/remoting/webapp/crd/js/desktop_viewport.js +++ b/remoting/webapp/crd/js/desktop_viewport.js @@ -21,7 +21,7 @@ var remoting = remoting || {}; * @param {HTMLElement} rootElement The outer element with id=scroller that we * are showing scrollbars on. * @param {remoting.HostDesktop} hostDesktop - * @param {remoting.Host.Options} hostOptions + * @param {remoting.HostOptions} hostOptions * * @constructor * @implements {base.Disposable} @@ -55,7 +55,7 @@ remoting.DesktopViewport = function(rootElement, hostDesktop, hostOptions) { this.hostDesktop_, remoting.HostDesktop.Events.sizeChanged, this.onDesktopSizeChanged_.bind(this))); - if (this.hostOptions_.resizeToClient) { + if (this.hostOptions_.getResizeToClient()) { this.resizeHostDesktop_(); } else { this.onDesktopSizeChanged_(); @@ -73,14 +73,14 @@ remoting.DesktopViewport.prototype.dispose = function() { * @return {boolean} True if shrink-to-fit is enabled; false otherwise. */ remoting.DesktopViewport.prototype.getShrinkToFit = function() { - return this.hostOptions_.shrinkToFit; + return this.hostOptions_.getShrinkToFit(); }; /** * @return {boolean} True if resize-to-client is enabled; false otherwise. */ remoting.DesktopViewport.prototype.getResizeToClient = function() { - return this.hostOptions_.resizeToClient; + return this.hostOptions_.getResizeToClient(); }; /** @@ -133,14 +133,14 @@ remoting.DesktopViewport.prototype.getBumpScrollerForTesting = function() { */ remoting.DesktopViewport.prototype.setScreenMode = function(shrinkToFit, resizeToClient) { - if (resizeToClient && !this.hostOptions_.resizeToClient) { + if (resizeToClient && !this.hostOptions_.getResizeToClient()) { this.resizeHostDesktop_(); } // If enabling shrink, reset bump-scroll offsets. - var needsScrollReset = shrinkToFit && !this.hostOptions_.shrinkToFit; - this.hostOptions_.shrinkToFit = shrinkToFit; - this.hostOptions_.resizeToClient = resizeToClient; + var needsScrollReset = shrinkToFit && !this.hostOptions_.getShrinkToFit(); + this.hostOptions_.setShrinkToFit(shrinkToFit); + this.hostOptions_.setResizeToClient(resizeToClient); this.hostOptions_.save(); this.updateScrollbarVisibility_(); @@ -231,7 +231,7 @@ remoting.DesktopViewport.prototype.onResize = function() { // Defer notifying the host of the change until the window stops resizing, to // avoid overloading the control channel with notifications. - if (this.hostOptions_.resizeToClient) { + if (this.hostOptions_.getResizeToClient()) { var kResizeRateLimitMs = 250; var clientArea = this.getClientArea(); this.resizeTimer_ = window.setTimeout(this.resizeHostDesktop_.bind(this), @@ -262,9 +262,10 @@ remoting.DesktopViewport.prototype.getClientArea = function() { */ remoting.DesktopViewport.prototype.resizeHostDesktop_ = function() { var clientArea = this.getClientArea(); - this.hostDesktop_.resize(clientArea.width * this.hostOptions_.desktopScale, - clientArea.height * this.hostOptions_.desktopScale, - window.devicePixelRatio); + this.hostDesktop_.resize( + clientArea.width * this.hostOptions_.getDesktopScale(), + clientArea.height * this.hostOptions_.getDesktopScale(), + window.devicePixelRatio); }; /** @@ -301,7 +302,7 @@ remoting.DesktopViewport.prototype.updateScrollbarVisibility_ = function() { var needsScrollY = false; var needsScrollX = false; - if (!this.hostOptions_.shrinkToFit) { + if (!this.hostOptions_.getShrinkToFit()) { // Determine whether or not horizontal or vertical scrollbars are // required, taking into account their width. var clientArea = this.getClientArea(); @@ -332,8 +333,8 @@ remoting.DesktopViewport.prototype.updateDimensions_ = function() { y: dimensions.yDpi }; var newSize = remoting.Viewport.choosePluginSize( this.getClientArea(), window.devicePixelRatio, - desktopSize, desktopDpi, this.hostOptions_.desktopScale, - remoting.fullscreen.isActive(), this.hostOptions_.shrinkToFit); + desktopSize, desktopDpi, this.hostOptions_.getDesktopScale(), + remoting.fullscreen.isActive(), this.hostOptions_.getShrinkToFit()); // Resize the plugin if necessary. console.log('plugin dimensions:' + newSize.width + 'x' + newSize.height); @@ -355,7 +356,7 @@ remoting.DesktopViewport.prototype.resetScroll_ = function() { * @param {number} desktopScale Scale factor to apply. */ remoting.DesktopViewport.prototype.setDesktopScale = function(desktopScale) { - this.hostOptions_.desktopScale = desktopScale; + this.hostOptions_.setDesktopScale(desktopScale); // onResize() will update the plugin size and scrollbars for the new // scaled plugin dimensions, and send a client resolution notification. diff --git a/remoting/webapp/crd/js/me2me_activity.js b/remoting/webapp/crd/js/me2me_activity.js index 3fd8251..5a35735 100644 --- a/remoting/webapp/crd/js/me2me_activity.js +++ b/remoting/webapp/crd/js/me2me_activity.js @@ -159,8 +159,7 @@ remoting.Me2MeActivity.prototype.createCredentialsProvider_ = function() { return new remoting.CredentialsProvider({ fetchPin: requestPin, - pairingInfo: /** @type{remoting.PairingInfo} */ ( - base.deepCopy(host.options.pairingInfo)), + pairingInfo: host.options.getPairingInfo(), fetchThirdPartyToken: fetchThirdPartyToken }); }; @@ -367,8 +366,8 @@ remoting.PinDialog.prototype.requestPairingIfNecessary = function(plugin) { * @param {string} sharedSecret */ var onPairingComplete = function(clientId, sharedSecret) { - that.host_.options.pairingInfo.clientId = clientId; - that.host_.options.pairingInfo.sharedSecret = sharedSecret; + that.host_.options.setPairingInfo({'clientId': clientId, + 'sharedSecret': sharedSecret}); that.host_.options.save(); }; diff --git a/remoting/webapp/crd/js/remoting_activity_test_driver.js b/remoting/webapp/crd/js/remoting_activity_test_driver.js index 462a51c..e5a7034 100644 --- a/remoting/webapp/crd/js/remoting_activity_test_driver.js +++ b/remoting/webapp/crd/js/remoting_activity_test_driver.js @@ -45,6 +45,8 @@ var MockDesktopConnectedView = function() {}; MockDesktopConnectedView.prototype.setVideoFrameRecorder = function() {}; /** @override */ MockDesktopConnectedView.prototype.dispose = function() {}; +/** @override */ +MockDesktopConnectedView.prototype.setRemapKeys = function() {}; /** * A test driver that mocks out the UI components that are required by the @@ -233,4 +235,4 @@ remoting.Me2MeTestDriver.FIXTURE = '<div class="host-needs-update-message"></div>' + '</div>'; -})();
\ No newline at end of file +})(); diff --git a/remoting/webapp/files.gni b/remoting/webapp/files.gni index 85d4409..8a0e9e9 100644 --- a/remoting/webapp/files.gni +++ b/remoting/webapp/files.gni @@ -90,6 +90,7 @@ remoting_webapp_unittests_js_files = [ "base/js/dns_blackhole_checker_unittest.js", "base/js/error_unittest.js", "base/js/fallback_signal_strategy_unittest.js", + "base/js/host_options_unittest.js", "base/js/identity_unittest.js", "base/js/ipc_unittest.js", "base/js/l10n_unittest.js", @@ -201,7 +202,7 @@ remoting_webapp_shared_js_core_files = [ # Host JavaScript files. remoting_webapp_shared_js_host_files = [ "base/js/host.js", - "base/js/host_settings.js", + "base/js/host_options.js", ] # Logging and stats JavaScript files. |