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

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

Issue 11745015: Update references to the extension messaging APIs to point to the "runtime" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 11 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() {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 // another here. 49 // another here.
50 sendMessage(); 50 sendMessage();
51 }); 51 });
52 }); 52 });
53 }); 53 });
54 54
55 chrome.experimental.keybinding.onCommand.addListener(function(command) { 55 chrome.experimental.keybinding.onCommand.addListener(function(command) {
56 chrome.tabs.create({url: "http://www.google.com/"}); 56 chrome.tabs.create({url: "http://www.google.com/"});
57 }); 57 });
58 58
59 chrome.extension.onMessage.addListener(function(msg, _, sendResponse) { 59 chrome.runtime.onMessage.addListener(function(msg, _, sendResponse) {
60 if (msg.setAlarm) { 60 if (msg.setAlarm) {
61 chrome.alarms.create({delayInMinutes: 0.1}); 61 chrome.alarms.create({delayInMinutes: 0.1});
62 } else if (msg.delayedResponse) { 62 } else if (msg.delayedResponse) {
63 // Note: setTimeout itself does NOT keep the page awake. We return true 63 // Note: setTimeout itself does NOT keep the page awake. We return true
64 // from the onMessage event handler, which keeps the message channel open - 64 // from the onMessage event handler, which keeps the message channel open -
65 // in turn keeping the event page awake - until we call sendResponse. 65 // in turn keeping the event page awake - until we call sendResponse.
66 setTimeout(function() { 66 setTimeout(function() {
67 sendResponse("Got your message."); 67 sendResponse("Got your message.");
68 }, 5000); 68 }, 5000);
69 return true; 69 return true;
(...skipping 12 matching lines...) Expand all
82 chrome.runtime.onSuspend.addListener(function() { 82 chrome.runtime.onSuspend.addListener(function() {
83 chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { 83 chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
84 // After the unload event listener runs, the page will unload, so any 84 // After the unload event listener runs, the page will unload, so any
85 // asynchronous callbacks will not fire. 85 // asynchronous callbacks will not fire.
86 alert("This does not show up."); 86 alert("This does not show up.");
87 }); 87 });
88 console.log("Unloading."); 88 console.log("Unloading.");
89 chrome.browserAction.setBadgeText({text: ""}); 89 chrome.browserAction.setBadgeText({text: ""});
90 chrome.tabs.sendMessage(lastTabId, "Background page unloaded."); 90 chrome.tabs.sendMessage(lastTabId, "Background page unloaded.");
91 }); 91 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698