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

Side by Side Diff: remoting/client/extension/client.js

Issue 2808104: Modify client to open up chromoting connection in a new tab. (Closed) Base URL: git://codf21.jail.google.com/chromium.git
Patch Set: rebased Created 10 years, 4 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 unified diff | Download patch
« no previous file with comments | « remoting/client/extension/chromoting_tab.html ('k') | remoting/client/extension/popup.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 function init_params() { 5 function init_params() {
6 var hash; 6 var hash;
7 var hashes = window.location.href.slice( 7 var hashes = window.location.href.slice(
8 window.location.href.indexOf('?') + 1).split('&'); 8 window.location.href.indexOf('?') + 1).split('&');
9 9
10 // Prepopulate via cookies first. 10 // Prepopulate via cookies first.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 } 51 }
52 52
53 function extract_auth_token(message) { 53 function extract_auth_token(message) {
54 var lines = message.split('\n'); 54 var lines = message.split('\n');
55 for (var i = 0; i < lines.length; i++) { 55 for (var i = 0; i < lines.length; i++) {
56 if (lines[i].match('^Auth=.*')) { 56 if (lines[i].match('^Auth=.*')) {
57 return lines[i].split('=')[1]; 57 return lines[i].split('=')[1];
58 } 58 }
59 } 59 }
60 60
61 debug_output('Could not parse auth token in : "' + message + '"'); 61 console.log('Could not parse auth token in : "' + message + '"');
62 return 'bad_token'; 62 return 'bad_token';
63 } 63 }
64 64
65 function do_gaia_login(username, password, service, done) { 65 function do_gaia_login(username, password, service, done) {
66 var xhr = new XMLHttpRequest(); 66 var xhr = new XMLHttpRequest();
67 xhr.open('POST', 'https://www.google.com/accounts/ClientLogin', true); 67 xhr.open('POST', 'https://www.google.com/accounts/ClientLogin', true);
68 xhr.onreadystatechange = function() { 68 xhr.onreadystatechange = function() {
69 if (xhr.readyState != 4) { 69 if (xhr.readyState != 4) {
70 return; 70 return;
71 } 71 }
72 if (xhr.status = 200) { 72 if (xhr.status = 200) {
73 done(extract_auth_token(xhr.responseText)); 73 done(extract_auth_token(xhr.responseText));
74 } else { 74 } else {
75 debug_output('Bad status on auth: ' + xhr.statusText); 75 console.log('Bad status on auth: ' + xhr.statusText);
76 } 76 }
77 }; 77 };
78 78
79 xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); 79 xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
80 xhr.send('accountType=HOSTED_OR_GOOGLE&Email=' + username + '&Passwd=' + passw ord + '&service=' + service + '&source=chromoclient'); 80 xhr.send('accountType=HOSTED_OR_GOOGLE&Email=' + username + '&Passwd=' + passw ord + '&service=' + service + '&source=chromoclient');
81 } 81 }
82 82
83 function do_login(username, password, done) { 83 function do_login(username, password, done) {
84 var count = 2; 84 var count = 2;
85 var barrier = function() { 85 var barrier = function() {
(...skipping 13 matching lines...) Expand all
99 function(token) { 99 function(token) {
100 set_cookie('xmpp_auth', token, 100); 100 set_cookie('xmpp_auth', token, 100);
101 document.getElementById('xmpp_auth').value = token; 101 document.getElementById('xmpp_auth').value = token;
102 barrier(); 102 barrier();
103 }); 103 });
104 } 104 }
105 105
106 function do_list_hosts() { 106 function do_list_hosts() {
107 var xhr = new XMLHttpRequest(); 107 var xhr = new XMLHttpRequest();
108 var token = get_cookie('chromoting_auth'); 108 var token = get_cookie('chromoting_auth');
109
110 // Unhide host list.
111 var hostlist_div = document.getElementById('hostlist_div');
112 hostlist_div.style.display = "block";
113
109 xhr.onreadystatechange = function() { 114 xhr.onreadystatechange = function() {
115 if (xhr.readyState == 1) {
116 hostlist_div.appendChild(document.createTextNode('Finding..'));
117 hostlist_div.appendChild(document.createElement('br'));
118 }
110 if (xhr.readyState != 4) { 119 if (xhr.readyState != 4) {
111 return; 120 return;
112 } 121 }
113 if (xhr.status == 200) { 122 if (xhr.status == 200) {
114 parsed_response = JSON.parse(xhr.responseText); 123 parsed_response = JSON.parse(xhr.responseText);
115 create_host_links(parsed_response.data.items); 124 hostlist_div.appendChild(document.createTextNode('--Found Hosts--'));
125 hostlist_div.appendChild(document.createElement('br'));
126 append_host_links(parsed_response.data.items);
116 } else { 127 } else {
117 debug_output('bad status on host list query: "' + xhr.status + ' ' + xhr.s tatusText); 128 console.log('bad status on host list query: "' + xhr.status + ' ' + xhr.st atusText);
129 hostlist_div.appendChild(document.createTextNode('!! Failed !!. :\'('));
118 } 130 }
119 }; 131 };
120 132
121 xhr.open('GET', 'http://www-googleapis-test.sandbox.google.com/chromoting/v1/@ me/hosts'); 133 xhr.open('GET', 'http://www-googleapis-test.sandbox.google.com/chromoting/v1/@ me/hosts');
122 xhr.setRequestHeader('Content-Type', 'text/plain;charset=UTF-8'); 134 xhr.setRequestHeader('Content-Type', 'text/plain;charset=UTF-8');
123 xhr.setRequestHeader('Authorization', 'GoogleLogin auth=' + token); 135 xhr.setRequestHeader('Authorization', 'GoogleLogin auth=' + token);
124 xhr.send(null); 136 xhr.send(null);
125 } 137 }
126 138
127 function create_host_links(hostlist) { 139 function append_host_links(hostlist) {
128 // A host link entry should look like: 140 // A host link entry should look like:
129 // - Host: <a onclick="open_chromoting_tab(host_jid); return false;">NAME (JID)< /a> <br /> 141 // - Host: <a onclick="open_chromoting_tab(host_jid); return false;">NAME (JID)< /a> <br />
130 var host; 142 var host;
131 var host_link; 143 var host_link;
132 var hostlist_div = document.getElementById('hostlist_div'); 144 var hostlist_div = document.getElementById('hostlist_div');
145
146 // Add the hosts.
133 for(var i = 0; i < hostlist.length; ++i) { 147 for(var i = 0; i < hostlist.length; ++i) {
134 hostlist_div.appendChild(document.createTextNode('-*- Host: ')); 148 hostlist_div.appendChild(document.createTextNode('-*- Host: '));
135 host = hostlist[i]; 149 host = hostlist[i];
136 host_link = document.createElement('a'); 150 host_link = document.createElement('a');
137 // TODO(ajwong): Reenable once we figure out how to control a new tab. 151 // TODO(ajwong): Reenable once we figure out how to control a new tab.
138 //host_link.setAttribute('onclick', 'open_chromoting_tab(\'' + host.jabberId + '\'); return false;'); 152 host_link.setAttribute('onclick', 'open_chromoting_tab(\'' + host.jabberId + '\'); return false;');
139 host_link.setAttribute('onclick', 'connect_in_popup(\'' + host.jabberId + '\ '); return false;');
140 host_link.setAttribute('href', 'javascript:void(0)'); 153 host_link.setAttribute('href', 'javascript:void(0)');
141 host_link.appendChild(document.createTextNode(host.hostName + ' (' + host.ho stId + ', ' + host.jabberId + ')')); 154 host_link.appendChild(document.createTextNode(host.hostName + ' (' + host.ho stId + ', ' + host.jabberId + ')'));
142 hostlist_div.appendChild(host_link); 155 hostlist_div.appendChild(host_link);
143 hostlist_div.appendChild(document.createElement('br')); 156 hostlist_div.appendChild(document.createElement('br'));
144 } 157 }
145 } 158 }
146 159
147 // Cookie reading code taken from quirksmode with modification for escaping. 160 // Cookie reading code taken from quirksmode with modification for escaping.
148 // http://www.quirksmode.org/js/cookies.html 161 // http://www.quirksmode.org/js/cookies.html
149 function set_cookie(name,value,days) { 162 function set_cookie(name,value,days) {
(...skipping 19 matching lines...) Expand all
169 182
170 function set_auth_cookies(form) { 183 function set_auth_cookies(form) {
171 var now = new Date(); 184 var now = new Date();
172 now.setTime(now.getTime() + 1000 * 60 * 60 * 24 * 365) 185 now.setTime(now.getTime() + 1000 * 60 * 60 * 24 * 365)
173 186
174 create_cookie('xmpp_auth', form.xmpp_auth.value, 100); 187 create_cookie('xmpp_auth', form.xmpp_auth.value, 100);
175 create_cookie('chromoting_auth', form.chromoting_auth.value, 100); 188 create_cookie('chromoting_auth', form.chromoting_auth.value, 100);
176 } 189 }
177 190
178 function connect(form) { 191 function connect(form) {
179 // TODO(ajwong): reenable once we figure out how to command the DOM in 192 open_chromoting_tab(form.host_jid.value);
180 // the opened tab.
181 //
182 // open_chromoting_tab(form.host_jid.value);
183 connect_in_popup(form.host_jid.value);
184 } 193 }
185 194
186 function debug_output(message) { 195 function debug_output(message) {
187 var debug_div = document.getElementById('debug_div'); 196 var debug_div = document.getElementById('debug_div');
188 debug_div.appendChild(document.createTextNode(message)); 197 debug_div.appendChild(document.createTextNode(message));
189 debug_div.appendChild(document.createElement('br')); 198 debug_div.appendChild(document.createElement('br'));
190 } 199 }
191 200
192 function connect_in_popup(host_jid) {
193 var username = get_cookie('username');
194 var xmpp_auth = get_cookie('xmpp_auth');
195 debug_output("Attempt to connect with " +
196 "username='" + username + "'" +
197 " host_jid='" + host_jid + "'" +
198 " auth_token='" + xmpp_auth + "'");
199
200 document.getElementById('chromoting').connect(username, host_jid, xmpp_auth);
201 }
202
203 function open_chromoting_tab(host_jid) { 201 function open_chromoting_tab(host_jid) {
204 var username = get_cookie('username'); 202 var username = get_cookie('username');
205 var xmpp_auth = get_cookie('xmpp_auth'); 203 var xmpp_auth = get_cookie('xmpp_auth');
206 debug_output("Attempt to connect with " + 204 var new_tab_url = chrome.extension.getURL("chromoting_tab.html");
207 "username='" + username + "'" + 205 var request = {
208 " host_jid='" + host_jid + "'" + 206 username: get_cookie('username'),
209 " auth_token='" + xmpp_auth + "'"); 207 xmpp_auth: get_cookie('xmpp_auth'),
210 208 host_jid: host_jid,
209 };
211 var tab_args = { 210 var tab_args = {
212 url: "chrome://remoting", 211 url: new_tab_url,
213 }; 212 };
214 213
214 console.log("Attempt to connect with " +
215 "username='" + request.username + "'" +
216 " host_jid='" + request.host_jid + "'" +
217 " auth_token='" + request.xmpp_auth + "'");
218
215 chrome.tabs.create(tab_args, function(tab) { 219 chrome.tabs.create(tab_args, function(tab) {
216 var details = {}; 220 console.log("We're trying now to send to " + tab.id);
217 details.code = function() { 221 // TODO(ajwong): This request does not always seem to make it through.
218 // TODO(ajwong): We need to punch a hole into the content script to 222 // I think there's a race condition sending to the view. Figure out how
219 // make this work. See 223 // to correctly synchronize this call.
220 // http://code.google.com/chrome/extensions/content_scripts.html 224 chrome.tabs.sendRequest(
221 var an_event = document.createEvent('Event'); 225 tab.id, request,
222 an_event.initEvent('startPlugin', true, true); 226 function() {console.log('Tab finished conenct.')});
223
224 alert('hi');
225 }
226 chrome.tabs.executeScript(tab.id, details, function() { alert('done');});
227 }); 227 });
228 } 228 }
OLDNEW
« no previous file with comments | « remoting/client/extension/chromoting_tab.html ('k') | remoting/client/extension/popup.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698