| OLD | NEW |
| 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_source.h" | 5 #include "chrome/browser/ui/webui/options2/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.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/string_split.h" | 9 #include "base/string_split.h" |
| 10 #include "chrome/browser/chromeos/login/default_user_images.h" | 10 #include "chrome/browser/chromeos/login/default_user_images.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 const char kKeyAnimated[] = "animated"; | 24 const char kKeyAnimated[] = "animated"; |
| 25 | 25 |
| 26 // Parses the user image URL, which looks like | 26 // Parses the user image URL, which looks like |
| 27 // "chrome://userimage/user@host?key1=value1&...&key_n=value_n@<scale>x", | 27 // "chrome://userimage/user@host?key1=value1&...&key_n=value_n@<scale>x", |
| 28 // to user email, optional parameters and scale factor. | 28 // to user email, optional parameters and scale factor. |
| 29 void ParseRequest(const GURL& url, | 29 void ParseRequest(const GURL& url, |
| 30 std::string* email, | 30 std::string* email, |
| 31 bool* is_image_animated, | 31 bool* is_image_animated, |
| 32 ui::ScaleFactor* scale_factor) { | 32 ui::ScaleFactor* scale_factor) { |
| 33 DCHECK(url.is_valid()); | 33 DCHECK(url.is_valid()); |
| 34 | 34 web_ui_util::ParsePathAndScale(url, email, scale_factor); |
| 35 *email = url.path(); | |
| 36 email->erase(0, 1); // Strip initial slash. | |
| 37 | |
| 38 // TODO(ivankr): when all chrome://userimage URLs have a valid @<scale>x, | |
| 39 // remove this and pass |email| instead of |&path| to ParsePathAndScale. | |
| 40 size_t pos = email->find('@'); | |
| 41 if (pos != std::string::npos) { | |
| 42 pos = email->find('@', pos + 1); | |
| 43 if (pos != std::string::npos) | |
| 44 email->erase(pos); | |
| 45 } | |
| 46 std::string path; | |
| 47 web_ui_util::ParsePathAndScale(url, &path, scale_factor); | |
| 48 | |
| 49 std::string url_spec = url.possibly_invalid_spec(); | 35 std::string url_spec = url.possibly_invalid_spec(); |
| 50 url_parse::Component query = url.parsed_for_possibly_invalid_spec().query; | 36 url_parse::Component query = url.parsed_for_possibly_invalid_spec().query; |
| 51 url_parse::Component key, value; | 37 url_parse::Component key, value; |
| 52 *is_image_animated = false; | 38 *is_image_animated = false; |
| 53 while (ExtractQueryKeyValue(url_spec.c_str(), &query, &key, &value)) { | 39 while (ExtractQueryKeyValue(url_spec.c_str(), &query, &key, &value)) { |
| 54 if (url_spec.substr(key.begin, key.len) == kKeyAnimated) { | 40 if (url_spec.substr(key.begin, key.len) == kKeyAnimated) { |
| 55 *is_image_animated = true; | 41 *is_image_animated = true; |
| 56 break; | 42 break; |
| 57 } | 43 } |
| 58 } | 44 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 if (is_image_animated) { | 105 if (is_image_animated) { |
| 120 const chromeos::User* user = chromeos::UserManager::Get()->FindUser(email); | 106 const chromeos::User* user = chromeos::UserManager::Get()->FindUser(email); |
| 121 if (user && user->has_animated_image()) | 107 if (user && user->has_animated_image()) |
| 122 return "image/gif"; | 108 return "image/gif"; |
| 123 } | 109 } |
| 124 return "image/png"; | 110 return "image/png"; |
| 125 } | 111 } |
| 126 | 112 |
| 127 } // namespace options2 | 113 } // namespace options2 |
| 128 } // namespace chromeos | 114 } // namespace chromeos |
| OLD | NEW |