Commit 4c66f0e4 authored by jyasskin@chromium.org's avatar jyasskin@chromium.org

Change the pageaction_by_content example to use declarativeContent.

The "Mappy" sample still provides an example of a content script searching for
text.

The new icon comes from http://en.wikipedia.org/wiki/File:Video_icon2.png, which
is public domain.

TEST=Install the extension, and visit http://www.html5rocks.com/en/tutorials/video/basics/. The page action icon should show up.
BUG=330359
NOTRY=true

Review URL: https://codereview.chromium.org/124603003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@243475 0039d316-1c4b-4281-b951-d872f2087c98
parent d5838dd8
......@@ -2,16 +2,18 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// 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);
// Update the declarative rules on install or upgrade.
chrome.runtime.onInstalled.addListener(function() {
chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
chrome.declarativeContent.onPageChanged.addRules([{
conditions: [
// When a page contains a <video> tag...
new chrome.declarativeContent.PageStateMatcher({
css: ["video"]
})
],
// ... show the page action.
actions: [new chrome.declarativeContent.ShowPageAction() ]
}]);
});
});
/*
* 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.
}
{
"name" : "Page action by content",
"version" : "1.1",
"description" : "Shows a page action for HTML pages containing the word 'sandwich'",
"description" : "Shows a page action for HTML pages containing a video",
"background" : {
"scripts": ["background.js"]
"scripts": ["background.js"],
"persistent": false
},
"page_action" :
{
"default_icon" : "sandwich-19.png",
"default_title" : "There's a 'sandwich' in this page!"
"default_icon" : "video-19.png",
"default_title" : "There's a <video> in this page!"
},
"content_scripts" : [
{
"matches" : [
"http://*/*",
"https://*/*"
],
"js" : ["contentscript.js"],
"run_at" : "document_idle",
"all_frames" : false
}
],
"permissions": [ "declarativeContent" ],
"icons" : {
"48" : "sandwich-48.png",
"128" : "sandwich-128.png"
"48" : "video-48.png",
"128" : "video-128.png"
},
"manifest_version": 2
}
\ No newline at end of file
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment