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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/options/chromeos/user_image_source.cc
diff --git a/chrome/browser/ui/webui/options/chromeos/user_image_source.cc b/chrome/browser/ui/webui/options/chromeos/user_image_source.cc
index fdddea0fe9ea473a17d2c2de744a936843ba309b..5ce8a16352fb88c96d3915708f26929c25bd7ff7 100644
--- a/chrome/browser/ui/webui/options/chromeos/user_image_source.cc
+++ b/chrome/browser/ui/webui/options/chromeos/user_image_source.cc
@@ -18,15 +18,31 @@
namespace {
+// Animated key is used in user image URL requests to specify that
+// animated version of user image is required. Without that key
+// non-animated version of user image should be returned.
+const char kKeyAnimated[] = "animated";
+
// Parses the user image URL, which looks like
// "chrome://userimage/user@host?key1=value1&...&key_n=value_n",
-// to user email.
+// to user email and optional parameters.
void ParseRequest(const GURL& url,
- std::string* email) {
+ std::string* email,
+ bool* is_image_animated) {
DCHECK(url.is_valid());
*email = net::UnescapeURLComponent(url.path().substr(1),
(net::UnescapeRule::URL_SPECIAL_CHARS |
net::UnescapeRule::SPACES));
+ std::string url_spec = url.possibly_invalid_spec();
+ url::Component query = url.parsed_for_possibly_invalid_spec().query;
+ url::Component key, value;
+ *is_image_animated = false;
+ while (ExtractQueryKeyValue(url_spec.c_str(), &query, &key, &value)) {
+ if (url_spec.substr(key.begin, key.len) == kKeyAnimated) {
+ *is_image_animated = true;
+ break;
+ }
+ }
}
} // namespace
@@ -36,10 +52,13 @@
base::RefCountedMemory* UserImageSource::GetUserImage(
const std::string& email,
+ bool is_image_animated,
ui::ScaleFactor scale_factor) const {
const chromeos::User* user = chromeos::UserManager::Get()->FindUser(email);
if (user) {
- if (user->has_raw_image()) {
+ if (user->has_animated_image() && is_image_animated) {
+ return new base::RefCountedBytes(user->animated_image());
+ } else if (user->has_raw_image()) {
return new base::RefCountedBytes(user->raw_image());
} else if (user->image_is_stub()) {
return ResourceBundle::GetSharedInstance().
@@ -73,14 +92,26 @@
int render_frame_id,
const content::URLDataSource::GotDataCallback& callback) {
std::string email;
+ bool is_image_animated = false;
GURL url(chrome::kChromeUIUserImageURL + path);
- ParseRequest(url, &email);
- callback.Run(GetUserImage(email, ui::SCALE_FACTOR_100P));
+ ParseRequest(url, &email, &is_image_animated);
+ callback.Run(GetUserImage(email, is_image_animated, ui::SCALE_FACTOR_100P));
}
std::string UserImageSource::GetMimeType(const std::string& path) const {
// We need to explicitly return a mime type, otherwise if the user tries to
// drag the image they get no extension.
+ std::string email;
+ bool is_image_animated = false;
+
+ GURL url(chrome::kChromeUIUserImageURL + path);
+ ParseRequest(url, &email, &is_image_animated);
+
+ if (is_image_animated) {
+ const chromeos::User* user = chromeos::UserManager::Get()->FindUser(email);
+ if (user && user->has_animated_image())
+ return "image/gif";
+ }
return "image/png";
}
« 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