mirror of
https://github.com/fergalmoran/chrometophone.git
synced 2025-12-22 09:41:51 +00:00
Refactoring and disabling of phone-to-chrome until v2.2
This commit is contained in:
@@ -19,21 +19,6 @@
|
||||
|
||||
<script>
|
||||
|
||||
// TODO: Remove when out of beta
|
||||
function maybeActivateBrowserChannel() {
|
||||
var activateBrowserChannel = localStorage['activateBrowserChannel'];
|
||||
if (activateBrowserChannel == undefined) {
|
||||
if (Math.random() < 0.1) {
|
||||
localStorage['activateBrowserChannel'] = 'true';
|
||||
} else {
|
||||
localStorage['activateBrowserChannel'] = 'false';
|
||||
}
|
||||
}
|
||||
if (localStorage['activateBrowserChannel'] == 'true') {
|
||||
initializeBrowserChannel();
|
||||
}
|
||||
}
|
||||
|
||||
function onClickHandler(info, tab) {
|
||||
var url = info.srcUrl;
|
||||
if (url == undefined) url = info.linkUrl;
|
||||
@@ -60,7 +45,6 @@ if (chrome.contextMenus) {
|
||||
'contexts': ['link', 'selection', 'image', 'video', 'audio']});
|
||||
}
|
||||
|
||||
// TODO: Replace with initializeBrowserChannel() when out of beta
|
||||
maybeActivateBrowserChannel();
|
||||
initializeBrowserChannel();
|
||||
|
||||
</script>
|
||||
|
||||
@@ -32,23 +32,10 @@ body,td {
|
||||
function loadHandler() {
|
||||
if (document.location.hash == '#signed_in') {
|
||||
var bg = chrome.extension.getBackgroundPage();
|
||||
bg.maybeActivateBrowserChannel(); // TODO: Replace with initializeBrowserChannel() when out of beta
|
||||
|
||||
bg.initializeBrowserChannel();
|
||||
document.getElementById('signed_in_div').innerHTML = '<p><b><font color="#00A000">' +
|
||||
chrome.i18n.getMessage('signed_in_message') + '</font></b></p>';
|
||||
}
|
||||
|
||||
// TODO: Remove when out of beta
|
||||
document.getElementById('p2c_checkbox').checked = (localStorage['activateBrowserChannel'] == 'true');
|
||||
}
|
||||
|
||||
// TODO: Remove when out of beta
|
||||
function checkBoxHandler() {
|
||||
document.getElementById('p2c_checkbox').checked ?
|
||||
localStorage['activateBrowserChannel'] = 'true' :
|
||||
localStorage['activateBrowserChannel'] = 'false';
|
||||
var bg = chrome.extension.getBackgroundPage();
|
||||
bg.initializeBrowserChannel();
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
@@ -97,10 +84,6 @@ body,td {
|
||||
</table>
|
||||
<br>
|
||||
|
||||
|
||||
<!-- TODO: Remove when out of beta -->
|
||||
<div id="experimental_div" align="center"><input id="p2c_checkbox" type="checkbox" onclick="checkBoxHandler()"> Enable Phone to Chrome Feature (Beta)</div>
|
||||
|
||||
<div align="center">©2010 Google - <a href="http://www.google.com/intl/en/about.html"><script>document.write(chrome.i18n.getMessage('about_google_message'));</script></a> -
|
||||
<a href="http://www.google.com/privacy.html"><script>document.write(chrome.i18n.getMessage('privacy_message'));</script></a> -
|
||||
<script>document.write('<a href="http://chrome.google.com/extensions/intl/' + window.navigator.language.substring(0, 2) + '/gallery_tos.html">' + chrome.i18n.getMessage('tos_message') + '</a>');</script></div>
|
||||
|
||||
@@ -21,7 +21,7 @@ var signInUrl = baseUrl + '/signin?extret=' +
|
||||
encodeURIComponent(chrome.extension.getURL('help.html')) + '%23signed_in&ver=' + apiVersion;
|
||||
var signOutUrl = baseUrl + '/signout?extret=' +
|
||||
encodeURIComponent(chrome.extension.getURL('signed_out.html')) + '&ver=' + apiVersion;
|
||||
var channelUrl = baseUrl + '/browserchannel?ver=' + apiVersion;
|
||||
var registerUrl = baseUrl + '/register?ver=' + apiVersion;
|
||||
|
||||
var STATUS_SUCCESS = 'success';
|
||||
var STATUS_LOGIN_REQUIRED = 'login_required';
|
||||
@@ -62,13 +62,25 @@ function sendToPhone(title, url, msgType, selection, listener) {
|
||||
}
|
||||
|
||||
function initializeBrowserChannel() {
|
||||
// TODO: Enable for v2.2
|
||||
return;
|
||||
|
||||
console.log('Initializing browser channel');
|
||||
req.open('POST', channelUrl, true);
|
||||
req.setRequestHeader('X-Same-Domain', 'true'); // XSRF protector
|
||||
|
||||
var deviceRegistrationId = localStorage['deviceRegistrationId'];
|
||||
if (deviceRegistrationId == undefined) {
|
||||
deviceRegistrationId = (Math.random() + '').substring(3);
|
||||
localStorage['deviceRegistrationId'] = deviceRegistrationId;
|
||||
}
|
||||
|
||||
req.open('POST', registerUrl, true);
|
||||
req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
||||
req.setRequestHeader('X-Same-Domain', 'true'); // XSRF protector
|
||||
|
||||
req.onreadystatechange = function() {
|
||||
if (this.readyState == 4) {
|
||||
if (req.status == 200) {
|
||||
var channelId = req.responseText;
|
||||
var channelId = req.responseText.substring(3); // expect 'OK <id>';
|
||||
channel = new goog.appengine.Channel(channelId);
|
||||
socket = channel.open();
|
||||
socket.onopen = function() {
|
||||
@@ -90,14 +102,17 @@ function initializeBrowserChannel() {
|
||||
}
|
||||
}
|
||||
} else if (req.status == 400) {
|
||||
if (req.responseText == 'LOGIN_REQUIRED') {
|
||||
if (req.responseText.indexOf('LOGIN_REQUIRED') == 0) {
|
||||
console.log('Not initializing browser channel because user not logged in');
|
||||
} else if (req.responseText.indexOf('NOT_ENABLED') == 0) {
|
||||
console.log('Not initializing browser channel because feature not enabled for user');
|
||||
}
|
||||
} else {
|
||||
setTimeout('initializeBrowserChannel()', BROWSER_CHANNEL_RETRY_INTERVAL_MS);
|
||||
}
|
||||
}
|
||||
};
|
||||
req.send();
|
||||
var data = 'devregid=' + deviceRegistrationId + '&deviceType=chrome' + '&deviceName=Chrome';
|
||||
req.send(data);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user