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. ...@@ -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."> <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. Chrome cannot set wallpaper.
</message> </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 --> <!-- 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."> <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() { ...@@ -263,6 +263,8 @@ bool WallpaperPrivateGetStringsFunction::RunSync() {
SET_STRING("invalidWallpaper", IDS_WALLPAPER_MANAGER_INVALID_WALLPAPER); SET_STRING("invalidWallpaper", IDS_WALLPAPER_MANAGER_INVALID_WALLPAPER);
SET_STRING("surpriseMeLabel", IDS_WALLPAPER_MANAGER_SURPRISE_ME_LABEL); SET_STRING("surpriseMeLabel", IDS_WALLPAPER_MANAGER_SURPRISE_ME_LABEL);
SET_STRING("learnMore", IDS_LEARN_MORE); SET_STRING("learnMore", IDS_LEARN_MORE);
SET_STRING("currentWallpaperSetByMessage",
IDS_CURRENT_WALLPAPER_SET_BY_MESSAGE);
#undef SET_STRING #undef SET_STRING
webui::SetFontAndTextDirection(dict); webui::SetFontAndTextDirection(dict);
...@@ -278,6 +280,12 @@ bool WallpaperPrivateGetStringsFunction::RunSync() { ...@@ -278,6 +280,12 @@ bool WallpaperPrivateGetStringsFunction::RunSync() {
dict->SetString("manifestBaseURL", kWallpaperManifestBaseURL); dict->SetString("manifestBaseURL", kWallpaperManifestBaseURL);
#endif #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->SetBoolean("isOEMDefaultWallpaper", IsOEMDefaultWallpaper());
dict->SetString("canceledWallpaper", dict->SetString("canceledWallpaper",
wallpaper_api_util::kCancelWallpaperMessage); wallpaper_api_util::kCancelWallpaperMessage);
......
...@@ -33,8 +33,9 @@ body { ...@@ -33,8 +33,9 @@ body {
} }
.dialog-container { .dialog-container {
-webkit-box-orient: vertical; display: flex;
display: -webkit-box; flex-direction: column;
height: 100%;
overflow: hidden; overflow: hidden;
} }
...@@ -116,15 +117,14 @@ body { ...@@ -116,15 +117,14 @@ body {
} }
.dialog-main { .dialog-main {
-webkit-box-align: stretch; display: flex;
-webkit-box-flex: 1; flex: 1;
display: -webkit-box;
} }
#category-container { #category-container {
-webkit-box-flex: 1; display: flex;
-webkit-box-orient: vertical; flex: 1;
display: -webkit-box; flex-direction: column;
position: relative; position: relative;
} }
...@@ -161,16 +161,26 @@ body { ...@@ -161,16 +161,26 @@ body {
width: 16px; 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 { .image-picker {
-webkit-padding-end: 5px; -webkit-padding-end: 5px;
-webkit-padding-start: 15px; -webkit-padding-start: 15px;
display: block; display: block;
flex: 1;
/* Set font size to 0 to remove the extra vertical margin between two rows of /* Set font size to 0 to remove the extra vertical margin between two rows of
* thumbnails. * thumbnails.
* TODO(bshe): Find the root cause of the margin. * TODO(bshe): Find the root cause of the margin.
*/ */
font-size: 0; font-size: 0;
height: 287px;
outline: none; outline: none;
overflow-y: auto; overflow-y: auto;
padding-bottom: 15px; padding-bottom: 15px;
......
...@@ -253,6 +253,11 @@ function WallpaperManager(dialogDom) { ...@@ -253,6 +253,11 @@ function WallpaperManager(dialogDom) {
$('set-wallpaper-layout').addEventListener( $('set-wallpaper-layout').addEventListener(
'change', this.onWallpaperLayoutChanged_.bind(this)); 'change', this.onWallpaperLayoutChanged_.bind(this));
if (loadTimeData.valueExists('wallpaperAppName')) {
$('wallpaper-set-by-message').textContent = loadTimeData.getStringF(
'currentWallpaperSetByMessage', str('wallpaperAppName'));
}
if (this.enableOnlineWallpaper_) { if (this.enableOnlineWallpaper_) {
var self = this; var self = this;
$('surprise-me').hidden = false; $('surprise-me').hidden = false;
...@@ -352,6 +357,7 @@ function WallpaperManager(dialogDom) { ...@@ -352,6 +357,7 @@ function WallpaperManager(dialogDom) {
// Active custom wallpaper is also copied in chronos data dir. It needs // Active custom wallpaper is also copied in chronos data dir. It needs
// to be deleted. // to be deleted.
chrome.wallpaperPrivate.resetWallpaper(); chrome.wallpaperPrivate.resetWallpaper();
this.onWallpaperChanged_(null, null);
} else { } else {
selectedIndex = Math.min(selectedIndex, customWallpaperCount - 1); selectedIndex = Math.min(selectedIndex, customWallpaperCount - 1);
wallpaperGrid.selectionModel.selectedIndex = selectedIndex; wallpaperGrid.selectionModel.selectedIndex = selectedIndex;
...@@ -472,6 +478,22 @@ function WallpaperManager(dialogDom) { ...@@ -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. * Sets wallpaper to the corresponding wallpaper of selected thumbnail.
* @param {{baseURL: string, layout: string, source: string, * @param {{baseURL: string, layout: string, source: string,
...@@ -485,10 +507,6 @@ function WallpaperManager(dialogDom) { ...@@ -485,10 +507,6 @@ function WallpaperManager(dialogDom) {
switch (selectedItem.source) { switch (selectedItem.source) {
case Constants.WallpaperSourceEnum.Custom: case Constants.WallpaperSourceEnum.Custom:
var errorHandler = this.onFileSystemError_.bind(this); var errorHandler = this.onFileSystemError_.bind(this);
var setActive = function() {
self.wallpaperGrid_.activeItem = selectedItem;
self.currentWallpaper_ = selectedItem.baseURL;
};
var success = function(dirEntry) { var success = function(dirEntry) {
dirEntry.getFile(selectedItem.baseURL, {create: false}, dirEntry.getFile(selectedItem.baseURL, {create: false},
function(fileEntry) { function(fileEntry) {
...@@ -500,7 +518,9 @@ function WallpaperManager(dialogDom) { ...@@ -500,7 +518,9 @@ function WallpaperManager(dialogDom) {
self.setCustomWallpaper(e.target.result, self.setCustomWallpaper(e.target.result,
selectedItem.layout, selectedItem.layout,
false, selectedItem.baseURL, false, selectedItem.baseURL,
setActive, errorHandler); self.onWallpaperChanged_.bind(self,
selectedItem, selectedItem.baseURL),
errorHandler);
}); });
}, errorHandler); }, errorHandler);
}, errorHandler); }, errorHandler);
...@@ -511,8 +531,7 @@ function WallpaperManager(dialogDom) { ...@@ -511,8 +531,7 @@ function WallpaperManager(dialogDom) {
case Constants.WallpaperSourceEnum.OEM: case Constants.WallpaperSourceEnum.OEM:
// Resets back to default wallpaper. // Resets back to default wallpaper.
chrome.wallpaperPrivate.resetWallpaper(); chrome.wallpaperPrivate.resetWallpaper();
this.currentWallpaper_ = selectedItem.baseURL; this.onWallpaperChanged_(selectedItem, selectedItem.baseURL);
this.wallpaperGrid_.activeItem = selectedItem;
WallpaperUtil.saveWallpaperInfo(wallpaperURL, selectedItem.layout, WallpaperUtil.saveWallpaperInfo(wallpaperURL, selectedItem.layout,
selectedItem.source); selectedItem.source);
break; break;
...@@ -525,8 +544,7 @@ function WallpaperManager(dialogDom) { ...@@ -525,8 +544,7 @@ function WallpaperManager(dialogDom) {
selectedItem.layout, selectedItem.layout,
function(exists) { function(exists) {
if (exists) { if (exists) {
self.currentWallpaper_ = wallpaperURL; self.onWallpaperChanged_(selectedItem, wallpaperURL);
self.wallpaperGrid_.activeItem = selectedItem;
WallpaperUtil.saveWallpaperInfo(wallpaperURL, selectedItem.layout, WallpaperUtil.saveWallpaperInfo(wallpaperURL, selectedItem.layout,
selectedItem.source); selectedItem.source);
return; return;
...@@ -543,8 +561,17 @@ function WallpaperManager(dialogDom) { ...@@ -543,8 +561,17 @@ function WallpaperManager(dialogDom) {
var image = xhr.response; var image = xhr.response;
chrome.wallpaperPrivate.setWallpaper(image, selectedItem.layout, chrome.wallpaperPrivate.setWallpaper(image, selectedItem.layout,
wallpaperURL, wallpaperURL,
self.onFinished_.bind(self, selectedGridItem, selectedItem)); function() {
self.currentWallpaper_ = wallpaperURL; 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, WallpaperUtil.saveWallpaperInfo(wallpaperURL, selectedItem.layout,
selectedItem.source); selectedItem.source);
self.wallpaperRequest_ = null; self.wallpaperRequest_ = null;
...@@ -790,8 +817,7 @@ function WallpaperManager(dialogDom) { ...@@ -790,8 +817,7 @@ function WallpaperManager(dialogDom) {
}; };
self.wallpaperGrid_.dataModel.splice(0, 0, wallpaperInfo); self.wallpaperGrid_.dataModel.splice(0, 0, wallpaperInfo);
self.wallpaperGrid_.selectedItem = wallpaperInfo; self.wallpaperGrid_.selectedItem = wallpaperInfo;
self.wallpaperGrid_.activeItem = wallpaperInfo; self.onWallpaperChanged_(wallpaperInfo, fileName);
self.currentWallpaper_ = fileName;
WallpaperUtil.saveToStorage(self.currentWallpaper_, layout, WallpaperUtil.saveToStorage(self.currentWallpaper_, layout,
false); false);
}; };
...@@ -901,29 +927,6 @@ function WallpaperManager(dialogDom) { ...@@ -901,29 +927,6 @@ function WallpaperManager(dialogDom) {
fileName, onFinished); 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. * Handles the layout setting change of custom wallpaper.
*/ */
...@@ -938,6 +941,8 @@ function WallpaperManager(dialogDom) { ...@@ -938,6 +941,8 @@ function WallpaperManager(dialogDom) {
$('set-wallpaper-layout').disabled = true; $('set-wallpaper-layout').disabled = true;
} else { } else {
WallpaperUtil.saveToStorage(self.currentWallpaper_, layout, false); WallpaperUtil.saveToStorage(self.currentWallpaper_, layout, false);
self.onWallpaperChanged_(self.wallpaperGrid_.activeItem,
self.currentWallpaper_);
} }
}); });
}; };
......
...@@ -97,6 +97,7 @@ found in the LICENSE file. ...@@ -97,6 +97,7 @@ found in the LICENSE file.
</div> </div>
<div class="dialog-main"> <div class="dialog-main">
<div id="category-container"> <div id="category-container">
<div id="wallpaper-set-by-message"></div>
<grid id="wallpaper-grid" class="image-picker"></grid> <grid id="wallpaper-grid" class="image-picker"></grid>
<div id="spinner-container" hidden> <div id="spinner-container" hidden>
<div id="spinner"></div> <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