Commit bba16e7a authored by xdai's avatar xdai Committed by Commit bot

If the current wallpaper was set by a third party application, we should...

If the current wallpaper was set by a third party application, we should disable surprise me feature,
otherwise the wallpaper will still be changed periodically.

Also fix the issue that wallpaper picker application can't load the local resource:
chrome://resources/css/text_defaults.css.

BUG=466709
TEST=Manually tested

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

Cr-Commit-Position: refs/heads/master@{#320972}
parent 745b6623
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/threading/worker_pool.h" #include "base/threading/worker_pool.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/extensions/wallpaper_private_api.h"
#include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_paths.h"
...@@ -22,6 +23,7 @@ ...@@ -22,6 +23,7 @@
#include "components/user_manager/user.h" #include "components/user_manager/user.h"
#include "components/user_manager/user_manager.h" #include "components/user_manager/user_manager.h"
#include "components/wallpaper/wallpaper_layout.h" #include "components/wallpaper/wallpaper_layout.h"
#include "extensions/browser/event_router.h"
#include "net/base/load_flags.h" #include "net/base/load_flags.h"
#include "net/http/http_status_code.h" #include "net/http/http_status_code.h"
#include "net/url_request/url_fetcher.h" #include "net/url_request/url_fetcher.h"
...@@ -177,6 +179,18 @@ void WallpaperSetWallpaperFunction::OnWallpaperDecoded( ...@@ -177,6 +179,18 @@ void WallpaperSetWallpaperFunction::OnWallpaperDecoded(
} }
SendResponse(true); SendResponse(true);
} }
// Inform the native Wallpaper Picker Application that the current wallpaper
// has been modified by a third party application.
Profile* profile = Profile::FromBrowserContext(browser_context());
extensions::EventRouter* event_router = extensions::EventRouter::Get(profile);
scoped_ptr<base::ListValue> event_args(new base::ListValue());
scoped_ptr<extensions::Event> event(
new extensions::Event(extensions::api::wallpaper_private::
OnWallpaperChangedBy3rdParty::kEventName,
event_args.Pass()));
event_router->DispatchEventToExtension(extension_misc::kWallpaperManagerId,
event.Pass());
} }
void WallpaperSetWallpaperFunction::GenerateThumbnail( void WallpaperSetWallpaperFunction::GenerateThumbnail(
......
...@@ -349,3 +349,9 @@ chrome.storage.onChanged.addListener(function(changes, namespace) { ...@@ -349,3 +349,9 @@ chrome.storage.onChanged.addListener(function(changes, namespace) {
chrome.alarms.onAlarm.addListener(function() { chrome.alarms.onAlarm.addListener(function() {
SurpriseWallpaper.getInstance().next(); SurpriseWallpaper.getInstance().next();
}); });
chrome.wallpaperPrivate.onWallpaperChangedBy3rdParty.addListener(function() {
WallpaperUtil.saveToStorage(Constants.AccessSurpriseMeEnabledKey,
false, true);
SurpriseWallpaper.getInstance().disable();
});
...@@ -223,6 +223,10 @@ cr.define('wallpapers', function() { ...@@ -223,6 +223,10 @@ cr.define('wallpapers', function() {
} }
}, },
get activeItem() {
return this.activeItem_;
},
/** /**
* A unique ID that assigned to each set dataModel operation. Note that this * A unique ID that assigned to each set dataModel operation. Note that this
* id wont increase if the new dataModel is null or empty. * id wont increase if the new dataModel is null or empty.
......
...@@ -203,12 +203,16 @@ function WallpaperManager(dialogDom) { ...@@ -203,12 +203,16 @@ function WallpaperManager(dialogDom) {
if (chrome.runtime.lastError == null) { if (chrome.runtime.lastError == null) {
if (shouldEnable) { if (shouldEnable) {
checkbox.classList.add('checked'); checkbox.classList.add('checked');
// Hides the wallpaper set by message if there is any.
$('wallpaper-set-by-message').textContent = '';
} else { } else {
// Unchecking the "Surprise me" checkbox falls back to the previous // Unchecking the "Surprise me" checkbox falls back to the previous
// wallpaper before "Surprise me" was turned on. // wallpaper before "Surprise me" was turned on.
self.setSelectedWallpaper_(self.wallpaperGrid_.activeItem_); if (self.wallpaperGrid_.activeItem) {
self.onWallpaperChanged_(self.wallpaperGrid_.activeItem_, self.setSelectedWallpaper_(self.wallpaperGrid_.activeItem);
self.onWallpaperChanged_(self.wallpaperGrid_.activeItem,
self.currentWallpaper_); self.currentWallpaper_);
}
checkbox.classList.remove('checked'); checkbox.classList.remove('checked');
} }
$('categories-list').disabled = shouldEnable; $('categories-list').disabled = shouldEnable;
......
...@@ -9,7 +9,7 @@ found in the LICENSE file. ...@@ -9,7 +9,7 @@ found in the LICENSE file.
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>Wallpaper Picker</title> <title>Wallpaper Picker</title>
<link rel="stylesheet" href="chrome://resources/css/text_defaults.css"> <link rel="stylesheet" href="../../../../../ui/webui/resources/css/text_defaults.css">
<link rel="stylesheet" href="../../../../../ui/webui/resources/css/widgets.css"> <link rel="stylesheet" href="../../../../../ui/webui/resources/css/widgets.css">
<link rel="stylesheet" href="../../../../../ui/webui/resources/css/menu.css"></link> <link rel="stylesheet" href="../../../../../ui/webui/resources/css/menu.css"></link>
......
...@@ -256,6 +256,13 @@ ...@@ -256,6 +256,13 @@
} }
] ]
} }
],
"events": [
{
"name": "onWallpaperChangedBy3rdParty",
"type": "function",
"description": "This event is sent when the current wallpaper was set by a third party application."
}
] ]
} }
] ]
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