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.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" |
11 #include "chrome/browser/chromeos/login/user_manager.h" | 11 #include "chrome/browser/chromeos/login/user_manager.h" |
| 12 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
12 #include "chrome/browser/ui/webui/web_ui_util.h" | 13 #include "chrome/browser/ui/webui/web_ui_util.h" |
13 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
14 #include "googleurl/src/url_parse.h" | 15 #include "googleurl/src/url_parse.h" |
15 #include "grit/theme_resources.h" | 16 #include "grit/theme_resources.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 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
21 // Animated key is used in user image URL requests to specify that | 22 // Animated key is used in user image URL requests to specify that |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 kDefaultImageResourceIDs[user->image_index()], | 70 kDefaultImageResourceIDs[user->image_index()], |
70 scale_factor); | 71 scale_factor); |
71 } else { | 72 } else { |
72 NOTREACHED() << "User with custom image missing raw data"; | 73 NOTREACHED() << "User with custom image missing raw data"; |
73 } | 74 } |
74 } | 75 } |
75 return ResourceBundle::GetSharedInstance(). | 76 return ResourceBundle::GetSharedInstance(). |
76 LoadDataResourceBytesForScale(IDR_LOGIN_DEFAULT_USER, scale_factor); | 77 LoadDataResourceBytesForScale(IDR_LOGIN_DEFAULT_USER, scale_factor); |
77 } | 78 } |
78 | 79 |
79 UserImageSource::UserImageSource() | 80 UserImageSource::UserImageSource() { |
80 : DataSource(chrome::kChromeUIUserImageHost, MessageLoop::current()) { | |
81 } | 81 } |
82 | 82 |
83 UserImageSource::~UserImageSource() {} | 83 UserImageSource::~UserImageSource() {} |
84 | 84 |
| 85 std::string UserImageSource::GetSource() { |
| 86 return chrome::kChromeUIUserImageHost; |
| 87 } |
| 88 |
85 void UserImageSource::StartDataRequest(const std::string& path, | 89 void UserImageSource::StartDataRequest(const std::string& path, |
86 bool is_incognito, | 90 bool is_incognito, |
87 int request_id) { | 91 int request_id) { |
88 std::string email; | 92 std::string email; |
89 bool is_image_animated = false; | 93 bool is_image_animated = false; |
90 ui::ScaleFactor scale_factor; | 94 ui::ScaleFactor scale_factor; |
91 GURL url(chrome::kChromeUIUserImageURL + path); | 95 GURL url(chrome::kChromeUIUserImageURL + path); |
92 ParseRequest(url, &email, &is_image_animated, &scale_factor); | 96 ParseRequest(url, &email, &is_image_animated, &scale_factor); |
93 SendResponse(request_id, | 97 url_data_source()->SendResponse( |
94 GetUserImage(email, is_image_animated, scale_factor)); | 98 request_id, |
| 99 GetUserImage(email, is_image_animated, scale_factor)); |
95 } | 100 } |
96 | 101 |
97 std::string UserImageSource::GetMimeType(const std::string& path) const { | 102 std::string UserImageSource::GetMimeType(const std::string& path) const { |
98 // We need to explicitly return a mime type, otherwise if the user tries to | 103 // We need to explicitly return a mime type, otherwise if the user tries to |
99 // drag the image they get no extension. | 104 // drag the image they get no extension. |
100 std::string email; | 105 std::string email; |
101 bool is_image_animated = false; | 106 bool is_image_animated = false; |
102 ui::ScaleFactor scale_factor; | 107 ui::ScaleFactor scale_factor; |
103 | 108 |
104 GURL url(chrome::kChromeUIUserImageURL + path); | 109 GURL url(chrome::kChromeUIUserImageURL + path); |
105 ParseRequest(url, &email, &is_image_animated, &scale_factor); | 110 ParseRequest(url, &email, &is_image_animated, &scale_factor); |
106 | 111 |
107 if (is_image_animated) { | 112 if (is_image_animated) { |
108 const chromeos::User* user = chromeos::UserManager::Get()->FindUser(email); | 113 const chromeos::User* user = chromeos::UserManager::Get()->FindUser(email); |
109 if (user && user->has_animated_image()) | 114 if (user && user->has_animated_image()) |
110 return "image/gif"; | 115 return "image/gif"; |
111 } | 116 } |
112 return "image/png"; | 117 return "image/png"; |
113 } | 118 } |
114 | 119 |
115 } // namespace options | 120 } // namespace options |
116 } // namespace chromeos | 121 } // namespace chromeos |
OLD | NEW |