| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 /** | 5 /** |
| 6 * @fileoverview Provides notification support for ChromeVox. | 6 * @fileoverview Provides notification support for ChromeVox. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 goog.provide('Notifications'); | 9 goog.provide('Notifications'); |
| 10 | 10 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 return !localStorage['notifications_update_notification_shown'] && | 26 return !localStorage['notifications_update_notification_shown'] && |
| 27 chrome.runtime.getManifest().version >= '53' && | 27 chrome.runtime.getManifest().version >= '53' && |
| 28 cvox.ChromeVox.isChromeOS; | 28 cvox.ChromeVox.isChromeOS; |
| 29 }, | 29 }, |
| 30 | 30 |
| 31 /** Shows the notification. */ | 31 /** Shows the notification. */ |
| 32 show: function() { | 32 show: function() { |
| 33 if (!this.shouldShow()) | 33 if (!this.shouldShow()) |
| 34 return; | 34 return; |
| 35 chrome.notifications.create('update', this.data); | 35 chrome.notifications.create('update', this.data); |
| 36 chrome.notifications.onClicked.addListener( | 36 chrome.notifications.onClicked.addListener(this.onClicked); |
| 37 this.onClicked.bind(this)); | 37 chrome.notifications.onClosed.addListener(this.onClosed); |
| 38 chrome.notifications.onClosed.addListener( | |
| 39 this.onClosed.bind(this)); | |
| 40 }, | 38 }, |
| 41 | 39 |
| 42 /** | 40 /** |
| 43 * Handles the chrome.notifications event. | 41 * Handles the chrome.notifications event. |
| 44 * @param {string} notificationId | 42 * @param {string} notificationId |
| 45 */ | 43 */ |
| 46 onClicked: function(notificationId) { | 44 onClicked: function(notificationId) { |
| 47 var nextUpdatePage = {url: 'cvox2/background/next_update.html'}; | 45 var nextUpdatePage = {url: 'cvox2/background/next_update.html'}; |
| 48 chrome.tabs.create(nextUpdatePage); | 46 chrome.tabs.create(nextUpdatePage); |
| 49 }, | 47 }, |
| 50 | 48 |
| 51 /** | 49 /** |
| 52 * Handles the chrome.notifications event. | 50 * Handles the chrome.notifications event. |
| 53 * @param {string} id | 51 * @param {string} id |
| 54 */ | 52 */ |
| 55 onClosed: function(id) { | 53 onClosed: function(id) { |
| 56 localStorage['notifications_update_notification_shown'] = true; | 54 localStorage['notifications_update_notification_shown'] = true; |
| 55 }, |
| 56 |
| 57 /** |
| 58 * Removes all listeners added by this object. |
| 59 */ |
| 60 removeAllListeners: function() { |
| 61 chrome.notifications.onClicked.removeListener(this.onClicked); |
| 62 chrome.notifications.onClosed.removeListener(this.onClosed); |
| 57 } | 63 } |
| 58 }; | 64 }; |
| 59 | 65 |
| 60 /** | 66 /** |
| 67 * Set after an update is shown. |
| 68 * @type {UpdateNotification} |
| 69 */ |
| 70 Notifications.currentUpdate; |
| 71 |
| 72 /** |
| 61 * Runs notifications that should be shown for startup. | 73 * Runs notifications that should be shown for startup. |
| 62 */ | 74 */ |
| 63 Notifications.onStartup = function() { | 75 Notifications.onStartup = function() { |
| 76 return; |
| 64 // Only run on background page. | 77 // Only run on background page. |
| 65 if (document.location.href.indexOf('background.html') == -1) | 78 if (document.location.href.indexOf('background.html') == -1) |
| 66 return; | 79 return; |
| 67 | 80 |
| 68 new UpdateNotification().show(); | 81 Notifications.reset(); |
| 82 Notifications.currentUpdate = new UpdateNotification(); |
| 83 Notifications.currentUpdate.show(); |
| 69 }; | 84 }; |
| 70 | 85 |
| 71 /** | 86 /** |
| 72 * Runs notifications that should be shown for mode changes. | 87 * Runs notifications that should be shown for mode changes. |
| 73 */ | 88 */ |
| 74 Notifications.onModeChange = function() { | 89 Notifications.onModeChange = function() { |
| 90 return; |
| 75 // Only run on background page. | 91 // Only run on background page. |
| 76 if (document.location.href.indexOf('background.html') == -1) | 92 if (document.location.href.indexOf('background.html') == -1) |
| 77 return; | 93 return; |
| 78 | 94 |
| 79 if (ChromeVoxState.instance.mode !== ChromeVoxMode.FORCE_NEXT) | 95 if (ChromeVoxState.instance.mode !== ChromeVoxMode.FORCE_NEXT) |
| 80 return; | 96 return; |
| 81 | 97 |
| 82 new UpdateNotification().show(); | 98 Notifications.reset(); |
| 99 Notifications.currentUpdate = new UpdateNotification(); |
| 100 Notifications.currentUpdate.show(); |
| 83 }; | 101 }; |
| 102 |
| 103 /** |
| 104 * Resets to a clean state. Future events will trigger update notifications. |
| 105 */ |
| 106 Notifications.reset = function() { |
| 107 if (Notifications.currentUpdate) |
| 108 Notifications.currentUpdate.removeAllListeners(); |
| 109 delete localStorage['notifications_update_notification_shown']; |
| 110 }; |
| OLD | NEW |