diff options
author | kathyw@chromium.org <kathyw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-05 22:15:33 +0000 |
---|---|---|
committer | kathyw@chromium.org <kathyw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-05 22:15:33 +0000 |
commit | f3f0c05dfbcbfec2ecbb79ba9bab6ffc8f93ea32 (patch) | |
tree | 9ecd31a7026f57ca975b6268985cb2eb2159c71e /chrome | |
parent | 37e4c90afd94c73f3d8c8fe014faac7917254c63 (diff) | |
download | chromium_src-f3f0c05dfbcbfec2ecbb79ba9bab6ffc8f93ea32.zip chromium_src-f3f0c05dfbcbfec2ecbb79ba9bab6ffc8f93ea32.tar.gz chromium_src-f3f0c05dfbcbfec2ecbb79ba9bab6ffc8f93ea32.tar.bz2 |
Arne's examples of two approaches to showing a page action:
* for particular URLs (chrome.tabs.onUpdated)
* for particular page content (content script)
TEST=none
BUG=34694
Review URL: http://codereview.chromium.org/561087
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38264 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
11 files changed, 106 insertions, 0 deletions
diff --git a/chrome/common/extensions/docs/examples/api/pageAction/pageaction_by_content/background.html b/chrome/common/extensions/docs/examples/api/pageAction/pageaction_by_content/background.html new file mode 100644 index 0000000..2c545fd --- /dev/null +++ b/chrome/common/extensions/docs/examples/api/pageAction/pageaction_by_content/background.html @@ -0,0 +1,25 @@ +<!DOCTYPE html> +<!-- + * Copyright (c) 2010 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> + // Called when a message is passed. We assume that the content script + // wants to show the page action. + function onRequest(request, sender, sendResponse) { + // Show the page action for the tab that the sender (content script) + // was on. + chrome.pageAction.show(sender.tab.id); + + // Return nothing to let the connection be cleaned up. + sendResponse({}); + }; + + // Listen for the content script to send a message to the background page. + chrome.extension.onRequest.addListener(onRequest); + </script> + </head> +</html> diff --git a/chrome/common/extensions/docs/examples/api/pageAction/pageaction_by_content/contentscript.js b/chrome/common/extensions/docs/examples/api/pageAction/pageaction_by_content/contentscript.js new file mode 100644 index 0000000..91037bb --- /dev/null +++ b/chrome/common/extensions/docs/examples/api/pageAction/pageaction_by_content/contentscript.js @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2010 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 regex = /sandwich/; + +// Test the text of the body element against our regular expression. +if (regex.test(document.body.innerText)) { + // The regular expression produced a match, so notify the background page. + chrome.extension.sendRequest({}, function(response) {}); +} else { + // No match was found. +} diff --git a/chrome/common/extensions/docs/examples/api/pageAction/pageaction_by_content/manifest.json b/chrome/common/extensions/docs/examples/api/pageAction/pageaction_by_content/manifest.json new file mode 100644 index 0000000..50643ee --- /dev/null +++ b/chrome/common/extensions/docs/examples/api/pageAction/pageaction_by_content/manifest.json @@ -0,0 +1,26 @@ +{ + "name" : "Page action by content", + "version" : "1.0", + "description" : "Shows a page action for HTML pages containing the word 'sandwich'", + "background_page" : "background.html", + "page_action" : + { + "default_icon" : "sandwich-19.png", + "default_title" : "There's a 'sandwich' in this page!" + }, + "content_scripts" : [ + { + "matches" : [ + "http://*/*", + "https://*/*" + ], + "js" : ["contentscript.js"], + "run_at" : "document_idle", + "all_frames" : false + } + ], + "icons" : { + "48" : "sandwich-48.png", + "128" : "sandwich-128.png" + } +} diff --git a/chrome/common/extensions/docs/examples/api/pageAction/pageaction_by_content/sandwich-128.png b/chrome/common/extensions/docs/examples/api/pageAction/pageaction_by_content/sandwich-128.png Binary files differnew file mode 100644 index 0000000..a233154 --- /dev/null +++ b/chrome/common/extensions/docs/examples/api/pageAction/pageaction_by_content/sandwich-128.png diff --git a/chrome/common/extensions/docs/examples/api/pageAction/pageaction_by_content/sandwich-19.png b/chrome/common/extensions/docs/examples/api/pageAction/pageaction_by_content/sandwich-19.png Binary files differnew file mode 100644 index 0000000..e84dc86 --- /dev/null +++ b/chrome/common/extensions/docs/examples/api/pageAction/pageaction_by_content/sandwich-19.png diff --git a/chrome/common/extensions/docs/examples/api/pageAction/pageaction_by_content/sandwich-48.png b/chrome/common/extensions/docs/examples/api/pageAction/pageaction_by_content/sandwich-48.png Binary files differnew file mode 100644 index 0000000..d7f2324 --- /dev/null +++ b/chrome/common/extensions/docs/examples/api/pageAction/pageaction_by_content/sandwich-48.png diff --git a/chrome/common/extensions/docs/examples/api/pageAction/pageaction_by_url/background.html b/chrome/common/extensions/docs/examples/api/pageAction/pageaction_by_url/background.html new file mode 100644 index 0000000..d30ace2 --- /dev/null +++ b/chrome/common/extensions/docs/examples/api/pageAction/pageaction_by_url/background.html @@ -0,0 +1,23 @@ +<!DOCTYPE html> +<!-- + * Copyright (c) 2010 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> + // Called when the url of a tab changes. + function checkForValidUrl(tabId, changeInfo, tab) { + // If the letter 'g' is found in the tab's URL... + if (tab.url.indexOf('g') > -1) { + // ... show the page action. + chrome.pageAction.show(tabId); + } + }; + + // Listen for any changes to the URL of any tab. + chrome.tabs.onUpdated.addListener(checkForValidUrl); + </script> + </head> +</html> diff --git a/chrome/common/extensions/docs/examples/api/pageAction/pageaction_by_url/icon-128.png b/chrome/common/extensions/docs/examples/api/pageAction/pageaction_by_url/icon-128.png Binary files differnew file mode 100644 index 0000000..fbfe538 --- /dev/null +++ b/chrome/common/extensions/docs/examples/api/pageAction/pageaction_by_url/icon-128.png diff --git a/chrome/common/extensions/docs/examples/api/pageAction/pageaction_by_url/icon-19.png b/chrome/common/extensions/docs/examples/api/pageAction/pageaction_by_url/icon-19.png Binary files differnew file mode 100644 index 0000000..91679f0 --- /dev/null +++ b/chrome/common/extensions/docs/examples/api/pageAction/pageaction_by_url/icon-19.png diff --git a/chrome/common/extensions/docs/examples/api/pageAction/pageaction_by_url/icon-48.png b/chrome/common/extensions/docs/examples/api/pageAction/pageaction_by_url/icon-48.png Binary files differnew file mode 100644 index 0000000..59e9935 --- /dev/null +++ b/chrome/common/extensions/docs/examples/api/pageAction/pageaction_by_url/icon-48.png diff --git a/chrome/common/extensions/docs/examples/api/pageAction/pageaction_by_url/manifest.json b/chrome/common/extensions/docs/examples/api/pageAction/pageaction_by_url/manifest.json new file mode 100644 index 0000000..ce991fa --- /dev/null +++ b/chrome/common/extensions/docs/examples/api/pageAction/pageaction_by_url/manifest.json @@ -0,0 +1,18 @@ +{ + "name": "Page action by URL", + "version": "1.0", + "description": "Shows a page action for urls which have the letter 'g' in them.", + "background_page": "background.html", + "page_action" : + { + "default_icon" : "icon-19.png", + "default_title" : "There's a 'G' in this URL!" + }, + "permissions" : [ + "tabs" + ], + "icons" : { + "48" : "icon-48.png", + "128" : "icon-128.png" + } +} |