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..5c6582f4d8930edd3ac8b947d7bc2cb9d58cc27b 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,64 @@ |
#include "chrome/browser/ui/webui/options2/chromeos/user_image_source2.h" |
+#include <utility> |
+#include <vector> |
+ |
+#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 "grit/theme_resources.h" |
#include "ui/base/resource/resource_bundle.h" |
#include "ui/gfx/codec/png_codec.h" |
+using std::pair; |
+using std::string; |
+using std::vector; |
+ |
+namespace { |
+ |
+const char* const kPathKeyAnimated = "animated"; |
+const char* const kPathKeyAnimatedTrueValue = "true"; |
+ |
+void ParseRequest(const string& path, string* email, bool* is_image_animated) { |
Ivan Korotkov
2012/05/29 10:50:23
Please use GURL and something like GetValueForKeyI
ygorshenin1
2012/05/30 12:17:34
Done.
|
+ // 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 |
+ size_t split_pos = path.find_first_of('?'); |
+ |
+ if (email) |
+ *email = path.substr(0, split_pos); |
+ |
+ if (is_image_animated) { |
+ string params = path.substr(split_pos + 1, path.size() - split_pos - 1); |
+ vector<pair<string, string> > key_value_pairs; |
+ base::SplitStringIntoKeyValuePairs(params, '=', '&', &key_value_pairs); |
+ *is_image_animated = false; |
+ for (size_t i = 0; i < key_value_pairs.size(); ++i) { |
+ if (key_value_pairs[i].first == kPathKeyAnimated && |
+ key_value_pairs[i].second == kPathKeyAnimatedTrueValue) { |
+ *is_image_animated = true; |
+ } |
+ } |
+ } |
+} |
+ |
+} // namespace |
+ |
namespace chromeos { |
namespace options2 { |
-std::vector<unsigned char> UserImageSource::GetUserImage( |
- const std::string& email) const { |
- std::vector<unsigned char> user_image; |
+vector<unsigned char> UserImageSource::GetUserImage( |
+ const string& email, bool is_image_animated) const { |
+ 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_gif_image() && is_image_animated) |
+ user->gif_image(&user_image); |
+ else |
+ gfx::PNGCodec::EncodeBGRASkBitmap(user->image(), false, &user_image); |
return user_image; |
} |
gfx::PNGCodec::EncodeBGRASkBitmap( |
@@ -37,18 +78,27 @@ UserImageSource::UserImageSource() |
UserImageSource::~UserImageSource() {} |
-void UserImageSource::StartDataRequest(const std::string& path, |
+void UserImageSource::StartDataRequest(const 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))); |
+ string email; |
+ bool is_image_animated; |
+ ParseRequest(path, &email, &is_image_animated); |
+ |
+ vector<unsigned char> image = GetUserImage(email, is_image_animated); |
+ SendResponse(request_id, new base::RefCountedBytes(image)); |
} |
-std::string UserImageSource::GetMimeType(const std::string&) const { |
+string UserImageSource::GetMimeType(const string& path) const { |
// We need to explicitly return a mime type, otherwise if the user tries to |
// drag the image they get no extension. |
+ string email; |
+ bool is_image_animated; |
+ ParseRequest(path, &email, &is_image_animated); |
+ |
+ const chromeos::User* user = chromeos::UserManager::Get()->FindUser(email); |
+ if (user && user->has_gif_image() && is_image_animated) |
+ return "image/gif"; |
return "image/png"; |
} |