| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/managed_mode/managed_mode_interstitial.h" | 5 #include "chrome/browser/managed_mode/managed_mode_interstitial.h" |
| 6 | 6 |
| 7 #include "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/browser/managed_mode/managed_user_service.h" | 12 #include "chrome/browser/managed_mode/managed_user_service.h" |
| 13 #include "chrome/browser/managed_mode/managed_user_service_factory.h" | 13 #include "chrome/browser/managed_mode/managed_user_service_factory.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
| 16 #include "chrome/common/url_constants.h" | 16 #include "chrome/common/url_constants.h" |
| 17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 18 #include "content/public/browser/interstitial_page.h" | 18 #include "content/public/browser/interstitial_page.h" |
| 19 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
| 20 #include "content/public/browser/web_contents_delegate.h" | |
| 21 #include "content/public/browser/web_ui.h" | 20 #include "content/public/browser/web_ui.h" |
| 22 #include "grit/browser_resources.h" | 21 #include "grit/browser_resources.h" |
| 23 #include "grit/generated_resources.h" | 22 #include "grit/generated_resources.h" |
| 24 #include "net/base/net_util.h" | 23 #include "net/base/net_util.h" |
| 25 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
| 26 #include "ui/base/resource/resource_bundle.h" | 25 #include "ui/base/resource/resource_bundle.h" |
| 27 #include "ui/webui/jstemplate_builder.h" | 26 #include "ui/webui/jstemplate_builder.h" |
| 28 #include "ui/webui/web_ui_util.h" | 27 #include "ui/webui/web_ui_util.h" |
| 29 | 28 |
| 30 using content::BrowserThread; | 29 using content::BrowserThread; |
| 31 | 30 |
| 32 ManagedModeInterstitial::ManagedModeInterstitial( | 31 ManagedModeInterstitial::ManagedModeInterstitial( |
| 33 content::WebContents* web_contents, | 32 content::WebContents* web_contents, |
| 34 const GURL& url, | 33 const GURL& url, |
| 35 const base::Callback<void(bool)>& callback) | 34 const base::Callback<void(bool)>& callback) |
| 36 : web_contents_(web_contents), | 35 : web_contents_(web_contents), |
| 36 interstitial_page_(NULL), |
| 37 url_(url), | 37 url_(url), |
| 38 weak_ptr_factory_(this), | |
| 39 callback_(callback) { | 38 callback_(callback) { |
| 39 if (ShouldProceed()) { |
| 40 // It can happen that the site was only allowed very recently and the URL |
| 41 // filter on the IO thread had not been updated yet. Proceed with the |
| 42 // request without showing the interstitial. |
| 43 DispatchContinueRequest(true); |
| 44 delete this; |
| 45 return; |
| 46 } |
| 47 |
| 48 // TODO(bauerb): Extract an observer callback on ManagedUserService for this. |
| 40 Profile* profile = | 49 Profile* profile = |
| 41 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 50 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 42 languages_ = profile->GetPrefs()->GetString(prefs::kAcceptLanguages); | 51 PrefService* prefs = profile->GetPrefs(); |
| 52 pref_change_registrar_.Init(prefs); |
| 53 pref_change_registrar_.Add( |
| 54 prefs::kDefaultManagedModeFilteringBehavior, |
| 55 base::Bind(&ManagedModeInterstitial::OnFilteringPrefsChanged, |
| 56 base::Unretained(this))); |
| 57 pref_change_registrar_.Add( |
| 58 prefs::kManagedModeManualHosts, |
| 59 base::Bind(&ManagedModeInterstitial::OnFilteringPrefsChanged, |
| 60 base::Unretained(this))); |
| 61 pref_change_registrar_.Add( |
| 62 prefs::kManagedModeManualURLs, |
| 63 base::Bind(&ManagedModeInterstitial::OnFilteringPrefsChanged, |
| 64 base::Unretained(this))); |
| 43 | 65 |
| 66 languages_ = prefs->GetString(prefs::kAcceptLanguages); |
| 44 interstitial_page_ = | 67 interstitial_page_ = |
| 45 content::InterstitialPage::Create(web_contents, true, url_, this); | 68 content::InterstitialPage::Create(web_contents, true, url_, this); |
| 46 interstitial_page_->Show(); | 69 interstitial_page_->Show(); |
| 47 } | 70 } |
| 48 | 71 |
| 49 ManagedModeInterstitial::~ManagedModeInterstitial() {} | 72 ManagedModeInterstitial::~ManagedModeInterstitial() {} |
| 50 | 73 |
| 51 std::string ManagedModeInterstitial::GetHTMLContents() { | 74 std::string ManagedModeInterstitial::GetHTMLContents() { |
| 52 DictionaryValue strings; | 75 DictionaryValue strings; |
| 53 strings.SetString("blockPageTitle", | 76 strings.SetString("blockPageTitle", |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 ManagedUserServiceFactory::GetForProfile(profile); | 141 ManagedUserServiceFactory::GetForProfile(profile); |
| 119 managed_user_service->AddAccessRequest(url_); | 142 managed_user_service->AddAccessRequest(url_); |
| 120 DVLOG(1) << "Sent access request for " << url_.spec(); | 143 DVLOG(1) << "Sent access request for " << url_.spec(); |
| 121 | 144 |
| 122 return; | 145 return; |
| 123 } | 146 } |
| 124 | 147 |
| 125 NOTREACHED(); | 148 NOTREACHED(); |
| 126 } | 149 } |
| 127 | 150 |
| 128 void ManagedModeInterstitial::OnProceed() { NOTREACHED(); } | 151 void ManagedModeInterstitial::OnProceed() { |
| 152 // CHECK instead of DCHECK as defense in depth in case we'd accidentally |
| 153 // proceed on a blocked page. |
| 154 CHECK(ShouldProceed()); |
| 155 DispatchContinueRequest(true); |
| 156 } |
| 129 | 157 |
| 130 void ManagedModeInterstitial::OnDontProceed() { | 158 void ManagedModeInterstitial::OnDontProceed() { |
| 131 DispatchContinueRequest(false); | 159 DispatchContinueRequest(false); |
| 132 } | 160 } |
| 133 | 161 |
| 162 bool ManagedModeInterstitial::ShouldProceed() { |
| 163 Profile* profile = |
| 164 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); |
| 165 ManagedUserService* managed_user_service = |
| 166 ManagedUserServiceFactory::GetForProfile(profile); |
| 167 ManagedModeURLFilter* url_filter = |
| 168 managed_user_service->GetURLFilterForUIThread(); |
| 169 return url_filter->GetFilteringBehaviorForURL(url_) != |
| 170 ManagedModeURLFilter::BLOCK; |
| 171 } |
| 172 |
| 173 void ManagedModeInterstitial::OnFilteringPrefsChanged() { |
| 174 if (ShouldProceed()) |
| 175 interstitial_page_->Proceed(); |
| 176 } |
| 177 |
| 134 void ManagedModeInterstitial::DispatchContinueRequest(bool continue_request) { | 178 void ManagedModeInterstitial::DispatchContinueRequest(bool continue_request) { |
| 135 BrowserThread::PostTask( | 179 BrowserThread::PostTask( |
| 136 BrowserThread::IO, FROM_HERE, base::Bind(callback_, continue_request)); | 180 BrowserThread::IO, FROM_HERE, base::Bind(callback_, continue_request)); |
| 137 } | 181 } |
| OLD | NEW |