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 // 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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.extension.onMessage.addListener(function(msg, _, sendResponse) { |
60 if (msg.setAlarm) { | 60 if (msg.setAlarm) { |
61 chrome.experimental.alarms.create({delayInSeconds: 5}); | 61 chrome.experimental.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; |
70 } else if (msg.getCounters) { | 70 } else if (msg.getCounters) { |
71 sendResponse({counter: counter++, | 71 sendResponse({counter: counter++, |
(...skipping 11 matching lines...) Expand all Loading... |
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 }); |
OLD | NEW |