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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
111 // static | 111 // static |
112 void SupervisedUserInterstitial::Show( | 112 void SupervisedUserInterstitial::Show( |
113 WebContents* web_contents, | 113 WebContents* web_contents, |
114 const GURL& url, | 114 const GURL& url, |
115 supervised_user_error_page::FilteringBehaviorReason reason, | 115 supervised_user_error_page::FilteringBehaviorReason reason, |
116 bool initial_page_load, | 116 bool initial_page_load, |
117 const base::Callback<void(bool)>& callback) { | 117 const base::Callback<void(bool)>& callback) { |
118 SupervisedUserInterstitial* interstitial = new SupervisedUserInterstitial( | 118 SupervisedUserInterstitial* interstitial = new SupervisedUserInterstitial( |
119 web_contents, url, reason, initial_page_load, callback); | 119 web_contents, url, reason, initial_page_load, callback); |
120 | 120 |
121 // If Init() does not complete fully, immediately delete the interstitial. | 121 // |interstitial_page_| is responsible for deleting the interstitial. |
122 if (!interstitial->Init()) | 122 interstitial->Init(); |
Marc Treib
2017/05/02 08:24:47
Should Init() now be merged into the ctor?
Bernhard Bauer
2017/05/02 09:02:53
I could do that, but then the constructor would do
| |
123 delete interstitial; | |
124 // Otherwise |interstitial_page_| is responsible for deleting it. | |
125 } | 123 } |
126 | 124 |
127 SupervisedUserInterstitial::SupervisedUserInterstitial( | 125 SupervisedUserInterstitial::SupervisedUserInterstitial( |
128 WebContents* web_contents, | 126 WebContents* web_contents, |
129 const GURL& url, | 127 const GURL& url, |
130 supervised_user_error_page::FilteringBehaviorReason reason, | 128 supervised_user_error_page::FilteringBehaviorReason reason, |
131 bool initial_page_load, | 129 bool initial_page_load, |
132 const base::Callback<void(bool)>& callback) | 130 const base::Callback<void(bool)>& callback) |
133 : web_contents_(web_contents), | 131 : web_contents_(web_contents), |
134 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), | 132 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), |
135 interstitial_page_(NULL), | 133 interstitial_page_(NULL), |
136 url_(url), | 134 url_(url), |
137 reason_(reason), | 135 reason_(reason), |
138 initial_page_load_(initial_page_load), | 136 initial_page_load_(initial_page_load), |
139 callback_(callback), | 137 callback_(callback), |
140 weak_ptr_factory_(this) {} | 138 weak_ptr_factory_(this) {} |
141 | 139 |
142 SupervisedUserInterstitial::~SupervisedUserInterstitial() { | 140 SupervisedUserInterstitial::~SupervisedUserInterstitial() { |
143 DCHECK(!web_contents_); | 141 DCHECK(!web_contents_); |
144 } | 142 } |
145 | 143 |
146 bool SupervisedUserInterstitial::Init() { | 144 void SupervisedUserInterstitial::Init() { |
147 if (ShouldProceed()) { | 145 DCHECK(!ShouldProceed()); |
148 // It can happen that the site was only allowed very recently and the URL | |
149 // filter on the IO thread had not been updated yet. Proceed with the | |
150 // request without showing the interstitial. | |
151 DispatchContinueRequest(true); | |
152 return false; | |
153 } | |
154 | 146 |
155 InfoBarService* service = InfoBarService::FromWebContents(web_contents_); | 147 InfoBarService* service = InfoBarService::FromWebContents(web_contents_); |
156 if (service) { | 148 if (service) { |
157 // Remove all the infobars which are attached to |web_contents_| and for | 149 // Remove all the infobars which are attached to |web_contents_| and for |
158 // which ShouldExpire() returns true. | 150 // which ShouldExpire() returns true. |
159 content::LoadCommittedDetails details; | 151 content::LoadCommittedDetails details; |
160 // |details.is_same_page| is default false, and |details.is_main_frame| is | 152 // |details.is_same_page| is default false, and |details.is_main_frame| is |
161 // default true. This results in is_navigation_to_different_page() returning | 153 // default true. This results in is_navigation_to_different_page() returning |
162 // true. | 154 // true. |
163 DCHECK(details.is_navigation_to_different_page()); | 155 DCHECK(details.is_navigation_to_different_page()); |
(...skipping 14 matching lines...) Expand all Loading... | |
178 } | 170 } |
179 } | 171 } |
180 | 172 |
181 SupervisedUserService* supervised_user_service = | 173 SupervisedUserService* supervised_user_service = |
182 SupervisedUserServiceFactory::GetForProfile(profile_); | 174 SupervisedUserServiceFactory::GetForProfile(profile_); |
183 supervised_user_service->AddObserver(this); | 175 supervised_user_service->AddObserver(this); |
184 | 176 |
185 interstitial_page_ = content::InterstitialPage::Create( | 177 interstitial_page_ = content::InterstitialPage::Create( |
186 web_contents_, initial_page_load_, url_, this); | 178 web_contents_, initial_page_load_, url_, this); |
187 interstitial_page_->Show(); | 179 interstitial_page_->Show(); |
188 | |
189 return true; | |
190 } | 180 } |
191 | 181 |
192 // static | 182 // static |
193 std::string SupervisedUserInterstitial::GetHTMLContents( | 183 std::string SupervisedUserInterstitial::GetHTMLContents( |
194 Profile* profile, | 184 Profile* profile, |
195 supervised_user_error_page::FilteringBehaviorReason reason) { | 185 supervised_user_error_page::FilteringBehaviorReason reason) { |
196 bool is_child_account = profile->IsChild(); | 186 bool is_child_account = profile->IsChild(); |
197 | 187 |
198 SupervisedUserService* supervised_user_service = | 188 SupervisedUserService* supervised_user_service = |
199 SupervisedUserServiceFactory::GetForProfile(profile); | 189 SupervisedUserServiceFactory::GetForProfile(profile); |
(...skipping 30 matching lines...) Expand all Loading... | |
230 NTP, | 220 NTP, |
231 ACCESS_REQUEST, | 221 ACCESS_REQUEST, |
232 HISTOGRAM_BOUNDING_VALUE | 222 HISTOGRAM_BOUNDING_VALUE |
233 }; | 223 }; |
234 | 224 |
235 if (command == "\"back\"") { | 225 if (command == "\"back\"") { |
236 UMA_HISTOGRAM_ENUMERATION("ManagedMode.BlockingInterstitialCommand", | 226 UMA_HISTOGRAM_ENUMERATION("ManagedMode.BlockingInterstitialCommand", |
237 BACK, | 227 BACK, |
238 HISTOGRAM_BOUNDING_VALUE); | 228 HISTOGRAM_BOUNDING_VALUE); |
239 | 229 |
240 DCHECK(web_contents_->GetController().GetTransientEntry()); | |
241 interstitial_page_->DontProceed(); | 230 interstitial_page_->DontProceed(); |
242 return; | 231 return; |
243 } | 232 } |
244 | 233 |
245 if (command == "\"request\"") { | 234 if (command == "\"request\"") { |
246 UMA_HISTOGRAM_ENUMERATION("ManagedMode.BlockingInterstitialCommand", | 235 UMA_HISTOGRAM_ENUMERATION("ManagedMode.BlockingInterstitialCommand", |
247 ACCESS_REQUEST, | 236 ACCESS_REQUEST, |
248 HISTOGRAM_BOUNDING_VALUE); | 237 HISTOGRAM_BOUNDING_VALUE); |
249 | 238 |
250 SupervisedUserService* supervised_user_service = | 239 SupervisedUserService* supervised_user_service = |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
341 | 330 |
342 TabCloser::MaybeClose(web_contents_); | 331 TabCloser::MaybeClose(web_contents_); |
343 } | 332 } |
344 | 333 |
345 void SupervisedUserInterstitial::DispatchContinueRequest( | 334 void SupervisedUserInterstitial::DispatchContinueRequest( |
346 bool continue_request) { | 335 bool continue_request) { |
347 SupervisedUserService* supervised_user_service = | 336 SupervisedUserService* supervised_user_service = |
348 SupervisedUserServiceFactory::GetForProfile(profile_); | 337 SupervisedUserServiceFactory::GetForProfile(profile_); |
349 supervised_user_service->RemoveObserver(this); | 338 supervised_user_service->RemoveObserver(this); |
350 | 339 |
351 if (!callback_.is_null()) | 340 callback_.Run(continue_request); |
352 callback_.Run(continue_request); | |
353 | 341 |
354 // After this, the WebContents may be destroyed. Make sure we don't try to use | 342 // After this, the WebContents may be destroyed. Make sure we don't try to use |
355 // it again. | 343 // it again. |
356 web_contents_ = nullptr; | 344 web_contents_ = nullptr; |
357 } | 345 } |
OLD | NEW |