OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Called when a message is passed. We assume that the content script | 5 // Update the declarative rules on install or upgrade. |
6 // wants to show the page action. | 6 chrome.runtime.onInstalled.addListener(function() { |
7 function onRequest(request, sender, sendResponse) { | 7 chrome.declarativeContent.onPageChanged.removeRules(undefined, function() { |
8 // Show the page action for the tab that the sender (content script) | 8 chrome.declarativeContent.onPageChanged.addRules([{ |
9 // was on. | 9 conditions: [ |
10 chrome.pageAction.show(sender.tab.id); | 10 // When a page contains a <video> tag... |
11 | 11 new chrome.declarativeContent.PageStateMatcher({ |
12 // Return nothing to let the connection be cleaned up. | 12 css: ["video"] |
13 sendResponse({}); | 13 }) |
14 }; | 14 ], |
15 | 15 // ... show the page action. |
16 // Listen for the content script to send a message to the background page. | 16 actions: [new chrome.declarativeContent.ShowPageAction() ] |
17 chrome.extension.onRequest.addListener(onRequest); | 17 }]); |
| 18 }); |
| 19 }); |
OLD | NEW |