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

Side by Side Diff: chrome/browser/managed_mode/managed_mode_interstitial.cc

Issue 23533014: Watch for filtering pref changes in ManagedModeInterstitial and unblock requests if they become… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: test Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/managed_mode/managed_mode_interstitial.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
Pam (message me for reviews) 2013/09/04 09:56:59 missing .
Bernhard Bauer 2013/09/04 11:48:35 Done.
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
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 DCHECK(ShouldProceed());
Pam (message me for reviews) 2013/09/04 09:56:59 Should we just crash? I could imagine some situati
Bernhard Bauer 2013/09/04 11:48:35 Well, this is really one of these "this cannot hap
Pam (message me for reviews) 2013/09/05 10:13:52 Keeping going somehow even though something unexpe
Bernhard Bauer 2013/09/05 12:49:10 What I meant by handling was that a CHECK results
153 DispatchContinueRequest(true);
154 }
129 155
130 void ManagedModeInterstitial::OnDontProceed() { 156 void ManagedModeInterstitial::OnDontProceed() {
131 DispatchContinueRequest(false); 157 DispatchContinueRequest(false);
132 } 158 }
133 159
160 bool ManagedModeInterstitial::ShouldProceed() {
161 Profile* profile =
162 Profile::FromBrowserContext(web_contents_->GetBrowserContext());
163 ManagedUserService* managed_user_service =
164 ManagedUserServiceFactory::GetForProfile(profile);
165 ManagedModeURLFilter* url_filter =
166 managed_user_service->GetURLFilterForUIThread();
167 return url_filter->GetFilteringBehaviorForURL(url_) !=
168 ManagedModeURLFilter::BLOCK;
169 }
170
171 void ManagedModeInterstitial::OnFilteringPrefsChanged() {
172 if (ShouldProceed())
173 interstitial_page_->Proceed();
174 }
175
134 void ManagedModeInterstitial::DispatchContinueRequest(bool continue_request) { 176 void ManagedModeInterstitial::DispatchContinueRequest(bool continue_request) {
135 BrowserThread::PostTask( 177 BrowserThread::PostTask(
136 BrowserThread::IO, FROM_HERE, base::Bind(callback_, continue_request)); 178 BrowserThread::IO, FROM_HERE, base::Bind(callback_, continue_request));
137 } 179 }
OLDNEW
« no previous file with comments | « chrome/browser/managed_mode/managed_mode_interstitial.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698