Commit 779569a6 authored by Kyle Milka's avatar Kyle Milka Committed by Commit Bot

[NTP] Handle users being signed-out while dialogs are open

If the user is redirected to sign-in to Google Photos the
customization dialog should be left open.

If the user signs out while the albums dialog is open clicking
on an album should redirect them to the sign-in page.

Bug: 865740, 865735
Change-Id: Ic6e0c529f7f42f05efff81b868b9a5042c87cac3
Reviewed-on: https://chromium-review.googlesource.com/1145869
Commit-Queue: Kyle Milka <kmilka@chromium.org>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#577238}
parent 201f4785
...@@ -327,16 +327,23 @@ customBackgrounds.showCollectionSelectionDialog = function(collectionsSource) { ...@@ -327,16 +327,23 @@ customBackgrounds.showCollectionSelectionDialog = function(collectionsSource) {
photos[0].photoContainerId == tile.dataset.photoContainerId); photos[0].photoContainerId == tile.dataset.photoContainerId);
} }
// Dependent upon the succces of the load, populate the image selection // Dependent upon the success of the load, populate the image selection
// dialog or close the current dialog. // dialog or close the current dialog.
customBackgrounds.resetSelectionDialog();
if (imageDataLoaded) { if (imageDataLoaded) {
customBackgrounds.resetSelectionDialog();
customBackgrounds.showImageSelectionDialog(tile.dataset.name); customBackgrounds.showImageSelectionDialog(tile.dataset.name);
} else { } else {
let source = customBackgrounds.dialogCollectionsSource; let errors =
customBackgrounds.closeCollectionDialog(menu); (collectionsSource ==
customBackgrounds.SOURCES.CHROME_BACKGROUNDS ?
let errors = source ? coll_img_errors : photos_errors; coll_img_errors :
photos_errors);
// If an auth error occurs leave the dialog open and redirect the
// user to sign-in again. Then they can return to the same place in
// the customization flow.
if (!errors.auth_error) {
customBackgrounds.closeCollectionDialog(menu);
}
customBackgrounds.handleError(errors); customBackgrounds.handleError(errors);
} }
}; };
...@@ -493,7 +500,7 @@ customBackgrounds.showImageSelectionDialog = function(dialogTitle) { ...@@ -493,7 +500,7 @@ customBackgrounds.showImageSelectionDialog = function(dialogTitle) {
* variable name "coll" which is a dict of background collections data. * variable name "coll" which is a dict of background collections data.
* @private * @private
*/ */
customBackgrounds.loadCollections = function() { customBackgrounds.loadChromeBackgrounds = function() {
var collElement = $('ntp-collection-loader'); var collElement = $('ntp-collection-loader');
if (collElement) { if (collElement) {
collElement.parentNode.removeChild(collElement); collElement.parentNode.removeChild(collElement);
...@@ -503,7 +510,14 @@ customBackgrounds.loadCollections = function() { ...@@ -503,7 +510,14 @@ customBackgrounds.loadCollections = function() {
collScript.src = 'chrome-search://local-ntp/ntp-background-collections.js?' + collScript.src = 'chrome-search://local-ntp/ntp-background-collections.js?' +
'collection_type=background'; 'collection_type=background';
document.body.appendChild(collScript); document.body.appendChild(collScript);
};
/**
* Load the NTPGooglePhotoAlbums script. It'll create a global
* variable name "albums" which is a dict of album data.
* @private
*/
customBackgrounds.loadGooglePhotosAlbums = function() {
var albumElement = $('ntp-album-loader'); var albumElement = $('ntp-album-loader');
if (albumElement) { if (albumElement) {
albumElement.parentNode.removeChild(albumElement); albumElement.parentNode.removeChild(albumElement);
...@@ -580,7 +594,6 @@ customBackgrounds.initCustomBackgrounds = function() { ...@@ -580,7 +594,6 @@ customBackgrounds.initCustomBackgrounds = function() {
// Edit gear icon interaction events. // Edit gear icon interaction events.
var editBackgroundInteraction = function(event) { var editBackgroundInteraction = function(event) {
customBackgrounds.loadCollections();
editDialog.showModal(); editDialog.showModal();
}; };
$(customBackgrounds.IDS.EDIT_BG).onclick = function(event) { $(customBackgrounds.IDS.EDIT_BG).onclick = function(event) {
...@@ -623,13 +636,16 @@ customBackgrounds.initCustomBackgrounds = function() { ...@@ -623,13 +636,16 @@ customBackgrounds.initCustomBackgrounds = function() {
// Interactions with the "Chrome backgrounds" option. // Interactions with the "Chrome backgrounds" option.
var defaultWallpapersInteraction = function(event) { var defaultWallpapersInteraction = function(event) {
editDialog.close(); customBackgrounds.loadChromeBackgrounds();
if (typeof coll != 'undefined' && coll.length > 0) { $('ntp-collection-loader').onload = function() {
customBackgrounds.showCollectionSelectionDialog( editDialog.close();
customBackgrounds.SOURCES.CHROME_BACKGROUNDS); if (typeof coll != 'undefined' && coll.length > 0) {
} else { customBackgrounds.showCollectionSelectionDialog(
customBackgrounds.handleError(coll_errors); customBackgrounds.SOURCES.CHROME_BACKGROUNDS);
} } else {
customBackgrounds.handleError(coll_errors);
}
};
}; };
$(customBackgrounds.IDS.DEFAULT_WALLPAPERS).onclick = $(customBackgrounds.IDS.DEFAULT_WALLPAPERS).onclick =
defaultWallpapersInteraction; defaultWallpapersInteraction;
...@@ -641,14 +657,24 @@ customBackgrounds.initCustomBackgrounds = function() { ...@@ -641,14 +657,24 @@ customBackgrounds.initCustomBackgrounds = function() {
// Interactions with the Google Photos option. // Interactions with the Google Photos option.
var googlePhotosInteraction = function(event) { var googlePhotosInteraction = function(event) {
editDialog.close(); customBackgrounds.loadGooglePhotosAlbums();
if (typeof albums != 'undefined' && !albums_errors.auth_error && $('ntp-album-loader').onload = function() {
!albums.net_error && !albums.service_error) { if (typeof albums != 'undefined' && !albums_errors.auth_error &&
customBackgrounds.showCollectionSelectionDialog( !albums.net_error && !albums.service_error) {
customBackgrounds.SOURCES.GOOGLE_PHOTOS); editDialog.close();
} else { customBackgrounds.showCollectionSelectionDialog(
customBackgrounds.handleError(albums_errors); customBackgrounds.SOURCES.GOOGLE_PHOTOS);
} } else {
// If an auth error occurs leave the dialog open and redirect the
// user to sign-in again. Then they can return to the same place in
// the customization flow.
if (!albums_errors.auth_error) {
editDialog.close();
}
customBackgrounds.handleError(albums_errors);
}
};
}; };
$(customBackgrounds.IDS.CONNECT_GOOGLE_PHOTOS).onclick = $(customBackgrounds.IDS.CONNECT_GOOGLE_PHOTOS).onclick =
googlePhotosInteraction; googlePhotosInteraction;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment