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

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

Issue 2845053002: Avoid showing the supervised user block interstitial more than once (Closed)
Patch Set: comment Created 3 years, 7 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
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_navigation_observer.h" 5 #include "chrome/browser/supervised_user/supervised_user_navigation_observer.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "chrome/browser/history/history_service_factory.h" 10 #include "chrome/browser/history/history_service_factory.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 } 42 }
43 43
44 // static 44 // static
45 void SupervisedUserNavigationObserver::OnRequestBlocked( 45 void SupervisedUserNavigationObserver::OnRequestBlocked(
46 content::WebContents* web_contents, 46 content::WebContents* web_contents,
47 const GURL& url, 47 const GURL& url,
48 supervised_user_error_page::FilteringBehaviorReason reason, 48 supervised_user_error_page::FilteringBehaviorReason reason,
49 const base::Callback<void(bool)>& callback) { 49 const base::Callback<void(bool)>& callback) {
50 SupervisedUserNavigationObserver* navigation_observer = 50 SupervisedUserNavigationObserver* navigation_observer =
51 SupervisedUserNavigationObserver::FromWebContents(web_contents); 51 SupervisedUserNavigationObserver::FromWebContents(web_contents);
52 if (navigation_observer)
53 navigation_observer->OnRequestBlockedInternal(url);
54 52
55 // Show the interstitial. 53 // Cancel the navigation if there is no navigation observer.
56 const bool initial_page_load = true; 54 if (!navigation_observer) {
57 SupervisedUserInterstitial::Show(web_contents, url, reason, initial_page_load, 55 callback.Run(false);
58 callback); 56 return;
57 }
58
59 navigation_observer->OnRequestBlockedInternal(url, reason, callback);
59 } 60 }
60 61
61 void SupervisedUserNavigationObserver::DidFinishNavigation( 62 void SupervisedUserNavigationObserver::DidFinishNavigation(
62 content::NavigationHandle* navigation_handle) { 63 content::NavigationHandle* navigation_handle) {
63 // Only filter same page navigations (eg. pushState/popState); others will 64 // Only filter same page navigations (eg. pushState/popState); others will
64 // have been filtered by the ResourceThrottle. 65 // have been filtered by the NavigationThrottle.
65 if (!navigation_handle->IsSameDocument()) 66 if (!navigation_handle->IsSameDocument())
66 return; 67 return;
67 68
68 if (!navigation_handle->IsInMainFrame()) 69 if (!navigation_handle->IsInMainFrame())
69 return; 70 return;
70 71
71 url_filter_->GetFilteringBehaviorForURLWithAsyncChecks( 72 url_filter_->GetFilteringBehaviorForURLWithAsyncChecks(
72 web_contents()->GetLastCommittedURL(), 73 web_contents()->GetLastCommittedURL(),
73 base::Bind(&SupervisedUserNavigationObserver::URLFilterCheckCallback, 74 base::Bind(&SupervisedUserNavigationObserver::URLFilterCheckCallback,
74 weak_ptr_factory_.GetWeakPtr(), 75 weak_ptr_factory_.GetWeakPtr(),
75 navigation_handle->GetURL())); 76 navigation_handle->GetURL()));
76 } 77 }
77 78
78 void SupervisedUserNavigationObserver::OnURLFilterChanged() { 79 void SupervisedUserNavigationObserver::OnURLFilterChanged() {
79 url_filter_->GetFilteringBehaviorForURLWithAsyncChecks( 80 url_filter_->GetFilteringBehaviorForURLWithAsyncChecks(
80 web_contents()->GetLastCommittedURL(), 81 web_contents()->GetLastCommittedURL(),
81 base::Bind(&SupervisedUserNavigationObserver::URLFilterCheckCallback, 82 base::Bind(&SupervisedUserNavigationObserver::URLFilterCheckCallback,
82 weak_ptr_factory_.GetWeakPtr(), 83 weak_ptr_factory_.GetWeakPtr(),
83 web_contents()->GetLastCommittedURL())); 84 web_contents()->GetLastCommittedURL()));
84 } 85 }
85 86
86 void SupervisedUserNavigationObserver::OnRequestBlockedInternal( 87 void SupervisedUserNavigationObserver::OnRequestBlockedInternal(
87 const GURL& url) { 88 const GURL& url,
89 supervised_user_error_page::FilteringBehaviorReason reason,
90 const base::Callback<void(bool)>& callback) {
88 Time timestamp = Time::Now(); // TODO(bauerb): Use SaneTime when available. 91 Time timestamp = Time::Now(); // TODO(bauerb): Use SaneTime when available.
89 // Create a history entry for the attempt and mark it as such. 92 // Create a history entry for the attempt and mark it as such.
90 history::HistoryAddPageArgs add_page_args( 93 history::HistoryAddPageArgs add_page_args(
91 url, timestamp, history::ContextIDForWebContents(web_contents()), 0, url, 94 url, timestamp, history::ContextIDForWebContents(web_contents()), 0, url,
92 history::RedirectList(), ui::PAGE_TRANSITION_BLOCKED, 95 history::RedirectList(), ui::PAGE_TRANSITION_BLOCKED,
93 history::SOURCE_BROWSED, false, true); 96 history::SOURCE_BROWSED, false, true);
94 97
95 // Add the entry to the history database. 98 // Add the entry to the history database.
96 Profile* profile = 99 Profile* profile =
97 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); 100 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
98 history::HistoryService* history_service = 101 history::HistoryService* history_service =
99 HistoryServiceFactory::GetForProfile(profile, 102 HistoryServiceFactory::GetForProfile(profile,
100 ServiceAccessType::IMPLICIT_ACCESS); 103 ServiceAccessType::IMPLICIT_ACCESS);
101 104
102 // |history_service| is null if saving history is disabled. 105 // |history_service| is null if saving history is disabled.
103 if (history_service) 106 if (history_service)
104 history_service->AddPage(add_page_args); 107 history_service->AddPage(add_page_args);
105 108
106 std::unique_ptr<NavigationEntry> entry = NavigationEntry::Create(); 109 std::unique_ptr<NavigationEntry> entry = NavigationEntry::Create();
107 entry->SetVirtualURL(url); 110 entry->SetVirtualURL(url);
108 entry->SetTimestamp(timestamp); 111 entry->SetTimestamp(timestamp);
109 auto serialized_entry = base::MakeUnique<sessions::SerializedNavigationEntry>( 112 auto serialized_entry = base::MakeUnique<sessions::SerializedNavigationEntry>(
110 sessions::ContentSerializedNavigationBuilder::FromNavigationEntry( 113 sessions::ContentSerializedNavigationBuilder::FromNavigationEntry(
111 blocked_navigations_.size(), *entry)); 114 blocked_navigations_.size(), *entry));
112 blocked_navigations_.push_back(std::move(serialized_entry)); 115 blocked_navigations_.push_back(std::move(serialized_entry));
113 supervised_user_service_->DidBlockNavigation(web_contents()); 116 supervised_user_service_->DidBlockNavigation(web_contents());
117
118 // Show the interstitial.
119 const bool initial_page_load = true;
120 MaybeShowInterstitial(url, reason, initial_page_load, callback);
114 } 121 }
115 122
116 void SupervisedUserNavigationObserver::URLFilterCheckCallback( 123 void SupervisedUserNavigationObserver::URLFilterCheckCallback(
117 const GURL& url, 124 const GURL& url,
118 SupervisedUserURLFilter::FilteringBehavior behavior, 125 SupervisedUserURLFilter::FilteringBehavior behavior,
119 supervised_user_error_page::FilteringBehaviorReason reason, 126 supervised_user_error_page::FilteringBehaviorReason reason,
120 bool uncertain) { 127 bool uncertain) {
121 // If the page has been changed in the meantime, we can exit. 128 // If the page has been changed in the meantime, we can exit.
122 if (url != web_contents()->GetLastCommittedURL()) 129 if (url != web_contents()->GetLastCommittedURL())
123 return; 130 return;
124 131
125 const bool initial_page_load = false;
126 if (behavior == SupervisedUserURLFilter::FilteringBehavior::BLOCK) { 132 if (behavior == SupervisedUserURLFilter::FilteringBehavior::BLOCK) {
127 SupervisedUserInterstitial::Show(web_contents(), url, reason, 133 const bool initial_page_load = false;
128 initial_page_load, 134 MaybeShowInterstitial(url, reason, initial_page_load,
129 base::Callback<void(bool)>()); 135 base::Callback<void(bool)>());
130 } 136 }
131 } 137 }
138
139 void SupervisedUserNavigationObserver::MaybeShowInterstitial(
140 const GURL& url,
141 supervised_user_error_page::FilteringBehaviorReason reason,
142 bool initial_page_load,
143 const base::Callback<void(bool)>& callback) {
144 if (is_showing_interstitial_)
145 return;
146
147 is_showing_interstitial_ = true;
148 base::Callback<void(bool)> wrapped_callback =
149 base::Bind(&SupervisedUserNavigationObserver::OnInterstitialResult,
150 weak_ptr_factory_.GetWeakPtr(), callback);
151 SupervisedUserInterstitial::Show(web_contents(), url, reason,
152 initial_page_load, wrapped_callback);
153 }
154
155 void SupervisedUserNavigationObserver::OnInterstitialResult(
156 const base::Callback<void(bool)>& callback,
157 bool result) {
158 is_showing_interstitial_ = false;
159 if (callback)
160 callback.Run(result);
161 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698