| 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 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 wallpaper_api_util::RecordCustomWallpaperLayout(layout); | 146 wallpaper_api_util::RecordCustomWallpaperLayout(layout); |
| 147 | 147 |
| 148 bool update_wallpaper = | 148 bool update_wallpaper = |
| 149 account_id_ == | 149 account_id_ == |
| 150 user_manager::UserManager::Get()->GetActiveUser()->GetAccountId(); | 150 user_manager::UserManager::Get()->GetActiveUser()->GetAccountId(); |
| 151 wallpaper_manager->SetCustomWallpaper( | 151 wallpaper_manager->SetCustomWallpaper( |
| 152 account_id_, user_id_hash_, params_->details.filename, layout, | 152 account_id_, user_id_hash_, params_->details.filename, layout, |
| 153 user_manager::User::CUSTOMIZED, image, update_wallpaper); | 153 user_manager::User::CUSTOMIZED, image, update_wallpaper); |
| 154 unsafe_wallpaper_decoder_ = NULL; | 154 unsafe_wallpaper_decoder_ = NULL; |
| 155 | 155 |
| 156 if (params_->details.thumbnail) { | 156 // Save current extenion name. It will be displayed in the component |
| 157 image.EnsureRepsForSupportedScales(); | 157 // wallpaper picker app. If current extension is the component wallpaper |
| 158 scoped_ptr<gfx::ImageSkia> deep_copy(image.DeepCopy()); | 158 // picker, set an empty string. |
| 159 // Generates thumbnail before call api function callback. We can then | 159 Profile* profile = Profile::FromBrowserContext(browser_context()); |
| 160 // request thumbnail in the javascript callback. | 160 if (extension()->id() == extension_misc::kWallpaperManagerId) { |
| 161 task_runner->PostTask( | 161 profile->GetPrefs()->SetString(prefs::kCurrentWallpaperAppName, |
| 162 FROM_HERE, | 162 std::string()); |
| 163 base::Bind(&WallpaperSetWallpaperFunction::GenerateThumbnail, this, | |
| 164 thumbnail_path, base::Passed(std::move(deep_copy)))); | |
| 165 } else { | 163 } else { |
| 166 // Save current extenion name. It will be displayed in the component | 164 profile->GetPrefs()->SetString(prefs::kCurrentWallpaperAppName, |
| 167 // wallpaper picker app. If current extension is the component wallpaper | 165 extension()->name()); |
| 168 // picker, set an empty string. | |
| 169 Profile* profile = Profile::FromBrowserContext(browser_context()); | |
| 170 if (extension()->id() == extension_misc::kWallpaperManagerId) { | |
| 171 profile->GetPrefs()->SetString(prefs::kCurrentWallpaperAppName, | |
| 172 std::string()); | |
| 173 } else { | |
| 174 profile->GetPrefs()->SetString(prefs::kCurrentWallpaperAppName, | |
| 175 extension()->name()); | |
| 176 } | |
| 177 SendResponse(true); | |
| 178 } | 166 } |
| 179 | 167 |
| 180 // Inform the native Wallpaper Picker Application that the current wallpaper | 168 if (!params_->details.thumbnail) |
| 181 // has been modified by a third party application. | 169 SendResponse(true); |
| 182 Profile* profile = Profile::FromBrowserContext(browser_context()); | 170 |
| 183 extensions::EventRouter* event_router = extensions::EventRouter::Get(profile); | 171 // We need to generate thumbnail image anyway to make the current third party |
| 184 scoped_ptr<base::ListValue> event_args(new base::ListValue()); | 172 // wallpaper syncable through different devices. |
| 185 scoped_ptr<extensions::Event> event(new extensions::Event( | 173 image.EnsureRepsForSupportedScales(); |
| 186 extensions::events::WALLPAPER_PRIVATE_ON_WALLPAPER_CHANGED_BY_3RD_PARTY, | 174 scoped_ptr<gfx::ImageSkia> deep_copy(image.DeepCopy()); |
| 187 extensions::api::wallpaper_private::OnWallpaperChangedBy3rdParty:: | 175 // Generates thumbnail before call api function callback. We can then |
| 188 kEventName, | 176 // request thumbnail in the javascript callback. |
| 189 std::move(event_args))); | 177 task_runner->PostTask( |
| 190 event_router->DispatchEventToExtension(extension_misc::kWallpaperManagerId, | 178 FROM_HERE, |
| 191 std::move(event)); | 179 base::Bind(&WallpaperSetWallpaperFunction::GenerateThumbnail, this, |
| 180 thumbnail_path, base::Passed(std::move(deep_copy)))); |
| 192 } | 181 } |
| 193 | 182 |
| 194 void WallpaperSetWallpaperFunction::GenerateThumbnail( | 183 void WallpaperSetWallpaperFunction::GenerateThumbnail( |
| 195 const base::FilePath& thumbnail_path, scoped_ptr<gfx::ImageSkia> image) { | 184 const base::FilePath& thumbnail_path, scoped_ptr<gfx::ImageSkia> image) { |
| 196 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( | 185 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( |
| 197 sequence_token_)); | 186 sequence_token_)); |
| 198 if (!base::PathExists(thumbnail_path.DirName())) | 187 if (!base::PathExists(thumbnail_path.DirName())) |
| 199 base::CreateDirectory(thumbnail_path.DirName()); | 188 base::CreateDirectory(thumbnail_path.DirName()); |
| 200 | 189 |
| 201 scoped_refptr<base::RefCountedBytes> data; | 190 scoped_refptr<base::RefCountedBytes> original_data; |
| 191 scoped_refptr<base::RefCountedBytes> thumbnail_data; |
| 192 chromeos::WallpaperManager::Get()->ResizeImage( |
| 193 *image, wallpaper::WALLPAPER_LAYOUT_STRETCH, image->width(), |
| 194 image->height(), &original_data, NULL); |
| 202 chromeos::WallpaperManager::Get()->ResizeImage( | 195 chromeos::WallpaperManager::Get()->ResizeImage( |
| 203 *image, wallpaper::WALLPAPER_LAYOUT_STRETCH, | 196 *image, wallpaper::WALLPAPER_LAYOUT_STRETCH, |
| 204 wallpaper::kWallpaperThumbnailWidth, wallpaper::kWallpaperThumbnailHeight, | 197 wallpaper::kWallpaperThumbnailWidth, wallpaper::kWallpaperThumbnailHeight, |
| 205 &data, NULL); | 198 &thumbnail_data, NULL); |
| 206 BrowserThread::PostTask( | 199 BrowserThread::PostTask( |
| 207 BrowserThread::UI, FROM_HERE, | 200 BrowserThread::UI, FROM_HERE, |
| 208 base::Bind( | 201 base::Bind(&WallpaperSetWallpaperFunction::ThumbnailGenerated, this, |
| 209 &WallpaperSetWallpaperFunction::ThumbnailGenerated, | 202 original_data, thumbnail_data)); |
| 210 this, data)); | |
| 211 } | 203 } |
| 212 | 204 |
| 213 void WallpaperSetWallpaperFunction::ThumbnailGenerated( | 205 void WallpaperSetWallpaperFunction::ThumbnailGenerated( |
| 214 base::RefCountedBytes* data) { | 206 base::RefCountedBytes* original_data, |
| 215 BinaryValue* result = BinaryValue::CreateWithCopiedBuffer( | 207 base::RefCountedBytes* thumbnail_data) { |
| 216 reinterpret_cast<const char*>(data->front()), data->size()); | 208 BinaryValue* original_result = BinaryValue::CreateWithCopiedBuffer( |
| 217 SetResult(result); | 209 reinterpret_cast<const char*>(original_data->front()), |
| 218 SendResponse(true); | 210 original_data->size()); |
| 211 BinaryValue* thumbnail_result = BinaryValue::CreateWithCopiedBuffer( |
| 212 reinterpret_cast<const char*>(thumbnail_data->front()), |
| 213 thumbnail_data->size()); |
| 214 |
| 215 if (params_->details.thumbnail) { |
| 216 SetResult(thumbnail_result); |
| 217 SendResponse(true); |
| 218 } |
| 219 |
| 220 // Inform the native Wallpaper Picker Application that the current wallpaper |
| 221 // has been modified by a third party application. |
| 222 Profile* profile = Profile::FromBrowserContext(browser_context()); |
| 223 extensions::EventRouter* event_router = extensions::EventRouter::Get(profile); |
| 224 scoped_ptr<base::ListValue> event_args(new base::ListValue()); |
| 225 event_args->Append(original_result); |
| 226 event_args->Append(thumbnail_result); |
| 227 event_args->Append(new base::StringValue( |
| 228 extensions::api::wallpaper::ToString(params_->details.layout))); |
| 229 scoped_ptr<extensions::Event> event(new extensions::Event( |
| 230 extensions::events::WALLPAPER_PRIVATE_ON_WALLPAPER_CHANGED_BY_3RD_PARTY, |
| 231 extensions::api::wallpaper_private::OnWallpaperChangedBy3rdParty:: |
| 232 kEventName, |
| 233 std::move(event_args))); |
| 234 event_router->DispatchEventToExtension(extension_misc::kWallpaperManagerId, |
| 235 std::move(event)); |
| 219 } | 236 } |
| 220 | 237 |
| 221 void WallpaperSetWallpaperFunction::OnWallpaperFetched( | 238 void WallpaperSetWallpaperFunction::OnWallpaperFetched( |
| 222 bool success, | 239 bool success, |
| 223 const std::string& response) { | 240 const std::string& response) { |
| 224 if (success) { | 241 if (success) { |
| 225 params_->details.data.reset( | 242 params_->details.data.reset( |
| 226 new std::vector<char>(response.begin(), response.end())); | 243 new std::vector<char>(response.begin(), response.end())); |
| 227 StartDecode(*params_->details.data); | 244 StartDecode(*params_->details.data); |
| 228 } else { | 245 } else { |
| 229 SetError(response); | 246 SetError(response); |
| 230 SendResponse(false); | 247 SendResponse(false); |
| 231 } | 248 } |
| 232 } | 249 } |
| OLD | NEW |