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

Side by Side Diff: chrome/common/extensions/docs/examples/api/transientPage/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: Created 8 years, 8 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 function() { 81 function() {
82 chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { 82 chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
83 // After the unload event listener runs, the page will unload, so any 83 // After the unload event listener runs, the page will unload, so any
84 // asynchronous callbacks will not fire. 84 // asynchronous callbacks will not fire.
85 alert("This does not show up."); 85 alert("This does not show up.");
86 }); 86 });
87 console.log("Unloading."); 87 console.log("Unloading.");
88 chrome.browserAction.setBadgeText({text: ""}); 88 chrome.browserAction.setBadgeText({text: ""});
89 chrome.tabs.sendMessage(lastTabId, "Background page unloaded."); 89 chrome.tabs.sendMessage(lastTabId, "Background page unloaded.");
90 }); 90 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698