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_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/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 supervised_user_service_ = | 171 supervised_user_service_ = |
172 SupervisedUserServiceFactory::GetForProfile(profile); | 172 SupervisedUserServiceFactory::GetForProfile(profile); |
173 url_filter_ = supervised_user_service_->GetURLFilterForUIThread(); | 173 url_filter_ = supervised_user_service_->GetURLFilterForUIThread(); |
174 } | 174 } |
175 | 175 |
176 void SupervisedUserNavigationObserver::WarnInfoBarDismissed() { | 176 void SupervisedUserNavigationObserver::WarnInfoBarDismissed() { |
177 DCHECK(warn_infobar_); | 177 DCHECK(warn_infobar_); |
178 warn_infobar_ = NULL; | 178 warn_infobar_ = NULL; |
179 } | 179 } |
180 | 180 |
181 void SupervisedUserNavigationObserver::ProvisionalChangeToMainFrameUrl( | |
182 const GURL& url, | |
183 content::RenderFrameHost* render_frame_host) { | |
184 SupervisedUserURLFilter::FilteringBehavior behavior = | |
185 url_filter_->GetFilteringBehaviorForURL(url); | |
186 | |
187 if (behavior == SupervisedUserURLFilter::WARN || !warn_infobar_) | |
188 return; | |
189 | |
190 // If we shouldn't have a warn infobar remove it here. | |
191 InfoBarService::FromWebContents(web_contents())->RemoveInfoBar(warn_infobar_); | |
192 warn_infobar_ = NULL; | |
193 } | |
194 | |
195 void SupervisedUserNavigationObserver::DidCommitProvisionalLoadForFrame( | 181 void SupervisedUserNavigationObserver::DidCommitProvisionalLoadForFrame( |
196 content::RenderFrameHost* render_frame_host, | 182 content::RenderFrameHost* render_frame_host, |
197 const GURL& url, | 183 const GURL& url, |
198 content::PageTransition transition_type) { | 184 content::PageTransition transition_type) { |
199 if (render_frame_host->GetParent()) | 185 if (render_frame_host->GetParent()) |
200 return; | 186 return; |
201 | 187 |
202 DVLOG(1) << "DidCommitProvisionalLoadForFrame " << url.spec(); | 188 DVLOG(1) << "DidCommitProvisionalLoadForFrame " << url.spec(); |
203 SupervisedUserURLFilter::FilteringBehavior behavior = | 189 SupervisedUserURLFilter::FilteringBehavior behavior = |
204 url_filter_->GetFilteringBehaviorForURL(url); | 190 url_filter_->GetFilteringBehaviorForURL(url); |
205 | 191 |
206 if (behavior == SupervisedUserURLFilter::WARN && !warn_infobar_) { | 192 if (behavior == SupervisedUserURLFilter::WARN && !warn_infobar_) { |
207 warn_infobar_ = SupervisedUserWarningInfoBarDelegate::Create( | 193 warn_infobar_ = SupervisedUserWarningInfoBarDelegate::Create( |
208 InfoBarService::FromWebContents(web_contents())); | 194 InfoBarService::FromWebContents(web_contents())); |
| 195 } else if (behavior != SupervisedUserURLFilter::WARN && warn_infobar_) { |
| 196 InfoBarService::FromWebContents(web_contents())-> |
| 197 RemoveInfoBar(warn_infobar_); |
| 198 warn_infobar_ = NULL; |
209 } | 199 } |
210 } | 200 } |
211 | 201 |
212 // static | 202 // static |
213 void SupervisedUserNavigationObserver::OnRequestBlocked( | 203 void SupervisedUserNavigationObserver::OnRequestBlocked( |
214 int render_process_host_id, | 204 int render_process_host_id, |
215 int render_view_id, | 205 int render_view_id, |
216 const GURL& url, | 206 const GURL& url, |
217 const base::Callback<void(bool)>& callback) { | 207 const base::Callback<void(bool)>& callback) { |
218 content::WebContents* web_contents = | 208 content::WebContents* web_contents = |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 history_service->AddPage(add_page_args); | 243 history_service->AddPage(add_page_args); |
254 | 244 |
255 scoped_ptr<NavigationEntry> entry(NavigationEntry::Create()); | 245 scoped_ptr<NavigationEntry> entry(NavigationEntry::Create()); |
256 entry->SetVirtualURL(url); | 246 entry->SetVirtualURL(url); |
257 entry->SetTimestamp(timestamp); | 247 entry->SetTimestamp(timestamp); |
258 blocked_navigations_.push_back(entry.release()); | 248 blocked_navigations_.push_back(entry.release()); |
259 SupervisedUserService* supervised_user_service = | 249 SupervisedUserService* supervised_user_service = |
260 SupervisedUserServiceFactory::GetForProfile(profile); | 250 SupervisedUserServiceFactory::GetForProfile(profile); |
261 supervised_user_service->DidBlockNavigation(web_contents()); | 251 supervised_user_service->DidBlockNavigation(web_contents()); |
262 } | 252 } |
OLD | NEW |