| Index: chrome/browser/supervised_user/supervised_user_navigation_observer.cc
|
| diff --git a/chrome/browser/supervised_user/supervised_user_navigation_observer.cc b/chrome/browser/supervised_user/supervised_user_navigation_observer.cc
|
| index 56edc80fde92452957ca4c5ecb9e76b72191ce1c..01bad11617023f3e40dccd057c42c29adc193c0e 100644
|
| --- a/chrome/browser/supervised_user/supervised_user_navigation_observer.cc
|
| +++ b/chrome/browser/supervised_user/supervised_user_navigation_observer.cc
|
| @@ -49,19 +49,20 @@ void SupervisedUserNavigationObserver::OnRequestBlocked(
|
| const base::Callback<void(bool)>& callback) {
|
| SupervisedUserNavigationObserver* navigation_observer =
|
| SupervisedUserNavigationObserver::FromWebContents(web_contents);
|
| - if (navigation_observer)
|
| - navigation_observer->OnRequestBlockedInternal(url);
|
|
|
| - // Show the interstitial.
|
| - const bool initial_page_load = true;
|
| - SupervisedUserInterstitial::Show(web_contents, url, reason, initial_page_load,
|
| - callback);
|
| + // Cancel the navigation if there is no navigation observer.
|
| + if (!navigation_observer) {
|
| + callback.Run(false);
|
| + return;
|
| + }
|
| +
|
| + navigation_observer->OnRequestBlockedInternal(url, reason, callback);
|
| }
|
|
|
| void SupervisedUserNavigationObserver::DidFinishNavigation(
|
| content::NavigationHandle* navigation_handle) {
|
| // Only filter same page navigations (eg. pushState/popState); others will
|
| - // have been filtered by the ResourceThrottle.
|
| + // have been filtered by the NavigationThrottle.
|
| if (!navigation_handle->IsSameDocument())
|
| return;
|
|
|
| @@ -84,7 +85,9 @@ void SupervisedUserNavigationObserver::OnURLFilterChanged() {
|
| }
|
|
|
| void SupervisedUserNavigationObserver::OnRequestBlockedInternal(
|
| - const GURL& url) {
|
| + const GURL& url,
|
| + supervised_user_error_page::FilteringBehaviorReason reason,
|
| + const base::Callback<void(bool)>& callback) {
|
| Time timestamp = Time::Now(); // TODO(bauerb): Use SaneTime when available.
|
| // Create a history entry for the attempt and mark it as such.
|
| history::HistoryAddPageArgs add_page_args(
|
| @@ -111,6 +114,10 @@ void SupervisedUserNavigationObserver::OnRequestBlockedInternal(
|
| blocked_navigations_.size(), *entry));
|
| blocked_navigations_.push_back(std::move(serialized_entry));
|
| supervised_user_service_->DidBlockNavigation(web_contents());
|
| +
|
| + // Show the interstitial.
|
| + const bool initial_page_load = true;
|
| + MaybeShowInterstitial(url, reason, initial_page_load, callback);
|
| }
|
|
|
| void SupervisedUserNavigationObserver::URLFilterCheckCallback(
|
| @@ -122,10 +129,33 @@ void SupervisedUserNavigationObserver::URLFilterCheckCallback(
|
| if (url != web_contents()->GetLastCommittedURL())
|
| return;
|
|
|
| - const bool initial_page_load = false;
|
| if (behavior == SupervisedUserURLFilter::FilteringBehavior::BLOCK) {
|
| - SupervisedUserInterstitial::Show(web_contents(), url, reason,
|
| - initial_page_load,
|
| - base::Callback<void(bool)>());
|
| + const bool initial_page_load = false;
|
| + MaybeShowInterstitial(url, reason, initial_page_load,
|
| + base::Callback<void(bool)>());
|
| }
|
| }
|
| +
|
| +void SupervisedUserNavigationObserver::MaybeShowInterstitial(
|
| + const GURL& url,
|
| + supervised_user_error_page::FilteringBehaviorReason reason,
|
| + bool initial_page_load,
|
| + const base::Callback<void(bool)>& callback) {
|
| + if (is_showing_interstitial_)
|
| + return;
|
| +
|
| + is_showing_interstitial_ = true;
|
| + base::Callback<void(bool)> wrapped_callback =
|
| + base::Bind(&SupervisedUserNavigationObserver::OnInterstitialResult,
|
| + weak_ptr_factory_.GetWeakPtr(), callback);
|
| + SupervisedUserInterstitial::Show(web_contents(), url, reason,
|
| + initial_page_load, wrapped_callback);
|
| +}
|
| +
|
| +void SupervisedUserNavigationObserver::OnInterstitialResult(
|
| + const base::Callback<void(bool)>& callback,
|
| + bool result) {
|
| + is_showing_interstitial_ = false;
|
| + if (callback)
|
| + callback.Run(result);
|
| +}
|
|
|