diff --git a/extension/background.html b/extension/background.js similarity index 84% rename from extension/background.html rename to extension/background.js index 10b838d..8b4e322 100644 --- a/extension/background.html +++ b/extension/background.js @@ -13,15 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - - - - - - - - - - - diff --git a/extension/help.html b/extension/help.html index 8aa53cd..1f8314e 100644 --- a/extension/help.html +++ b/extension/help.html @@ -32,44 +32,27 @@ body, td { - - + - +

 Google Chrome to Phone Extension

-

-

+

+

-

+

@@ -80,8 +63,8 @@ body, td { - - + + @@ -89,16 +72,15 @@ body, td { - - - + +
+ (QR)

-
©2010 Google - - - - -
+
©2010 Google - - + -
diff --git a/extension/help.js b/extension/help.js new file mode 100644 index 0000000..d86708c --- /dev/null +++ b/extension/help.js @@ -0,0 +1,39 @@ +document.addEventListener("DOMContentLoaded", function() { + // localize easy stuff + Array.prototype.forEach.call(document.querySelectorAll("*[i18n-message]"), + function(node) { + node.textContent = chrome.i18n.getMessage(node.getAttribute('i18n-message')); + }); + + // localize tos link + document.querySelector('#gallery_tos_link').href = + 'http://chrome.google.com/extensions/intl/' + + navigator.language.substring(0, 2) + '/gallery_tos.html'; + + + if (oauth.hasToken()) { + var link = document.createElement('a'); + link.href = 'help.html'; + link.onclick = function() { + chrome.extension.getBackgroundPage().closeBrowserChannel(); + oauth.clearTokens(); + }; + link.text = chrome.i18n.getMessage('sign_out_message'); + document.querySelector('#sign_in_out_div').appendChild(link); + + if (document.location.hash == '#just_signed_in') { + var p = document.createElement('p'); + p.style.fontWeight = 'bold'; + p.style.color = '#0a0'; + p.textContent = chrome.i18n.getMessage('signed_in_message'); + document.querySelector('#just_signed_in_div').appendChild(p); + } + } else { + var sign_in_message = chrome.i18n.getMessage('sign_in_message'); + sign_in_message = sign_in_message.substring(0, 1).toUpperCase() + sign_in_message.substring(1); // TODO: Get a new title case string translated + var link = document.createElement('a'); + link.href = 'oauth_interstitial.html'; + link.textContent = sign_in_message; + document.querySelector('#sign_in_out_div').appendChild(link); + } +}); diff --git a/extension/manifest.json b/extension/manifest.json index 35decfb..dad2d23 100644 --- a/extension/manifest.json +++ b/extension/manifest.json @@ -1,7 +1,9 @@ { + "update_url":"http://clients2.google.com/service/update2/crx", + "manifest_version": 2, "name": "__MSG_app_name__", "description": "__MSG_app_desc__", - "version": "2.3.1", + "version": "2.3.2", "default_locale": "en", "icons": { "16": "icon_16.png", @@ -14,14 +16,18 @@ "default_icon": "icon_19.png", "default_popup": "popup.html" }, - "background_page": "background.html", + "background": { + "persistent": false, + "scripts": [ + "channel.js", + "chrome_ex_oauthsimple.js", + "chrome_ex_oauth.js", + "send_logic.js", + "background.js" + ] + }, + "content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'", "permissions": [ "contextMenus", "tabs", "http://*/*", "https://*/*" - ], - "content_scripts": [ - { - "matches": ["http://*/*", "https://*/*"], - "js": ["content_script.js"] - } - ] + ] } diff --git a/extension/oauth_interstitial.html b/extension/oauth_interstitial.html index fe5580c..fe969c4 100644 --- a/extension/oauth_interstitial.html +++ b/extension/oauth_interstitial.html @@ -34,29 +34,11 @@ body { - - + - + Redirecting... diff --git a/extension/oauth_interstitial.js b/extension/oauth_interstitial.js new file mode 100644 index 0000000..14d9102 --- /dev/null +++ b/extension/oauth_interstitial.js @@ -0,0 +1,16 @@ +window.onload = function() { + // We may be called directly, as options, or as result of a + // redirect from OAuth1 flow + var params = ChromeExOAuth.getQueryStringParams(); + if (params['chromeexoauthcallback'] == 'true') { + // End of the oauth request flow, get access token + oauth.initOAuthFlow(function(token, secret) { + chrome.extension.getBackgroundPage().initializeBrowserChannel(); + window.location = 'help.html#just_signed_in'; + }); + } else { + oauth.initOAuthFlow(function(token, secret) { + chrome.extension.getBackgroundPage().initializeBrowserChannel(); + }); + } + }; diff --git a/extension/popup.html b/extension/popup.html index 2ed29bd..a7e0a96 100644 --- a/extension/popup.html +++ b/extension/popup.html @@ -28,97 +28,26 @@ td { font-size: 12px; color: black; } + +*:focus { + outline: none; +} - - - + + - +
-

| +

|

diff --git a/extension/popup.js b/extension/popup.js new file mode 100644 index 0000000..4163c71 --- /dev/null +++ b/extension/popup.js @@ -0,0 +1,96 @@ +window.onload = function() { + document.getElementById('help').textContent = chrome.i18n.getMessage('help_message'); + + if (oauth.hasToken()) { + document.getElementById('msg').textContent = chrome.i18n.getMessage('sending_message'); + document.getElementById('signout').textContent = chrome.i18n.getMessage('sign_out_message'); + + chrome.tabs.getSelected(null, function(tab) { + if (tab.url.indexOf('http:') == 0 || + tab.url.indexOf('https:') == 0) { + chrome.tabs.executeScript(null, {file: "content_script.js"}); + } else { + document.getElementById('msg').textContent = chrome.i18n.getMessage('invalid_scheme_message'); + } + }); + } else { + // we need the options page to show signin + activateSignInLink(function() { + chrome.tabs.create({url: 'oauth_interstitial.html'}) + }); + } + + document.querySelector("#help").onclick = function() { + chrome.tabs.create({url: 'help.html'}); + }; + + document.querySelector("#close").onclick = function() { + window.close(); + } +} + +function sendToPhoneListener(status, responseText) { + if (status == STATUS_SUCCESS) { + document.getElementById('msg').textContent = chrome.i18n.getMessage('sent_message'); + activateSignOutLink(); + } else if (status == STATUS_LOGIN_REQUIRED) { + activateSignInLink(function() { + chrome.tabs.create({url: 'help.html?fromPopup=1'}); // token revoked + }); + } else if (status == STATUS_DEVICE_NOT_REGISTERED) { + document.getElementById('msg').textContent = chrome.i18n.getMessage('device_not_registered_message'); + activateSignOutLink(); + } else { + document.getElementById('msg').textContent = + chrome.i18n.getMessage('error_sending_message', responseText); + activateSignOutLink(); + } +} + +chrome.extension.onConnect.addListener(function(port) { + // This will get called by the content script. We go through + // these hoops to get the optional text selection. + port.onMessage.addListener(function(info) { + var msgType = (info.selection && info.selection.length > 0) ? 'selection' : 'page'; + sendToPhone(info.title, info.url, msgType, info.selection, sendToPhoneListener); + }); +}); + +function setSignOutVisibility(visible) { + var signOutLink = document.getElementById('signout'); + signOutLink.style.visibility = visible ? 'visible' : 'hidden'; + var sep = document.getElementById('sep'); + sep.style.visibility = visible ? 'visible' : 'hidden'; +} + +function activateSignOutLink() { + setSignOutVisibility(true); + var signOutLink = document.getElementById('signout'); + signOutLink.textContent = chrome.i18n.getMessage('sign_out_message'); + signOutLink.style.color = 'blue'; + signOutLink.onclick = function() { + chrome.extension.getBackgroundPage().closeBrowserChannel(); + oauth.clearTokens(); + window.close(); + } +} + +function activateSignInLink(onclick) { + var link = document.createElement("a"); + link.href = "#"; + link.onclick = onclick; + link.textContent = chrome.i18n.getMessage('sign_in_message'); + var linkToken = '$link$'; + var msg = chrome.i18n.getMessage('sign_in_required_message', linkToken); + var linkIndex = msg.indexOf(linkToken); + + var parent = document.getElementById('msg'); + parent.textContent = ''; + parent.appendChild(document.createTextNode(msg.substring(0, linkIndex))); + parent.appendChild(link); + parent.appendChild( + document.createTextNode(msg.substring(linkIndex + linkToken.length))); + + setSignOutVisibility(false); +} +