Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(364)

Side by Side Diff: chrome/browser/supervised_user/supervised_user_interstitial.cc

Issue 483703002: Supervised users: Use custodian avatar image(s) in the block interstitial if they're available. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review comments Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/resources/supervised_user_block_interstitial.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 GURL& base_url,
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 return base_url.Resolve(result).spec();
50 }
51
52 } // namespace
53
36 // static 54 // static
37 void SupervisedUserInterstitial::Show(content::WebContents* web_contents, 55 void SupervisedUserInterstitial::Show(
38 const GURL& url, 56 content::WebContents* web_contents,
39 const base::Callback<void(bool)>& callback) { 57 const GURL& url,
58 const base::Callback<void(bool)>& callback) {
40 SupervisedUserInterstitial* interstitial = 59 SupervisedUserInterstitial* interstitial =
41 new SupervisedUserInterstitial(web_contents, url, callback); 60 new SupervisedUserInterstitial(web_contents, url, callback);
42 61
43 // If Init() does not complete fully, immediately delete the interstitial. 62 // If Init() does not complete fully, immediately delete the interstitial.
44 if (!interstitial->Init()) 63 if (!interstitial->Init())
45 delete interstitial; 64 delete interstitial;
46 // Otherwise |interstitial_page_| is responsible for deleting it. 65 // Otherwise |interstitial_page_| is responsible for deleting it.
47 } 66 }
48 67
49 SupervisedUserInterstitial::SupervisedUserInterstitial( 68 SupervisedUserInterstitial::SupervisedUserInterstitial(
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 l10n_util::GetStringUTF16(IDS_BLOCK_INTERSTITIAL_TITLE)); 144 l10n_util::GetStringUTF16(IDS_BLOCK_INTERSTITIAL_TITLE));
126 145
127 Profile* profile = 146 Profile* profile =
128 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); 147 Profile::FromBrowserContext(web_contents_->GetBrowserContext());
129 SupervisedUserService* supervised_user_service = 148 SupervisedUserService* supervised_user_service =
130 SupervisedUserServiceFactory::GetForProfile(profile); 149 SupervisedUserServiceFactory::GetForProfile(profile);
131 150
132 bool allow_access_requests = supervised_user_service->AccessRequestsEnabled(); 151 bool allow_access_requests = supervised_user_service->AccessRequestsEnabled();
133 strings.SetBoolean("allowAccessRequests", allow_access_requests); 152 strings.SetBoolean("allowAccessRequests", allow_access_requests);
134 153
154 GURL profile_url = GURL(profile->GetPrefs()->GetString(
155 prefs::kSupervisedUserCustodianProfileURL));
156 std::string profile_image_url = profile->GetPrefs()->GetString(
157 prefs::kSupervisedUserCustodianProfileImageURL);
158 strings.SetString("avatarURL1x", BuildAvatarImageUrl(profile_image_url,
159 profile_url,
160 kAvatarSize1x));
161 strings.SetString("avatarURL2x", BuildAvatarImageUrl(profile_image_url,
162 profile_url,
163 kAvatarSize2x));
164
165 GURL profile_url2 = GURL(profile->GetPrefs()->GetString(
166 prefs::kSupervisedUserSecondCustodianProfileURL));
167 std::string profile_image_url2 = profile->GetPrefs()->GetString(
168 prefs::kSupervisedUserSecondCustodianProfileImageURL);
169 strings.SetString("secondAvatarURL1x", BuildAvatarImageUrl(profile_image_url2,
170 profile_url2,
171 kAvatarSize1x));
172 strings.SetString("secondAvatarURL2x", BuildAvatarImageUrl(profile_image_url2,
173 profile_url2,
174 kAvatarSize2x));
175
135 base::string16 custodian = 176 base::string16 custodian =
136 base::UTF8ToUTF16(supervised_user_service->GetCustodianName()); 177 base::UTF8ToUTF16(supervised_user_service->GetCustodianName());
137 strings.SetString( 178 strings.SetString(
138 "blockPageMessage", 179 "blockPageMessage",
139 allow_access_requests 180 allow_access_requests
140 ? l10n_util::GetStringFUTF16(IDS_BLOCK_INTERSTITIAL_MESSAGE, 181 ? l10n_util::GetStringFUTF16(IDS_BLOCK_INTERSTITIAL_MESSAGE,
141 custodian) 182 custodian)
142 : l10n_util::GetStringUTF16( 183 : l10n_util::GetStringUTF16(
143 IDS_BLOCK_INTERSTITIAL_MESSAGE_ACCESS_REQUESTS_DISABLED)); 184 IDS_BLOCK_INTERSTITIAL_MESSAGE_ACCESS_REQUESTS_DISABLED));
144 185
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 void SupervisedUserInterstitial::DispatchContinueRequest( 268 void SupervisedUserInterstitial::DispatchContinueRequest(
228 bool continue_request) { 269 bool continue_request) {
229 // If there is no history entry to go back to, close the tab instead. 270 // If there is no history entry to go back to, close the tab instead.
230 int nav_entry_count = web_contents_->GetController().GetEntryCount(); 271 int nav_entry_count = web_contents_->GetController().GetEntryCount();
231 if (!continue_request && nav_entry_count == 0) 272 if (!continue_request && nav_entry_count == 0)
232 web_contents_->Close(); 273 web_contents_->Close();
233 274
234 BrowserThread::PostTask( 275 BrowserThread::PostTask(
235 BrowserThread::IO, FROM_HERE, base::Bind(callback_, continue_request)); 276 BrowserThread::IO, FROM_HERE, base::Bind(callback_, continue_request));
236 } 277 }
OLDNEW
« no previous file with comments | « chrome/browser/resources/supervised_user_block_interstitial.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698