| 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/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/common/url_constants.h" | 10 #include "chrome/common/url_constants.h" |
| 11 #include "components/user_manager/user_id.h" |
| 11 #include "components/user_manager/user_image/default_user_images.h" | 12 #include "components/user_manager/user_image/default_user_images.h" |
| 12 #include "components/user_manager/user_manager.h" | 13 #include "components/user_manager/user_manager.h" |
| 13 #include "grit/theme_resources.h" | 14 #include "grit/theme_resources.h" |
| 14 #include "grit/ui_chromeos_resources.h" | 15 #include "grit/ui_chromeos_resources.h" |
| 15 #include "net/base/escape.h" | 16 #include "net/base/escape.h" |
| 16 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
| 17 #include "ui/gfx/codec/png_codec.h" | 18 #include "ui/gfx/codec/png_codec.h" |
| 18 #include "url/url_parse.h" | 19 #include "url/url_parse.h" |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 // Parses the user image URL, which looks like | 23 // Parses the user image URL, which looks like |
| 23 // "chrome://userimage/user@host?key1=value1&...&key_n=value_n", | 24 // "chrome://userimage/user@host?key1=value1&...&key_n=value_n", |
| 24 // to user email. | 25 // to user email. |
| 25 void ParseRequest(const GURL& url, | 26 void ParseRequest(const GURL& url, |
| 26 std::string* email) { | 27 std::string* email) { |
| 27 DCHECK(url.is_valid()); | 28 DCHECK(url.is_valid()); |
| 28 *email = net::UnescapeURLComponent(url.path().substr(1), | 29 *email = net::UnescapeURLComponent(url.path().substr(1), |
| 29 (net::UnescapeRule::URL_SPECIAL_CHARS | | 30 (net::UnescapeRule::URL_SPECIAL_CHARS | |
| 30 net::UnescapeRule::SPACES)); | 31 net::UnescapeRule::SPACES)); |
| 31 } | 32 } |
| 32 | 33 |
| 33 } // namespace | 34 } // namespace |
| 34 | 35 |
| 35 namespace chromeos { | 36 namespace chromeos { |
| 36 namespace options { | 37 namespace options { |
| 37 | 38 |
| 38 // Static. | 39 // Static. |
| 39 base::RefCountedMemory* UserImageSource::GetUserImage( | 40 base::RefCountedMemory* UserImageSource::GetUserImage( |
| 40 const std::string& email, | 41 const user_manager::UserID& user_id, |
| 41 ui::ScaleFactor scale_factor) { | 42 ui::ScaleFactor scale_factor) { |
| 42 const user_manager::User* user = | 43 const user_manager::User* user = |
| 43 user_manager::UserManager::Get()->FindUser(email); | 44 user_manager::UserManager::Get()->FindUser(user_id); |
| 44 if (user) { | 45 if (user) { |
| 45 if (user->has_raw_image()) { | 46 if (user->has_raw_image()) { |
| 46 return new base::RefCountedBytes(user->raw_image()); | 47 return new base::RefCountedBytes(user->raw_image()); |
| 47 } else if (user->image_is_stub()) { | 48 } else if (user->image_is_stub()) { |
| 48 return ResourceBundle::GetSharedInstance(). | 49 return ResourceBundle::GetSharedInstance(). |
| 49 LoadDataResourceBytesForScale(IDR_PROFILE_PICTURE_LOADING, | 50 LoadDataResourceBytesForScale(IDR_PROFILE_PICTURE_LOADING, |
| 50 scale_factor); | 51 scale_factor); |
| 51 } else if (user->HasDefaultImage()) { | 52 } else if (user->HasDefaultImage()) { |
| 52 return ResourceBundle::GetSharedInstance(). | 53 return ResourceBundle::GetSharedInstance(). |
| 53 LoadDataResourceBytesForScale( | 54 LoadDataResourceBytesForScale( |
| (...skipping 17 matching lines...) Expand all Loading... |
| 71 } | 72 } |
| 72 | 73 |
| 73 void UserImageSource::StartDataRequest( | 74 void UserImageSource::StartDataRequest( |
| 74 const std::string& path, | 75 const std::string& path, |
| 75 int render_process_id, | 76 int render_process_id, |
| 76 int render_frame_id, | 77 int render_frame_id, |
| 77 const content::URLDataSource::GotDataCallback& callback) { | 78 const content::URLDataSource::GotDataCallback& callback) { |
| 78 std::string email; | 79 std::string email; |
| 79 GURL url(chrome::kChromeUIUserImageURL + path); | 80 GURL url(chrome::kChromeUIUserImageURL + path); |
| 80 ParseRequest(url, &email); | 81 ParseRequest(url, &email); |
| 81 callback.Run(GetUserImage(email, ui::SCALE_FACTOR_100P)); | 82 callback.Run(GetUserImage(user_manager::UserID::FromUserEmail(email), ui::SCAL
E_FACTOR_100P)); |
| 82 } | 83 } |
| 83 | 84 |
| 84 std::string UserImageSource::GetMimeType(const std::string& path) const { | 85 std::string UserImageSource::GetMimeType(const std::string& path) const { |
| 85 // We need to explicitly return a mime type, otherwise if the user tries to | 86 // We need to explicitly return a mime type, otherwise if the user tries to |
| 86 // drag the image they get no extension. | 87 // drag the image they get no extension. |
| 87 return "image/png"; | 88 return "image/png"; |
| 88 } | 89 } |
| 89 | 90 |
| 90 } // namespace options | 91 } // namespace options |
| 91 } // namespace chromeos | 92 } // namespace chromeos |
| OLD | NEW |