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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 sendMessage(); | 49 sendMessage(); |
50 }); | 50 }); |
51 }); | 51 }); |
52 | 52 |
53 chrome.experimental.keybinding.onCommand.addListener(function(command) { | 53 chrome.experimental.keybinding.onCommand.addListener(function(command) { |
54 chrome.tabs.create({url: "http://www.google.com/"}); | 54 chrome.tabs.create({url: "http://www.google.com/"}); |
55 }); | 55 }); |
56 | 56 |
57 chrome.extension.onMessage.addListener(function(msg, _, sendResponse) { | 57 chrome.extension.onMessage.addListener(function(msg, _, sendResponse) { |
58 if (msg.setAlarm) { | 58 if (msg.setAlarm) { |
59 chrome.experimental.alarms.create({delayInSeconds: 5}); | 59 chrome.experimental.alarms.create({delayInMinutes: 0.1}); |
60 } else if (msg.delayedResponse) { | 60 } else if (msg.delayedResponse) { |
61 // Note: setTimeout itself does NOT keep the page awake. We return true | 61 // Note: setTimeout itself does NOT keep the page awake. We return true |
62 // from the onMessage event handler, which keeps the message channel open - | 62 // from the onMessage event handler, which keeps the message channel open - |
63 // in turn keeping the transient page awake - until we call sendResponse. | 63 // in turn keeping the transient page awake - until we call sendResponse. |
64 setTimeout(function() { | 64 setTimeout(function() { |
65 sendResponse("Got your message."); | 65 sendResponse("Got your message."); |
66 }, 5000); | 66 }, 5000); |
67 return true; | 67 return true; |
68 } else if (msg.getCounters) { | 68 } else if (msg.getCounters) { |
69 sendResponse({counter: counter++, | 69 sendResponse({counter: counter++, |
(...skipping 11 matching lines...) Expand all Loading... |
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 }); |
OLD | NEW |