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

Side by Side Diff: chrome/browser/ui/webui/options/chromeos/user_image_source.cc

Issue 411523005: Revert of Clean up. Experimental user avatars removed. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 | Annotate | Revision Log
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/options/chromeos/user_image_source.h" 5 #include "chrome/browser/ui/webui/options/chromeos/user_image_source.h"
6 6
7 #include "base/memory/ref_counted_memory.h" 7 #include "base/memory/ref_counted_memory.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/strings/string_split.h" 9 #include "base/strings/string_split.h"
10 #include "chrome/browser/chromeos/login/users/avatar/default_user_images.h" 10 #include "chrome/browser/chromeos/login/users/avatar/default_user_images.h"
11 #include "chrome/browser/chromeos/login/users/user_manager.h" 11 #include "chrome/browser/chromeos/login/users/user_manager.h"
12 #include "chrome/common/url_constants.h" 12 #include "chrome/common/url_constants.h"
13 #include "grit/theme_resources.h" 13 #include "grit/theme_resources.h"
14 #include "net/base/escape.h" 14 #include "net/base/escape.h"
15 #include "ui/base/resource/resource_bundle.h" 15 #include "ui/base/resource/resource_bundle.h"
16 #include "ui/gfx/codec/png_codec.h" 16 #include "ui/gfx/codec/png_codec.h"
17 #include "url/url_parse.h" 17 #include "url/url_parse.h"
18 18
19 namespace { 19 namespace {
20 20
21 // Animated key is used in user image URL requests to specify that
22 // animated version of user image is required. Without that key
23 // non-animated version of user image should be returned.
24 const char kKeyAnimated[] = "animated";
25
21 // Parses the user image URL, which looks like 26 // Parses the user image URL, which looks like
22 // "chrome://userimage/user@host?key1=value1&...&key_n=value_n", 27 // "chrome://userimage/user@host?key1=value1&...&key_n=value_n",
23 // to user email. 28 // to user email and optional parameters.
24 void ParseRequest(const GURL& url, 29 void ParseRequest(const GURL& url,
25 std::string* email) { 30 std::string* email,
31 bool* is_image_animated) {
26 DCHECK(url.is_valid()); 32 DCHECK(url.is_valid());
27 *email = net::UnescapeURLComponent(url.path().substr(1), 33 *email = net::UnescapeURLComponent(url.path().substr(1),
28 (net::UnescapeRule::URL_SPECIAL_CHARS | 34 (net::UnescapeRule::URL_SPECIAL_CHARS |
29 net::UnescapeRule::SPACES)); 35 net::UnescapeRule::SPACES));
36 std::string url_spec = url.possibly_invalid_spec();
37 url::Component query = url.parsed_for_possibly_invalid_spec().query;
38 url::Component key, value;
39 *is_image_animated = false;
40 while (ExtractQueryKeyValue(url_spec.c_str(), &query, &key, &value)) {
41 if (url_spec.substr(key.begin, key.len) == kKeyAnimated) {
42 *is_image_animated = true;
43 break;
44 }
45 }
30 } 46 }
31 47
32 } // namespace 48 } // namespace
33 49
34 namespace chromeos { 50 namespace chromeos {
35 namespace options { 51 namespace options {
36 52
37 base::RefCountedMemory* UserImageSource::GetUserImage( 53 base::RefCountedMemory* UserImageSource::GetUserImage(
38 const std::string& email, 54 const std::string& email,
55 bool is_image_animated,
39 ui::ScaleFactor scale_factor) const { 56 ui::ScaleFactor scale_factor) const {
40 const chromeos::User* user = chromeos::UserManager::Get()->FindUser(email); 57 const chromeos::User* user = chromeos::UserManager::Get()->FindUser(email);
41 if (user) { 58 if (user) {
42 if (user->has_raw_image()) { 59 if (user->has_animated_image() && is_image_animated) {
60 return new base::RefCountedBytes(user->animated_image());
61 } else if (user->has_raw_image()) {
43 return new base::RefCountedBytes(user->raw_image()); 62 return new base::RefCountedBytes(user->raw_image());
44 } else if (user->image_is_stub()) { 63 } else if (user->image_is_stub()) {
45 return ResourceBundle::GetSharedInstance(). 64 return ResourceBundle::GetSharedInstance().
46 LoadDataResourceBytesForScale(IDR_PROFILE_PICTURE_LOADING, 65 LoadDataResourceBytesForScale(IDR_PROFILE_PICTURE_LOADING,
47 scale_factor); 66 scale_factor);
48 } else if (user->HasDefaultImage()) { 67 } else if (user->HasDefaultImage()) {
49 return ResourceBundle::GetSharedInstance(). 68 return ResourceBundle::GetSharedInstance().
50 LoadDataResourceBytesForScale( 69 LoadDataResourceBytesForScale(
51 kDefaultImageResourceIDs[user->image_index()], 70 kDefaultImageResourceIDs[user->image_index()],
52 scale_factor); 71 scale_factor);
(...skipping 13 matching lines...) Expand all
66 std::string UserImageSource::GetSource() const { 85 std::string UserImageSource::GetSource() const {
67 return chrome::kChromeUIUserImageHost; 86 return chrome::kChromeUIUserImageHost;
68 } 87 }
69 88
70 void UserImageSource::StartDataRequest( 89 void UserImageSource::StartDataRequest(
71 const std::string& path, 90 const std::string& path,
72 int render_process_id, 91 int render_process_id,
73 int render_frame_id, 92 int render_frame_id,
74 const content::URLDataSource::GotDataCallback& callback) { 93 const content::URLDataSource::GotDataCallback& callback) {
75 std::string email; 94 std::string email;
95 bool is_image_animated = false;
76 GURL url(chrome::kChromeUIUserImageURL + path); 96 GURL url(chrome::kChromeUIUserImageURL + path);
77 ParseRequest(url, &email); 97 ParseRequest(url, &email, &is_image_animated);
78 callback.Run(GetUserImage(email, ui::SCALE_FACTOR_100P)); 98 callback.Run(GetUserImage(email, is_image_animated, ui::SCALE_FACTOR_100P));
79 } 99 }
80 100
81 std::string UserImageSource::GetMimeType(const std::string& path) const { 101 std::string UserImageSource::GetMimeType(const std::string& path) const {
82 // We need to explicitly return a mime type, otherwise if the user tries to 102 // We need to explicitly return a mime type, otherwise if the user tries to
83 // drag the image they get no extension. 103 // drag the image they get no extension.
104 std::string email;
105 bool is_image_animated = false;
106
107 GURL url(chrome::kChromeUIUserImageURL + path);
108 ParseRequest(url, &email, &is_image_animated);
109
110 if (is_image_animated) {
111 const chromeos::User* user = chromeos::UserManager::Get()->FindUser(email);
112 if (user && user->has_animated_image())
113 return "image/gif";
114 }
84 return "image/png"; 115 return "image/png";
85 } 116 }
86 117
87 } // namespace options 118 } // namespace options
88 } // namespace chromeos 119 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/options/chromeos/user_image_source.h ('k') | components/user_manager/user_image/user_image.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698