Commit d2da50a8 authored by garykac@chromium.org's avatar garykac@chromium.org

Add basic versioning check to Chromoting's plugin/JS code.

Fixup order of elements in the ScriptableObject interface header. It's supposed to match the .CC file but had gotten seriously out of sync.

BUG=none
TEST=manual


Review URL: http://codereview.chromium.org/7065036

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86655 0039d316-1c4b-4281-b951-d872f2087c98
parent cfa46c0e
......@@ -6,6 +6,16 @@
// Only the most recent <n> lines are displayed.
var MAX_DEBUG_LOG_SIZE = 1000;
// Chromoting session API version (for this javascript).
// This is compared with the plugin API version to verify that they are
// compatible.
chromoting.apiVersion = 1;
// The oldest API version that we support.
// This will differ from the |apiVersion| if we decide to maintain backward
// compatibility with older API versions.
chromoting.apiMinVersion = 1;
// Message id so that we can identify (and ignore) message fade operations for
// old messages. This starts at 1 and is incremented for each new message.
chromoting.messageId = 1;
......@@ -93,6 +103,11 @@ function sendIq(msg) {
"&host_jid=" + encodeURIComponent(chromoting.hostjid));
}
function checkVersion(plugin) {
return chromoting.apiVersion >= plugin.apiMinVersion &&
plugin.apiVersion >= chromoting.apiMinVersion;
}
function init() {
// Kick off the connection.
var plugin = document.getElementById('chromoting');
......@@ -123,6 +138,12 @@ function init() {
plugin.desktopSizeUpdate = desktopSizeChanged;
plugin.loginChallenge = loginChallengeCallback;
if (!checkVersion(plugin)) {
// TODO(garykac): We need better messaging here. Perhaps an install link.
setClientStateMessage("Out of date. Please re-install.");
return;
}
addToDebugLog('Connect to ' + chromoting.hostname + ' as user ' +
chromoting.username);
......
......@@ -18,6 +18,8 @@ namespace remoting {
namespace {
const char kApiVersionAttribute[] = "apiVersion";
const char kApiMinVersionAttribute[] = "apiMinVersion";
const char kConnectionInfoUpdate[] = "connectionInfoUpdate";
const char kDebugInfo[] = "debugInfo";
const char kDesktopHeight[] = "desktopHeight";
......@@ -48,6 +50,14 @@ void ChromotingScriptableObject::Init() {
// Property addition order should match the interface description at the
// top of chromoting_scriptable_object.h.
// Plugin API version.
// This should be incremented whenever the API interface changes.
AddAttribute(kApiVersionAttribute, Var(1));
// This should be updated whenever we remove support for an older version
// of the API.
AddAttribute(kApiMinVersionAttribute, Var(1));
// Connection status.
AddAttribute(kStatusAttribute, Var(STATUS_UNKNOWN));
......
......@@ -7,6 +7,16 @@
//
// interface ChromotingScriptableObject {
//
// // Chromoting session API version (for this plugin).
// // This is compared with the javascript API version to verify that they are
// // compatible.
// readonly attribute unsigned short apiVersion;
//
// // The oldest API version that we support.
// // This will differ from |apiVersion| if we decide to maintain backward
// // compatibility with older API versions.
// readonly attribute unsigned short apiMinVersion;
//
// // Dimension of the desktop area.
// readonly attribute int desktopWidth;
// readonly attribute int desktopHeight;
......
......@@ -5,8 +5,19 @@
// Maximum numer of lines to record in the debug log.
// Only the most recent <n> lines are displayed.
var MAX_DEBUG_LOG_SIZE = 1000;
var remoting = chrome.extension.getBackgroundPage().remoting;
// Chromoting session API version (for this javascript).
// This is compared with the plugin API version to verify that they are
// compatible.
remoting.apiVersion = 1;
// The oldest API version that we support.
// This will differ from the |apiVersion| if we maintain backward
// compatibility with older API versions.
remoting.apiMinVersion = 1;
// Message id so that we can identify (and ignore) message fade operations for
// old messages. This starts at 1 and is incremented for each new message.
remoting.messageId = 1;
......@@ -95,6 +106,11 @@ function sendIq(msg) {
'&host_jid=' + encodeURIComponent(remoting.hostjid));
}
function checkVersion(plugin) {
return remoting.apiVersion >= plugin.apiMinVersion &&
plugin.apiVersion >= remoting.apiMinVersion;
}
function init() {
// Kick off the connection.
var plugin = document.getElementById('remoting');
......@@ -116,6 +132,12 @@ function init() {
plugin.desktopSizeUpdate = desktopSizeChanged;
plugin.loginChallenge = loginChallengeCallback;
if (!checkVersion(plugin)) {
// TODO(garykac): We need better messaging here. Perhaps an install link.
setClientStateMessage("Out of date. Please re-install.");
return;
}
addToDebugLog('Connect as user ' + remoting.username);
// TODO(garykac): Clean exit if |connect| isn't a function.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment