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

Unified Diff: remoting/webapp/crd/js/client_plugin_impl.js

Issue 929323003: Separate host desktop related functionality into remoting.HostDesktop (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Jamie's feedback Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: remoting/webapp/crd/js/client_plugin_impl.js
diff --git a/remoting/webapp/crd/js/client_plugin_impl.js b/remoting/webapp/crd/js/client_plugin_impl.js
index 6327770c4ffd662b1d8ae0d416da07b96719f453..87d3d18a4da25659badee3d38bd06f87cf6b1a12 100644
--- a/remoting/webapp/crd/js/client_plugin_impl.js
+++ b/remoting/webapp/crd/js/client_plugin_impl.js
@@ -48,15 +48,6 @@ remoting.ClientPluginImpl = function(container, onExtensionMessage,
*/
this.requiredCapabilities_ = requiredCapabilities;
- /** @private */
- this.desktopWidth_ = 0;
- /** @private */
- this.desktopHeight_ = 0;
- /** @private */
- this.desktopXDpi_ = 96;
- /** @private */
- this.desktopYDpi_ = 96;
-
/**
* @param {string} iq The Iq stanza received from the host.
* @private
@@ -95,13 +86,6 @@ remoting.ClientPluginImpl = function(container, onExtensionMessage,
*/
this.fetchThirdPartyTokenHandler_ = function(
tokenUrl, hostPublicKey, scope) {};
- /** @private */
- this.onDesktopSizeUpdateHandler_ = function () {};
- /**
- * @param {Array<Array<number>>} rects
- * @private
- */
- this.onDesktopShapeUpdateHandler_ = function (rects) {};
/**
* @param {!Array<string>} capabilities The negotiated capabilities.
* @private
@@ -149,6 +133,11 @@ remoting.ClientPluginImpl = function(container, onExtensionMessage,
*/
this.capabilities_ = [];
/**
+ * @type {!Array<string>}
+ * @private
+ */
+ this.hostCapabilities_ = [];
+ /**
* @type {boolean}
* @private
*/
@@ -180,6 +169,9 @@ remoting.ClientPluginImpl = function(container, onExtensionMessage,
if (remoting.settings.CLIENT_PLUGIN_TYPE == 'native') {
window.setTimeout(this.showPluginForClickToPlay_.bind(this), 500);
}
+
+ this.hostDesktop_ = new remoting.ClientPlugin.HostDesktopImpl(
+ this, this.postMessage_.bind(this));
};
/**
@@ -265,22 +257,6 @@ remoting.ClientPluginImpl.prototype.setConnectionReadyHandler =
};
/**
- * @param {function():void} handler
- */
-remoting.ClientPluginImpl.prototype.setDesktopSizeUpdateHandler =
- function(handler) {
- this.onDesktopSizeUpdateHandler_ = handler;
-};
-
-/**
- * @param {function(Array<Array<number>>):void} handler
- */
-remoting.ClientPluginImpl.prototype.setDesktopShapeUpdateHandler =
- function(handler) {
- this.onDesktopShapeUpdateHandler_ = handler;
-};
-
-/**
* @param {function(!Array<string>):void} handler
*/
remoting.ClientPluginImpl.prototype.setCapabilitiesHandler = function(handler) {
@@ -374,14 +350,6 @@ remoting.ClientPluginImpl.prototype.handleMessageMethod_ = function(message) {
tokenize(getStringAttr(message.data, 'apiFeatures'));
// Negotiate capabilities.
-
- /** @type {!Array<string>} */
- var requestedCapabilities = [];
- if ('requestedCapabilities' in message.data) {
- requestedCapabilities =
- tokenize(getStringAttr(message.data, 'requestedCapabilities'));
- }
-
/** @type {!Array<string>} */
var supportedCapabilities = [];
if ('supportedCapabilities' in message.data) {
@@ -425,23 +393,9 @@ remoting.ClientPluginImpl.prototype.handleMessageMethod_ = function(message) {
this.onRouteChangedHandler_(channel, connectionType);
} else if (message.method == 'onDesktopSize') {
- this.desktopWidth_ = getNumberAttr(message.data, 'width');
- this.desktopHeight_ = getNumberAttr(message.data, 'height');
- this.desktopXDpi_ = getNumberAttr(message.data, 'x_dpi', 96);
- this.desktopYDpi_ = getNumberAttr(message.data, 'y_dpi', 96);
- this.onDesktopSizeUpdateHandler_();
-
+ this.hostDesktop_.onSizeUpdated(message);
} else if (message.method == 'onDesktopShape') {
- var rects = getArrayAttr(message.data, 'rects');
- for (var i = 0; i < rects.length; ++i) {
- /** @type {Array<number>} */
- var rect = rects[i];
- if (typeof rect != 'object' || rect.length != 4) {
- throw 'Received invalid onDesktopShape message';
- }
- }
- this.onDesktopShapeUpdateHandler_(rects);
-
+ this.hostDesktop_.onShapeUpdated(message);
} else if (message.method == 'onPerfStats') {
// Return value is ignored. These calls will throw an error if the value
// is not a number.
@@ -601,6 +555,19 @@ remoting.ClientPluginImpl.prototype.hasFeature = function(feature) {
};
/**
+ * @param {string} capability The capability to test for.
+ * @return {boolean} True if the host supports the named capability.
+ */
+remoting.ClientPluginImpl.prototype.hasCapability = function(capability) {
Jamie 2015/02/19 22:44:04 I don't think you need this any more.
kelvinp 2015/02/19 23:36:20 I am keeping this function as it still would be us
+ if (!this.hostCapabilities_) {
+ console.error(
+ "hasCapability() is called before the capabilities are received.");
+ return false;
+ }
+ return this.hostCapabilities_.indexOf(capability) > -1;
+};
+
+/**
* @return {boolean} True if the plugin supports the injectKeyEvent API.
*/
remoting.ClientPluginImpl.prototype.isInjectKeyEventSupported = function() {
@@ -758,14 +725,7 @@ remoting.ClientPluginImpl.prototype.sendClipboardItem =
*/
remoting.ClientPluginImpl.prototype.notifyClientResolution =
function(width, height, device_scale) {
- if (this.hasFeature(remoting.ClientPlugin.Feature.NOTIFY_CLIENT_RESOLUTION)) {
- var dpi = Math.floor(device_scale * 96);
- this.plugin_.postMessage(JSON.stringify(
- { method: 'notifyClientResolution',
- data: { width: Math.floor(width * device_scale),
- height: Math.floor(height * device_scale),
- x_dpi: dpi, y_dpi: dpi }}));
- }
+ this.hostDesktop_.resize(width, height, device_scale);
};
/**
@@ -907,21 +867,9 @@ remoting.ClientPluginImpl.prototype.sendClientMessage =
};
-remoting.ClientPluginImpl.prototype.getDesktopWidth = function() {
- return this.desktopWidth_;
-}
-
-remoting.ClientPluginImpl.prototype.getDesktopHeight = function() {
- return this.desktopHeight_;
-}
-
-remoting.ClientPluginImpl.prototype.getDesktopXDpi = function() {
- return this.desktopXDpi_;
-}
-
-remoting.ClientPluginImpl.prototype.getDesktopYDpi = function() {
- return this.desktopYDpi_;
-}
+remoting.ClientPluginImpl.prototype.hostDesktop = function() {
+ return this.hostDesktop_;
+};
/**
* If we haven't yet received a "hello" message from the plugin, change its
@@ -956,6 +904,17 @@ remoting.ClientPluginImpl.prototype.hidePluginForClickToPlay_ = function() {
this.plugin_.style.position = '';
};
+/**
+ * Callback passed to submodules to post a message to the plugin.
+ *
+ * @param {Object} objectLiteral
Jamie 2015/02/19 22:44:04 |objectLiteral| doesn't describe what this paramet
kelvinp 2015/02/19 23:36:20 Done.
+ * @private
+ */
+remoting.ClientPluginImpl.prototype.postMessage_ = function(objectLiteral) {
+ if (this.plugin_ && this.plugin_.postMessage) {
+ this.plugin_.postMessage(JSON.stringify(objectLiteral));
+ }
+};
/**
* @constructor

Powered by Google App Engine
This is Rietveld 408576698