Commit 14b629f0 authored by bshe@chromium.org's avatar bshe@chromium.org

Show third party wallpaper app name in wallpaper picker


If current wallpaper is set by third party app/extension, show its name
in wallpaper picker.


BUG=360695

Review URL: https://codereview.chromium.org/338883004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@278399 0039d316-1c4b-4281-b951-d872f2087c98
parent 4d01d553
......@@ -115,6 +115,9 @@ Press any key to continue exploring.
<message name="IDS_WALLPAPER_MANAGER_INVALID_WALLPAPER" desc="The string displayed to user when user selected wallpaper can not be set as a wallpaper.">
Chrome cannot set wallpaper.
</message>
<message name="IDS_CURRENT_WALLPAPER_SET_BY_MESSAGE" desc="The string displayed to user if the current wallpaper is set by a third party wallpaper app/extension.">
Current wallpaper is set by '<ph name="APP_NAME">$1</ph>'
</message>
<!-- File Manager -->
<message name="IDS_FLAGS_ENABLE_FILE_MANAGER_MTP_NAME" desc="Name of the about:flag option to enable MTP support in file manager.">
......
......@@ -263,6 +263,8 @@ bool WallpaperPrivateGetStringsFunction::RunSync() {
SET_STRING("invalidWallpaper", IDS_WALLPAPER_MANAGER_INVALID_WALLPAPER);
SET_STRING("surpriseMeLabel", IDS_WALLPAPER_MANAGER_SURPRISE_ME_LABEL);
SET_STRING("learnMore", IDS_LEARN_MORE);
SET_STRING("currentWallpaperSetByMessage",
IDS_CURRENT_WALLPAPER_SET_BY_MESSAGE);
#undef SET_STRING
webui::SetFontAndTextDirection(dict);
......@@ -278,6 +280,12 @@ bool WallpaperPrivateGetStringsFunction::RunSync() {
dict->SetString("manifestBaseURL", kWallpaperManifestBaseURL);
#endif
Profile* profile = Profile::FromBrowserContext(browser_context());
std::string app_name(
profile->GetPrefs()->GetString(prefs::kCurrentWallpaperAppName));
if (!app_name.empty())
dict->SetString("wallpaperAppName", app_name);
dict->SetBoolean("isOEMDefaultWallpaper", IsOEMDefaultWallpaper());
dict->SetString("canceledWallpaper",
wallpaper_api_util::kCancelWallpaperMessage);
......
......@@ -33,8 +33,9 @@ body {
}
.dialog-container {
-webkit-box-orient: vertical;
display: -webkit-box;
display: flex;
flex-direction: column;
height: 100%;
overflow: hidden;
}
......@@ -116,15 +117,14 @@ body {
}
.dialog-main {
-webkit-box-align: stretch;
-webkit-box-flex: 1;
display: -webkit-box;
display: flex;
flex: 1;
}
#category-container {
-webkit-box-flex: 1;
-webkit-box-orient: vertical;
display: -webkit-box;
display: flex;
flex: 1;
flex-direction: column;
position: relative;
}
......@@ -161,16 +161,26 @@ body {
width: 16px;
}
#wallpaper-set-by-message {
-webkit-padding-end: 5px;
-webkit-padding-start: 15px;
height: 17px;
}
#wallpaper-set-by-message:empty {
display: none;
}
.image-picker {
-webkit-padding-end: 5px;
-webkit-padding-start: 15px;
display: block;
flex: 1;
/* Set font size to 0 to remove the extra vertical margin between two rows of
* thumbnails.
* TODO(bshe): Find the root cause of the margin.
*/
font-size: 0;
height: 287px;
outline: none;
overflow-y: auto;
padding-bottom: 15px;
......
......@@ -253,6 +253,11 @@ function WallpaperManager(dialogDom) {
$('set-wallpaper-layout').addEventListener(
'change', this.onWallpaperLayoutChanged_.bind(this));
if (loadTimeData.valueExists('wallpaperAppName')) {
$('wallpaper-set-by-message').textContent = loadTimeData.getStringF(
'currentWallpaperSetByMessage', str('wallpaperAppName'));
}
if (this.enableOnlineWallpaper_) {
var self = this;
$('surprise-me').hidden = false;
......@@ -352,6 +357,7 @@ function WallpaperManager(dialogDom) {
// Active custom wallpaper is also copied in chronos data dir. It needs
// to be deleted.
chrome.wallpaperPrivate.resetWallpaper();
this.onWallpaperChanged_(null, null);
} else {
selectedIndex = Math.min(selectedIndex, customWallpaperCount - 1);
wallpaperGrid.selectionModel.selectedIndex = selectedIndex;
......@@ -472,6 +478,22 @@ function WallpaperManager(dialogDom) {
}
};
/**
* Moves the check mark to |activeItem| and hides the wallpaper set by third
* party message if any. Called when wallpaper changed successfully.
* @param {?Object} activeItem The active item in WallpaperThumbnailsGrid's
* data model.
* @param {?string} currentWallpaperURL The URL or filename of current
* wallpaper.
*/
WallpaperManager.prototype.onWallpaperChanged_ = function(
activeItem, currentWallpaperURL) {
this.wallpaperGrid_.activeItem = activeItem;
this.currentWallpaper_ = currentWallpaperURL;
// Hides the wallpaper set by message.
$('wallpaper-set-by-message').textContent = '';
};
/**
* Sets wallpaper to the corresponding wallpaper of selected thumbnail.
* @param {{baseURL: string, layout: string, source: string,
......@@ -485,10 +507,6 @@ function WallpaperManager(dialogDom) {
switch (selectedItem.source) {
case Constants.WallpaperSourceEnum.Custom:
var errorHandler = this.onFileSystemError_.bind(this);
var setActive = function() {
self.wallpaperGrid_.activeItem = selectedItem;
self.currentWallpaper_ = selectedItem.baseURL;
};
var success = function(dirEntry) {
dirEntry.getFile(selectedItem.baseURL, {create: false},
function(fileEntry) {
......@@ -500,7 +518,9 @@ function WallpaperManager(dialogDom) {
self.setCustomWallpaper(e.target.result,
selectedItem.layout,
false, selectedItem.baseURL,
setActive, errorHandler);
self.onWallpaperChanged_.bind(self,
selectedItem, selectedItem.baseURL),
errorHandler);
});
}, errorHandler);
}, errorHandler);
......@@ -511,8 +531,7 @@ function WallpaperManager(dialogDom) {
case Constants.WallpaperSourceEnum.OEM:
// Resets back to default wallpaper.
chrome.wallpaperPrivate.resetWallpaper();
this.currentWallpaper_ = selectedItem.baseURL;
this.wallpaperGrid_.activeItem = selectedItem;
this.onWallpaperChanged_(selectedItem, selectedItem.baseURL);
WallpaperUtil.saveWallpaperInfo(wallpaperURL, selectedItem.layout,
selectedItem.source);
break;
......@@ -525,8 +544,7 @@ function WallpaperManager(dialogDom) {
selectedItem.layout,
function(exists) {
if (exists) {
self.currentWallpaper_ = wallpaperURL;
self.wallpaperGrid_.activeItem = selectedItem;
self.onWallpaperChanged_(selectedItem, wallpaperURL);
WallpaperUtil.saveWallpaperInfo(wallpaperURL, selectedItem.layout,
selectedItem.source);
return;
......@@ -543,8 +561,17 @@ function WallpaperManager(dialogDom) {
var image = xhr.response;
chrome.wallpaperPrivate.setWallpaper(image, selectedItem.layout,
wallpaperURL,
self.onFinished_.bind(self, selectedGridItem, selectedItem));
self.currentWallpaper_ = wallpaperURL;
function() {
self.progressManager_.hideProgressBar(selectedGridItem);
if (chrome.runtime.lastError != undefined &&
chrome.runtime.lastError.message !=
str('canceledWallpaper')) {
self.showError_(chrome.runtime.lastError.message);
} else {
self.onWallpaperChanged_(selectedItem, wallpaperURL);
}
});
WallpaperUtil.saveWallpaperInfo(wallpaperURL, selectedItem.layout,
selectedItem.source);
self.wallpaperRequest_ = null;
......@@ -790,8 +817,7 @@ function WallpaperManager(dialogDom) {
};
self.wallpaperGrid_.dataModel.splice(0, 0, wallpaperInfo);
self.wallpaperGrid_.selectedItem = wallpaperInfo;
self.wallpaperGrid_.activeItem = wallpaperInfo;
self.currentWallpaper_ = fileName;
self.onWallpaperChanged_(wallpaperInfo, fileName);
WallpaperUtil.saveToStorage(self.currentWallpaper_, layout,
false);
};
......@@ -901,29 +927,6 @@ function WallpaperManager(dialogDom) {
fileName, onFinished);
};
/**
* Sets wallpaper finished. Displays error message if any.
* @param {WallpaperThumbnailsGridItem=} opt_selectedGridItem The wallpaper
* thumbnail grid item. It extends from cr.ui.ListItem.
* @param {{baseURL: string, layout: string, source: string,
* availableOffline: boolean, opt_dynamicURL: string,
* opt_author: string, opt_authorWebsite: string}=}
* opt_selectedItem the selected item in WallpaperThumbnailsGrid's data
* model.
*/
WallpaperManager.prototype.onFinished_ = function(opt_selectedGridItem,
opt_selectedItem) {
if (opt_selectedGridItem)
this.progressManager_.hideProgressBar(opt_selectedGridItem);
if (chrome.runtime.lastError != undefined &&
chrome.runtime.lastError.message != str('canceledWallpaper')) {
this.showError_(chrome.runtime.lastError.message);
} else if (opt_selectedItem) {
this.wallpaperGrid_.activeItem = opt_selectedItem;
}
};
/**
* Handles the layout setting change of custom wallpaper.
*/
......@@ -938,6 +941,8 @@ function WallpaperManager(dialogDom) {
$('set-wallpaper-layout').disabled = true;
} else {
WallpaperUtil.saveToStorage(self.currentWallpaper_, layout, false);
self.onWallpaperChanged_(self.wallpaperGrid_.activeItem,
self.currentWallpaper_);
}
});
};
......
......@@ -97,6 +97,7 @@ found in the LICENSE file.
</div>
<div class="dialog-main">
<div id="category-container">
<div id="wallpaper-set-by-message"></div>
<grid id="wallpaper-grid" class="image-picker"></grid>
<div id="spinner-container" hidden>
<div id="spinner"></div>
......
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