forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
kathyw@chromium.org
committed
Feb 5, 2010
1 parent
37e4c90
commit f3f0c05
Showing
11 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
chrome/common/extensions/docs/examples/api/pageAction/pageaction_by_content/background.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
14 changes: 14 additions & 0 deletions
14
chrome/common/extensions/docs/examples/api/pageAction/pageaction_by_content/contentscript.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
} |
26 changes: 26 additions & 0 deletions
26
chrome/common/extensions/docs/examples/api/pageAction/pageaction_by_content/manifest.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
} |
Binary file added
BIN
+7.89 KB
.../extensions/docs/examples/api/pageAction/pageaction_by_content/sandwich-128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+657 Bytes
...n/extensions/docs/examples/api/pageAction/pageaction_by_content/sandwich-19.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.56 KB
...n/extensions/docs/examples/api/pageAction/pageaction_by_content/sandwich-48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions
23
chrome/common/extensions/docs/examples/api/pageAction/pageaction_by_url/background.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
Binary file added
BIN
+9.98 KB
...e/common/extensions/docs/examples/api/pageAction/pageaction_by_url/icon-128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+809 Bytes
...me/common/extensions/docs/examples/api/pageAction/pageaction_by_url/icon-19.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.31 KB
...me/common/extensions/docs/examples/api/pageAction/pageaction_by_url/icon-48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions
18
chrome/common/extensions/docs/examples/api/pageAction/pageaction_by_url/manifest.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
} |