Index: chrome/browser/resources/google_now/background.js |
diff --git a/chrome/browser/resources/google_now/background.js b/chrome/browser/resources/google_now/background.js |
index ef01369e63aecc436adebc359e65cc9de482fabe..cf39590dc31d766573b9940b7886682a7f3c501a 100644 |
--- a/chrome/browser/resources/google_now/background.js |
+++ b/chrome/browser/resources/google_now/background.js |
@@ -153,6 +153,7 @@ wrapper.instrumentChromeApiFunction('location.onLocationUpdate.addListener', 0); |
wrapper.instrumentChromeApiFunction('metricsPrivate.getVariationParams', 1); |
wrapper.instrumentChromeApiFunction('notifications.clear', 1); |
wrapper.instrumentChromeApiFunction('notifications.create', 2); |
+wrapper.instrumentChromeApiFunction('notifications.getPermissionLevel', 0); |
wrapper.instrumentChromeApiFunction('notifications.update', 2); |
wrapper.instrumentChromeApiFunction('notifications.getAll', 0); |
wrapper.instrumentChromeApiFunction( |
@@ -160,6 +161,8 @@ wrapper.instrumentChromeApiFunction( |
wrapper.instrumentChromeApiFunction('notifications.onClicked.addListener', 0); |
wrapper.instrumentChromeApiFunction('notifications.onClosed.addListener', 0); |
wrapper.instrumentChromeApiFunction( |
+ 'notifications.onPermissionLevelChanged.addListener', 0); |
+wrapper.instrumentChromeApiFunction( |
'preferencesPrivate.googleGeolocationAccessEnabled.get', |
1); |
wrapper.instrumentChromeApiFunction( |
@@ -273,8 +276,6 @@ function showNotificationCards(cards) { |
instrumented.notifications.getAll(function(notifications) { |
console.log('showNotificationCards-getAll ' + |
JSON.stringify(notifications)); |
- // TODO(vadimt): Figure out what to do when notifications are |
- // disabled for our extension. |
notifications = notifications || {}; |
// Build a set of non-expired recent dismissals. It will be used for |
@@ -920,14 +921,19 @@ function setBackgroundEnable(backgroundEnable) { |
* the geolocation option is enabled. |
* @param {boolean} enableBackground true if |
* the background permission should be requested. |
+ * @param {boolean} notificationEnabled true if |
+ * Google Now for Chrome is allowed to show notifications. |
*/ |
function updateRunningState( |
signedIn, |
geolocationEnabled, |
- enableBackground) { |
+ enableBackground, |
+ notificationEnabled) { |
console.log( |
'State Update signedIn=' + signedIn + ' ' + |
- 'geolocationEnabled=' + geolocationEnabled); |
+ 'geolocationEnabled=' + geolocationEnabled + ' ' + |
+ 'enableBackground=' + enableBackground + ' ' + |
+ 'notificationEnabled=' + notificationEnabled); |
// TODO(vadimt): Remove this line once state machine design is finalized. |
geolocationEnabled = true; |
@@ -935,7 +941,7 @@ function updateRunningState( |
var shouldPollCards = false; |
var shouldSetBackground = false; |
- if (signedIn) { |
+ if (signedIn && notificationEnabled) { |
if (geolocationEnabled) { |
if (enableBackground) |
shouldSetBackground = true; |
@@ -967,7 +973,9 @@ function onStateChange() { |
function(response) { |
var enableBackground = |
(!response || (response.enableBackground != 'false')); |
- instrumented. |
+ instrumented.notifications.getPermissionLevel(function(level) { |
+ var notificationEnabled = (level == 'granted'); |
+ instrumented. |
preferencesPrivate. |
googleGeolocationAccessEnabled. |
get({}, function(prefValue) { |
@@ -975,8 +983,10 @@ function onStateChange() { |
updateRunningState( |
signedIn, |
geolocationEnabled, |
- enableBackground); |
+ enableBackground, |
+ notificationEnabled); |
}); |
+ }); |
}); |
}); |
}); |
@@ -1044,6 +1054,12 @@ instrumented.notifications.onButtonClicked.addListener( |
instrumented.notifications.onClosed.addListener(onNotificationClosed); |
+instrumented.notifications.onPermissionLevelChanged.addListener( |
+ function(permissionLevel) { |
+ console.log('Notifications permissionLevel Change'); |
+ onStateChange(); |
+ }); |
+ |
instrumented.location.onLocationUpdate.addListener(function(position) { |
recordEvent(GoogleNowEvent.LOCATION_UPDATE); |
updateNotificationsCards(position); |