Added context menu for Chrome 6 Beta and later.

This commit is contained in:
burke.davey
2010-08-26 21:19:07 +00:00
parent 7b4626719e
commit 672f83fd75
8 changed files with 147 additions and 54 deletions

View File

@@ -3,6 +3,10 @@
"message": "Google Chrome to Phone Extension",
"description": "Name of the application"
},
"app_name_short": {
"message": "Chrome to Phone",
"description": "Short name of the application"
},
"app_desc": {
"message": "Google Chrome to Phone Extension enables you to send links and other information from Chrome to your Android device.",
"description": "Description of the application."

View File

@@ -3,6 +3,10 @@
"message": "Extension Chrome to Phone par Google",
"description": "Name of the application"
},
"app_name_short": {
"message": "Chrome to Phone",
"description": "Short name of the application"
},
"app_desc": {
"message": "Lextension Chrome to Phone par Google vous permet denvoyer des liens et autres informations depuis Chrome vers votre appareil Android.",
"description": "Description of the application."

45
extension/background.html Normal file
View File

@@ -0,0 +1,45 @@
/*
* Copyright 2010 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
<script src="send_logic.js"/>
<script>
function onClickHandler(info, tab) {
var url = info.srcUrl;
if (url == undefined) url = info.linkUrl;
if (url == undefined) url = tab.url;
var msgType = info.mediaType;
if (msgType == undefined) msgType = 'page';
var sel = info.selectionText;
if (sel == undefined) sel = '';
var bg = chrome.extension.getBackgroundPage();
bg.sendToPhone(tab.title, url, msgType, sel, function(status) {
if (status == STATUS_LOGIN_REQUIRED) {
chrome.tabs.create({url: signInUrl});
}
});
}
if (chrome.contextMenus) {
chrome.contextMenus.create({'title': chrome.i18n.getMessage('app_name_short'),
'documentUrlPatterns': [ 'http://*/*', 'https://*/*' ],
'onclick': onClickHandler,
'contexts': ['link', 'selection', 'image', 'video', 'audio']});
}
</script>

View File

