diff options
author | dmaclach@chromium.org <dmaclach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-12 20:21:42 +0000 |
---|---|---|
committer | dmaclach@chromium.org <dmaclach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-12 20:21:42 +0000 |
commit | 0926ff2adeefa0aff414ec8ee1bf542fa72c3fa2 (patch) | |
tree | e708aa97fc8dcaf73a8d67ceedc258af96175099 /remoting/webapp | |
parent | 791dde56613234c90fb0e4444cacabd7674610b7 (diff) | |
download | chromium_src-0926ff2adeefa0aff414ec8ee1bf542fa72c3fa2.zip chromium_src-0926ff2adeefa0aff414ec8ee1bf542fa72c3fa2.tar.gz chromium_src-0926ff2adeefa0aff414ec8ee1bf542fa72c3fa2.tar.bz2 |
Mocks up the host plugin.
BUG=NONE
TEST=BUILD
Review URL: http://codereview.chromium.org/6982014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@85174 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/webapp')
-rw-r--r-- | remoting/webapp/build-webapp.py | 47 | ||||
-rw-r--r-- | remoting/webapp/me2mom/choice.html | 12 | ||||
-rw-r--r-- | remoting/webapp/me2mom/remoting.js | 78 |
3 files changed, 90 insertions, 47 deletions
diff --git a/remoting/webapp/build-webapp.py b/remoting/webapp/build-webapp.py index 8d1c519..8e137e3 100644 --- a/remoting/webapp/build-webapp.py +++ b/remoting/webapp/build-webapp.py @@ -4,11 +4,25 @@ # found in the LICENSE file. # Copies the remoting webapp resources and host plugin into a single directory. +# Massages the files appropriately with host plugin data. + +# Python 2.5 compatibility +from __future__ import with_statement import os import shutil import sys +def findAndReplace( filepath, findString, replaceString ): + oldFilename = os.path.basename(filepath) + '.old' + oldFilepath = os.path.join(os.path.dirname(filepath), oldFilename) + os.rename(filepath, oldFilepath) + with open(oldFilepath) as input: + with open(filepath, 'w') as output: + for s in input: + output.write(s.replace(findString, replaceString)) + os.remove(oldFilepath) + # Temporary hack to work around fact that some build machines don't have # python 2.6 # TODO(dmaclach): fix this @@ -20,13 +34,14 @@ except Exception: # Do not copy git and svn files into the build. IGNORE_PATTERNS = ('.git', '.svn') -if len(sys.argv) != 4: - print 'Usage: build-webapp.py <webapp-resource-dir> <host-plugin> <dst>' +if len(sys.argv) != 5: + print 'Usage: build-webapp.py <mime-type> <webapp-dir> <host-plugin> <dst>' sys.exit(1) -resources = sys.argv[1] -plugin = sys.argv[2] -destination = sys.argv[3] +mimetype = sys.argv[1] +resources = sys.argv[2] +plugin = sys.argv[3] +destination = sys.argv[4] try: shutil.rmtree(destination) @@ -51,17 +66,11 @@ else: shutil.copy2(plugin, newPluginPath) # Now massage the manifest to the right plugin name -manifestPath = os.path.join(destination, 'manifest.json') -manifestBasePath = os.path.join(destination, 'manifest.base') -os.rename(manifestPath, manifestBasePath) -input = open(manifestBasePath) -output = open(manifestPath, 'w') -for s in input: - # Using this complex matching string to keep the json valid so that people - # who don't need the host plugin don't need to build the plugin all the time. - output.write(s.replace('"PLUGINS": "PLACEHOLDER"', - '"plugins": [\n { "path": "' - + pluginName +'" }\n ]')) -input.close() -output.close() -os.remove(manifestBasePath) +findAndReplace(os.path.join(destination,'manifest.json'), + '"PLUGINS": "PLACEHOLDER"', + '"plugins": [\n { "path": "' + pluginName +'" }\n ]') + +# Now massage files with our mimetype +findAndReplace(os.path.join(destination,'remoting.js'), + 'HOST_PLUGIN_MIMETYPE', + mimetype) diff --git a/remoting/webapp/me2mom/choice.html b/remoting/webapp/me2mom/choice.html index 01071e8..3c6cb52 100644 --- a/remoting/webapp/me2mom/choice.html +++ b/remoting/webapp/me2mom/choice.html @@ -31,6 +31,8 @@ found in the LICENSE file. <!-- Host UI --> <div id="host"> + <div id="plugin_wrapper"> + </div> <div id="unshared"> <p class="message"> @@ -50,13 +52,19 @@ found in the LICENSE file. </p> </div> + <div id="preparing_to_share"> + <p class="message"> + Connecting... + </p> + </div> + <div id="ready_to_share"> <p class="message"> To begin sharing your desktop, read out the access code below to the person who will be assisting you. </p> <p id="access_code_display"> - ABCD-1234-WXYZ + FAILED! </p> <p class="message"> Waiting for connection... @@ -77,7 +85,7 @@ found in the LICENSE file. </p> <button type="button" class="cancel" - onclick="setHostMode('unshared');"> + onclick="cancelShare();"> Stop sharing </button> </div> diff --git a/remoting/webapp/me2mom/remoting.js b/remoting/webapp/me2mom/remoting.js index 7912710..ac496ed 100644 --- a/remoting/webapp/me2mom/remoting.js +++ b/remoting/webapp/me2mom/remoting.js @@ -2,13 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -var chromoting = {}; +var remoting = {}; XMPP_TOKEN_NAME = 'xmpp_token'; OAUTH2_TOKEN_NAME = 'oauth2_token'; +HOST_PLUGIN_ID = 'host_plugin_id'; function updateAuthStatus() { var oauth1_status = document.getElementById('oauth1_status'); - if (chromoting.oauth.hasToken()) { + if (remoting.oauth.hasToken()) { oauth1_status.innerText = 'OK'; oauth1_status.style.color='green'; } else { @@ -18,29 +19,29 @@ function updateAuthStatus() { } function authorizeOAuth1() { - chromoting.oauth.authorize(updateAuthStatus); + remoting.oauth.authorize(updateAuthStatus); } function clearOAuth1() { - chromoting.oauth.clearTokens(); + remoting.oauth.clearTokens(); updateAuthStatus(); } function initAuthPanel_() { document.getElementById('xmpp_token').value = - chromoting.getItem(XMPP_TOKEN_NAME); + remoting.getItem(XMPP_TOKEN_NAME); updateAuthStatus(); } function initBackgroundFuncs_() { - chromoting.getItem = chrome.extension.getBackgroundPage().getItem; - chromoting.setItem = chrome.extension.getBackgroundPage().setItem; - chromoting.oauth = chrome.extension.getBackgroundPage().oauth; + remoting.getItem = chrome.extension.getBackgroundPage().getItem; + remoting.setItem = chrome.extension.getBackgroundPage().setItem; + remoting.oauth = chrome.extension.getBackgroundPage().oauth; } function saveCredentials(form) { - chromoting.setItem(OAUTH2_TOKEN_NAME, form['oauth2_token'].value); - chromoting.setItem(XMPP_TOKEN_NAME, form['xmpp_token'].value); + remoting.setItem(OAUTH2_TOKEN_NAME, form['oauth2_token'].value); + remoting.setItem(XMPP_TOKEN_NAME, form['xmpp_token'].value); } function init() { @@ -48,7 +49,7 @@ function init() { initAuthPanel_(); setHostMode('unshared'); setClientMode('unconnected'); - setGlobalMode(chromoting.getItem('startup-mode', 'host')); + setGlobalMode(remoting.getItem('startup-mode', 'host')); } // Show the div with id |mode| and hide those with other ids in |modes|. @@ -69,11 +70,14 @@ function setGlobalMode(mode) { function setGlobalModePersistent(mode) { setGlobalMode(mode); - chromoting.setItem('startup-mode', mode); + remoting.setItem('startup-mode', mode); } function setHostMode(mode) { - setMode_(mode, ['unshared', 'ready_to_share', 'shared']); + setMode_(mode, ['unshared', + 'preparing_to_share', + 'ready_to_share', + 'shared']); } function setClientMode(mode) { @@ -81,33 +85,55 @@ function setClientMode(mode) { } function tryShare() { - setHostMode('ready_to_share'); - chromoting.hostTimer = setTimeout( - function() { - setHostMode('shared'); - }, - 3000); + var div = document.getElementById('plugin_wrapper'); + var plugin = document.createElement('embed'); + plugin.setAttribute('type', 'HOST_PLUGIN_MIMETYPE'); + plugin.setAttribute('hidden', 'true'); + plugin.setAttribute('id', HOST_PLUGIN_ID); + div.appendChild(plugin); + plugin.onStateChanged = onStateChanged; + plugin.connect('uid', 'authtoken'); +} + +function onStateChanged() { + var plugin = document.getElementById(HOST_PLUGIN_ID); + var state = plugin.state; + if (state == plugin.REQUESTED_SUPPORT_ID) { + setHostMode('preparing_to_share'); + } else if (state == plugin.RECEIVED_SUPPORT_ID) { + var support_id = plugin.supportID; + var access_code = document.getElementById('access_code_display'); + access_code.innerHTML = support_id; + setHostMode('ready_to_share'); + } else if (state == plugin.CONNECTED) { + setHostMode('shared'); + } else if (state == plugin.DISCONNECTED) { + setHostMode('unshared'); + plugin.parentNode.removeChild(plugin); + } else { + window.alert("Unknown state -> " + state); + } } function cancelShare() { - setHostMode('unshared'); - clearTimeout(chromoting.hostTimer); + var plugin = document.getElementById(HOST_PLUGIN_ID); + plugin.disconnect(); } function tryConnect(form) { - chromoting.accessCode = form['access_code_entry'].value; + remoting.accessCode = form['access_code_entry'].value; setClientMode('connecting'); - chromoting.clientTimer = setTimeout( + remoting.clientTimer = setTimeout( function() { var code = document.getElementById('access_code_proof'); - code.innerHTML = chromoting.accessCode; + code.innerHTML = remoting.accessCode; setGlobalMode('session'); }, 3000); } function cancelConnect() { - chromoting.accessCode = ''; + remoting.accessCode = ''; setClientMode('unconnected'); - clearTimeout(chromoting.clientTimer); + clearTimeout(remoting.clientTimer); } |