blob: 1f7b6065488c170ede14cb4b3bc396844a08824c [file] [log] [blame]
[email protected]cce15bb2014-06-17 13:43:511// Copyright 2014 The Chromium Authors. All rights reserved.
[email protected]a09159a2012-11-29 12:51:482// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]cce15bb2014-06-17 13:43:515#include "chrome/browser/supervised_user/supervised_user_interstitial.h"
[email protected]a09159a2012-11-29 12:51:486
avi664c07b2015-12-26 02:18:317#include <stddef.h>
8
treibe7ccb7e2014-09-09 19:21:459#include "base/memory/weak_ptr.h"
[email protected]2c145422013-01-24 18:15:4010#include "base/metrics/histogram.h"
[email protected]3853a4c2013-02-11 17:15:5711#include "base/prefs/pref_service.h"
[email protected]95c47d02014-08-19 09:17:5012#include "base/strings/string_number_conversions.h"
khannansf3b27192015-01-09 17:28:1713#include "base/strings/stringprintf.h"
[email protected]112158af2013-06-07 23:46:1814#include "base/strings/utf_string_conversions.h"
[email protected]59f21562013-05-23 16:19:3015#include "base/values.h"
avi664c07b2015-12-26 02:18:3116#include "build/build_config.h"
dbeam622e9f32015-01-28 21:22:4517#include "chrome/browser/browser_process.h"
[email protected]93c23212013-09-19 14:22:3818#include "chrome/browser/infobars/infobar_service.h"
[email protected]a09159a2012-11-29 12:51:4819#include "chrome/browser/profiles/profile.h"
[email protected]cce15bb2014-06-17 13:43:5120#include "chrome/browser/supervised_user/supervised_user_service.h"
21#include "chrome/browser/supervised_user/supervised_user_service_factory.h"
sievers2f1e8112015-12-04 18:43:5622#include "chrome/common/features.h"
[email protected]a09159a2012-11-29 12:51:4823#include "chrome/common/pref_names.h"
[email protected]af39f002014-08-22 10:18:1824#include "chrome/grit/generated_resources.h"
[email protected]051655ad2014-04-18 15:09:4125#include "components/infobars/core/infobar.h"
26#include "components/infobars/core/infobar_delegate.h"
[email protected]a09159a2012-11-29 12:51:4827#include "content/public/browser/browser_thread.h"
28#include "content/public/browser/interstitial_page.h"
[email protected]93c23212013-09-19 14:22:3829#include "content/public/browser/navigation_controller.h"
30#include "content/public/browser/navigation_details.h"
31#include "content/public/browser/navigation_entry.h"
khannansf3b27192015-01-09 17:28:1732#include "content/public/browser/render_frame_host.h"
33#include "content/public/browser/render_view_host.h"
[email protected]a09159a2012-11-29 12:51:4834#include "content/public/browser/web_contents.h"
treibe7ccb7e2014-09-09 19:21:4535#include "content/public/browser/web_contents_user_data.h"
[email protected]59f21562013-05-23 16:19:3036#include "content/public/browser/web_ui.h"
[email protected]a09159a2012-11-29 12:51:4837#include "grit/browser_resources.h"
[email protected]a09159a2012-11-29 12:51:4838#include "ui/base/l10n/l10n_util.h"
39#include "ui/base/resource/resource_bundle.h"
[email protected]cd67ed52013-10-15 01:22:1340#include "ui/base/webui/jstemplate_builder.h"
41#include "ui/base/webui/web_ui_util.h"
[email protected]a09159a2012-11-29 12:51:4842
sievers2f1e8112015-12-04 18:43:5643#if BUILDFLAG(ANDROID_JAVA_UI)
treib9dbb9302015-01-08 14:42:3944#include "chrome/browser/supervised_user/child_accounts/child_account_feedback_reporter_android.h"
sievers2f1e8112015-12-04 18:43:5645#elif !defined(OS_ANDROID)
treibe7ccb7e2014-09-09 19:21:4546#include "chrome/browser/ui/browser_finder.h"
treib5dd8daf32014-12-18 17:36:3747#include "chrome/browser/ui/chrome_pages.h"
treibe7ccb7e2014-09-09 19:21:4548#include "chrome/browser/ui/tabs/tab_strip_model.h"
49#endif
50
[email protected]a09159a2012-11-29 12:51:4851using content::BrowserThread;
treibe7ccb7e2014-09-09 19:21:4552using content::WebContents;
[email protected]a09159a2012-11-29 12:51:4853
[email protected]95c47d02014-08-19 09:17:5054namespace {
55
56static const int kAvatarSize1x = 45;
57static const int kAvatarSize2x = 90;
58
treib885fee12014-08-29 08:07:5859std::string BuildAvatarImageUrl(const std::string& url, int size) {
[email protected]95c47d02014-08-19 09:17:5060 std::string result = url;
61 size_t slash = result.rfind('/');
62 if (slash != std::string::npos)
63 result.insert(slash, "/s" + base::IntToString(size));
treib885fee12014-08-29 08:07:5864 return result;
[email protected]95c47d02014-08-19 09:17:5065}
66
treibe7ccb7e2014-09-09 19:21:4567class TabCloser : public content::WebContentsUserData<TabCloser> {
bauerb34f34c5f2015-10-21 15:38:3268 public:
69 static void MaybeClose(WebContents* web_contents) {
70 // Close the tab if there is no history entry to go back to and there is a
71 // browser for the tab (which is not the case for example in a <webview>).
72 if (!web_contents->GetController().IsInitialBlankNavigation())
73 return;
74
75#if !defined(OS_ANDROID)
76 if (!chrome::FindBrowserWithWebContents(web_contents))
77 return;
78#endif
79 TabCloser::CreateForWebContents(web_contents);
80 }
81
treibe7ccb7e2014-09-09 19:21:4582 private:
83 friend class content::WebContentsUserData<TabCloser>;
84
85 explicit TabCloser(WebContents* web_contents)
86 : web_contents_(web_contents), weak_ptr_factory_(this) {
87 BrowserThread::PostTask(
88 BrowserThread::UI,
89 FROM_HERE,
90 base::Bind(&TabCloser::CloseTabImpl, weak_ptr_factory_.GetWeakPtr()));
91 }
dchengc072fff2014-10-21 11:39:0592 ~TabCloser() override {}
treibe7ccb7e2014-09-09 19:21:4593
94 void CloseTabImpl() {
95 // On Android, FindBrowserWithWebContents and TabStripModel don't exist.
96#if !defined(OS_ANDROID)
97 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_);
98 DCHECK(browser);
99 TabStripModel* tab_strip = browser->tab_strip_model();
100 DCHECK_NE(TabStripModel::kNoTab,
101 tab_strip->GetIndexOfWebContents(web_contents_));
102 if (tab_strip->count() <= 1) {
103 // Don't close the last tab in the window.
104 web_contents_->RemoveUserData(UserDataKey());
105 return;
106 }
107#endif
108 web_contents_->Close();
109 }
110
111 WebContents* web_contents_;
112 base::WeakPtrFactory<TabCloser> weak_ptr_factory_;
113};
114
115} // namespace
116
117DEFINE_WEB_CONTENTS_USER_DATA_KEY(TabCloser);
[email protected]95c47d02014-08-19 09:17:50118
meacerfc55bd52015-03-05 19:12:00119content::InterstitialPageDelegate::TypeID
120 SupervisedUserInterstitial::kTypeForTesting =
121 &SupervisedUserInterstitial::kTypeForTesting;
122
[email protected]b8af2d12014-04-29 07:30:42123// static
[email protected]95c47d02014-08-19 09:17:50124void SupervisedUserInterstitial::Show(
treibe7ccb7e2014-09-09 19:21:45125 WebContents* web_contents,
[email protected]95c47d02014-08-19 09:17:50126 const GURL& url,
treib170c3f82014-12-10 19:13:25127 SupervisedUserURLFilter::FilteringBehaviorReason reason,
[email protected]95c47d02014-08-19 09:17:50128 const base::Callback<void(bool)>& callback) {
[email protected]cce15bb2014-06-17 13:43:51129 SupervisedUserInterstitial* interstitial =
treib170c3f82014-12-10 19:13:25130 new SupervisedUserInterstitial(web_contents, url, reason, callback);
[email protected]b8af2d12014-04-29 07:30:42131
132 // If Init() does not complete fully, immediately delete the interstitial.
133 if (!interstitial->Init())
134 delete interstitial;
135 // Otherwise |interstitial_page_| is responsible for deleting it.
136}
137
[email protected]cce15bb2014-06-17 13:43:51138SupervisedUserInterstitial::SupervisedUserInterstitial(
treibe7ccb7e2014-09-09 19:21:45139 WebContents* web_contents,
[email protected]a09159a2012-11-29 12:51:48140 const GURL& url,
treib170c3f82014-12-10 19:13:25141 SupervisedUserURLFilter::FilteringBehaviorReason reason,
[email protected]a09159a2012-11-29 12:51:48142 const base::Callback<void(bool)>& callback)
143 : web_contents_(web_contents),
treibab0a39e2014-09-24 14:48:28144 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())),
[email protected]61f5da22013-09-05 15:52:10145 interstitial_page_(NULL),
[email protected]a09159a2012-11-29 12:51:48146 url_(url),
treib170c3f82014-12-10 19:13:25147 reason_(reason),
bauerb646019b12014-10-16 16:23:09148 callback_(callback),
149 weak_ptr_factory_(this) {}
[email protected]b8af2d12014-04-29 07:30:42150
treibab0a39e2014-09-24 14:48:28151SupervisedUserInterstitial::~SupervisedUserInterstitial() {
152 DCHECK(!web_contents_);
153}
[email protected]b8af2d12014-04-29 07:30:42154
[email protected]cce15bb2014-06-17 13:43:51155bool SupervisedUserInterstitial::Init() {
[email protected]61f5da22013-09-05 15:52:10156 if (ShouldProceed()) {
157 // It can happen that the site was only allowed very recently and the URL
158 // filter on the IO thread had not been updated yet. Proceed with the
159 // request without showing the interstitial.
160 DispatchContinueRequest(true);
[email protected]b8af2d12014-04-29 07:30:42161 return false;
[email protected]61f5da22013-09-05 15:52:10162 }
163
[email protected]b8af2d12014-04-29 07:30:42164 InfoBarService* service = InfoBarService::FromWebContents(web_contents_);
[email protected]93c23212013-09-19 14:22:38165 if (service) {
[email protected]b8af2d12014-04-29 07:30:42166 // Remove all the infobars which are attached to |web_contents_| and for
[email protected]93c23212013-09-19 14:22:38167 // which ShouldExpire() returns true.
168 content::LoadCommittedDetails details;
169 // |details.is_in_page| is default false, and |details.is_main_frame| is
170 // default true. This results in is_navigation_to_different_page() returning
171 // true.
172 DCHECK(details.is_navigation_to_different_page());
173 const content::NavigationController& controller =
[email protected]b8af2d12014-04-29 07:30:42174 web_contents_->GetController();
[email protected]93c23212013-09-19 14:22:38175 details.entry = controller.GetActiveEntry();
176 if (controller.GetLastCommittedEntry()) {
177 details.previous_entry_index = controller.GetLastCommittedEntryIndex();
178 details.previous_url = controller.GetLastCommittedEntry()->GetURL();
179 }
180 details.type = content::NAVIGATION_TYPE_NEW_PAGE;
[email protected]b44f1d32014-04-10 13:53:26181 for (int i = service->infobar_count() - 1; i >= 0; --i) {
[email protected]051655ad2014-04-18 15:09:41182 infobars::InfoBar* infobar = service->infobar_at(i);
[email protected]5daf1d92014-04-04 15:52:13183 if (infobar->delegate()->ShouldExpire(
184 InfoBarService::NavigationDetailsFromLoadCommittedDetails(
185 details)))
[email protected]b44f1d32014-04-10 13:53:26186 service->RemoveInfoBar(infobar);
[email protected]93c23212013-09-19 14:22:38187 }
188 }
189
treibab0a39e2014-09-24 14:48:28190 SupervisedUserService* supervised_user_service =
191 SupervisedUserServiceFactory::GetForProfile(profile_);
192 supervised_user_service->AddObserver(this);
[email protected]a09159a2012-11-29 12:51:48193
[email protected]0369d6ab2013-08-09 01:52:59194 interstitial_page_ =
[email protected]b8af2d12014-04-29 07:30:42195 content::InterstitialPage::Create(web_contents_, true, url_, this);
[email protected]a09159a2012-11-29 12:51:48196 interstitial_page_->Show();
[email protected]a09159a2012-11-29 12:51:48197
[email protected]b8af2d12014-04-29 07:30:42198 return true;
199}
[email protected]a09159a2012-11-29 12:51:48200
jam2187ddb2015-12-17 20:10:03201std::string SupervisedUserInterstitial::GetHTMLContents() {
[email protected]cb1078de2013-12-23 20:04:22202 base::DictionaryValue strings;
[email protected]a09159a2012-11-29 12:51:48203 strings.SetString("blockPageTitle",
204 l10n_util::GetStringUTF16(IDS_BLOCK_INTERSTITIAL_TITLE));
[email protected]fae057a2013-06-21 22:46:08205
[email protected]cce15bb2014-06-17 13:43:51206 SupervisedUserService* supervised_user_service =
jam2187ddb2015-12-17 20:10:03207 SupervisedUserServiceFactory::GetForProfile(profile_);
[email protected]0369d6ab2013-08-09 01:52:59208
[email protected]cce15bb2014-06-17 13:43:51209 bool allow_access_requests = supervised_user_service->AccessRequestsEnabled();
[email protected]0369d6ab2013-08-09 01:52:59210 strings.SetBoolean("allowAccessRequests", allow_access_requests);
211
jam2187ddb2015-12-17 20:10:03212 std::string profile_image_url = profile_->GetPrefs()->GetString(
[email protected]95c47d02014-08-19 09:17:50213 prefs::kSupervisedUserCustodianProfileImageURL);
214 strings.SetString("avatarURL1x", BuildAvatarImageUrl(profile_image_url,
[email protected]95c47d02014-08-19 09:17:50215 kAvatarSize1x));
216 strings.SetString("avatarURL2x", BuildAvatarImageUrl(profile_image_url,
[email protected]95c47d02014-08-19 09:17:50217 kAvatarSize2x));
218
jam2187ddb2015-12-17 20:10:03219 std::string profile_image_url2 = profile_->GetPrefs()->GetString(
[email protected]95c47d02014-08-19 09:17:50220 prefs::kSupervisedUserSecondCustodianProfileImageURL);
221 strings.SetString("secondAvatarURL1x", BuildAvatarImageUrl(profile_image_url2,
[email protected]95c47d02014-08-19 09:17:50222 kAvatarSize1x));
223 strings.SetString("secondAvatarURL2x", BuildAvatarImageUrl(profile_image_url2,
[email protected]95c47d02014-08-19 09:17:50224 kAvatarSize2x));
225
jam2187ddb2015-12-17 20:10:03226 bool is_child_account = profile_->IsChild();
treib5fc1aed2014-12-08 12:46:03227
[email protected]0085863a2013-12-06 21:19:03228 base::string16 custodian =
[email protected]cce15bb2014-06-17 13:43:51229 base::UTF8ToUTF16(supervised_user_service->GetCustodianName());
treib5fc1aed2014-12-08 12:46:03230 base::string16 second_custodian =
231 base::UTF8ToUTF16(supervised_user_service->GetSecondCustodianName());
232
233 base::string16 block_message;
234 if (allow_access_requests) {
235 if (is_child_account) {
236 block_message = l10n_util::GetStringUTF16(
237 second_custodian.empty()
238 ? IDS_CHILD_BLOCK_INTERSTITIAL_MESSAGE_SINGLE_PARENT
239 : IDS_CHILD_BLOCK_INTERSTITIAL_MESSAGE_MULTI_PARENT);
240 } else {
241 block_message = l10n_util::GetStringFUTF16(
242 IDS_BLOCK_INTERSTITIAL_MESSAGE, custodian);
243 }
244 } else {
245 block_message = l10n_util::GetStringUTF16(
246 IDS_BLOCK_INTERSTITIAL_MESSAGE_ACCESS_REQUESTS_DISABLED);
247 }
248 strings.SetString("blockPageMessage", block_message);
jam2187ddb2015-12-17 20:10:03249 strings.SetString("blockReasonMessage", is_child_account
250 ? l10n_util::GetStringUTF16(
251 SupervisedUserURLFilter::GetBlockMessageID(reason_))
252 : base::string16());
[email protected]fae057a2013-06-21 22:46:08253
treib5dd8daf32014-12-18 17:36:37254 bool show_feedback = false;
treib9dbb9302015-01-08 14:42:39255#if defined(GOOGLE_CHROME_BUILD)
jam2187ddb2015-12-17 20:10:03256 show_feedback = is_child_account &&
257 SupervisedUserURLFilter::ReasonIsAutomatic(reason_);
treib5dd8daf32014-12-18 17:36:37258#endif
259 strings.SetBoolean("showFeedbackLink", show_feedback);
260 strings.SetString("feedbackLink",
261 l10n_util::GetStringUTF16(IDS_BLOCK_INTERSTITIAL_SEND_FEEDBACK));
262
[email protected]a09159a2012-11-29 12:51:48263 strings.SetString("backButton", l10n_util::GetStringUTF16(IDS_BACK_BUTTON));
treib5fc1aed2014-12-08 12:46:03264 strings.SetString("requestAccessButton", l10n_util::GetStringUTF16(
265 is_child_account
266 ? IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_ACCESS_BUTTON
267 : IDS_BLOCK_INTERSTITIAL_REQUEST_ACCESS_BUTTON));
[email protected]59f21562013-05-23 16:19:30268
treib5fc1aed2014-12-08 12:46:03269 base::string16 request_sent_message;
khannansf3b27192015-01-09 17:28:17270 base::string16 request_failed_message;
treib5fc1aed2014-12-08 12:46:03271 if (is_child_account) {
khannansf3b27192015-01-09 17:28:17272 if (second_custodian.empty()) {
273 request_sent_message = l10n_util::GetStringUTF16(
274 IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_SENT_MESSAGE_SINGLE_PARENT);
275 request_failed_message = l10n_util::GetStringUTF16(
276 IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_FAILED_MESSAGE_SINGLE_PARENT);
277 } else {
278 request_sent_message = l10n_util::GetStringUTF16(
279 IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_SENT_MESSAGE_MULTI_PARENT);
280 request_failed_message = l10n_util::GetStringUTF16(
281 IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_FAILED_MESSAGE_MULTI_PARENT);
282 }
treib5fc1aed2014-12-08 12:46:03283 } else {
284 request_sent_message = l10n_util::GetStringFUTF16(
285 IDS_BLOCK_INTERSTITIAL_REQUEST_SENT_MESSAGE, custodian);
khannansf3b27192015-01-09 17:28:17286 request_failed_message = l10n_util::GetStringFUTF16(
287 IDS_BLOCK_INTERSTITIAL_REQUEST_FAILED_MESSAGE, custodian);
treib5fc1aed2014-12-08 12:46:03288 }
289 strings.SetString("requestSentMessage", request_sent_message);
khannansf3b27192015-01-09 17:28:17290 strings.SetString("requestFailedMessage", request_failed_message);
[email protected]59f21562013-05-23 16:19:30291
dbeam622e9f32015-01-28 21:22:45292 const std::string& app_locale = g_browser_process->GetApplicationLocale();
293 webui::SetLoadTimeDataDefaults(app_locale, &strings);
[email protected]a09159a2012-11-29 12:51:48294
bauerbd0399182015-01-26 10:20:45295 std::string html =
296 ResourceBundle::GetSharedInstance()
297 .GetRawDataResource(IDR_SUPERVISED_USER_BLOCK_INTERSTITIAL_HTML)
298 .as_string();
299 webui::AppendWebUiCssTextDefaults(&html);
[email protected]a09159a2012-11-29 12:51:48300
[email protected]2779e3a2013-01-22 18:40:21301 return webui::GetI18nTemplateHtml(html, &strings);
[email protected]a09159a2012-11-29 12:51:48302}
303
[email protected]cce15bb2014-06-17 13:43:51304void SupervisedUserInterstitial::CommandReceived(const std::string& command) {
[email protected]2c145422013-01-24 18:15:40305 // For use in histograms.
306 enum Commands {
307 PREVIEW,
308 BACK,
309 NTP,
[email protected]59f21562013-05-23 16:19:30310 ACCESS_REQUEST,
[email protected]2c145422013-01-24 18:15:40311 HISTOGRAM_BOUNDING_VALUE
312 };
313
[email protected]a09159a2012-11-29 12:51:48314 if (command == "\"back\"") {
[email protected]2c145422013-01-24 18:15:40315 UMA_HISTOGRAM_ENUMERATION("ManagedMode.BlockingInterstitialCommand",
316 BACK,
317 HISTOGRAM_BOUNDING_VALUE);
treibe7ccb7e2014-09-09 19:21:45318
creisf82a92ee2015-10-19 19:59:08319 // The interstitial's reference to the WebContents will go away after the
320 // DontProceed call.
321 WebContents* web_contents = web_contents_;
322 DCHECK(web_contents->GetController().GetTransientEntry());
[email protected]a09159a2012-11-29 12:51:48323 interstitial_page_->DontProceed();
creisf82a92ee2015-10-19 19:59:08324
bauerb34f34c5f2015-10-21 15:38:32325 TabCloser::MaybeClose(web_contents);
[email protected]a09159a2012-11-29 12:51:48326 return;
327 }
328
[email protected]59f21562013-05-23 16:19:30329 if (command == "\"request\"") {
[email protected]2c145422013-01-24 18:15:40330 UMA_HISTOGRAM_ENUMERATION("ManagedMode.BlockingInterstitialCommand",
[email protected]59f21562013-05-23 16:19:30331 ACCESS_REQUEST,
[email protected]2c145422013-01-24 18:15:40332 HISTOGRAM_BOUNDING_VALUE);
[email protected]ad7a89e2013-05-31 12:03:24333
[email protected]cce15bb2014-06-17 13:43:51334 SupervisedUserService* supervised_user_service =
treibab0a39e2014-09-24 14:48:28335 SupervisedUserServiceFactory::GetForProfile(profile_);
treib8ecc1eb52015-03-04 18:29:06336 supervised_user_service->AddURLAccessRequest(
bauerb646019b12014-10-16 16:23:09337 url_, base::Bind(&SupervisedUserInterstitial::OnAccessRequestAdded,
338 weak_ptr_factory_.GetWeakPtr()));
[email protected]a09159a2012-11-29 12:51:48339 return;
340 }
341
treib5dd8daf32014-12-18 17:36:37342 if (command == "\"feedback\"") {
treibd733ef8b2015-01-21 19:56:32343 base::string16 reason = l10n_util::GetStringUTF16(
344 SupervisedUserURLFilter::GetBlockMessageID(reason_));
345 std::string message = l10n_util::GetStringFUTF8(
346 IDS_BLOCK_INTERSTITIAL_DEFAULT_FEEDBACK_TEXT, reason);
sievers2f1e8112015-12-04 18:43:56347#if BUILDFLAG(ANDROID_JAVA_UI)
treibd733ef8b2015-01-21 19:56:32348 ReportChildAccountFeedback(web_contents_, message, url_);
treib9dbb9302015-01-08 14:42:39349#else
treib8a6a5d92015-05-12 16:33:16350 chrome::ShowFeedbackPage(chrome::FindBrowserWithWebContents(web_contents_),
351 message, std::string());
treib9dbb9302015-01-08 14:42:39352#endif
treib5dd8daf32014-12-18 17:36:37353 return;
354 }
treib5dd8daf32014-12-18 17:36:37355
[email protected]a09159a2012-11-29 12:51:48356 NOTREACHED();
357}
358
[email protected]cce15bb2014-06-17 13:43:51359void SupervisedUserInterstitial::OnProceed() {
[email protected]61f5da22013-09-05 15:52:10360 DispatchContinueRequest(true);
361}
[email protected]a09159a2012-11-29 12:51:48362
[email protected]cce15bb2014-06-17 13:43:51363void SupervisedUserInterstitial::OnDontProceed() {
[email protected]6c7af96d2013-03-28 22:55:14364 DispatchContinueRequest(false);
[email protected]a09159a2012-11-29 12:51:48365}
366
meacerfc55bd52015-03-05 19:12:00367content::InterstitialPageDelegate::TypeID
368SupervisedUserInterstitial::GetTypeForTesting() const {
369 return SupervisedUserInterstitial::kTypeForTesting;
370}
371
treibab0a39e2014-09-24 14:48:28372void SupervisedUserInterstitial::OnURLFilterChanged() {
373 if (ShouldProceed())
374 interstitial_page_->Proceed();
375}
376
bauerb646019b12014-10-16 16:23:09377void SupervisedUserInterstitial::OnAccessRequestAdded(bool success) {
bauerbfc4af2ac2014-11-07 14:27:05378 VLOG(1) << "Sent access request for " << url_.spec()
379 << (success ? " successfully" : " unsuccessfully");
khannansf3b27192015-01-09 17:28:17380 std::string jsFunc =
381 base::StringPrintf("setRequestStatus(%s);", success ? "true" : "false");
382 interstitial_page_->GetMainFrame()->ExecuteJavaScript(
383 base::ASCIIToUTF16(jsFunc));
bauerb646019b12014-10-16 16:23:09384}
385
[email protected]cce15bb2014-06-17 13:43:51386bool SupervisedUserInterstitial::ShouldProceed() {
[email protected]cce15bb2014-06-17 13:43:51387 SupervisedUserService* supervised_user_service =
treibab0a39e2014-09-24 14:48:28388 SupervisedUserServiceFactory::GetForProfile(profile_);
[email protected]cce15bb2014-06-17 13:43:51389 SupervisedUserURLFilter* url_filter =
390 supervised_user_service->GetURLFilterForUIThread();
treib9e4fab902014-10-29 14:25:26391 SupervisedUserURLFilter::FilteringBehavior behavior;
treib22c3a042015-01-15 21:30:13392 if (url_filter->HasAsyncURLChecker()) {
393 if (!url_filter->GetManualFilteringBehaviorForURL(url_, &behavior))
394 return false;
395 } else {
396 behavior = url_filter->GetFilteringBehaviorForURL(url_);
397 }
398 return behavior != SupervisedUserURLFilter::BLOCK;
[email protected]61f5da22013-09-05 15:52:10399}
400
[email protected]cce15bb2014-06-17 13:43:51401void SupervisedUserInterstitial::DispatchContinueRequest(
402 bool continue_request) {
treibab0a39e2014-09-24 14:48:28403 SupervisedUserService* supervised_user_service =
404 SupervisedUserServiceFactory::GetForProfile(profile_);
405 supervised_user_service->RemoveObserver(this);
406
peconna2092d42015-09-17 17:28:59407 if (!callback_.is_null())
408 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
409 base::Bind(callback_, continue_request));
treibab0a39e2014-09-24 14:48:28410
411 // After this, the WebContents may be destroyed. Make sure we don't try to use
412 // it again.
413 web_contents_ = NULL;
[email protected]6c7af96d2013-03-28 22:55:14414}