@@ -48,7 +48,13 @@ body,td {
<h2 style="padding-left: 10px"><script>document.write(chrome.i18n.getMessage('features_title_message'));</script></h2>
<script>document.write(chrome.i18n.getMessage('features_message'));</script>
<ul>
<li><script>document.write(chrome.i18n.getMessage('features_message1'));</script></li>
<li><script>document.write(chrome.i18n.getMessage('features_message2'));</script></li>
<li><script>document.write(chrome.i18n.getMessage('features_message3'));</script></li>
<li><script>document.write(chrome.i18n.getMessage('features_message4'));</script></li>
<li><script>document.write(chrome.i18n.getMessage('features_message5'));</script></li>
</ul>
<table width="1131px">
<tr>

BIN
extension/icon_16.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 529 B

View File

@@ -1,17 +1,21 @@
{
"name": "__MSG_app_name__",
"description": "__MSG_app_desc__",
"version": "2.0.0",
"version": "2.1.0",
"default_locale": "en",
"icons": { "128": "icon_128.png" },
"icons": {
"16": "icon_16.png",
"128": "icon_128.png"
},
"options_page": "help.html",
"browser_action": {
"default_title": "__MSG_app_name__",
"default_icon": "icon_19.png",
"default_popup": "popup.html"
},
"background_page": "background.html",
"permissions": [
"tabs", "http://*/*", "https://*/*"
"contextMenus", "tabs", "http://*/*", "https://*/*"
],
"content_scripts": [
{

View File

@@ -30,17 +30,8 @@ td {
}
</style>
<script type="text/javascript">
var apiVersion = 4;
var baseUrl = 'https://chrometophone.appspot.com';
var sendUrl = baseUrl + '/send?ver=' + apiVersion;;
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 req = new XMLHttpRequest();
<script src="send_logic.js"></script>
<script>
function loadHandler() {
document.getElementById('msg').innerHTML = chrome.i18n.getMessage('sending_message');
document.getElementById('help').innerHTML = chrome.i18n.getMessage('help_message');
@@ -56,51 +47,32 @@ function loadHandler() {
});
}
function sendToPhone(title, url, selection) {
req.open('POST', sendUrl, 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 body = req.responseText;
if (body.indexOf('OK') == 0) {
document.getElementById('msg').innerHTML = chrome.i18n.getMessage('sent_message');
activateSignOutLink();
} else if (body.indexOf('LOGIN_REQUIRED') == 0) {
var link = '<a href="#" onclick="chrome.tabs.create({url: \'' + signInUrl + '\'})">' +
chrome.i18n.getMessage('sign_in_message') + '</a>';
document.getElementById('msg').innerHTML =
chrome.i18n.getMessage('sign_in_required_message', link);
setSignOutVisibility(false);
} else if (body.indexOf('DEVICE_NOT_REGISTERED') == 0) {
document.getElementById('msg').innerHTML = chrome.i18n.getMessage('device_not_registered_message');
activateSignOutLink();
}
} else {
document.getElementById('msg').innerHTML =
chrome.i18n.getMessage('error_sending_message', req.responseText);
activateSignOutLink();
}
}
function sendToPhoneListener(status) {
if (status == STATUS_SUCCESS) {
document.getElementById('msg').innerHTML = chrome.i18n.getMessage('sent_message');
activateSignOutLink();
} else if (status == STATUS_LOGIN_REQUIRED) {
var link = '<a href="#" onclick="chrome.tabs.create({url: \'' + signInUrl + '\'})">' +
chrome.i18n.getMessage('sign_in_message') + '</a>';
document.getElementById('msg').innerHTML =
chrome.i18n.getMessage('sign_in_required_message', link);
setSignOutVisibility(false);
} else if (status == STATUS_DEVICE_NOT_REGISTERED) {
document.getElementById('msg').innerHTML = chrome.i18n.getMessage('device_not_registered_message');
activateSignOutLink();
} else {
document.getElementById('msg').innerHTML =
chrome.i18n.getMessage('error_sending_message', req.responseText);
activateSignOutLink();
}
var data = 'title=' + encodeURIComponent(title) + '&url=' + encodeURIComponent(url) +
'&sel=' + encodeURIComponent(selection);
req.send(data);
}
chrome.extension.onConnect.addListener(function(port) {
var tab = port.sender.tab;
// 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 max_length = 1024;
if (info.selection.length > max_length) {
info.selection = info.selection.substring(0, max_length);
}
sendToPhone(info.title, info.url, info.selection);
var msgType = (info.selection && info.selection.length > 0) ? 'selection' : 'page';
sendToPhone(info.title, info.url, msgType, info.selection, sendToPhoneListener);
});
});
@@ -110,7 +82,7 @@ function activateSignOutLink() {
signOutLink.style.color = 'blue';
signOutLink.onclick = function() {
chrome.tabs.create({url: signOutUrl});
}
};
}
function setSignOutVisibility(visible) {

58
extension/send_logic.js Normal file
View File

@@ -0,0 +1,58 @@
/*
* Copyright 2010 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var apiVersion = 5;
var baseUrl = 'https://chrometophone.appspot.com';
var sendUrl = baseUrl + '/send?ver=' + apiVersion;
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 STATUS_SUCCESS = 'success';
var STATUS_LOGIN_REQUIRED = 'login_required';
var STATUS_DEVICE_NOT_REGISTERED = 'device_not_registered';
var STATUS_GENERAL_ERROR = 'general_error';
var req = new XMLHttpRequest();
function sendToPhone(title, url, msgType, selection, listener) {
req.open('POST', sendUrl, 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 body = req.responseText;
if (body.indexOf('OK') == 0) {
listener(STATUS_SUCCESS);
} else if (body.indexOf('LOGIN_REQUIRED') == 0) {
listener(STATUS_LOGIN_REQUIRED);
} else if (body.indexOf('DEVICE_NOT_REGISTERED') == 0) {
listener(STATUS_DEVICE_NOT_REGISTERED);
}
} else {
listener(STATUS_GENERAL_ERROR);
}
}
}
var data = 'title=' + encodeURIComponent(title) + '&url=' + encodeURIComponent(url) +
'&sel=' + encodeURIComponent(selection) + '&type=' + encodeURIComponent(msgType);
req.send(data);
}