OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/supervised_user/supervised_user_interstitial.h" | 5 #include "chrome/browser/supervised_user/supervised_user_interstitial.h" |
6 | 6 |
7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 #include "ui/base/webui/jstemplate_builder.h" | 30 #include "ui/base/webui/jstemplate_builder.h" |
31 #include "ui/base/webui/web_ui_util.h" | 31 #include "ui/base/webui/web_ui_util.h" |
32 | 32 |
33 using content::BrowserThread; | 33 using content::BrowserThread; |
34 | 34 |
35 namespace { | 35 namespace { |
36 | 36 |
37 static const int kAvatarSize1x = 45; | 37 static const int kAvatarSize1x = 45; |
38 static const int kAvatarSize2x = 90; | 38 static const int kAvatarSize2x = 90; |
39 | 39 |
40 std::string BuildAvatarImageUrl(const std::string& url, | 40 std::string BuildAvatarImageUrl(const std::string& url, int size) { |
41 const GURL& base_url, | |
42 int size) { | |
43 std::string result = url; | 41 std::string result = url; |
44 size_t slash = result.rfind('/'); | 42 size_t slash = result.rfind('/'); |
45 if (slash != std::string::npos) | 43 if (slash != std::string::npos) |
46 result.insert(slash, "/s" + base::IntToString(size)); | 44 result.insert(slash, "/s" + base::IntToString(size)); |
47 return base_url.Resolve(result).spec(); | 45 return result; |
48 } | 46 } |
49 | 47 |
50 } // namespace | 48 } // namespace |
51 | 49 |
52 // static | 50 // static |
53 void SupervisedUserInterstitial::Show( | 51 void SupervisedUserInterstitial::Show( |
54 content::WebContents* web_contents, | 52 content::WebContents* web_contents, |
55 const GURL& url, | 53 const GURL& url, |
56 const base::Callback<void(bool)>& callback) { | 54 const base::Callback<void(bool)>& callback) { |
57 SupervisedUserInterstitial* interstitial = | 55 SupervisedUserInterstitial* interstitial = |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 l10n_util::GetStringUTF16(IDS_BLOCK_INTERSTITIAL_TITLE)); | 139 l10n_util::GetStringUTF16(IDS_BLOCK_INTERSTITIAL_TITLE)); |
142 | 140 |
143 Profile* profile = | 141 Profile* profile = |
144 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); | 142 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); |
145 SupervisedUserService* supervised_user_service = | 143 SupervisedUserService* supervised_user_service = |
146 SupervisedUserServiceFactory::GetForProfile(profile); | 144 SupervisedUserServiceFactory::GetForProfile(profile); |
147 | 145 |
148 bool allow_access_requests = supervised_user_service->AccessRequestsEnabled(); | 146 bool allow_access_requests = supervised_user_service->AccessRequestsEnabled(); |
149 strings.SetBoolean("allowAccessRequests", allow_access_requests); | 147 strings.SetBoolean("allowAccessRequests", allow_access_requests); |
150 | 148 |
151 GURL base_url = GURL(profile->GetPrefs()->GetString( | |
152 prefs::kSupervisedUserCustodianProfileURL)); | |
153 if (!base_url.is_valid()) | |
154 base_url = GURL("https://dummy.url"); | |
155 DCHECK(base_url.is_valid()); | |
156 std::string profile_image_url = profile->GetPrefs()->GetString( | 149 std::string profile_image_url = profile->GetPrefs()->GetString( |
157 prefs::kSupervisedUserCustodianProfileImageURL); | 150 prefs::kSupervisedUserCustodianProfileImageURL); |
158 strings.SetString("avatarURL1x", BuildAvatarImageUrl(profile_image_url, | 151 strings.SetString("avatarURL1x", BuildAvatarImageUrl(profile_image_url, |
159 base_url, | |
160 kAvatarSize1x)); | 152 kAvatarSize1x)); |
161 strings.SetString("avatarURL2x", BuildAvatarImageUrl(profile_image_url, | 153 strings.SetString("avatarURL2x", BuildAvatarImageUrl(profile_image_url, |
162 base_url, | |
163 kAvatarSize2x)); | 154 kAvatarSize2x)); |
164 | 155 |
165 GURL base_url2 = GURL(profile->GetPrefs()->GetString( | |
166 prefs::kSupervisedUserSecondCustodianProfileURL)); | |
167 if (!base_url2.is_valid()) | |
168 base_url2 = GURL("https://dummy.url"); | |
169 DCHECK(base_url2.is_valid()); | |
170 std::string profile_image_url2 = profile->GetPrefs()->GetString( | 156 std::string profile_image_url2 = profile->GetPrefs()->GetString( |
171 prefs::kSupervisedUserSecondCustodianProfileImageURL); | 157 prefs::kSupervisedUserSecondCustodianProfileImageURL); |
172 strings.SetString("secondAvatarURL1x", BuildAvatarImageUrl(profile_image_url2, | 158 strings.SetString("secondAvatarURL1x", BuildAvatarImageUrl(profile_image_url2, |
173 base_url2, | |
174 kAvatarSize1x)); | 159 kAvatarSize1x)); |
175 strings.SetString("secondAvatarURL2x", BuildAvatarImageUrl(profile_image_url2, | 160 strings.SetString("secondAvatarURL2x", BuildAvatarImageUrl(profile_image_url2, |
176 base_url2, | |
177 kAvatarSize2x)); | 161 kAvatarSize2x)); |
178 | 162 |
179 base::string16 custodian = | 163 base::string16 custodian = |
180 base::UTF8ToUTF16(supervised_user_service->GetCustodianName()); | 164 base::UTF8ToUTF16(supervised_user_service->GetCustodianName()); |
181 strings.SetString( | 165 strings.SetString( |
182 "blockPageMessage", | 166 "blockPageMessage", |
183 allow_access_requests | 167 allow_access_requests |
184 ? l10n_util::GetStringFUTF16(IDS_BLOCK_INTERSTITIAL_MESSAGE, | 168 ? l10n_util::GetStringFUTF16(IDS_BLOCK_INTERSTITIAL_MESSAGE, |
185 custodian) | 169 custodian) |
186 : l10n_util::GetStringUTF16( | 170 : l10n_util::GetStringUTF16( |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 void SupervisedUserInterstitial::DispatchContinueRequest( | 255 void SupervisedUserInterstitial::DispatchContinueRequest( |
272 bool continue_request) { | 256 bool continue_request) { |
273 // If there is no history entry to go back to, close the tab instead. | 257 // If there is no history entry to go back to, close the tab instead. |
274 int nav_entry_count = web_contents_->GetController().GetEntryCount(); | 258 int nav_entry_count = web_contents_->GetController().GetEntryCount(); |
275 if (!continue_request && nav_entry_count == 0) | 259 if (!continue_request && nav_entry_count == 0) |
276 web_contents_->Close(); | 260 web_contents_->Close(); |
277 | 261 |
278 BrowserThread::PostTask( | 262 BrowserThread::PostTask( |
279 BrowserThread::IO, FROM_HERE, base::Bind(callback_, continue_request)); | 263 BrowserThread::IO, FROM_HERE, base::Bind(callback_, continue_request)); |
280 } | 264 } |
OLD | NEW |