| 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 "chrome/browser/history/history_service_factory.h" | 9 #include "chrome/browser/history/history_service_factory.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/supervised_user/supervised_user_interstitial.h" | 11 #include "chrome/browser/supervised_user/supervised_user_interstitial.h" |
| 12 #include "chrome/browser/supervised_user/supervised_user_service.h" | 12 #include "chrome/browser/supervised_user/supervised_user_service.h" |
| 13 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" | 13 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" |
| 14 #include "chrome/browser/tab_contents/tab_util.h" | 14 #include "chrome/browser/tab_contents/tab_util.h" |
| 15 #include "components/history/content/browser/history_context_helper.h" | 15 #include "components/history/content/browser/history_context_helper.h" |
| 16 #include "components/history/core/browser/history_service.h" | 16 #include "components/history/core/browser/history_service.h" |
| 17 #include "components/history/core/browser/history_types.h" | 17 #include "components/history/core/browser/history_types.h" |
| 18 #include "components/sessions/content/content_serialized_navigation_builder.h" |
| 18 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 19 #include "content/public/browser/navigation_entry.h" | 20 #include "content/public/browser/navigation_entry.h" |
| 20 | 21 |
| 21 using base::Time; | 22 using base::Time; |
| 22 using content::NavigationEntry; | 23 using content::NavigationEntry; |
| 23 | 24 |
| 24 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SupervisedUserNavigationObserver); | 25 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SupervisedUserNavigationObserver); |
| 25 | 26 |
| 26 SupervisedUserNavigationObserver::~SupervisedUserNavigationObserver() { | 27 SupervisedUserNavigationObserver::~SupervisedUserNavigationObserver() { |
| 27 supervised_user_service_->RemoveObserver(this); | 28 supervised_user_service_->RemoveObserver(this); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 HistoryServiceFactory::GetForProfile(profile, | 79 HistoryServiceFactory::GetForProfile(profile, |
| 79 ServiceAccessType::IMPLICIT_ACCESS); | 80 ServiceAccessType::IMPLICIT_ACCESS); |
| 80 | 81 |
| 81 // |history_service| is null if saving history is disabled. | 82 // |history_service| is null if saving history is disabled. |
| 82 if (history_service) | 83 if (history_service) |
| 83 history_service->AddPage(add_page_args); | 84 history_service->AddPage(add_page_args); |
| 84 | 85 |
| 85 scoped_ptr<NavigationEntry> entry(NavigationEntry::Create()); | 86 scoped_ptr<NavigationEntry> entry(NavigationEntry::Create()); |
| 86 entry->SetVirtualURL(url); | 87 entry->SetVirtualURL(url); |
| 87 entry->SetTimestamp(timestamp); | 88 entry->SetTimestamp(timestamp); |
| 88 blocked_navigations_.push_back(entry.release()); | 89 scoped_ptr<sessions::SerializedNavigationEntry> serialized_entry( |
| 90 new sessions::SerializedNavigationEntry()); |
| 91 *serialized_entry = |
| 92 sessions::ContentSerializedNavigationBuilder::FromNavigationEntry( |
| 93 blocked_navigations_.size(), *entry); |
| 94 blocked_navigations_.push_back(serialized_entry.release()); |
| 89 supervised_user_service_->DidBlockNavigation(web_contents_); | 95 supervised_user_service_->DidBlockNavigation(web_contents_); |
| 90 } | 96 } |
| 91 | 97 |
| 92 void SupervisedUserNavigationObserver::OnURLFilterChanged() { | 98 void SupervisedUserNavigationObserver::OnURLFilterChanged() { |
| 93 url_filter_->GetFilteringBehaviorForURLWithAsyncChecks( | 99 url_filter_->GetFilteringBehaviorForURLWithAsyncChecks( |
| 94 web_contents_->GetLastCommittedURL(), | 100 web_contents_->GetLastCommittedURL(), |
| 95 base::Bind(&SupervisedUserNavigationObserver::URLFilterCheckCallback, | 101 base::Bind(&SupervisedUserNavigationObserver::URLFilterCheckCallback, |
| 96 weak_ptr_factory_.GetWeakPtr(), | 102 weak_ptr_factory_.GetWeakPtr(), |
| 97 web_contents_->GetLastCommittedURL())); | 103 web_contents_->GetLastCommittedURL())); |
| 98 } | 104 } |
| 99 | 105 |
| 100 void SupervisedUserNavigationObserver::URLFilterCheckCallback( | 106 void SupervisedUserNavigationObserver::URLFilterCheckCallback( |
| 101 const GURL& url, | 107 const GURL& url, |
| 102 SupervisedUserURLFilter::FilteringBehavior behavior, | 108 SupervisedUserURLFilter::FilteringBehavior behavior, |
| 103 SupervisedUserURLFilter::FilteringBehaviorReason reason, | 109 SupervisedUserURLFilter::FilteringBehaviorReason reason, |
| 104 bool uncertain) { | 110 bool uncertain) { |
| 105 // If the page has been changed in the meantime, we can exit. | 111 // If the page has been changed in the meantime, we can exit. |
| 106 if (url != web_contents_->GetLastCommittedURL()) | 112 if (url != web_contents_->GetLastCommittedURL()) |
| 107 return; | 113 return; |
| 108 | 114 |
| 109 if (behavior == SupervisedUserURLFilter::FilteringBehavior::BLOCK) { | 115 if (behavior == SupervisedUserURLFilter::FilteringBehavior::BLOCK) { |
| 110 SupervisedUserInterstitial::Show(web_contents_, url, reason, | 116 SupervisedUserInterstitial::Show(web_contents_, url, reason, |
| 111 base::Callback<void(bool)>()); | 117 base::Callback<void(bool)>()); |
| 112 } | 118 } |
| 113 } | 119 } |
| OLD | NEW |