OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ui/webui/options2/chromeos/user_image_source.h" |
| 6 |
| 7 #include "base/memory/ref_counted_memory.h" |
| 8 #include "chrome/browser/chromeos/login/user_manager.h" |
| 9 #include "chrome/common/url_constants.h" |
| 10 #include "grit/theme_resources.h" |
| 11 #include "ui/base/resource/resource_bundle.h" |
| 12 #include "ui/gfx/codec/png_codec.h" |
| 13 |
| 14 namespace chromeos { |
| 15 |
| 16 std::vector<unsigned char> UserImageSource::GetUserImage( |
| 17 const std::string& email) const { |
| 18 std::vector<unsigned char> user_image; |
| 19 const chromeos::User* user = chromeos::UserManager::Get()->FindUser(email); |
| 20 if (user) { |
| 21 gfx::PNGCodec::EncodeBGRASkBitmap(user->image(), false, &user_image); |
| 22 return user_image; |
| 23 } |
| 24 gfx::PNGCodec::EncodeBGRASkBitmap( |
| 25 *ResourceBundle::GetSharedInstance().GetBitmapNamed( |
| 26 IDR_LOGIN_DEFAULT_USER), |
| 27 false, |
| 28 &user_image); |
| 29 return user_image; |
| 30 } |
| 31 |
| 32 UserImageSource::UserImageSource() |
| 33 : DataSource(chrome::kChromeUIUserImageHost, MessageLoop::current()) { |
| 34 } |
| 35 |
| 36 UserImageSource::~UserImageSource() {} |
| 37 |
| 38 void UserImageSource::StartDataRequest(const std::string& path, |
| 39 bool is_incognito, |
| 40 int request_id) { |
| 41 // Strip the query param value - we only use it as a hack to ensure our |
| 42 // image gets reloaded instead of being pulled from the browser cache |
| 43 std::string email = path.substr(0, path.find_first_of("?")); |
| 44 SendResponse(request_id, new RefCountedBytes(GetUserImage(email))); |
| 45 } |
| 46 |
| 47 std::string UserImageSource::GetMimeType(const std::string&) const { |
| 48 // We need to explicitly return a mime type, otherwise if the user tries to |
| 49 // drag the image they get no extension. |
| 50 return "image/png"; |
| 51 } |
| 52 |
| 53 } // namespace chromeos |
OLD | NEW |