[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
[email protected] | a09159a | 2012-11-29 12:51:48 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 5 | #include "chrome/browser/supervised_user/supervised_user_interstitial.h" |
[email protected] | a09159a | 2012-11-29 12:51:48 | [diff] [blame] | 6 | |
treib | e7ccb7e | 2014-09-09 19:21:45 | [diff] [blame] | 7 | #include "base/memory/weak_ptr.h" |
[email protected] | 2c14542 | 2013-01-24 18:15:40 | [diff] [blame] | 8 | #include "base/metrics/histogram.h" |
[email protected] | 3853a4c | 2013-02-11 17:15:57 | [diff] [blame] | 9 | #include "base/prefs/pref_service.h" |
[email protected] | 95c47d0 | 2014-08-19 09:17:50 | [diff] [blame] | 10 | #include "base/strings/string_number_conversions.h" |
[email protected] | 112158af | 2013-06-07 23:46:18 | [diff] [blame] | 11 | #include "base/strings/utf_string_conversions.h" |
[email protected] | 59f2156 | 2013-05-23 16:19:30 | [diff] [blame] | 12 | #include "base/values.h" |
[email protected] | 93c2321 | 2013-09-19 14:22:38 | [diff] [blame] | 13 | #include "chrome/browser/infobars/infobar_service.h" |
[email protected] | a09159a | 2012-11-29 12:51:48 | [diff] [blame] | 14 | #include "chrome/browser/profiles/profile.h" |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 15 | #include "chrome/browser/supervised_user/supervised_user_service.h" |
| 16 | #include "chrome/browser/supervised_user/supervised_user_service_factory.h" |
[email protected] | a09159a | 2012-11-29 12:51:48 | [diff] [blame] | 17 | #include "chrome/common/pref_names.h" |
[email protected] | af39f00 | 2014-08-22 10:18:18 | [diff] [blame] | 18 | #include "chrome/grit/generated_resources.h" |
[email protected] | 051655ad | 2014-04-18 15:09:41 | [diff] [blame] | 19 | #include "components/infobars/core/infobar.h" |
| 20 | #include "components/infobars/core/infobar_delegate.h" |
[email protected] | a09159a | 2012-11-29 12:51:48 | [diff] [blame] | 21 | #include "content/public/browser/browser_thread.h" |
| 22 | #include "content/public/browser/interstitial_page.h" |
[email protected] | 93c2321 | 2013-09-19 14:22:38 | [diff] [blame] | 23 | #include "content/public/browser/navigation_controller.h" |
| 24 | #include "content/public/browser/navigation_details.h" |
| 25 | #include "content/public/browser/navigation_entry.h" |
[email protected] | a09159a | 2012-11-29 12:51:48 | [diff] [blame] | 26 | #include "content/public/browser/web_contents.h" |
treib | e7ccb7e | 2014-09-09 19:21:45 | [diff] [blame] | 27 | #include "content/public/browser/web_contents_user_data.h" |
[email protected] | 59f2156 | 2013-05-23 16:19:30 | [diff] [blame] | 28 | #include "content/public/browser/web_ui.h" |
[email protected] | a09159a | 2012-11-29 12:51:48 | [diff] [blame] | 29 | #include "grit/browser_resources.h" |
[email protected] | a09159a | 2012-11-29 12:51:48 | [diff] [blame] | 30 | #include "ui/base/l10n/l10n_util.h" |
| 31 | #include "ui/base/resource/resource_bundle.h" |
[email protected] | cd67ed5 | 2013-10-15 01:22:13 | [diff] [blame] | 32 | #include "ui/base/webui/jstemplate_builder.h" |
| 33 | #include "ui/base/webui/web_ui_util.h" |
[email protected] | a09159a | 2012-11-29 12:51:48 | [diff] [blame] | 34 | |
treib | e7ccb7e | 2014-09-09 19:21:45 | [diff] [blame] | 35 | #if !defined(OS_ANDROID) |
| 36 | #include "chrome/browser/ui/browser_finder.h" |
| 37 | #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 38 | #endif |
| 39 | |
[email protected] | a09159a | 2012-11-29 12:51:48 | [diff] [blame] | 40 | using content::BrowserThread; |
treib | e7ccb7e | 2014-09-09 19:21:45 | [diff] [blame] | 41 | using content::WebContents; |
[email protected] | a09159a | 2012-11-29 12:51:48 | [diff] [blame] | 42 | |
[email protected] | 95c47d0 | 2014-08-19 09:17:50 | [diff] [blame] | 43 | namespace { |
| 44 | |
| 45 | static const int kAvatarSize1x = 45; |
| 46 | static const int kAvatarSize2x = 90; |
| 47 | |
treib | 885fee1 | 2014-08-29 08:07:58 | [diff] [blame] | 48 | std::string BuildAvatarImageUrl(const std::string& url, int size) { |
[email protected] | 95c47d0 | 2014-08-19 09:17:50 | [diff] [blame] | 49 | std::string result = url; |
| 50 | size_t slash = result.rfind('/'); |
| 51 | if (slash != std::string::npos) |
| 52 | result.insert(slash, "/s" + base::IntToString(size)); |
treib | 885fee1 | 2014-08-29 08:07:58 | [diff] [blame] | 53 | return result; |
[email protected] | 95c47d0 | 2014-08-19 09:17:50 | [diff] [blame] | 54 | } |
| 55 | |
treib | e7ccb7e | 2014-09-09 19:21:45 | [diff] [blame] | 56 | class TabCloser : public content::WebContentsUserData<TabCloser> { |
| 57 | // To use, call TabCloser::CreateForWebContents. |
| 58 | private: |
| 59 | friend class content::WebContentsUserData<TabCloser>; |
| 60 | |
| 61 | explicit TabCloser(WebContents* web_contents) |
| 62 | : web_contents_(web_contents), weak_ptr_factory_(this) { |
| 63 | BrowserThread::PostTask( |
| 64 | BrowserThread::UI, |
| 65 | FROM_HERE, |
| 66 | base::Bind(&TabCloser::CloseTabImpl, weak_ptr_factory_.GetWeakPtr())); |
| 67 | } |
dcheng | c072fff | 2014-10-21 11:39:05 | [diff] [blame^] | 68 | ~TabCloser() override {} |
treib | e7ccb7e | 2014-09-09 19:21:45 | [diff] [blame] | 69 | |
| 70 | void CloseTabImpl() { |
| 71 | // On Android, FindBrowserWithWebContents and TabStripModel don't exist. |
| 72 | #if !defined(OS_ANDROID) |
| 73 | Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); |
| 74 | DCHECK(browser); |
| 75 | TabStripModel* tab_strip = browser->tab_strip_model(); |
| 76 | DCHECK_NE(TabStripModel::kNoTab, |
| 77 | tab_strip->GetIndexOfWebContents(web_contents_)); |
| 78 | if (tab_strip->count() <= 1) { |
| 79 | // Don't close the last tab in the window. |
| 80 | web_contents_->RemoveUserData(UserDataKey()); |
| 81 | return; |
| 82 | } |
| 83 | #endif |
| 84 | web_contents_->Close(); |
| 85 | } |
| 86 | |
| 87 | WebContents* web_contents_; |
| 88 | base::WeakPtrFactory<TabCloser> weak_ptr_factory_; |
| 89 | }; |
| 90 | |
| 91 | } // namespace |
| 92 | |
| 93 | DEFINE_WEB_CONTENTS_USER_DATA_KEY(TabCloser); |
[email protected] | 95c47d0 | 2014-08-19 09:17:50 | [diff] [blame] | 94 | |
[email protected] | b8af2d1 | 2014-04-29 07:30:42 | [diff] [blame] | 95 | // static |
[email protected] | 95c47d0 | 2014-08-19 09:17:50 | [diff] [blame] | 96 | void SupervisedUserInterstitial::Show( |
treib | e7ccb7e | 2014-09-09 19:21:45 | [diff] [blame] | 97 | WebContents* web_contents, |
[email protected] | 95c47d0 | 2014-08-19 09:17:50 | [diff] [blame] | 98 | const GURL& url, |
| 99 | const base::Callback<void(bool)>& callback) { |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 100 | SupervisedUserInterstitial* interstitial = |
| 101 | new SupervisedUserInterstitial(web_contents, url, callback); |
[email protected] | b8af2d1 | 2014-04-29 07:30:42 | [diff] [blame] | 102 | |
| 103 | // If Init() does not complete fully, immediately delete the interstitial. |
| 104 | if (!interstitial->Init()) |
| 105 | delete interstitial; |
| 106 | // Otherwise |interstitial_page_| is responsible for deleting it. |
| 107 | } |
| 108 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 109 | SupervisedUserInterstitial::SupervisedUserInterstitial( |
treib | e7ccb7e | 2014-09-09 19:21:45 | [diff] [blame] | 110 | WebContents* web_contents, |
[email protected] | a09159a | 2012-11-29 12:51:48 | [diff] [blame] | 111 | const GURL& url, |
| 112 | const base::Callback<void(bool)>& callback) |
| 113 | : web_contents_(web_contents), |
treib | ab0a39e | 2014-09-24 14:48:28 | [diff] [blame] | 114 | profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), |
[email protected] | 61f5da2 | 2013-09-05 15:52:10 | [diff] [blame] | 115 | interstitial_page_(NULL), |
[email protected] | a09159a | 2012-11-29 12:51:48 | [diff] [blame] | 116 | url_(url), |
bauerb | 646019b1 | 2014-10-16 16:23:09 | [diff] [blame] | 117 | callback_(callback), |
| 118 | weak_ptr_factory_(this) {} |
[email protected] | b8af2d1 | 2014-04-29 07:30:42 | [diff] [blame] | 119 | |
treib | ab0a39e | 2014-09-24 14:48:28 | [diff] [blame] | 120 | SupervisedUserInterstitial::~SupervisedUserInterstitial() { |
| 121 | DCHECK(!web_contents_); |
| 122 | } |
[email protected] | b8af2d1 | 2014-04-29 07:30:42 | [diff] [blame] | 123 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 124 | bool SupervisedUserInterstitial::Init() { |
[email protected] | 61f5da2 | 2013-09-05 15:52:10 | [diff] [blame] | 125 | if (ShouldProceed()) { |
| 126 | // It can happen that the site was only allowed very recently and the URL |
| 127 | // filter on the IO thread had not been updated yet. Proceed with the |
| 128 | // request without showing the interstitial. |
| 129 | DispatchContinueRequest(true); |
[email protected] | b8af2d1 | 2014-04-29 07:30:42 | [diff] [blame] | 130 | return false; |
[email protected] | 61f5da2 | 2013-09-05 15:52:10 | [diff] [blame] | 131 | } |
| 132 | |
[email protected] | b8af2d1 | 2014-04-29 07:30:42 | [diff] [blame] | 133 | InfoBarService* service = InfoBarService::FromWebContents(web_contents_); |
[email protected] | 93c2321 | 2013-09-19 14:22:38 | [diff] [blame] | 134 | if (service) { |
[email protected] | b8af2d1 | 2014-04-29 07:30:42 | [diff] [blame] | 135 | // Remove all the infobars which are attached to |web_contents_| and for |
[email protected] | 93c2321 | 2013-09-19 14:22:38 | [diff] [blame] | 136 | // which ShouldExpire() returns true. |
| 137 | content::LoadCommittedDetails details; |
| 138 | // |details.is_in_page| is default false, and |details.is_main_frame| is |
| 139 | // default true. This results in is_navigation_to_different_page() returning |
| 140 | // true. |
| 141 | DCHECK(details.is_navigation_to_different_page()); |
| 142 | const content::NavigationController& controller = |
[email protected] | b8af2d1 | 2014-04-29 07:30:42 | [diff] [blame] | 143 | web_contents_->GetController(); |
[email protected] | 93c2321 | 2013-09-19 14:22:38 | [diff] [blame] | 144 | details.entry = controller.GetActiveEntry(); |
| 145 | if (controller.GetLastCommittedEntry()) { |
| 146 | details.previous_entry_index = controller.GetLastCommittedEntryIndex(); |
| 147 | details.previous_url = controller.GetLastCommittedEntry()->GetURL(); |
| 148 | } |
| 149 | details.type = content::NAVIGATION_TYPE_NEW_PAGE; |
[email protected] | b44f1d3 | 2014-04-10 13:53:26 | [diff] [blame] | 150 | for (int i = service->infobar_count() - 1; i >= 0; --i) { |
[email protected] | 051655ad | 2014-04-18 15:09:41 | [diff] [blame] | 151 | infobars::InfoBar* infobar = service->infobar_at(i); |
[email protected] | 5daf1d9 | 2014-04-04 15:52:13 | [diff] [blame] | 152 | if (infobar->delegate()->ShouldExpire( |
| 153 | InfoBarService::NavigationDetailsFromLoadCommittedDetails( |
| 154 | details))) |
[email protected] | b44f1d3 | 2014-04-10 13:53:26 | [diff] [blame] | 155 | service->RemoveInfoBar(infobar); |
[email protected] | 93c2321 | 2013-09-19 14:22:38 | [diff] [blame] | 156 | } |
| 157 | } |
| 158 | |
treib | ab0a39e | 2014-09-24 14:48:28 | [diff] [blame] | 159 | SupervisedUserService* supervised_user_service = |
| 160 | SupervisedUserServiceFactory::GetForProfile(profile_); |
| 161 | supervised_user_service->AddObserver(this); |
[email protected] | a09159a | 2012-11-29 12:51:48 | [diff] [blame] | 162 | |
[email protected] | 0369d6ab | 2013-08-09 01:52:59 | [diff] [blame] | 163 | interstitial_page_ = |
[email protected] | b8af2d1 | 2014-04-29 07:30:42 | [diff] [blame] | 164 | content::InterstitialPage::Create(web_contents_, true, url_, this); |
[email protected] | a09159a | 2012-11-29 12:51:48 | [diff] [blame] | 165 | interstitial_page_->Show(); |
[email protected] | a09159a | 2012-11-29 12:51:48 | [diff] [blame] | 166 | |
[email protected] | b8af2d1 | 2014-04-29 07:30:42 | [diff] [blame] | 167 | return true; |
| 168 | } |
[email protected] | a09159a | 2012-11-29 12:51:48 | [diff] [blame] | 169 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 170 | std::string SupervisedUserInterstitial::GetHTMLContents() { |
[email protected] | cb1078de | 2013-12-23 20:04:22 | [diff] [blame] | 171 | base::DictionaryValue strings; |
[email protected] | a09159a | 2012-11-29 12:51:48 | [diff] [blame] | 172 | strings.SetString("blockPageTitle", |
| 173 | l10n_util::GetStringUTF16(IDS_BLOCK_INTERSTITIAL_TITLE)); |
[email protected] | fae057a | 2013-06-21 22:46:08 | [diff] [blame] | 174 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 175 | SupervisedUserService* supervised_user_service = |
treib | ab0a39e | 2014-09-24 14:48:28 | [diff] [blame] | 176 | SupervisedUserServiceFactory::GetForProfile(profile_); |
[email protected] | 0369d6ab | 2013-08-09 01:52:59 | [diff] [blame] | 177 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 178 | bool allow_access_requests = supervised_user_service->AccessRequestsEnabled(); |
[email protected] | 0369d6ab | 2013-08-09 01:52:59 | [diff] [blame] | 179 | strings.SetBoolean("allowAccessRequests", allow_access_requests); |
| 180 | |
treib | ab0a39e | 2014-09-24 14:48:28 | [diff] [blame] | 181 | std::string profile_image_url = profile_->GetPrefs()->GetString( |
[email protected] | 95c47d0 | 2014-08-19 09:17:50 | [diff] [blame] | 182 | prefs::kSupervisedUserCustodianProfileImageURL); |
| 183 | strings.SetString("avatarURL1x", BuildAvatarImageUrl(profile_image_url, |
[email protected] | 95c47d0 | 2014-08-19 09:17:50 | [diff] [blame] | 184 | kAvatarSize1x)); |
| 185 | strings.SetString("avatarURL2x", BuildAvatarImageUrl(profile_image_url, |
[email protected] | 95c47d0 | 2014-08-19 09:17:50 | [diff] [blame] | 186 | kAvatarSize2x)); |
| 187 | |
treib | ab0a39e | 2014-09-24 14:48:28 | [diff] [blame] | 188 | std::string profile_image_url2 = profile_->GetPrefs()->GetString( |
[email protected] | 95c47d0 | 2014-08-19 09:17:50 | [diff] [blame] | 189 | prefs::kSupervisedUserSecondCustodianProfileImageURL); |
| 190 | strings.SetString("secondAvatarURL1x", BuildAvatarImageUrl(profile_image_url2, |
[email protected] | 95c47d0 | 2014-08-19 09:17:50 | [diff] [blame] | 191 | kAvatarSize1x)); |
| 192 | strings.SetString("secondAvatarURL2x", BuildAvatarImageUrl(profile_image_url2, |
[email protected] | 95c47d0 | 2014-08-19 09:17:50 | [diff] [blame] | 193 | kAvatarSize2x)); |
| 194 | |
[email protected] | 0085863a | 2013-12-06 21:19:03 | [diff] [blame] | 195 | base::string16 custodian = |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 196 | base::UTF8ToUTF16(supervised_user_service->GetCustodianName()); |
[email protected] | fae057a | 2013-06-21 22:46:08 | [diff] [blame] | 197 | strings.SetString( |
| 198 | "blockPageMessage", |
[email protected] | 0369d6ab | 2013-08-09 01:52:59 | [diff] [blame] | 199 | allow_access_requests |
| 200 | ? l10n_util::GetStringFUTF16(IDS_BLOCK_INTERSTITIAL_MESSAGE, |
| 201 | custodian) |
| 202 | : l10n_util::GetStringUTF16( |
| 203 | IDS_BLOCK_INTERSTITIAL_MESSAGE_ACCESS_REQUESTS_DISABLED)); |
[email protected] | fae057a | 2013-06-21 22:46:08 | [diff] [blame] | 204 | |
[email protected] | a09159a | 2012-11-29 12:51:48 | [diff] [blame] | 205 | strings.SetString("backButton", l10n_util::GetStringUTF16(IDS_BACK_BUTTON)); |
| 206 | strings.SetString( |
[email protected] | 59f2156 | 2013-05-23 16:19:30 | [diff] [blame] | 207 | "requestAccessButton", |
| 208 | l10n_util::GetStringUTF16(IDS_BLOCK_INTERSTITIAL_REQUEST_ACCESS_BUTTON)); |
| 209 | |
[email protected] | 59f2156 | 2013-05-23 16:19:30 | [diff] [blame] | 210 | strings.SetString( |
| 211 | "requestSentMessage", |
| 212 | l10n_util::GetStringFUTF16(IDS_BLOCK_INTERSTITIAL_REQUEST_SENT_MESSAGE, |
[email protected] | fae057a | 2013-06-21 22:46:08 | [diff] [blame] | 213 | custodian)); |
[email protected] | 59f2156 | 2013-05-23 16:19:30 | [diff] [blame] | 214 | |
[email protected] | 5053d40 | 2013-01-23 05:19:26 | [diff] [blame] | 215 | webui::SetFontAndTextDirection(&strings); |
[email protected] | a09159a | 2012-11-29 12:51:48 | [diff] [blame] | 216 | |
[email protected] | 0369d6ab | 2013-08-09 01:52:59 | [diff] [blame] | 217 | base::StringPiece html(ResourceBundle::GetSharedInstance().GetRawDataResource( |
[email protected] | a7340d61 | 2014-06-25 22:09:15 | [diff] [blame] | 218 | IDR_SUPERVISED_USER_BLOCK_INTERSTITIAL_HTML)); |
[email protected] | a09159a | 2012-11-29 12:51:48 | [diff] [blame] | 219 | |
[email protected] | 2779e3a | 2013-01-22 18:40:21 | [diff] [blame] | 220 | return webui::GetI18nTemplateHtml(html, &strings); |
[email protected] | a09159a | 2012-11-29 12:51:48 | [diff] [blame] | 221 | } |
| 222 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 223 | void SupervisedUserInterstitial::CommandReceived(const std::string& command) { |
[email protected] | 2c14542 | 2013-01-24 18:15:40 | [diff] [blame] | 224 | // For use in histograms. |
| 225 | enum Commands { |
| 226 | PREVIEW, |
| 227 | BACK, |
| 228 | NTP, |
[email protected] | 59f2156 | 2013-05-23 16:19:30 | [diff] [blame] | 229 | ACCESS_REQUEST, |
[email protected] | 2c14542 | 2013-01-24 18:15:40 | [diff] [blame] | 230 | HISTOGRAM_BOUNDING_VALUE |
| 231 | }; |
| 232 | |
[email protected] | a09159a | 2012-11-29 12:51:48 | [diff] [blame] | 233 | if (command == "\"back\"") { |
[email protected] | 2c14542 | 2013-01-24 18:15:40 | [diff] [blame] | 234 | UMA_HISTOGRAM_ENUMERATION("ManagedMode.BlockingInterstitialCommand", |
| 235 | BACK, |
| 236 | HISTOGRAM_BOUNDING_VALUE); |
treib | e7ccb7e | 2014-09-09 19:21:45 | [diff] [blame] | 237 | |
| 238 | // Close the tab if there is no history entry to go back to. |
| 239 | DCHECK(web_contents_->GetController().GetTransientEntry()); |
| 240 | if (web_contents_->GetController().GetEntryCount() == 1) |
| 241 | TabCloser::CreateForWebContents(web_contents_); |
| 242 | |
[email protected] | a09159a | 2012-11-29 12:51:48 | [diff] [blame] | 243 | interstitial_page_->DontProceed(); |
| 244 | return; |
| 245 | } |
| 246 | |
[email protected] | 59f2156 | 2013-05-23 16:19:30 | [diff] [blame] | 247 | if (command == "\"request\"") { |
[email protected] | 2c14542 | 2013-01-24 18:15:40 | [diff] [blame] | 248 | UMA_HISTOGRAM_ENUMERATION("ManagedMode.BlockingInterstitialCommand", |
[email protected] | 59f2156 | 2013-05-23 16:19:30 | [diff] [blame] | 249 | ACCESS_REQUEST, |
[email protected] | 2c14542 | 2013-01-24 18:15:40 | [diff] [blame] | 250 | HISTOGRAM_BOUNDING_VALUE); |
[email protected] | ad7a89e | 2013-05-31 12:03:24 | [diff] [blame] | 251 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 252 | SupervisedUserService* supervised_user_service = |
treib | ab0a39e | 2014-09-24 14:48:28 | [diff] [blame] | 253 | SupervisedUserServiceFactory::GetForProfile(profile_); |
bauerb | 646019b1 | 2014-10-16 16:23:09 | [diff] [blame] | 254 | supervised_user_service->AddAccessRequest( |
| 255 | url_, base::Bind(&SupervisedUserInterstitial::OnAccessRequestAdded, |
| 256 | weak_ptr_factory_.GetWeakPtr())); |
[email protected] | a09159a | 2012-11-29 12:51:48 | [diff] [blame] | 257 | return; |
| 258 | } |
| 259 | |
| 260 | NOTREACHED(); |
| 261 | } |
| 262 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 263 | void SupervisedUserInterstitial::OnProceed() { |
[email protected] | 61f5da2 | 2013-09-05 15:52:10 | [diff] [blame] | 264 | // CHECK instead of DCHECK as defense in depth in case we'd accidentally |
| 265 | // proceed on a blocked page. |
| 266 | CHECK(ShouldProceed()); |
| 267 | DispatchContinueRequest(true); |
| 268 | } |
[email protected] | a09159a | 2012-11-29 12:51:48 | [diff] [blame] | 269 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 270 | void SupervisedUserInterstitial::OnDontProceed() { |
[email protected] | 6c7af96d | 2013-03-28 22:55:14 | [diff] [blame] | 271 | DispatchContinueRequest(false); |
[email protected] | a09159a | 2012-11-29 12:51:48 | [diff] [blame] | 272 | } |
| 273 | |
treib | ab0a39e | 2014-09-24 14:48:28 | [diff] [blame] | 274 | void SupervisedUserInterstitial::OnURLFilterChanged() { |
| 275 | if (ShouldProceed()) |
| 276 | interstitial_page_->Proceed(); |
| 277 | } |
| 278 | |
bauerb | 646019b1 | 2014-10-16 16:23:09 | [diff] [blame] | 279 | void SupervisedUserInterstitial::OnAccessRequestAdded(bool success) { |
| 280 | // TODO(akuegel): Figure out how to show the result of issuing the permission |
| 281 | // request in the UI. Currently, we assume the permission request was created |
| 282 | // successfully. |
| 283 | DVLOG(1) << "Sent access request for " << url_.spec() |
| 284 | << (success ? " successfully" : " unsuccessfully"); |
| 285 | } |
| 286 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 287 | bool SupervisedUserInterstitial::ShouldProceed() { |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 288 | SupervisedUserService* supervised_user_service = |
treib | ab0a39e | 2014-09-24 14:48:28 | [diff] [blame] | 289 | SupervisedUserServiceFactory::GetForProfile(profile_); |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 290 | SupervisedUserURLFilter* url_filter = |
| 291 | supervised_user_service->GetURLFilterForUIThread(); |
[email protected] | 61f5da2 | 2013-09-05 15:52:10 | [diff] [blame] | 292 | return url_filter->GetFilteringBehaviorForURL(url_) != |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 293 | SupervisedUserURLFilter::BLOCK; |
[email protected] | 61f5da2 | 2013-09-05 15:52:10 | [diff] [blame] | 294 | } |
| 295 | |
[email protected] | cce15bb | 2014-06-17 13:43:51 | [diff] [blame] | 296 | void SupervisedUserInterstitial::DispatchContinueRequest( |
| 297 | bool continue_request) { |
treib | ab0a39e | 2014-09-24 14:48:28 | [diff] [blame] | 298 | SupervisedUserService* supervised_user_service = |
| 299 | SupervisedUserServiceFactory::GetForProfile(profile_); |
| 300 | supervised_user_service->RemoveObserver(this); |
| 301 | |
[email protected] | 0369d6ab | 2013-08-09 01:52:59 | [diff] [blame] | 302 | BrowserThread::PostTask( |
| 303 | BrowserThread::IO, FROM_HERE, base::Bind(callback_, continue_request)); |
treib | ab0a39e | 2014-09-24 14:48:28 | [diff] [blame] | 304 | |
| 305 | // After this, the WebContents may be destroyed. Make sure we don't try to use |
| 306 | // it again. |
| 307 | web_contents_ = NULL; |
[email protected] | 6c7af96d | 2013-03-28 22:55:14 | [diff] [blame] | 308 | } |