summaryrefslogtreecommitdiffstats
path: root/chrome/common/extensions/docs/examples
diff options
context:
space:
mode:
authorfinnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-01 17:10:09 +0000
committerfinnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-01 17:10:09 +0000
commit0a71b4a13e7652f140c39b88a5a971bee0363b87 (patch)
treeef483c53bdf2ad8c532b52487822c39b411bd015 /chrome/common/extensions/docs/examples
parent0174f34a029bddd6ed4de54c7a8d3ff248a4edad (diff)
downloadchromium_src-0a71b4a13e7652f140c39b88a5a971bee0363b87.zip
chromium_src-0a71b4a13e7652f140c39b88a5a971bee0363b87.tar.gz
chromium_src-0a71b4a13e7652f140c39b88a5a971bee0363b87.tar.bz2
Adding extension EmailThisPage.
BUG=None TEST=Load the extension, try emailing pages loaded using file://, http://, https://, chrome:// and in each case at least the url of the page should appear in an email in your default mail handler and in the case of http:// and https://, also the page title. Then use the Options page for the extension and try the same with gmail. Review URL: http://codereview.chromium.org/431028 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33447 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/extensions/docs/examples')
-rw-r--r--chrome/common/extensions/docs/examples/extensions/email_this_page/background.html66
-rw-r--r--chrome/common/extensions/docs/examples/extensions/email_this_page/email_16x16.pngbin0 -> 572 bytes
-rw-r--r--chrome/common/extensions/docs/examples/extensions/email_this_page/mail_128x128.pngbin0 -> 4696 bytes
-rw-r--r--chrome/common/extensions/docs/examples/extensions/email_this_page/manifest.json15
-rw-r--r--chrome/common/extensions/docs/examples/extensions/email_this_page/options.html60
5 files changed, 141 insertions, 0 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
new file mode 100644
index 0000000..b3b0f5ba
--- /dev/null
+++ b/chrome/common/extensions/docs/examples/extensions/email_this_page/background.html
@@ -0,0 +1,66 @@
+<!--
+ * 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.
+-->
+<html>
+<head>
+<script>
+ function customMailtoUrl() {
+ if (window.localStorage == null)
+ return "";
+ if (window.localStorage.customMailtoUrl == null)
+ return "";
+ return window.localStorage.customMailtoUrl;
+ }
+
+ function executeMailto(tab_id, subject, body) {
+ var action_url = "mailto:?"
+ if (subject.length > 0)
+ action_url += "subject=" + subject + "%26"; // 26 is ampersand.
+ if (body.length > 0)
+ action_url += "body=" + body;
+
+ var custom_url = customMailtoUrl();
+ if (custom_url.length > 0) {
+ // Custom URL's (such as opening mailto in Gmail tab) should have a
+ // separate tab to avoid clobbering the page you are on.
+ action_url = custom_url.replace("%s", action_url);
+ console.log('Custom url: ' + action_url);
+ chrome.tabs.create({ url: action_url });
+ } else {
+ // Plain vanilla mailto links open up in the same tab to prevent
+ // blank tabs being left behind.
+ console.log('Action url: ' + action_url);
+ chrome.tabs.update(tab_id, { url: action_url });
+ }
+ }
+
+ chrome.extension.onConnect.addListener(function(port) {
+ var tab = port.sender.tab;
+
+ // 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));
+ });
+ });
+
+ // Called when the user clicks on the browser action icon.
+ chrome.browserAction.onClicked.addListener(function(tab) {
+ // We can only inject scripts to find the title on pages loaded with http
+ // 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));
+ } 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);
+ }
+ });
+</script>
+</head>
+</html>
diff --git a/chrome/common/extensions/docs/examples/extensions/email_this_page/email_16x16.png b/chrome/common/extensions/docs/examples/extensions/email_this_page/email_16x16.png
new file mode 100644
index 0000000..492bdc6
--- /dev/null
+++ b/chrome/common/extensions/docs/examples/extensions/email_this_page/email_16x16.png
Binary files differ
diff --git a/chrome/common/extensions/docs/examples/extensions/email_this_page/mail_128x128.png b/chrome/common/extensions/docs/examples/extensions/email_this_page/mail_128x128.png
new file mode 100644
index 0000000..4221ec5
--- /dev/null
+++ b/chrome/common/extensions/docs/examples/extensions/email_this_page/mail_128x128.png
Binary files differ
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
new file mode 100644
index 0000000..124111b
--- /dev/null
+++ b/chrome/common/extensions/docs/examples/extensions/email_this_page/manifest.json
@@ -0,0 +1,15 @@
+{
+ "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",
+ "background_page": "background.html",
+ "icons": { "128": "mail_128x128.png" },
+ "options_page": "options.html",
+ "permissions": [
+ "tabs", "http://*/*", "https://*/*"
+ ],
+ "browser_action": {
+ "default_title": "Email this page",
+ "default_icon": "email_16x16.png"
+ }
+} \ No newline at end of file
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
new file mode 100644
index 0000000..1fa4cf5
--- /dev/null
+++ b/chrome/common/extensions/docs/examples/extensions/email_this_page/options.html
@@ -0,0 +1,60 @@
+<!DOCTYPE>
+<!--
+ * 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.
+-->
+<html>
+<head>
+ <title>Options for the Send as Email extension</title>
+<style>
+body {
+ font-family: Helvetica, Arial, sans-serif;
+ font-size: 10pt;
+}
+</style>
+<script>
+function toggle(radioButton) {
+ if (window.localStorage == null) {
+ alert('Local storage is required for changing providers');
+ return;
+ }
+
+ var selected = radioButton.value;
+ if (selected == "gmail") {
+ window.localStorage.customMailtoUrl =
+ 'https://mail.google.com/mail/?extsrc=mailto&url=%s';
+ } else {
+ window.localStorage.customMailtoUrl = "";
+ }
+}
+
+function main() {
+ if (window.localStorage == null) {
+ alert("LocalStorage must be enabled for changing options.");
+ document.getElementById('default').disabled = true;
+ document.getElementById('gmail').disabled = true;
+ return;
+ }
+
+ // Default handler is checked. If we've chosen another provider, we must
+ // change the checkmark.
+ if (window.localStorage.customMailtoUrl != null &&
+ window.localStorage.customMailtoUrl != "")
+ 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>
+</body>
+</html>