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 var animationFrames = 36; | 5 var animationFrames = 36; |
6 var animationSpeed = 10; // ms | 6 var animationSpeed = 10; // ms |
7 var canvas = document.getElementById('canvas'); | 7 var canvas = document.getElementById('canvas'); |
8 var loggedInImage = document.getElementById('logged_in'); | 8 var loggedInImage = document.getElementById('logged_in'); |
9 var canvasContext = canvas.getContext('2d'); | 9 var canvasContext = canvas.getContext('2d'); |
10 var pollIntervalMin = 5; // 5 minutes | 10 var pollIntervalMin = 5; // 5 minutes |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 chrome.runtime.onInstalled.addListener(onInit); | 317 chrome.runtime.onInstalled.addListener(onInit); |
318 chrome.alarms.onAlarm.addListener(onAlarm); | 318 chrome.alarms.onAlarm.addListener(onAlarm); |
319 } | 319 } |
320 | 320 |
321 var filters = { | 321 var filters = { |
322 // TODO(aa): Cannot use urlPrefix because all the url fields lack the protocol | 322 // TODO(aa): Cannot use urlPrefix because all the url fields lack the protocol |
323 // part. See crbug.com/140238. | 323 // part. See crbug.com/140238. |
324 url: [{urlContains: getGmailUrl().replace(/^https?\:\/\//, '')}] | 324 url: [{urlContains: getGmailUrl().replace(/^https?\:\/\//, '')}] |
325 }; | 325 }; |
326 | 326 |
327 chrome.webNavigation.onDOMContentLoaded.addListener(function(changeInfo) { | 327 function onNavigate(details) { |
328 if (changeInfo.url && isGmailUrl(changeInfo.url)) { | 328 if (details.url && isGmailUrl(details.url)) { |
329 console.log('Recognized Gmail navigation to: ' + changeInfo.url + '.' + | 329 console.log('Recognized Gmail navigation to: ' + details.url + '.' + |
330 'Refreshing count...'); | 330 'Refreshing count...'); |
331 startRequest({scheduleRequest:false, showLoadingAnimation:false}); | 331 startRequest({scheduleRequest:false, showLoadingAnimation:false}); |
332 } | 332 } |
333 }, filters); | 333 } |
| 334 if (chrome.webNavigation && chrome.webNavigation.onDOMContentLoaded && |
| 335 chrome.webNavigation.onReferenceFragmentUpdated) { |
| 336 chrome.webNavigation.onDOMContentLoaded.addListener(onNavigate, filters); |
| 337 chrome.webNavigation.onReferenceFragmentUpdated.addListener( |
| 338 onNavigate, filters); |
| 339 } else { |
| 340 chrome.tabs.onUpdated.addListener(function(_, details) { |
| 341 onNavigate(details); |
| 342 }); |
| 343 } |
334 | 344 |
335 chrome.browserAction.onClicked.addListener(goToInbox); | 345 chrome.browserAction.onClicked.addListener(goToInbox); |
336 | 346 |
337 // This hack is needed because Chrome 22 does not persist browserAction icon | 347 // This hack is needed because Chrome 22 does not persist browserAction icon |
338 // state, and also doesn't expose onStartup. So the icon always starts out in | 348 // state, and also doesn't expose onStartup. So the icon always starts out in |
339 // wrong state. We don't actually need onStartup, we just use it as a clue | 349 // wrong state. We don't actually need onStartup, we just use it as a clue |
340 // that we're in a version of Chrome that has this problem. | 350 // that we're in a version of Chrome that has this problem. |
341 if (chrome.runtime && !chrome.runtime.onStartup) { | 351 if (chrome.runtime && !chrome.runtime.onStartup) { |
342 chrome.windows.onCreated.addListener(function() { | 352 chrome.windows.onCreated.addListener(function() { |
343 console.log('Window created... updating icon.'); | 353 console.log('Window created... updating icon.'); |
344 updateIcon(); | 354 updateIcon(); |
345 }); | 355 }); |
346 } | 356 } |
OLD | NEW |