diff options
author | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-04 20:22:09 +0000 |
---|---|---|
committer | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-04 20:22:09 +0000 |
commit | 58963a902ffe3f89502718dda31a20ab6a5f6be6 (patch) | |
tree | 1911817976654c88264474d0d9721f887d09a5fc /remoting | |
parent | 81aafe07bdc27930754a44693fa0328233d64f35 (diff) | |
download | chromium_src-58963a902ffe3f89502718dda31a20ab6a5f6be6.zip chromium_src-58963a902ffe3f89502718dda31a20ab6a5f6be6.tar.gz chromium_src-58963a902ffe3f89502718dda31a20ab6a5f6be6.tar.bz2 |
Modify client to open up chromoting connection in a new tab.
BUG=50248
TEST=connects locally.
TBR=hclam
Review URL: http://codereview.chromium.org/2808104
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@54958 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r-- | remoting/client/extension/chromoting_tab.html | 41 | ||||
-rw-r--r-- | remoting/client/extension/client.js | 80 | ||||
-rw-r--r-- | remoting/client/extension/popup.html | 16 |
3 files changed, 83 insertions, 54 deletions
diff --git a/remoting/client/extension/chromoting_tab.html b/remoting/client/extension/chromoting_tab.html new file mode 100644 index 0000000..dbe42a56 --- /dev/null +++ b/remoting/client/extension/chromoting_tab.html @@ -0,0 +1,41 @@ +<html> + <head> + <title id="title">New Chromoting Session</title> + <script> + function set_listener() { + // This page should only get one request, and it should be + // from the chromoting extension asking for initial connection. + // Later we may need to create a more persistent channel for + // better UI communication. Then, we should probably switch + // to chrome.extension.connect(). + chrome.extension.onRequest.addListener( + function(request, sender, sendResponse) { + console.log(sender.tab ? + "from a content script:" + sender.tab.url : + "from the extension"); + + // Kick off the connection. Hold on to your butts! + var chromoting = document.getElementById('chromoting'); + if (typeof chromoting.connect === 'function') { + chromoting.connect(request.username, request.host_jid, request.xmpp_auth); + } + + var connect_info = "On [" + request.host_jid + "] as [" + request.username + "]"; + document.getElementById("title").innerText = connect_info; + document.getElementById("connectinfo").innerText = connect_info; + + // Send an empty response since we have nothing to say. + sendResponse({}); + }); + } + </script> + </head> + <body onload="set_listener();"> + Why hello there! I'm your friendly Chromoting Tab. + <div id="connectinfo"></div> + <div id="plugin_div" style="border: black 1px dashed;"> + <embed width="100%" height="100%" name="chromoting" id="chromoting" + src="about://none" type="pepper-application/x-chromoting"> + </div> + </body> +</html> diff --git a/remoting/client/extension/client.js b/remoting/client/extension/client.js index a9e25a0..e01de07 100644 --- a/remoting/client/extension/client.js +++ b/remoting/client/extension/client.js @@ -58,7 +58,7 @@ function extract_auth_token(message) { } } - debug_output('Could not parse auth token in : "' + message + '"'); + console.log('Could not parse auth token in : "' + message + '"'); return 'bad_token'; } @@ -72,7 +72,7 @@ function do_gaia_login(username, password, service, done) { if (xhr.status = 200) { done(extract_auth_token(xhr.responseText)); } else { - debug_output('Bad status on auth: ' + xhr.statusText); + console.log('Bad status on auth: ' + xhr.statusText); } }; @@ -106,15 +106,27 @@ function do_login(username, password, done) { function do_list_hosts() { var xhr = new XMLHttpRequest(); var token = get_cookie('chromoting_auth'); + + // Unhide host list. + var hostlist_div = document.getElementById('hostlist_div'); + hostlist_div.style.display = "block"; + xhr.onreadystatechange = function() { + if (xhr.readyState == 1) { + hostlist_div.appendChild(document.createTextNode('Finding..')); + hostlist_div.appendChild(document.createElement('br')); + } if (xhr.readyState != 4) { return; } if (xhr.status == 200) { parsed_response = JSON.parse(xhr.responseText); - create_host_links(parsed_response.data.items); + hostlist_div.appendChild(document.createTextNode('--Found Hosts--')); + hostlist_div.appendChild(document.createElement('br')); + append_host_links(parsed_response.data.items); } else { - debug_output('bad status on host list query: "' + xhr.status + ' ' + xhr.statusText); + console.log('bad status on host list query: "' + xhr.status + ' ' + xhr.statusText); + hostlist_div.appendChild(document.createTextNode('!! Failed !!. :\'(')); } }; @@ -124,19 +136,20 @@ function do_list_hosts() { xhr.send(null); } -function create_host_links(hostlist) { +function append_host_links(hostlist) { // A host link entry should look like: // - Host: <a onclick="open_chromoting_tab(host_jid); return false;">NAME (JID)</a> <br /> var host; var host_link; var hostlist_div = document.getElementById('hostlist_div'); + + // Add the hosts. for(var i = 0; i < hostlist.length; ++i) { hostlist_div.appendChild(document.createTextNode('-*- Host: ')); host = hostlist[i]; host_link = document.createElement('a'); // TODO(ajwong): Reenable once we figure out how to control a new tab. - //host_link.setAttribute('onclick', 'open_chromoting_tab(\'' + host.jabberId + '\'); return false;'); - host_link.setAttribute('onclick', 'connect_in_popup(\'' + host.jabberId + '\'); return false;'); + host_link.setAttribute('onclick', 'open_chromoting_tab(\'' + host.jabberId + '\'); return false;'); host_link.setAttribute('href', 'javascript:void(0)'); host_link.appendChild(document.createTextNode(host.hostName + ' (' + host.hostId + ', ' + host.jabberId + ')')); hostlist_div.appendChild(host_link); @@ -176,11 +189,7 @@ function set_auth_cookies(form) { } function connect(form) { - // TODO(ajwong): reenable once we figure out how to command the DOM in - // the opened tab. - // - // open_chromoting_tab(form.host_jid.value); - connect_in_popup(form.host_jid.value); + open_chromoting_tab(form.host_jid.value); } function debug_output(message) { @@ -189,40 +198,31 @@ function debug_output(message) { debug_div.appendChild(document.createElement('br')); } -function connect_in_popup(host_jid) { - var username = get_cookie('username'); - var xmpp_auth = get_cookie('xmpp_auth'); - debug_output("Attempt to connect with " + - "username='" + username + "'" + - " host_jid='" + host_jid + "'" + - " auth_token='" + xmpp_auth + "'"); - - document.getElementById('chromoting').connect(username, host_jid, xmpp_auth); -} - function open_chromoting_tab(host_jid) { var username = get_cookie('username'); var xmpp_auth = get_cookie('xmpp_auth'); - debug_output("Attempt to connect with " + - "username='" + username + "'" + - " host_jid='" + host_jid + "'" + - " auth_token='" + xmpp_auth + "'"); - + var new_tab_url = chrome.extension.getURL("chromoting_tab.html"); + var request = { + username: get_cookie('username'), + xmpp_auth: get_cookie('xmpp_auth'), + host_jid: host_jid, + }; var tab_args = { - url: "chrome://remoting", + url: new_tab_url, }; + console.log("Attempt to connect with " + + "username='" + request.username + "'" + + " host_jid='" + request.host_jid + "'" + + " auth_token='" + request.xmpp_auth + "'"); + chrome.tabs.create(tab_args, function(tab) { - var details = {}; - details.code = function() { - // TODO(ajwong): We need to punch a hole into the content script to - // make this work. See - // http://code.google.com/chrome/extensions/content_scripts.html - var an_event = document.createEvent('Event'); - an_event.initEvent('startPlugin', true, true); - - alert('hi'); - } - chrome.tabs.executeScript(tab.id, details, function() { alert('done');}); + console.log("We're trying now to send to " + tab.id); + // TODO(ajwong): This request does not always seem to make it through. + // I think there's a race condition sending to the view. Figure out how + // to correctly synchronize this call. + chrome.tabs.sendRequest( + tab.id, request, + function() {console.log('Tab finished conenct.')}); }); } diff --git a/remoting/client/extension/popup.html b/remoting/client/extension/popup.html index c632dd6..7b2bab9 100644 --- a/remoting/client/extension/popup.html +++ b/remoting/client/extension/popup.html @@ -9,7 +9,7 @@ found in the LICENSE file. <script type="text/javascript" src="client.js"></script> <title>Get hosts</title> </head> - <body onload="init_params();"> + <body onload="init_params();" style="width:250;"> <div style="border: blue 1px dotted;"> <form name="hostqueryform" action="" method="GET"> @@ -40,21 +40,9 @@ found in the LICENSE file. <br /> - <div id="debug_div" style="border: red 1px solid;"> - -- Debugging messages go here -- <br /> + <div id="hostlist_div" style="border: blue 1px solid; display: none;"> </div> <br /> - - <div id="hostlist_div" style="border: blue 1px solid;"> - -- Hosts go here -- <br /> - </div> - - <br /> - - <div id="plugin_div" style="border: black 1px dashed;"> - <embed width="100%" height="100%" name="chromoting" id="chromoting" - src="about://none" type="pepper-application/x-chromoting"> - </div> </body> </html> |