summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authoraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-16 09:10:02 +0000
committeraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-16 09:10:02 +0000
commit0e29e3e759d7fd331ff1c7d811733a57a20f3efe (patch)
tree2c1a3461e202d789c414f25520b9d42b5b9695ec /chrome
parent0e42a9cc87d1b4235ee76e76e244b650c100591e (diff)
downloadchromium_src-0e29e3e759d7fd331ff1c7d811733a57a20f3efe.zip
chromium_src-0e29e3e759d7fd331ff1c7d811733a57a20f3efe.tar.gz
chromium_src-0e29e3e759d7fd331ff1c7d811733a57a20f3efe.tar.bz2
Merge 33576 - Minor polish to the EmailThisPage extension.
Add the page selection to the body of the email, if something is selected. BUG=None TEST=None Review URL: http://codereview.chromium.org/460002 TBR=finnur@chromium.org git-svn-id: svn://svn.chromium.org/chrome/branches/249/src@34689 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/common/extensions/docs/examples/extensions/email_this_page/background.html26
-rw-r--r--chrome/common/extensions/docs/examples/extensions/email_this_page/content_script.js12
-rw-r--r--chrome/common/extensions/docs/examples/extensions/email_this_page/manifest.json2
-rw-r--r--chrome/common/extensions/docs/examples/extensions/email_this_page/options.html40
4 files changed, 54 insertions, 26 deletions
diff --git a/chrome/common/extensions/docs/examples/extensions/email_this_page/background.html b/chrome/common/extensions/docs/examples/extensions/email_this_page/background.html
index b3b0f5ba..6893cc5 100644
--- a/chrome/common/extensions/docs/examples/extensions/email_this_page/background.html
+++ b/chrome/common/extensions/docs/examples/extensions/email_this_page/background.html
@@ -14,13 +14,19 @@
return window.localStorage.customMailtoUrl;
}
- function executeMailto(tab_id, subject, body) {
+ function executeMailto(tab_id, subject, body, selection) {
var action_url = "mailto:?"
if (subject.length > 0)
action_url += "subject=" + subject + "%26"; // 26 is ampersand.
- if (body.length > 0)
+ if (body.length > 0) {
action_url += "body=" + body;
+ // Append the current selection to the end of the text message.
+ var new_line = "%0D%0A";
+ if (selection.length > 0)
+ action_url += new_line + new_line + selection;
+ }
+
var custom_url = customMailtoUrl();
if (custom_url.length > 0) {
// Custom URL's (such as opening mailto in Gmail tab) should have a
@@ -41,8 +47,12 @@
// This will get called by the content script we execute in
// the tab as a result of the user pressing the browser action.
- port.onMessage.addListener(function(pageTitle) {
- executeMailto(tab.id, encodeURI(pageTitle), encodeURI(tab.url));
+ port.onMessage.addListener(function(info) {
+ var max_length = 1024;
+ if (info.selection.length > max_length)
+ info.selection = info.selection.substring(0, max_length);
+ executeMailto(tab.id, encodeURI(info.title),
+ encodeURI(tab.url), encodeURI(info.selection));
});
});
@@ -52,13 +62,9 @@
// and https so for all other pages, we don't ask for the title.
if (tab.url.indexOf("http:") != 0 &&
tab.url.indexOf("https:") != 0) {
- executeMailto(tab.id, "", encodeURI(tab.url));
+ executeMailto(tab.id, "", encodeURI(tab.url), "");
} else {
- // Execute a script that sends us the page title through postMessage.
- var script_file = {};
- script_file.code =
- "chrome.extension.connect().postMessage(document.title);";
- chrome.tabs.executeScript(tab.id, script_file);
+ chrome.tabs.executeScript(null, {file: "content_script.js"});
}
});
</script>
diff --git a/chrome/common/extensions/docs/examples/extensions/email_this_page/content_script.js b/chrome/common/extensions/docs/examples/extensions/email_this_page/content_script.js
new file mode 100644
index 0000000..fc0ef93
--- /dev/null
+++ b/chrome/common/extensions/docs/examples/extensions/email_this_page/content_script.js
@@ -0,0 +1,12 @@
+/*
+ * Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
+ * source code is governed by a BSD-style license that can be found in the
+ * LICENSE file.
+ */
+
+var additionalInfo = {
+ "title": document.title,
+ "selection": window.getSelection().toString()
+};
+
+chrome.extension.connect().postMessage(additionalInfo);
diff --git a/chrome/common/extensions/docs/examples/extensions/email_this_page/manifest.json b/chrome/common/extensions/docs/examples/extensions/email_this_page/manifest.json
index 124111b..d22ef4e 100644
--- a/chrome/common/extensions/docs/examples/extensions/email_this_page/manifest.json
+++ b/chrome/common/extensions/docs/examples/extensions/email_this_page/manifest.json
@@ -1,7 +1,7 @@
{
"name": "Email this page",
"description": "This extension adds an email button to the toolbar which allows you to email the page link using your default mail client or Gmail",
- "version": "1.2.1",
+ "version": "1.2.2",
"background_page": "background.html",
"icons": { "128": "mail_128x128.png" },
"options_page": "options.html",
diff --git a/chrome/common/extensions/docs/examples/extensions/email_this_page/options.html b/chrome/common/extensions/docs/examples/extensions/email_this_page/options.html
index 1fa4cf5..405afdf 100644
--- a/chrome/common/extensions/docs/examples/extensions/email_this_page/options.html
+++ b/chrome/common/extensions/docs/examples/extensions/email_this_page/options.html
@@ -8,12 +8,14 @@
<head>
<title>Options for the Send as Email extension</title>
<style>
-body {
+#providerSelection {
font-family: Helvetica, Arial, sans-serif;
font-size: 10pt;
}
</style>
<script>
+ var gmail = "https://mail.google.com/mail/?extsrc=mailto&url=%s";
+
function toggle(radioButton) {
if (window.localStorage == null) {
alert('Local storage is required for changing providers');
@@ -22,8 +24,7 @@ function toggle(radioButton) {
var selected = radioButton.value;
if (selected == "gmail") {
- window.localStorage.customMailtoUrl =
- 'https://mail.google.com/mail/?extsrc=mailto&url=%s';
+ window.localStorage.customMailtoUrl = gmail;
} else {
window.localStorage.customMailtoUrl = "";
}
@@ -39,22 +40,31 @@ function main() {
// Default handler is checked. If we've chosen another provider, we must
// change the checkmark.
- if (window.localStorage.customMailtoUrl != null &&
- window.localStorage.customMailtoUrl != "")
+ if (window.localStorage.customMailtoUrl == gmail)
document.getElementById('gmail').checked = true;
}
</script>
</head>
<body onload="main()">
-<div id="providerSelection">
- <br/>
- <strong>Select provider to use when emailing a web
- page address:</strong>
- <br /><br />
- <input id="default" type="radio" name="mailto" value="mailto"
- onclick="toggle(this)" checked>Your default mail handler<br>
- <input id="gmail" type="radio" name="mailto" value="gmail"
- onclick="toggle(this)">Gmail<br>
-</div>
+<table border="0">
+<tr>
+ <td rowspan="2" valign="top" align="center" width="80">
+ <img src="mail_128x128.png" width="64" height="64" />
+ </td>
+ <td height="22"></td>
+</tr>
+<tr>
+ <td valign="center">
+ <div id="providerSelection">
+ <strong>Select provider to use when emailing a web page address:</strong>
+ <br /><br />
+ <input id="default" type="radio" name="mailto" value="mailto"
+ onclick="toggle(this)" checked>Your default mail handler<br>
+ <input id="gmail" type="radio" name="mailto" value="gmail"
+ onclick="toggle(this)">Gmail<br>
+ </div>
+ </td>
+</tr>
+</table>
</body>
</html>