Commit 841235c1 authored by Wenzhao Zang's avatar Wenzhao Zang Committed by Commit Bot

cros: Clean up old wallpaper picker code (Part I)

Remove the |useNewWallpaperPicker| checks, and modify some comments.

Will need follow-up CLs to:
1) Remove the flag in //ash.
2) Take a second pass to check which CSS styles/functions/variables
   are unused.

Bug: 812085
Change-Id: I7faa99c16715360a95feed50b5041d89c8c322a1
Reviewed-on: https://chromium-review.googlesource.com/c/1297308Reviewed-by: default avatarXiaoqian Dai <xdai@chromium.org>
Commit-Queue: Wenzhao (Colin) Zang <wzang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#602432}
parent 16826e3d
...@@ -25,8 +25,7 @@ ...@@ -25,8 +25,7 @@
AccessSyncWallpaperInfoKey: 'wallpaper-sync-info-key', AccessSyncWallpaperInfoKey: 'wallpaper-sync-info-key',
/** /**
* Key to access last changed date of a surprise me wallpaper (on the old * Key to access last changed date of a daily refresh wallpaper in
* picker) or a daily refresh wallpaper (on the new picker) in
* chrome.storage.local or chrome.storage.sync. * chrome.storage.local or chrome.storage.sync.
*/ */
AccessLastSurpriseWallpaperChangedDate: 'wallpaper-last-changed-date-key', AccessLastSurpriseWallpaperChangedDate: 'wallpaper-last-changed-date-key',
...@@ -44,20 +43,19 @@ ...@@ -44,20 +43,19 @@
AccessSyncSurpriseMeEnabledKey: 'sync-surprise-me-enabled-key', AccessSyncSurpriseMeEnabledKey: 'sync-surprise-me-enabled-key',
/** /**
* Key to access the info related to daily refresh feature (on the new * Key to access the info related to daily refresh feature in
* wallpaper picker) in chrome.storage.local. * chrome.storage.local.
*/ */
AccessLocalDailyRefreshInfoKey: 'daily-refresh-info-key', AccessLocalDailyRefreshInfoKey: 'daily-refresh-info-key',
/** /**
* Key to access the info related to daily refresh feature (on the new * Key to access the info related to daily refresh feature in
* wallpaper picker) in chrome.storage.sync. * chrome.storage.sync.
*/ */
AccessSyncDailyRefreshInfoKey: 'sync-daily-refresh-info-key', AccessSyncDailyRefreshInfoKey: 'sync-daily-refresh-info-key',
/** /**
* Key to access the images info (on the new wallpaper picker) in * Key to access the images info in chrome.storage.local.
* chrome.storage.local.
*/ */
AccessLocalImagesInfoKey: 'images-info-key', AccessLocalImagesInfoKey: 'images-info-key',
......
...@@ -7,14 +7,13 @@ var wallpaperPickerWindow = null; ...@@ -7,14 +7,13 @@ var wallpaperPickerWindow = null;
var surpriseWallpaper = null; var surpriseWallpaper = null;
/** /**
* Returns information related to the wallpaper picker. * Returns the highResolutionSuffix.
* @param {function} callback A callback function that takes two values: * @param {function} callback A callback function that takes one value:
* |useNewWallpaperPicker|: if the new wallpaper picker is enabled.
* |highResolutionSuffix|: the suffix to append to the wallpaper urls. * |highResolutionSuffix|: the suffix to append to the wallpaper urls.
*/ */
function getWallpaperPickerInfo(callback) { function getHighResolutionSuffix(callback) {
chrome.wallpaperPrivate.getStrings(strings => { chrome.wallpaperPrivate.getStrings(strings => {
callback(strings['useNewWallpaperPicker'], strings['highResolutionSuffix']); callback(strings['highResolutionSuffix']);
}); });
} }
...@@ -170,45 +169,11 @@ SurpriseWallpaper.prototype.setRandomWallpaper_ = function(dateString) { ...@@ -170,45 +169,11 @@ SurpriseWallpaper.prototype.setRandomWallpaper_ = function(dateString) {
}); });
}; };
getWallpaperPickerInfo((useNewWallpaperPicker, highResolutionSuffix) => { getHighResolutionSuffix(highResolutionSuffix => {
if (useNewWallpaperPicker) this.setRandomWallpaperFromServer_(onSuccess, highResolutionSuffix);
this.setRandomWallpaperFromServer_(onSuccess, highResolutionSuffix);
else
this.setRandomWallpaperFromManifest_(onSuccess, highResolutionSuffix);
}); });
}; };
/**
* Sets wallpaper to be a random one found in the stored manifest file. If the
* wallpaper download fails, retry one hour later. Wallpapers that are disabled
* for surprise me are excluded.
* @param {function} onSuccess The success callback.
* @param {string} suffix The url suffix for high resolution wallpaper.
* @private
*/
SurpriseWallpaper.prototype.setRandomWallpaperFromManifest_ = function(
onSuccess, suffix) {
Constants.WallpaperLocalStorage.get(
Constants.AccessLocalManifestKey, items => {
var manifest = items[Constants.AccessLocalManifestKey];
if (manifest && manifest.wallpaper_list) {
var filtered = manifest.wallpaper_list.filter(function(element) {
// Older version manifest do not have available_for_surprise_me
// field. In this case, no wallpaper should be filtered out.
return element.available_for_surprise_me ||
element.available_for_surprise_me == undefined;
});
var index = Math.floor(Math.random() * filtered.length);
var wallpaper = filtered[index];
var wallpaperUrl = wallpaper.base_url + suffix;
WallpaperUtil.setOnlineWallpaperWithoutPreview(
wallpaperUrl, wallpaper.default_layout,
onSuccess.bind(null, wallpaperUrl, wallpaper.default_layout),
this.retryLater_.bind(this));
}
});
};
/** /**
* Sets wallpaper to be a random one retrieved from the backend service. If the * Sets wallpaper to be a random one retrieved from the backend service. If the
* wallpaper download fails, retry one hour later. * wallpaper download fails, retry one hour later.
...@@ -351,47 +316,33 @@ chrome.app.runtime.onLaunched.addListener(function() { ...@@ -351,47 +316,33 @@ chrome.app.runtime.onLaunched.addListener(function() {
return; return;
} }
getWallpaperPickerInfo((useNewWallpaperPicker, highResolutionSuffix) => { var options = {
var options = frame: 'none',
useNewWallpaperPicker ? innerBounds: {width: 768, height: 512, minWidth: 768, minHeight: 512},
{ resizable: true,
frame: 'none', alphaEnabled: true
innerBounds: {width: 768, height: 512, minWidth: 768, minHeight: 512}, };
resizable: true,
alphaEnabled: true chrome.app.window.create('main.html', options, function(window) {
} : wallpaperPickerWindow = window;
{ chrome.wallpaperPrivate.minimizeInactiveWindows();
frame: 'none', window.onClosed.addListener(function() {
width: 574, wallpaperPickerWindow = null;
height: 420, // In case the app exits unexpectedly during preview.
resizable: false, chrome.wallpaperPrivate.cancelPreviewWallpaper(() => {});
alphaEnabled: true // If the app exits during preview, do not restore the previously active
}; // windows. Continue to show the new wallpaper.
if (!window.contentWindow.document.body.classList.contains(
chrome.app.window.create('main.html', options, function(window) { 'preview-mode')) {
wallpaperPickerWindow = window; chrome.wallpaperPrivate.restoreMinimizedWindows();
chrome.wallpaperPrivate.minimizeInactiveWindows();
window.onClosed.addListener(function() {
wallpaperPickerWindow = null;
// In case the app exits unexpectedly during preview.
chrome.wallpaperPrivate.cancelPreviewWallpaper(() => {});
// If the app exits during preview, do not restore the previously active
// windows. Continue to show the new wallpaper.
if (!window.contentWindow.document.body.classList.contains(
'preview-mode')) {
chrome.wallpaperPrivate.restoreMinimizedWindows();
}
});
if (useNewWallpaperPicker) {
// By design, the new wallpaper picker should never be shown on top of
// another window.
wallpaperPickerWindow.contentWindow.addEventListener(
'focus', function() {
chrome.wallpaperPrivate.minimizeInactiveWindows();
});
} }
WallpaperUtil.testSendMessage('wallpaper-window-created');
}); });
// By design, the wallpaper picker should never be shown on top of
// another window.
wallpaperPickerWindow.contentWindow.addEventListener('focus', function() {
chrome.wallpaperPrivate.minimizeInactiveWindows();
});
WallpaperUtil.testSendMessage('wallpaper-window-created');
}); });
}); });
...@@ -433,7 +384,6 @@ chrome.syncFileSystem.onFileStatusChanged.addListener(function(detail) { ...@@ -433,7 +384,6 @@ chrome.syncFileSystem.onFileStatusChanged.addListener(function(detail) {
chrome.storage.onChanged.addListener(function(changes, namespace) { chrome.storage.onChanged.addListener(function(changes, namespace) {
WallpaperUtil.enabledSyncThemesCallback(function(syncEnabled) { WallpaperUtil.enabledSyncThemesCallback(function(syncEnabled) {
// Daily refresh feature is on the new wallpaper picker only.
var updateDailyRefreshStates = key => { var updateDailyRefreshStates = key => {
if (!changes[key]) if (!changes[key])
return; return;
...@@ -474,17 +424,6 @@ chrome.storage.onChanged.addListener(function(changes, namespace) { ...@@ -474,17 +424,6 @@ chrome.storage.onChanged.addListener(function(changes, namespace) {
if (!wallpaperPickerWindow) if (!wallpaperPickerWindow)
return; return;
var wpDocument = wallpaperPickerWindow.contentWindow.document; var wpDocument = wallpaperPickerWindow.contentWindow.document;
var hideCheckMarkIfNeeded = () => {
getWallpaperPickerInfo(
(useNewWallpaperPicker, highResolutionSuffix) => {
// Do not hide the check mark on the new picker.
if (!useNewWallpaperPicker &&
wpDocument.querySelector('.check')) {
wpDocument.querySelector('.check').style.visibility =
'hidden';
}
});
};
if (!!appName) { if (!!appName) {
chrome.wallpaperPrivate.getStrings(function(strings) { chrome.wallpaperPrivate.getStrings(function(strings) {
...@@ -493,7 +432,6 @@ chrome.storage.onChanged.addListener(function(changes, namespace) { ...@@ -493,7 +432,6 @@ chrome.storage.onChanged.addListener(function(changes, namespace) {
wpDocument.querySelector('#wallpaper-set-by-message').textContent = wpDocument.querySelector('#wallpaper-set-by-message').textContent =
message; message;
wpDocument.querySelector('#wallpaper-grid').classList.add('small'); wpDocument.querySelector('#wallpaper-grid').classList.add('small');
hideCheckMarkIfNeeded();
wpDocument.querySelector('#checkbox').classList.remove('checked'); wpDocument.querySelector('#checkbox').classList.remove('checked');
wpDocument.querySelector('#categories-list').disabled = false; wpDocument.querySelector('#categories-list').disabled = false;
wpDocument.querySelector('#wallpaper-grid').disabled = false; wpDocument.querySelector('#wallpaper-grid').disabled = false;
...@@ -511,7 +449,6 @@ chrome.storage.onChanged.addListener(function(changes, namespace) { ...@@ -511,7 +449,6 @@ chrome.storage.onChanged.addListener(function(changes, namespace) {
if (enable) { if (enable) {
wpDocument.querySelector('#checkbox') wpDocument.querySelector('#checkbox')
.classList.add('checked'); .classList.add('checked');
hideCheckMarkIfNeeded();
} else { } else {
wpDocument.querySelector('#checkbox') wpDocument.querySelector('#checkbox')
.classList.remove('checked'); .classList.remove('checked');
...@@ -519,15 +456,6 @@ chrome.storage.onChanged.addListener(function(changes, namespace) { ...@@ -519,15 +456,6 @@ chrome.storage.onChanged.addListener(function(changes, namespace) {
wpDocument.querySelector('.check').style.visibility = wpDocument.querySelector('.check').style.visibility =
'visible'; 'visible';
} }
getWallpaperPickerInfo(
(useNewWallpaperPicker, highResolutionSuffix) => {
if (!useNewWallpaperPicker) {
wpDocument.querySelector('#wallpaper-grid').disabled =
enable;
wpDocument.querySelector('#categories-list').disabled =
enable;
}
});
}); });
} }
}; };
...@@ -665,13 +593,6 @@ chrome.wallpaperPrivate.onWallpaperChangedBy3rdParty.addListener(function( ...@@ -665,13 +593,6 @@ chrome.wallpaperPrivate.onWallpaperChangedBy3rdParty.addListener(function(
WallpaperUtil.saveWallpaperInfo( WallpaperUtil.saveWallpaperInfo(
fileName, layout, Constants.WallpaperSourceEnum.ThirdParty, appName); fileName, layout, Constants.WallpaperSourceEnum.ThirdParty, appName);
getWallpaperPickerInfo((useNewWallpaperPicker, highResolutionSuffix) => {
// Surprise me/daily refresh should be auto-disabled if wallpaper is changed
// by third-party apps.
if (!useNewWallpaperPicker) {
SurpriseWallpaper.getInstance().disable();
return;
}
WallpaperUtil.saveDailyRefreshInfo( WallpaperUtil.saveDailyRefreshInfo(
{enabled: false, collectionId: null, resumeToken: null}); {enabled: false, collectionId: null, resumeToken: null});
...@@ -681,5 +602,4 @@ chrome.wallpaperPrivate.onWallpaperChangedBy3rdParty.addListener(function( ...@@ -681,5 +602,4 @@ chrome.wallpaperPrivate.onWallpaperChangedBy3rdParty.addListener(function(
{detail: {wallpaperFileName: fileName}}); {detail: {wallpaperFileName: fileName}});
wallpaperPickerWindow.contentWindow.dispatchEvent(event); wallpaperPickerWindow.contentWindow.dispatchEvent(event);
} }
});
}); });
...@@ -391,15 +391,6 @@ WallpaperUtil.setOnlineWallpaperWithoutPreview = function( ...@@ -391,15 +391,6 @@ WallpaperUtil.setOnlineWallpaperWithoutPreview = function(
}); });
}; };
/**
* Gets the suffix to append to the base url of an online wallpaper. The
* requested thumbnail is displayed in the wallpaper picker grid.
*/
WallpaperUtil.getOnlineWallpaperThumbnailSuffix = function() {
return loadTimeData.getBoolean('useNewWallpaperPicker') ? '' :
'_thumbnail.png';
};
/** /**
* Creates a blob of type 'image/png'. * Creates a blob of type 'image/png'.
* @param {string} data The image data. * @param {string} data The image data.
...@@ -427,35 +418,22 @@ WallpaperUtil.displayImage = function(imageElement, data, opt_callback) { ...@@ -427,35 +418,22 @@ WallpaperUtil.displayImage = function(imageElement, data, opt_callback) {
}; };
/** /**
* Sets the value of the surprise me checkbox (or the daily refresh toggle on * Sets the value of the daily refresh toggle.
* the new picker).
* @param {boolean} checked The value used to set the checkbox. * @param {boolean} checked The value used to set the checkbox.
*/ */
WallpaperUtil.setSurpriseMeCheckboxValue = function(checked) { WallpaperUtil.setSurpriseMeCheckboxValue = function(checked) {
if (loadTimeData.getBoolean('useNewWallpaperPicker')) {
document.querySelectorAll('.daily-refresh-slider').forEach(element => { document.querySelectorAll('.daily-refresh-slider').forEach(element => {
element.classList.toggle('checked', checked); element.classList.toggle('checked', checked);
}); });
} else {
$('surprise-me')
.querySelector('#checkbox')
.classList.toggle('checked', checked);
}
}; };
/** /**
* Gets the value of the surprise me checkbox (or the value of the daily refresh * Gets the state of the daily refresh toggle.
* toggle on the new picker).
* @return {boolean} The value of the checkbox. * @return {boolean} The value of the checkbox.
*/ */
WallpaperUtil.getSurpriseMeCheckboxValue = function() { WallpaperUtil.getSurpriseMeCheckboxValue = function() {
if (loadTimeData.getBoolean('useNewWallpaperPicker')) {
return document.querySelector('.daily-refresh-slider') return document.querySelector('.daily-refresh-slider')
.classList.contains('checked'); .classList.contains('checked');
}
return $('surprise-me')
.querySelector('#checkbox')
.classList.contains('checked');
}; };
/** /**
...@@ -475,8 +453,7 @@ WallpaperUtil.displayThumbnail = function(imageElement, url, source) { ...@@ -475,8 +453,7 @@ WallpaperUtil.displayThumbnail = function(imageElement, url, source) {
// operation within |WallpaperThumbnailsGridItem.decorate| hasn't // operation within |WallpaperThumbnailsGridItem.decorate| hasn't
// completed. See http://crbug.com/792829. // completed. See http://crbug.com/792829.
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
xhr.open( xhr.open('GET', url, true);
'GET', url + WallpaperUtil.getOnlineWallpaperThumbnailSuffix(), true);
xhr.responseType = 'arraybuffer'; xhr.responseType = 'arraybuffer';
xhr.send(null); xhr.send(null);
xhr.addEventListener('load', function(e) { xhr.addEventListener('load', function(e) {
......
...@@ -70,11 +70,9 @@ cr.define('wallpapers', function() { ...@@ -70,11 +70,9 @@ cr.define('wallpapers', function() {
var div = self.ownerDocument.createElement('div'); var div = self.ownerDocument.createElement('div');
div.textContent = entry; div.textContent = entry;
li.appendChild(div); li.appendChild(div);
if (loadTimeData.getBoolean('useNewWallpaperPicker')) {
li.addEventListener('mousedown', e => { li.addEventListener('mousedown', e => {
e.preventDefault(); e.preventDefault();
}); });
}
return li; return li;
}; };
}, },
......
...@@ -86,21 +86,18 @@ cr.define('wallpapers', function() { ...@@ -86,21 +86,18 @@ cr.define('wallpapers', function() {
} }
var imageEl = cr.doc.createElement('img'); var imageEl = cr.doc.createElement('img');
if (loadTimeData.getBoolean('useNewWallpaperPicker')) { // Do not show the image until |cropImageToFitGrid_| is done.
// On the new picker, do not show the image until |cropImageToFitGrid_| imageEl.style.visibility = 'hidden';
// is done. imageEl.setAttribute('aria-hidden', 'true');
imageEl.style.visibility = 'hidden'; this.setAttribute('aria-label', this.dataItem.ariaLabel);
imageEl.setAttribute('aria-hidden', 'true'); this.tabIndex = 0;
this.setAttribute('aria-label', this.dataItem.ariaLabel); this.addEventListener('keypress', e => {
this.tabIndex = 0; if (e.keyCode == 13)
this.addEventListener('keypress', e => { this.parentNode.selectedItem = this.dataItem;
if (e.keyCode == 13) });
this.parentNode.selectedItem = this.dataItem; this.addEventListener('mousedown', e => {
}); e.preventDefault();
this.addEventListener('mousedown', e => { });
e.preventDefault();
});
}
imageEl.classList.add('thumbnail'); imageEl.classList.add('thumbnail');
cr.defineProperty(imageEl, 'offline', cr.PropertyKind.BOOL_ATTR); cr.defineProperty(imageEl, 'offline', cr.PropertyKind.BOOL_ATTR);
...@@ -119,10 +116,7 @@ cr.define('wallpapers', function() { ...@@ -119,10 +116,7 @@ cr.define('wallpapers', function() {
window.setTimeout(this.callback_.bind(this, this.dataModelId_), 0); window.setTimeout(this.callback_.bind(this, this.dataModelId_), 0);
break; break;
case Constants.WallpaperSourceEnum.Custom: case Constants.WallpaperSourceEnum.Custom:
if (loadTimeData.getBoolean('useNewWallpaperPicker')) this.decorateCustomWallpaper_(imageEl, this.dataItem);
this.decorateCustomWallpaper_(imageEl, this.dataItem);
else
this.decorateCustomWallpaperForOldPicker_(imageEl, this.dataItem);
break; break;
case Constants.WallpaperSourceEnum.OEM: case Constants.WallpaperSourceEnum.OEM:
case Constants.WallpaperSourceEnum.Online: case Constants.WallpaperSourceEnum.Online:
...@@ -141,8 +135,7 @@ cr.define('wallpapers', function() { ...@@ -141,8 +135,7 @@ cr.define('wallpapers', function() {
}, },
/** /**
* Initializes the grid item for custom wallpapers. Used by the new * Initializes the grid item for custom wallpapers.
* wallpaper picker.
* @param {Object} imageElement The image element. * @param {Object} imageElement The image element.
* @param {{filePath: string, baseURL: string, layout: string, * @param {{filePath: string, baseURL: string, layout: string,
* source: string, availableOffline: boolean} * source: string, availableOffline: boolean}
...@@ -181,45 +174,6 @@ cr.define('wallpapers', function() { ...@@ -181,45 +174,6 @@ cr.define('wallpapers', function() {
}); });
}, },
/**
* Initializes the grid item for custom wallpapers. Used by the old
* wallpaper picker (to be deprecated).
* @param {Object} imageElement The image element.
* @param {{filePath: string, baseURL: string, layout: string,
* source: string, availableOffline: boolean}
* dataItem The info related to the wallpaper image.
* @private
*/
decorateCustomWallpaperForOldPicker_(imageElement, dataItem) {
if (dataItem.source != Constants.WallpaperSourceEnum.Custom) {
console.error(
'|decorateCustomWallpaperForOldPicker_| is called but the ' +
'wallpaper source is not custom.');
return;
}
var errorHandler = e => {
console.error('Can not access file system.');
this.callback_(this.dataModelId_);
};
var setURL = fileEntry => {
imageElement.src = fileEntry.toURL();
this.callback_(this.dataModelId_, dataItem.wallpaperId, imageElement);
};
var wallpaperDirectories = WallpaperDirectories.getInstance();
var fallback = () => {
wallpaperDirectories.getDirectory(
Constants.WallpaperDirNameEnum.ORIGINAL, function(dirEntry) {
dirEntry.getFile(
dataItem.baseURL, {create: false}, setURL, errorHandler);
}, errorHandler);
};
var success = dirEntry => {
dirEntry.getFile(dataItem.baseURL, {create: false}, setURL, fallback);
};
wallpaperDirectories.getDirectory(
Constants.WallpaperDirNameEnum.THUMBNAIL, success, errorHandler);
},
/** /**
* Initializes the grid item for online or OEM wallpapers. * Initializes the grid item for online or OEM wallpapers.
* @param {Object} imageElement The image element. * @param {Object} imageElement The image element.
...@@ -248,11 +202,7 @@ cr.define('wallpapers', function() { ...@@ -248,11 +202,7 @@ cr.define('wallpapers', function() {
} else if ( } else if (
dataItem.source == Constants.WallpaperSourceEnum.Online) { dataItem.source == Constants.WallpaperSourceEnum.Online) {
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
xhr.open( xhr.open('GET', dataItem.baseURL, true);
'GET',
dataItem.baseURL +
WallpaperUtil.getOnlineWallpaperThumbnailSuffix(),
true);
xhr.responseType = 'arraybuffer'; xhr.responseType = 'arraybuffer';
xhr.send(null); xhr.send(null);
xhr.addEventListener('load', e => { xhr.addEventListener('load', e => {
...@@ -443,22 +393,9 @@ cr.define('wallpapers', function() { ...@@ -443,22 +393,9 @@ cr.define('wallpapers', function() {
// item is constructed in function itemConstructor below. // item is constructed in function itemConstructor below.
this.pendingItems_ = 0; this.pendingItems_ = 0;
// Only show the spinner on the old wallpaper picker.
if (!this.useNewWallpaperPicker_) {
this.style.visibility = 'hidden';
// If spinner is hidden, schedule to show the spinner after
// ShowSpinnerDelayMs delay. Otherwise, keep it spinning.
if ($('spinner-container').hidden) {
this.spinnerTimeout_ = window.setTimeout(function() {
$('spinner-container').hidden = false;
}, ShowSpinnerDelayMs);
}
}
// Add a daily refresh item as the first element of the grid when // Add a daily refresh item as the first element of the grid when
// showing online wallpapers on the new wallpaper picker. // showing online wallpapers.
if (this.useNewWallpaperPicker_ && if (dataModel.item(0).source == Constants.WallpaperSourceEnum.Online) {
dataModel.item(0).source == Constants.WallpaperSourceEnum.Online) {
dataModel.splice( dataModel.splice(
0, 0, {isDailyRefreshItem: true, availableOffline: false}); 0, 0, {isDailyRefreshItem: true, availableOffline: false});
} }
...@@ -542,10 +479,9 @@ cr.define('wallpapers', function() { ...@@ -542,10 +479,9 @@ cr.define('wallpapers', function() {
if (opt_wallpaperId && opt_thumbnail) if (opt_wallpaperId && opt_thumbnail)
this.thumbnailList_[opt_wallpaperId] = opt_thumbnail; this.thumbnailList_[opt_wallpaperId] = opt_thumbnail;
if (opt_thumbnail && this.useNewWallpaperPicker_) if (opt_thumbnail)
this.cropImageToFitGrid_(opt_thumbnail); this.cropImageToFitGrid_(opt_thumbnail);
// Daily refresh item only exists in new wallpaper picker.
if (this.isShowingDailyRefresh) { if (this.isShowingDailyRefresh) {
var dailyRefreshItemReady = this.dailyRefreshItem && var dailyRefreshItemReady = this.dailyRefreshItem &&
this.dailyRefreshImages.length >= DAILY_REFRESH_IMAGES_NUM; this.dailyRefreshImages.length >= DAILY_REFRESH_IMAGES_NUM;
...@@ -592,10 +528,8 @@ cr.define('wallpapers', function() { ...@@ -592,10 +528,8 @@ cr.define('wallpapers', function() {
window.clearTimeout(this.dailyRefreshTimer_); window.clearTimeout(this.dailyRefreshTimer_);
this.showNextImage_(0); this.showNextImage_(0);
} }
if (this.useNewWallpaperPicker_ && if (this.classList.contains('image-picker-offline'))
this.classList.contains('image-picker-offline')) {
this.highlightOfflineWallpapers(); this.highlightOfflineWallpapers();
}
} }
}, },
...@@ -612,8 +546,6 @@ cr.define('wallpapers', function() { ...@@ -612,8 +546,6 @@ cr.define('wallpapers', function() {
this.checkmark_.tabIndex = 0; this.checkmark_.tabIndex = 0;
this.dataModel = new ArrayDataModel([]); this.dataModel = new ArrayDataModel([]);
this.thumbnailList_ = new ArrayDataModel([]); this.thumbnailList_ = new ArrayDataModel([]);
this.useNewWallpaperPicker_ =
loadTimeData.getBoolean('useNewWallpaperPicker');
var self = this; var self = this;
this.itemConstructor = function(value) { this.itemConstructor = function(value) {
var dataModelId = self.dataModelId_; var dataModelId = self.dataModelId_;
...@@ -768,10 +700,8 @@ cr.define('wallpapers', function() { ...@@ -768,10 +700,8 @@ cr.define('wallpapers', function() {
* the other wallpapers. * the other wallpapers.
*/ */
highlightOfflineWallpapers: function() { highlightOfflineWallpapers: function() {
if (!this.useNewWallpaperPicker_ || if (!this.classList.contains('image-picker-offline'))
!this.classList.contains('image-picker-offline')) {
return; return;
}
chrome.wallpaperPrivate.getOfflineWallpaperList(list => { chrome.wallpaperPrivate.getOfflineWallpaperList(list => {
var offlineWallpaperList = {}; var offlineWallpaperList = {};
...@@ -802,23 +732,21 @@ cr.define('wallpapers', function() { ...@@ -802,23 +732,21 @@ cr.define('wallpapers', function() {
// The active thumbnail maybe deleted in the above redraw(). Sets it again // The active thumbnail maybe deleted in the above redraw(). Sets it again
// to make sure checkmark shows correctly. // to make sure checkmark shows correctly.
this.updateActiveThumb_(); this.updateActiveThumb_();
if (this.useNewWallpaperPicker_) { if (this.dataModel) {
if (this.dataModel) { var scrollUp =
var scrollUp = this.cachedScrollTop_ && this.cachedScrollTop_ > this.scrollTop;
this.cachedScrollTop_ && this.cachedScrollTop_ > this.scrollTop; for (var i = 0; i < this.dataModel.length; ++i) {
for (var i = 0; i < this.dataModel.length; ++i) { if (this.getListItemByIndex(i)) {
if (this.getListItemByIndex(i)) { this.getListItemByIndex(i).classList.toggle(
this.getListItemByIndex(i).classList.toggle( 'first-row',
'first-row', i < this.columns &&
i < this.columns && (this.firstIndex_ == 0 || i != this.firstIndex_ ||
(this.firstIndex_ == 0 || i != this.firstIndex_ || scrollUp));
scrollUp));
}
} }
} }
wallpaperManager.onScrollPositionChanged(this.scrollTop);
this.cachedScrollTop_ = this.scrollTop;
} }
wallpaperManager.onScrollPositionChanged(this.scrollTop);
this.cachedScrollTop_ = this.scrollTop;
} }
}; };
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
var TestConstants = { var TestConstants = {
isPowerwashed: 0, isPowerwashed: 0,
isUsingNewWallpaperPicker: false,
wallpaperUrl: 'https://test.com/test.jpg', wallpaperUrl: 'https://test.com/test.jpg',
highResolutionSuffix: 'suffix', highResolutionSuffix: 'suffix',
// A dummy string which is used to mock an image. // A dummy string which is used to mock an image.
...@@ -269,7 +268,6 @@ var chrome = { ...@@ -269,7 +268,6 @@ var chrome = {
wallpaperPrivate: { wallpaperPrivate: {
getStrings: function(callback) { getStrings: function(callback) {
callback({ callback({
useNewWallpaperPicker: TestConstants.isUsingNewWallpaperPicker,
highResolutionSuffix: TestConstants.highResolutionSuffix highResolutionSuffix: TestConstants.highResolutionSuffix
}); });
}, },
...@@ -292,12 +290,7 @@ var chrome = { ...@@ -292,12 +290,7 @@ var chrome = {
{imageUrl: TestConstants.wallpaperUrl}, null /*nextResumeToken=*/); {imageUrl: TestConstants.wallpaperUrl}, null /*nextResumeToken=*/);
} }
}, },
runtime: {lastError: null}, runtime: {lastError: null}
commandLinePrivate: {
hasSwitch: function(arg, callback) {
callback(TestConstants.isUsingNewWallpaperPicker);
}
}
}; };
(function (exports) { (function (exports) {
......
...@@ -123,12 +123,11 @@ function testSyncOnlineWallpaper() { ...@@ -123,12 +123,11 @@ function testSyncOnlineWallpaper() {
// Test the surprise wallpaper's UMA stats is recorded correctly. // Test the surprise wallpaper's UMA stats is recorded correctly.
function testSurpriseWallpaper() { function testSurpriseWallpaper() {
TestConstants.isUsingNewWallpaperPicker = false;
var mockSetWallpaperIfExists = mockController.createFunctionMock( var mockSetWallpaperIfExists = mockController.createFunctionMock(
chrome.wallpaperPrivate, 'setWallpaperIfExists'); chrome.wallpaperPrivate, 'setWallpaperIfExists');
mockSetWallpaperIfExists.addExpectation( mockSetWallpaperIfExists.addExpectation(
TestConstants.wallpaperUrl + TestConstants.highResolutionSuffix, 'dummy', TestConstants.wallpaperUrl + TestConstants.highResolutionSuffix,
false /*previewMode=*/); 'CENTER_CROPPED', false /*previewMode=*/);
mockSetWallpaperIfExists.callbackData = [true]; mockSetWallpaperIfExists.callbackData = [true];
var mockRecordWallpaperUMA = mockController.createFunctionMock( var mockRecordWallpaperUMA = mockController.createFunctionMock(
...@@ -137,15 +136,4 @@ function testSurpriseWallpaper() { ...@@ -137,15 +136,4 @@ function testSurpriseWallpaper() {
var dateString = new Date().toDateString(); var dateString = new Date().toDateString();
SurpriseWallpaper.getInstance().setRandomWallpaper_(dateString); SurpriseWallpaper.getInstance().setRandomWallpaper_(dateString);
// Repeat the above process for the new wallpaper picker. Test that the UMA
// stats is also recorded correctly.
TestConstants.isUsingNewWallpaperPicker = true;
mockSetWallpaperIfExists.addExpectation(
TestConstants.wallpaperUrl + TestConstants.highResolutionSuffix,
'CENTER_CROPPED', false /*previewMode=*/);
mockRecordWallpaperUMA.addExpectation(Constants.WallpaperSourceEnum.Daily);
var dateString = new Date().toDateString();
SurpriseWallpaper.getInstance().setRandomWallpaper_(dateString);
} }
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