Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(716)

Side by Side Diff: chrome/common/extensions/docs/examples/api/eventPage/basic/background.js

Issue 10257006: Move Declarative Web Request API out of experimental and make it a feature (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merged with ToT Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 // Global variables only exist for the life of the page, so they get reset 5 // Global variables only exist for the life of the page, so they get reset
6 // each time the page is unloaded. 6 // each time the page is unloaded.
7 var counter = 1; 7 var counter = 1;
8 8
9 var lastTabId = -1; 9 var lastTabId = -1;
10 function sendMessage() { 10 function sendMessage() {
11 chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { 11 chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
12 lastTabId = tabs[0].id; 12 lastTabId = tabs[0].id;
13 chrome.tabs.sendMessage(lastTabId, "Background page started."); 13 chrome.tabs.sendMessage(lastTabId, "Background page started.");
14 }); 14 });
15 } 15 }
16 16
17 sendMessage(); 17 sendMessage();
18 chrome.browserAction.setBadgeText({text: "ON"}); 18 chrome.browserAction.setBadgeText({text: "ON"});
19 console.log("Loaded."); 19 console.log("Loaded.");
20 20
21 chrome.experimental.runtime.onInstalled.addListener(function() { 21 chrome.experimental.runtime.onInstalled.addListener(function() {
22 console.log("Installed."); 22 console.log("Installed.");
23 23
24 // localStorage is persisted, so it's a good place to keep state that you 24 // localStorage is persisted, so it's a good place to keep state that you
25 // need to persist across page reloads. 25 // need to persist across page reloads.
26 localStorage.counter = 1; 26 localStorage.counter = 1;
27 27
28 // Register a webRequest rule to redirect bing to google. 28 // Register a webRequest rule to redirect bing to google.
29 var wr = chrome.experimental.webRequest; 29 var wr = chrome.declarativeWebRequest;
30 chrome.experimental.webRequest.onRequest.addRules([{ 30 chrome.declarativeWebRequest.onRequest.addRules([{
31 id: "0", 31 id: "0",
32 conditions: [new wr.RequestMatcher({url: {hostSuffix: "bing.com"}})], 32 conditions: [new wr.RequestMatcher({url: {hostSuffix: "bing.com"}})],
33 actions: [new wr.RedirectRequest({redirectUrl: "http://google.com"})] 33 actions: [new wr.RedirectRequest({redirectUrl: "http://google.com"})]
34 }]); 34 }]);
35 }); 35 });
36 36
37 chrome.bookmarks.onRemoved.addListener(function(id, info) { 37 chrome.bookmarks.onRemoved.addListener(function(id, info) {
38 alert("I never liked that site anyway."); 38 alert("I never liked that site anyway.");
39 }); 39 });
40 40
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 function() { 83 function() {
84 chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { 84 chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
85 // After the unload event listener runs, the page will unload, so any 85 // After the unload event listener runs, the page will unload, so any
86 // asynchronous callbacks will not fire. 86 // asynchronous callbacks will not fire.
87 alert("This does not show up."); 87 alert("This does not show up.");
88 }); 88 });
89 console.log("Unloading."); 89 console.log("Unloading.");
90 chrome.browserAction.setBadgeText({text: ""}); 90 chrome.browserAction.setBadgeText({text: ""});
91 chrome.tabs.sendMessage(lastTabId, "Background page unloaded."); 91 chrome.tabs.sendMessage(lastTabId, "Background page unloaded.");
92 }); 92 });
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/examples/api/eventPage/basic.zip ('k') | chrome/common/extensions/docs/experimental.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698