Chromium Code Reviews| 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/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/strings/string_number_conversions.h" | |
| 10 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 11 #include "base/values.h" | 12 #include "base/values.h" |
| 12 #include "chrome/browser/infobars/infobar_service.h" | 13 #include "chrome/browser/infobars/infobar_service.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/supervised_user/supervised_user_service.h" | 15 #include "chrome/browser/supervised_user/supervised_user_service.h" |
| 15 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" | 16 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" |
| 16 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 17 #include "components/infobars/core/infobar.h" | 18 #include "components/infobars/core/infobar.h" |
| 18 #include "components/infobars/core/infobar_delegate.h" | 19 #include "components/infobars/core/infobar_delegate.h" |
| 19 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 20 #include "content/public/browser/interstitial_page.h" | 21 #include "content/public/browser/interstitial_page.h" |
| 21 #include "content/public/browser/navigation_controller.h" | 22 #include "content/public/browser/navigation_controller.h" |
| 22 #include "content/public/browser/navigation_details.h" | 23 #include "content/public/browser/navigation_details.h" |
| 23 #include "content/public/browser/navigation_entry.h" | 24 #include "content/public/browser/navigation_entry.h" |
| 24 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
| 25 #include "content/public/browser/web_ui.h" | 26 #include "content/public/browser/web_ui.h" |
| 26 #include "grit/browser_resources.h" | 27 #include "grit/browser_resources.h" |
| 27 #include "grit/generated_resources.h" | 28 #include "grit/generated_resources.h" |
| 28 #include "net/base/net_util.h" | 29 #include "net/base/net_util.h" |
| 29 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
| 30 #include "ui/base/resource/resource_bundle.h" | 31 #include "ui/base/resource/resource_bundle.h" |
| 31 #include "ui/base/webui/jstemplate_builder.h" | 32 #include "ui/base/webui/jstemplate_builder.h" |
| 32 #include "ui/base/webui/web_ui_util.h" | 33 #include "ui/base/webui/web_ui_util.h" |
| 33 | 34 |
| 34 using content::BrowserThread; | 35 using content::BrowserThread; |
| 35 | 36 |
| 37 namespace { | |
| 38 | |
| 39 static const int kAvatarSize1x = 45; | |
| 40 static const int kAvatarSize2x = 90; | |
| 41 | |
| 42 std::string BuildAvatarImageUrl(const std::string& url, | |
| 43 const std::string& base_url, | |
|
Bernhard Bauer
2014/08/18 15:57:31
Consider passing this as a GURL.
Marc Treib
2014/08/18 16:35:34
Done.
| |
| 44 int size) { | |
| 45 std::string result = url; | |
| 46 size_t slash = result.rfind('/'); | |
| 47 if (slash != std::string::npos) | |
| 48 result.insert(slash, "/s" + base::IntToString(size)); | |
| 49 result = GURL(base_url).Resolve(result).spec(); | |
|
Bernhard Bauer
2014/08/18 15:57:31
Inline this into the return?
Marc Treib
2014/08/18 16:35:34
Done.
| |
| 50 return result; | |
| 51 } | |
| 52 | |
| 53 } // namespace | |
| 54 | |
| 36 // static | 55 // static |
| 37 void SupervisedUserInterstitial::Show(content::WebContents* web_contents, | 56 void SupervisedUserInterstitial::Show( |
| 38 const GURL& url, | 57 content::WebContents* web_contents, |
| 39 const base::Callback<void(bool)>& callback) { | 58 const GURL& url, |
| 59 const base::Callback<void(bool)>& callback) { | |
| 40 SupervisedUserInterstitial* interstitial = | 60 SupervisedUserInterstitial* interstitial = |
| 41 new SupervisedUserInterstitial(web_contents, url, callback); | 61 new SupervisedUserInterstitial(web_contents, url, callback); |
| 42 | 62 |
| 43 // If Init() does not complete fully, immediately delete the interstitial. | 63 // If Init() does not complete fully, immediately delete the interstitial. |
| 44 if (!interstitial->Init()) | 64 if (!interstitial->Init()) |
| 45 delete interstitial; | 65 delete interstitial; |
| 46 // Otherwise |interstitial_page_| is responsible for deleting it. | 66 // Otherwise |interstitial_page_| is responsible for deleting it. |
| 47 } | 67 } |
| 48 | 68 |
| 49 SupervisedUserInterstitial::SupervisedUserInterstitial( | 69 SupervisedUserInterstitial::SupervisedUserInterstitial( |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 125 l10n_util::GetStringUTF16(IDS_BLOCK_INTERSTITIAL_TITLE)); | 145 l10n_util::GetStringUTF16(IDS_BLOCK_INTERSTITIAL_TITLE)); |
| 126 | 146 |
| 127 Profile* profile = | 147 Profile* profile = |
| 128 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); | 148 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); |
| 129 SupervisedUserService* supervised_user_service = | 149 SupervisedUserService* supervised_user_service = |
| 130 SupervisedUserServiceFactory::GetForProfile(profile); | 150 SupervisedUserServiceFactory::GetForProfile(profile); |
| 131 | 151 |
| 132 bool allow_access_requests = supervised_user_service->AccessRequestsEnabled(); | 152 bool allow_access_requests = supervised_user_service->AccessRequestsEnabled(); |
| 133 strings.SetBoolean("allowAccessRequests", allow_access_requests); | 153 strings.SetBoolean("allowAccessRequests", allow_access_requests); |
| 134 | 154 |
| 155 std::string profile_url = profile->GetPrefs()->GetString( | |
| 156 prefs::kSupervisedUserCustodianProfileURL); | |
| 157 std::string profile_image_url = profile->GetPrefs()->GetString( | |
| 158 prefs::kSupervisedUserCustodianProfileImageURL); | |
| 159 strings.SetString("avatarURL1x", BuildAvatarImageUrl(profile_image_url, | |
| 160 profile_url, | |
| 161 kAvatarSize1x)); | |
| 162 strings.SetString("avatarURL2x", BuildAvatarImageUrl(profile_image_url, | |
| 163 profile_url, | |
| 164 kAvatarSize2x)); | |
| 165 | |
| 166 std::string profile_url2 = profile->GetPrefs()->GetString( | |
| 167 prefs::kSupervisedUserSecondCustodianProfileURL); | |
| 168 std::string profile_image_url2 = profile->GetPrefs()->GetString( | |
| 169 prefs::kSupervisedUserSecondCustodianProfileImageURL); | |
| 170 strings.SetString("secondAvatarURL1x", BuildAvatarImageUrl(profile_image_url2, | |
| 171 profile_url2, | |
| 172 kAvatarSize1x)); | |
| 173 strings.SetString("secondAvatarURL2x", BuildAvatarImageUrl(profile_image_url2, | |
| 174 profile_url2, | |
| 175 kAvatarSize2x)); | |
| 176 | |
| 135 base::string16 custodian = | 177 base::string16 custodian = |
| 136 base::UTF8ToUTF16(supervised_user_service->GetCustodianName()); | 178 base::UTF8ToUTF16(supervised_user_service->GetCustodianName()); |
| 137 strings.SetString( | 179 strings.SetString( |
| 138 "blockPageMessage", | 180 "blockPageMessage", |
| 139 allow_access_requests | 181 allow_access_requests |
| 140 ? l10n_util::GetStringFUTF16(IDS_BLOCK_INTERSTITIAL_MESSAGE, | 182 ? l10n_util::GetStringFUTF16(IDS_BLOCK_INTERSTITIAL_MESSAGE, |
| 141 custodian) | 183 custodian) |
| 142 : l10n_util::GetStringUTF16( | 184 : l10n_util::GetStringUTF16( |
| 143 IDS_BLOCK_INTERSTITIAL_MESSAGE_ACCESS_REQUESTS_DISABLED)); | 185 IDS_BLOCK_INTERSTITIAL_MESSAGE_ACCESS_REQUESTS_DISABLED)); |
| 144 | 186 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 227 void SupervisedUserInterstitial::DispatchContinueRequest( | 269 void SupervisedUserInterstitial::DispatchContinueRequest( |
| 228 bool continue_request) { | 270 bool continue_request) { |
| 229 // If there is no history entry to go back to, close the tab instead. | 271 // If there is no history entry to go back to, close the tab instead. |
| 230 int nav_entry_count = web_contents_->GetController().GetEntryCount(); | 272 int nav_entry_count = web_contents_->GetController().GetEntryCount(); |
| 231 if (!continue_request && nav_entry_count == 0) | 273 if (!continue_request && nav_entry_count == 0) |
| 232 web_contents_->Close(); | 274 web_contents_->Close(); |
| 233 | 275 |
| 234 BrowserThread::PostTask( | 276 BrowserThread::PostTask( |
| 235 BrowserThread::IO, FROM_HERE, base::Bind(callback_, continue_request)); | 277 BrowserThread::IO, FROM_HERE, base::Bind(callback_, continue_request)); |
| 236 } | 278 } |
| OLD | NEW |