Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Side by Side Diff: chrome/browser/ui/webui/options2/chromeos/user_image_source2.cc

Issue 10454044: Added support for animated/nonanimated user image. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixed mock. Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/webui/options2/chromeos/user_image_source2.h" 5 #include "chrome/browser/ui/webui/options2/chromeos/user_image_source2.h"
6 6
7 #include "base/logging.h"
Nikita (slow) 2012/05/30 17:19:11 nit: not needed
ygorshenin1 2012/05/31 11:17:46 Done.
7 #include "base/memory/ref_counted_memory.h" 8 #include "base/memory/ref_counted_memory.h"
8 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/string_split.h"
9 #include "chrome/browser/chromeos/login/user_manager.h" 11 #include "chrome/browser/chromeos/login/user_manager.h"
10 #include "chrome/common/url_constants.h" 12 #include "chrome/common/url_constants.h"
13 #include "googleurl/src/url_parse.h"
11 #include "grit/theme_resources.h" 14 #include "grit/theme_resources.h"
12 #include "ui/base/resource/resource_bundle.h" 15 #include "ui/base/resource/resource_bundle.h"
13 #include "ui/gfx/codec/png_codec.h" 16 #include "ui/gfx/codec/png_codec.h"
14 17
18 namespace {
19
20 const char kKeyAnimated[] = "animated";
21
22 void ParseRequest(const std::string& path,
23 std::string* email,
24 bool* is_image_animated) {
25 url_parse::Parsed parsed;
26 url_parse::ParseStandardURL(path.c_str(), path.size(), &parsed);
27 if (email) {
28 DCHECK(parsed.username.is_valid());
29 DCHECK(parsed.host.is_valid());
30
31 *email = path.substr(parsed.username.begin, parsed.username.len);
32 email->append("@");
33 email->append(path.substr(parsed.host.begin, parsed.host.len));
34 }
35
36 if (is_image_animated && parsed.query.is_valid()) {
37 url_parse::Component query = parsed.query;
38 url_parse::Component key, value;
39
40 *is_image_animated = false;
41 while (ExtractQueryKeyValue(path.c_str(), &query, &key, &value)) {
42 if (path.substr(key.begin, key.len) == kKeyAnimated) {
43 *is_image_animated = true;
44 break;
45 }
46 }
47 }
48 }
49
50 } // namespace
51
15 namespace chromeos { 52 namespace chromeos {
16 namespace options2 { 53 namespace options2 {
17 54
18 std::vector<unsigned char> UserImageSource::GetUserImage( 55 std::vector<unsigned char> UserImageSource::GetUserImage(
19 const std::string& email) const { 56 const std::string& email, bool is_image_animated) const {
20 std::vector<unsigned char> user_image; 57 std::vector<unsigned char> user_image;
21 const chromeos::User* user = chromeos::UserManager::Get()->FindUser(email); 58 const chromeos::User* user = chromeos::UserManager::Get()->FindUser(email);
22 if (user) { 59 if (user) {
23 gfx::PNGCodec::EncodeBGRASkBitmap(user->image(), false, &user_image); 60 if (user->has_animated_image() && is_image_animated)
61 user->GetAnimatedImage(&user_image);
62 else
63 gfx::PNGCodec::EncodeBGRASkBitmap(user->image(), false, &user_image);
24 return user_image; 64 return user_image;
25 } 65 }
26 gfx::PNGCodec::EncodeBGRASkBitmap( 66 gfx::PNGCodec::EncodeBGRASkBitmap(
27 *ResourceBundle::GetSharedInstance().GetBitmapNamed( 67 *ResourceBundle::GetSharedInstance().GetBitmapNamed(
28 IDR_LOGIN_DEFAULT_USER), 68 IDR_LOGIN_DEFAULT_USER),
29 false, 69 false,
30 &user_image); 70 &user_image);
31 return user_image; 71 return user_image;
32 } 72 }
33 73
34 UserImageSource::UserImageSource() 74 UserImageSource::UserImageSource()
35 : DataSource(chrome::kChromeUIUserImageHost, MessageLoop::current()) { 75 : DataSource(chrome::kChromeUIUserImageHost, MessageLoop::current()) {
36 } 76 }
37 77
38 UserImageSource::~UserImageSource() {} 78 UserImageSource::~UserImageSource() {}
39 79
40 void UserImageSource::StartDataRequest(const std::string& path, 80 void UserImageSource::StartDataRequest(const std::string& path,
41 bool is_incognito, 81 bool is_incognito,
42 int request_id) { 82 int request_id) {
43 // Strip the query param value - we only use it as a hack to ensure our 83 std::string email;
44 // image gets reloaded instead of being pulled from the browser cache 84 bool is_image_animated;
45 std::string email = path.substr(0, path.find_first_of("?")); 85 ParseRequest(path, &email, &is_image_animated);
46 SendResponse(request_id, new base::RefCountedBytes(GetUserImage(email))); 86
87 std::vector<unsigned char> image = GetUserImage(email, is_image_animated);
88 SendResponse(request_id, new base::RefCountedBytes(image));
47 } 89 }
48 90
49 std::string UserImageSource::GetMimeType(const std::string&) const { 91 std::string UserImageSource::GetMimeType(const std::string& path) const {
50 // We need to explicitly return a mime type, otherwise if the user tries to 92 // We need to explicitly return a mime type, otherwise if the user tries to
51 // drag the image they get no extension. 93 // drag the image they get no extension.
94 std::string email;
95 bool is_image_animated;
96 ParseRequest(path, &email, &is_image_animated);
97
98 if (is_image_animated) {
99 const chromeos::User* user = chromeos::UserManager::Get()->FindUser(email);
100 if (user && user->has_animated_image())
101 return "image/gif";
102 }
52 return "image/png"; 103 return "image/png";
53 } 104 }
54 105
55 } // namespace options2 106 } // namespace options2
56 } // namespace chromeos 107 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698