| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/extensions/wallpaper_api.h" | 5 #include "chrome/browser/chromeos/extensions/wallpaper_api.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "ash/desktop_background/desktop_background_controller.h" | 11 #include "ash/desktop_background/desktop_background_controller.h" |
| 12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
| 14 #include "base/memory/ref_counted_memory.h" | 14 #include "base/memory/ref_counted_memory.h" |
| 15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 16 #include "base/threading/worker_pool.h" | 16 #include "base/threading/worker_pool.h" |
| 17 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
| 18 #include "chrome/browser/chromeos/extensions/wallpaper_private_api.h" | 18 #include "chrome/browser/chromeos/extensions/wallpaper_private_api.h" |
| 19 #include "chrome/browser/chromeos/file_manager/app_id.h" |
| 19 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" | 20 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/common/chrome_paths.h" | 22 #include "chrome/common/chrome_paths.h" |
| 22 #include "chrome/common/extensions/extension_constants.h" | 23 #include "chrome/common/extensions/extension_constants.h" |
| 23 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
| 24 #include "components/prefs/pref_service.h" | 25 #include "components/prefs/pref_service.h" |
| 25 #include "components/user_manager/user.h" | 26 #include "components/user_manager/user.h" |
| 26 #include "components/user_manager/user_manager.h" | 27 #include "components/user_manager/user_manager.h" |
| 27 #include "components/wallpaper/wallpaper_layout.h" | 28 #include "components/wallpaper/wallpaper_layout.h" |
| 28 #include "extensions/browser/event_router.h" | 29 #include "extensions/browser/event_router.h" |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 wallpaper_api_util::RecordCustomWallpaperLayout(layout); | 153 wallpaper_api_util::RecordCustomWallpaperLayout(layout); |
| 153 | 154 |
| 154 bool update_wallpaper = | 155 bool update_wallpaper = |
| 155 account_id_ == | 156 account_id_ == |
| 156 user_manager::UserManager::Get()->GetActiveUser()->GetAccountId(); | 157 user_manager::UserManager::Get()->GetActiveUser()->GetAccountId(); |
| 157 wallpaper_manager->SetCustomWallpaper( | 158 wallpaper_manager->SetCustomWallpaper( |
| 158 account_id_, wallpaper_files_id_, params_->details.filename, layout, | 159 account_id_, wallpaper_files_id_, params_->details.filename, layout, |
| 159 user_manager::User::CUSTOMIZED, image, update_wallpaper); | 160 user_manager::User::CUSTOMIZED, image, update_wallpaper); |
| 160 unsafe_wallpaper_decoder_ = NULL; | 161 unsafe_wallpaper_decoder_ = NULL; |
| 161 | 162 |
| 162 // Save current extenion name. It will be displayed in the component | 163 // Save current extension name. It will be displayed in the component |
| 163 // wallpaper picker app. If current extension is the component wallpaper | 164 // wallpaper picker app. If current extension is the component wallpaper |
| 164 // picker, set an empty string. | 165 // picker, set an empty string. |
| 166 // TODO(xdai): This preference is unused now. For compatiblity concern, we |
| 167 // need to keep it until it's safe to clean it up. |
| 165 Profile* profile = Profile::FromBrowserContext(browser_context()); | 168 Profile* profile = Profile::FromBrowserContext(browser_context()); |
| 166 if (extension()->id() == extension_misc::kWallpaperManagerId) { | 169 if (extension()->id() == extension_misc::kWallpaperManagerId) { |
| 167 profile->GetPrefs()->SetString(prefs::kCurrentWallpaperAppName, | 170 profile->GetPrefs()->SetString(prefs::kCurrentWallpaperAppName, |
| 168 std::string()); | 171 std::string()); |
| 169 } else { | 172 } else { |
| 170 profile->GetPrefs()->SetString(prefs::kCurrentWallpaperAppName, | 173 profile->GetPrefs()->SetString(prefs::kCurrentWallpaperAppName, |
| 171 extension()->name()); | 174 extension()->name()); |
| 172 } | 175 } |
| 173 | 176 |
| 174 if (!params_->details.thumbnail) | 177 if (!params_->details.thumbnail) |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 // has been modified by a third party application. | 232 // has been modified by a third party application. |
| 230 if (extension()->id() != extension_misc::kWallpaperManagerId) { | 233 if (extension()->id() != extension_misc::kWallpaperManagerId) { |
| 231 Profile* profile = Profile::FromBrowserContext(browser_context()); | 234 Profile* profile = Profile::FromBrowserContext(browser_context()); |
| 232 extensions::EventRouter* event_router = | 235 extensions::EventRouter* event_router = |
| 233 extensions::EventRouter::Get(profile); | 236 extensions::EventRouter::Get(profile); |
| 234 std::unique_ptr<base::ListValue> event_args(new base::ListValue()); | 237 std::unique_ptr<base::ListValue> event_args(new base::ListValue()); |
| 235 event_args->Append(original_result); | 238 event_args->Append(original_result); |
| 236 event_args->Append(thumbnail_result); | 239 event_args->Append(thumbnail_result); |
| 237 event_args->Append(new base::StringValue( | 240 event_args->Append(new base::StringValue( |
| 238 extensions::api::wallpaper::ToString(params_->details.layout))); | 241 extensions::api::wallpaper::ToString(params_->details.layout))); |
| 239 event_args->Append(new base::StringValue(extension()->name())); | 242 // Setting wallpaper from right click menu in 'Files' app is a feature that |
| 243 // was implemented in crbug.com/578935. Since 'Files' app is a built-in v1 |
| 244 // app in ChromeOS, we should treat it slightly differently with other third |
| 245 // party apps: the wallpaper set by the 'Files' app should still be syncable |
| 246 // and it should not appear in the wallpaper grid in the Wallpaper Picker. |
| 247 // But we should not display the 'wallpaper-set-by-mesage' since it might |
| 248 // introduce confusion as shown in crbug.com/599407. |
| 249 event_args->Append(new base::StringValue( |
| 250 (extension()->id() == file_manager::kFileManagerAppId) |
| 251 ? std::string() |
| 252 : extension()->name())); |
| 240 std::unique_ptr<extensions::Event> event(new extensions::Event( | 253 std::unique_ptr<extensions::Event> event(new extensions::Event( |
| 241 extensions::events::WALLPAPER_PRIVATE_ON_WALLPAPER_CHANGED_BY_3RD_PARTY, | 254 extensions::events::WALLPAPER_PRIVATE_ON_WALLPAPER_CHANGED_BY_3RD_PARTY, |
| 242 extensions::api::wallpaper_private::OnWallpaperChangedBy3rdParty:: | 255 extensions::api::wallpaper_private::OnWallpaperChangedBy3rdParty:: |
| 243 kEventName, | 256 kEventName, |
| 244 std::move(event_args))); | 257 std::move(event_args))); |
| 245 event_router->DispatchEventToExtension(extension_misc::kWallpaperManagerId, | 258 event_router->DispatchEventToExtension(extension_misc::kWallpaperManagerId, |
| 246 std::move(event)); | 259 std::move(event)); |
| 247 } | 260 } |
| 248 } | 261 } |
| 249 | 262 |
| 250 void WallpaperSetWallpaperFunction::OnWallpaperFetched( | 263 void WallpaperSetWallpaperFunction::OnWallpaperFetched( |
| 251 bool success, | 264 bool success, |
| 252 const std::string& response) { | 265 const std::string& response) { |
| 253 if (success) { | 266 if (success) { |
| 254 params_->details.data.reset( | 267 params_->details.data.reset( |
| 255 new std::vector<char>(response.begin(), response.end())); | 268 new std::vector<char>(response.begin(), response.end())); |
| 256 StartDecode(*params_->details.data); | 269 StartDecode(*params_->details.data); |
| 257 } else { | 270 } else { |
| 258 SetError(response); | 271 SetError(response); |
| 259 SendResponse(false); | 272 SendResponse(false); |
| 260 } | 273 } |
| 261 } | 274 } |
| OLD | NEW |