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

Unified 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: Added clarifying comment. Created 8 years, 7 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
« no previous file with comments | « chrome/browser/ui/webui/options2/chromeos/user_image_source2.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/webui/options2/chromeos/user_image_source2.cc
diff --git a/chrome/browser/ui/webui/options2/chromeos/user_image_source2.cc b/chrome/browser/ui/webui/options2/chromeos/user_image_source2.cc
index 03d929b1edffa4a78d068f9b8c733ffdf9663cad..25fbeef44fc1cf92c8652a35000256d09a040ef4 100644
--- a/chrome/browser/ui/webui/options2/chromeos/user_image_source2.cc
+++ b/chrome/browser/ui/webui/options2/chromeos/user_image_source2.cc
@@ -4,23 +4,63 @@
#include "chrome/browser/ui/webui/options2/chromeos/user_image_source2.h"
+#include "base/logging.h"
#include "base/memory/ref_counted_memory.h"
#include "base/message_loop.h"
+#include "base/string_split.h"
#include "chrome/browser/chromeos/login/user_manager.h"
#include "chrome/common/url_constants.h"
+#include "googleurl/src/url_parse.h"
#include "grit/theme_resources.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/codec/png_codec.h"
+namespace {
+
+const char kKeyAnimated[] = "animated";
James Hawkins 2012/05/30 15:18:48 nit: Document (e.g. rationale, use, etc.).
ygorshenin1 2012/05/31 11:17:46 Done.
+
+void ParseRequest(const std::string& path,
James Hawkins 2012/05/30 15:18:48 nit: Document function and parameters.
ygorshenin1 2012/05/31 11:17:46 Done.
+ std::string* email,
+ bool* is_image_animated) {
+ url_parse::Parsed parsed;
+ url_parse::ParseStandardURL(path.c_str(), path.size(), &parsed);
+ if (email) {
James Hawkins 2012/05/30 15:18:48 The current uses always pass a non-NULL |email|.
ygorshenin1 2012/05/31 11:17:46 Done.
+ DCHECK(parsed.username.is_valid());
+ DCHECK(parsed.host.is_valid());
+
+ *email = path.substr(parsed.username.begin, parsed.username.len);
+ email->append("@");
+ email->append(path.substr(parsed.host.begin, parsed.host.len));
+ }
+
+ if (is_image_animated && parsed.query.is_valid()) {
+ url_parse::Component query = parsed.query;
+ url_parse::Component key, value;
+
+ *is_image_animated = false;
+ while (ExtractQueryKeyValue(path.c_str(), &query, &key, &value)) {
+ if (path.substr(key.begin, key.len) == kKeyAnimated) {
+ *is_image_animated = true;
+ break;
+ }
+ }
+ }
+}
+
+} // namespace
+
namespace chromeos {
namespace options2 {
std::vector<unsigned char> UserImageSource::GetUserImage(
- const std::string& email) const {
+ const std::string& email, bool is_image_animated) const {
std::vector<unsigned char> user_image;
const chromeos::User* user = chromeos::UserManager::Get()->FindUser(email);
if (user) {
- gfx::PNGCodec::EncodeBGRASkBitmap(user->image(), false, &user_image);
+ if (user->has_animated_image() && is_image_animated)
+ user->GetAnimatedImage(&user_image);
+ else
+ gfx::PNGCodec::EncodeBGRASkBitmap(user->image(), false, &user_image);
return user_image;
}
gfx::PNGCodec::EncodeBGRASkBitmap(
@@ -40,15 +80,26 @@ UserImageSource::~UserImageSource() {}
void UserImageSource::StartDataRequest(const std::string& path,
bool is_incognito,
int request_id) {
- // Strip the query param value - we only use it as a hack to ensure our
- // image gets reloaded instead of being pulled from the browser cache
- std::string email = path.substr(0, path.find_first_of("?"));
- SendResponse(request_id, new base::RefCountedBytes(GetUserImage(email)));
+ std::string email;
+ bool is_image_animated;
+ ParseRequest(path, &email, &is_image_animated);
+
+ std::vector<unsigned char> image = GetUserImage(email, is_image_animated);
+ SendResponse(request_id, new base::RefCountedBytes(image));
}
-std::string UserImageSource::GetMimeType(const std::string&) const {
+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;
+ ParseRequest(path, &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/options2/chromeos/user_image_source2.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698