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

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

Issue 9997001: Fix transient page sample extension to use 'runtime' API, which landed just (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.extension.onInstalled.addListener(function() { 21 chrome.experimental.runtime.onInstalled.addListener(function() {
22 // localStorage is persisted, so it's a good place to keep state that you 22 // localStorage is persisted, so it's a good place to keep state that you
23 // need to persist across page reloads. 23 // need to persist across page reloads.
24 localStorage.counter = 1; 24 localStorage.counter = 1;
25 console.log("Installed."); 25 console.log("Installed.");
26 }); 26 });
27 27
28 chrome.bookmarks.onRemoved.addListener(function(id, info) { 28 chrome.bookmarks.onRemoved.addListener(function(id, info) {
29 alert("I never liked that site anyway."); 29 alert("I never liked that site anyway.");
30 }); 30 });
31 31
(...skipping 25 matching lines...) Expand all
57 persistentCounter: localStorage.counter++}); 57 persistentCounter: localStorage.counter++});
58 } 58 }
59 // If we don't return anything, the message channel will close, regardless 59 // If we don't return anything, the message channel will close, regardless
60 // of whether we called sendResponse. 60 // of whether we called sendResponse.
61 }); 61 });
62 62
63 chrome.experimental.alarms.onAlarm.addListener(function() { 63 chrome.experimental.alarms.onAlarm.addListener(function() {
64 alert("Time's up!"); 64 alert("Time's up!");
65 }); 65 });
66 66
67 chrome.experimental.extension.onBackgroundPageUnloadingSoon.addListener( 67 chrome.experimental.runtime.onBackgroundPageUnloadingSoon.addListener(
68 function() { 68 function() {
69 chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { 69 chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
70 // After the unload event listener runs, the page will unload, so any 70 // After the unload event listener runs, the page will unload, so any
71 // asynchronous callbacks will not fire. 71 // asynchronous callbacks will not fire.
72 alert("This does not show up."); 72 alert("This does not show up.");
73 }); 73 });
74 console.log("Unloading."); 74 console.log("Unloading.");
75 chrome.browserAction.setBadgeText({text: ""}); 75 chrome.browserAction.setBadgeText({text: ""});
76 chrome.tabs.sendMessage(lastTabId, "Background page unloaded."); 76 chrome.tabs.sendMessage(lastTabId, "Background page unloaded.");
77 }); 77 });
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/examples/api/transientPage/basic.zip ('k') | chrome/common/extensions/docs/privacy.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698