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