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 @@ ...@@ -2,16 +2,18 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// Called when a message is passed. We assume that the content script // Update the declarative rules on install or upgrade.
// wants to show the page action. chrome.runtime.onInstalled.addListener(function() {
function onRequest(request, sender, sendResponse) { chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
// Show the page action for the tab that the sender (content script) chrome.declarativeContent.onPageChanged.addRules([{
// was on. conditions: [
chrome.pageAction.show(sender.tab.id); // When a page contains a <video> tag...
new chrome.declarativeContent.PageStateMatcher({
// Return nothing to let the connection be cleaned up. css: ["video"]
sendResponse({}); })
}; ],
// ... show the page action.
// Listen for the content script to send a message to the background page. actions: [new chrome.declarativeContent.ShowPageAction() ]
chrome.extension.onRequest.addListener(onRequest); }]);
});
});
/*
* 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", "name" : "Page action by content",
"version" : "1.1", "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" : { "background" : {
"scripts": ["background.js"] "scripts": ["background.js"],
"persistent": false
}, },
"page_action" : "page_action" :
{ {
"default_icon" : "sandwich-19.png", "default_icon" : "video-19.png",
"default_title" : "There's a 'sandwich' in this page!" "default_title" : "There's a <video> in this page!"
}, },
"content_scripts" : [ "permissions": [ "declarativeContent" ],
{
"matches" : [
"http://*/*",
"https://*/*"
],
"js" : ["contentscript.js"],
"run_at" : "document_idle",
"all_frames" : false
}
],
"icons" : { "icons" : {
"48" : "sandwich-48.png", "48" : "video-48.png",
"128" : "sandwich-128.png" "128" : "video-128.png"
}, },
"manifest_version": 2 "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