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

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

Issue 335833003: Rename "managed (mode|user)" to "supervised user" (part 2) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review comments (+ a few other cleanups) Created 6 years, 6 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
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/supervised_user/supervised_user_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/infobars/infobar_service.h" 12 #include "chrome/browser/infobars/infobar_service.h"
13 #include "chrome/browser/managed_mode/managed_user_service.h"
14 #include "chrome/browser/managed_mode/managed_user_service_factory.h"
15 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/supervised_user/supervised_user_service.h"
15 #include "chrome/browser/supervised_user/supervised_user_service_factory.h"
16 #include "chrome/common/pref_names.h" 16 #include "chrome/common/pref_names.h"
17 #include "components/infobars/core/infobar.h" 17 #include "components/infobars/core/infobar.h"
18 #include "components/infobars/core/infobar_delegate.h" 18 #include "components/infobars/core/infobar_delegate.h"
19 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
20 #include "content/public/browser/interstitial_page.h" 20 #include "content/public/browser/interstitial_page.h"
21 #include "content/public/browser/navigation_controller.h" 21 #include "content/public/browser/navigation_controller.h"
22 #include "content/public/browser/navigation_details.h" 22 #include "content/public/browser/navigation_details.h"
23 #include "content/public/browser/navigation_entry.h" 23 #include "content/public/browser/navigation_entry.h"
24 #include "content/public/browser/web_contents.h" 24 #include "content/public/browser/web_contents.h"
25 #include "content/public/browser/web_ui.h" 25 #include "content/public/browser/web_ui.h"
26 #include "grit/browser_resources.h" 26 #include "grit/browser_resources.h"
27 #include "grit/generated_resources.h" 27 #include "grit/generated_resources.h"
28 #include "net/base/net_util.h" 28 #include "net/base/net_util.h"
29 #include "ui/base/l10n/l10n_util.h" 29 #include "ui/base/l10n/l10n_util.h"
30 #include "ui/base/resource/resource_bundle.h" 30 #include "ui/base/resource/resource_bundle.h"
31 #include "ui/base/webui/jstemplate_builder.h" 31 #include "ui/base/webui/jstemplate_builder.h"
32 #include "ui/base/webui/web_ui_util.h" 32 #include "ui/base/webui/web_ui_util.h"
33 33
34 using content::BrowserThread; 34 using content::BrowserThread;
35 35
36 // static 36 // static
37 void ManagedModeInterstitial::Show(content::WebContents* web_contents, 37 void SupervisedUserInterstitial::Show(content::WebContents* web_contents,
38 const GURL& url, 38 const GURL& url,
39 const base::Callback<void(bool)>& callback) { 39 const base::Callback<void(bool)>& callback) {
40 ManagedModeInterstitial* interstitial = 40 SupervisedUserInterstitial* interstitial =
41 new ManagedModeInterstitial(web_contents, url, callback); 41 new SupervisedUserInterstitial(web_contents, url, callback);
42 42
43 // If Init() does not complete fully, immediately delete the interstitial. 43 // If Init() does not complete fully, immediately delete the interstitial.
44 if (!interstitial->Init()) 44 if (!interstitial->Init())
45 delete interstitial; 45 delete interstitial;
46 // Otherwise |interstitial_page_| is responsible for deleting it. 46 // Otherwise |interstitial_page_| is responsible for deleting it.
47 } 47 }
48 48
49 ManagedModeInterstitial::ManagedModeInterstitial( 49 SupervisedUserInterstitial::SupervisedUserInterstitial(
50 content::WebContents* web_contents, 50 content::WebContents* web_contents,
51 const GURL& url, 51 const GURL& url,
52 const base::Callback<void(bool)>& callback) 52 const base::Callback<void(bool)>& callback)
53 : web_contents_(web_contents), 53 : web_contents_(web_contents),
54 interstitial_page_(NULL), 54 interstitial_page_(NULL),
55 url_(url), 55 url_(url),
56 callback_(callback) {} 56 callback_(callback) {}
57 57
58 ManagedModeInterstitial::~ManagedModeInterstitial() {} 58 SupervisedUserInterstitial::~SupervisedUserInterstitial() {}
59 59
60 bool ManagedModeInterstitial::Init() { 60 bool SupervisedUserInterstitial::Init() {
61 if (ShouldProceed()) { 61 if (ShouldProceed()) {
62 // It can happen that the site was only allowed very recently and the URL 62 // It can happen that the site was only allowed very recently and the URL
63 // filter on the IO thread had not been updated yet. Proceed with the 63 // filter on the IO thread had not been updated yet. Proceed with the
64 // request without showing the interstitial. 64 // request without showing the interstitial.
65 DispatchContinueRequest(true); 65 DispatchContinueRequest(true);
66 return false; 66 return false;
67 } 67 }
68 68
69 InfoBarService* service = InfoBarService::FromWebContents(web_contents_); 69 InfoBarService* service = InfoBarService::FromWebContents(web_contents_);
70 if (service) { 70 if (service) {
(...skipping 14 matching lines...) Expand all
85 details.type = content::NAVIGATION_TYPE_NEW_PAGE; 85 details.type = content::NAVIGATION_TYPE_NEW_PAGE;
86 for (int i = service->infobar_count() - 1; i >= 0; --i) { 86 for (int i = service->infobar_count() - 1; i >= 0; --i) {
87 infobars::InfoBar* infobar = service->infobar_at(i); 87 infobars::InfoBar* infobar = service->infobar_at(i);
88 if (infobar->delegate()->ShouldExpire( 88 if (infobar->delegate()->ShouldExpire(
89 InfoBarService::NavigationDetailsFromLoadCommittedDetails( 89 InfoBarService::NavigationDetailsFromLoadCommittedDetails(
90 details))) 90 details)))
91 service->RemoveInfoBar(infobar); 91 service->RemoveInfoBar(infobar);
92 } 92 }
93 } 93 }
94 94
95 // TODO(bauerb): Extract an observer callback on ManagedUserService for this. 95 // TODO(bauerb): Extract an observer callback on SupervisedUserService for
96 // this.
96 Profile* profile = 97 Profile* profile =
97 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); 98 Profile::FromBrowserContext(web_contents_->GetBrowserContext());
98 PrefService* prefs = profile->GetPrefs(); 99 PrefService* prefs = profile->GetPrefs();
99 pref_change_registrar_.Init(prefs); 100 pref_change_registrar_.Init(prefs);
100 pref_change_registrar_.Add( 101 pref_change_registrar_.Add(
101 prefs::kDefaultSupervisedUserFilteringBehavior, 102 prefs::kDefaultSupervisedUserFilteringBehavior,
102 base::Bind(&ManagedModeInterstitial::OnFilteringPrefsChanged, 103 base::Bind(&SupervisedUserInterstitial::OnFilteringPrefsChanged,
103 base::Unretained(this))); 104 base::Unretained(this)));
104 pref_change_registrar_.Add( 105 pref_change_registrar_.Add(
105 prefs::kSupervisedUserManualHosts, 106 prefs::kSupervisedUserManualHosts,
106 base::Bind(&ManagedModeInterstitial::OnFilteringPrefsChanged, 107 base::Bind(&SupervisedUserInterstitial::OnFilteringPrefsChanged,
107 base::Unretained(this))); 108 base::Unretained(this)));
108 pref_change_registrar_.Add( 109 pref_change_registrar_.Add(
109 prefs::kSupervisedUserManualURLs, 110 prefs::kSupervisedUserManualURLs,
110 base::Bind(&ManagedModeInterstitial::OnFilteringPrefsChanged, 111 base::Bind(&SupervisedUserInterstitial::OnFilteringPrefsChanged,
111 base::Unretained(this))); 112 base::Unretained(this)));
112 113
113 languages_ = prefs->GetString(prefs::kAcceptLanguages); 114 languages_ = prefs->GetString(prefs::kAcceptLanguages);
114 interstitial_page_ = 115 interstitial_page_ =
115 content::InterstitialPage::Create(web_contents_, true, url_, this); 116 content::InterstitialPage::Create(web_contents_, true, url_, this);
116 interstitial_page_->Show(); 117 interstitial_page_->Show();
117 118
118 return true; 119 return true;
119 } 120 }
120 121
121 std::string ManagedModeInterstitial::GetHTMLContents() { 122 std::string SupervisedUserInterstitial::GetHTMLContents() {
122 base::DictionaryValue strings; 123 base::DictionaryValue strings;
123 strings.SetString("blockPageTitle", 124 strings.SetString("blockPageTitle",
124 l10n_util::GetStringUTF16(IDS_BLOCK_INTERSTITIAL_TITLE)); 125 l10n_util::GetStringUTF16(IDS_BLOCK_INTERSTITIAL_TITLE));
125 126
126 Profile* profile = 127 Profile* profile =
127 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); 128 Profile::FromBrowserContext(web_contents_->GetBrowserContext());
128 ManagedUserService* managed_user_service = 129 SupervisedUserService* supervised_user_service =
129 ManagedUserServiceFactory::GetForProfile(profile); 130 SupervisedUserServiceFactory::GetForProfile(profile);
130 131
131 bool allow_access_requests = managed_user_service->AccessRequestsEnabled(); 132 bool allow_access_requests = supervised_user_service->AccessRequestsEnabled();
132 strings.SetBoolean("allowAccessRequests", allow_access_requests); 133 strings.SetBoolean("allowAccessRequests", allow_access_requests);
133 134
134 base::string16 custodian = 135 base::string16 custodian =
135 base::UTF8ToUTF16(managed_user_service->GetCustodianName()); 136 base::UTF8ToUTF16(supervised_user_service->GetCustodianName());
136 strings.SetString( 137 strings.SetString(
137 "blockPageMessage", 138 "blockPageMessage",
138 allow_access_requests 139 allow_access_requests
139 ? l10n_util::GetStringFUTF16(IDS_BLOCK_INTERSTITIAL_MESSAGE, 140 ? l10n_util::GetStringFUTF16(IDS_BLOCK_INTERSTITIAL_MESSAGE,
140 custodian) 141 custodian)
141 : l10n_util::GetStringUTF16( 142 : l10n_util::GetStringUTF16(
142 IDS_BLOCK_INTERSTITIAL_MESSAGE_ACCESS_REQUESTS_DISABLED)); 143 IDS_BLOCK_INTERSTITIAL_MESSAGE_ACCESS_REQUESTS_DISABLED));
143 144
144 strings.SetString("backButton", l10n_util::GetStringUTF16(IDS_BACK_BUTTON)); 145 strings.SetString("backButton", l10n_util::GetStringUTF16(IDS_BACK_BUTTON));
145 strings.SetString( 146 strings.SetString(
146 "requestAccessButton", 147 "requestAccessButton",
147 l10n_util::GetStringUTF16(IDS_BLOCK_INTERSTITIAL_REQUEST_ACCESS_BUTTON)); 148 l10n_util::GetStringUTF16(IDS_BLOCK_INTERSTITIAL_REQUEST_ACCESS_BUTTON));
148 149
149 strings.SetString( 150 strings.SetString(
150 "requestSentMessage", 151 "requestSentMessage",
151 l10n_util::GetStringFUTF16(IDS_BLOCK_INTERSTITIAL_REQUEST_SENT_MESSAGE, 152 l10n_util::GetStringFUTF16(IDS_BLOCK_INTERSTITIAL_REQUEST_SENT_MESSAGE,
152 custodian)); 153 custodian));
153 154
154 webui::SetFontAndTextDirection(&strings); 155 webui::SetFontAndTextDirection(&strings);
155 156
156 base::StringPiece html(ResourceBundle::GetSharedInstance().GetRawDataResource( 157 base::StringPiece html(ResourceBundle::GetSharedInstance().GetRawDataResource(
157 IDR_MANAGED_MODE_BLOCK_INTERSTITIAL_HTML)); 158 IDR_MANAGED_MODE_BLOCK_INTERSTITIAL_HTML));
158 159
159 webui::UseVersion2 version; 160 webui::UseVersion2 version;
160 return webui::GetI18nTemplateHtml(html, &strings); 161 return webui::GetI18nTemplateHtml(html, &strings);
161 } 162 }
162 163
163 void ManagedModeInterstitial::CommandReceived(const std::string& command) { 164 void SupervisedUserInterstitial::CommandReceived(const std::string& command) {
164 // For use in histograms. 165 // For use in histograms.
165 enum Commands { 166 enum Commands {
166 PREVIEW, 167 PREVIEW,
167 BACK, 168 BACK,
168 NTP, 169 NTP,
169 ACCESS_REQUEST, 170 ACCESS_REQUEST,
170 HISTOGRAM_BOUNDING_VALUE 171 HISTOGRAM_BOUNDING_VALUE
171 }; 172 };
172 173
173 if (command == "\"back\"") { 174 if (command == "\"back\"") {
174 UMA_HISTOGRAM_ENUMERATION("ManagedMode.BlockingInterstitialCommand", 175 UMA_HISTOGRAM_ENUMERATION("ManagedMode.BlockingInterstitialCommand",
175 BACK, 176 BACK,
176 HISTOGRAM_BOUNDING_VALUE); 177 HISTOGRAM_BOUNDING_VALUE);
177 interstitial_page_->DontProceed(); 178 interstitial_page_->DontProceed();
178 return; 179 return;
179 } 180 }
180 181
181 if (command == "\"request\"") { 182 if (command == "\"request\"") {
182 UMA_HISTOGRAM_ENUMERATION("ManagedMode.BlockingInterstitialCommand", 183 UMA_HISTOGRAM_ENUMERATION("ManagedMode.BlockingInterstitialCommand",
183 ACCESS_REQUEST, 184 ACCESS_REQUEST,
184 HISTOGRAM_BOUNDING_VALUE); 185 HISTOGRAM_BOUNDING_VALUE);
185 186
186 Profile* profile = 187 Profile* profile =
187 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); 188 Profile::FromBrowserContext(web_contents_->GetBrowserContext());
188 ManagedUserService* managed_user_service = 189 SupervisedUserService* supervised_user_service =
189 ManagedUserServiceFactory::GetForProfile(profile); 190 SupervisedUserServiceFactory::GetForProfile(profile);
190 managed_user_service->AddAccessRequest(url_); 191 supervised_user_service->AddAccessRequest(url_);
191 DVLOG(1) << "Sent access request for " << url_.spec(); 192 DVLOG(1) << "Sent access request for " << url_.spec();
192 193
193 return; 194 return;
194 } 195 }
195 196
196 NOTREACHED(); 197 NOTREACHED();
197 } 198 }
198 199
199 void ManagedModeInterstitial::OnProceed() { 200 void SupervisedUserInterstitial::OnProceed() {
200 // CHECK instead of DCHECK as defense in depth in case we'd accidentally 201 // CHECK instead of DCHECK as defense in depth in case we'd accidentally
201 // proceed on a blocked page. 202 // proceed on a blocked page.
202 CHECK(ShouldProceed()); 203 CHECK(ShouldProceed());
203 DispatchContinueRequest(true); 204 DispatchContinueRequest(true);
204 } 205 }
205 206
206 void ManagedModeInterstitial::OnDontProceed() { 207 void SupervisedUserInterstitial::OnDontProceed() {
207 DispatchContinueRequest(false); 208 DispatchContinueRequest(false);
208 } 209 }
209 210
210 bool ManagedModeInterstitial::ShouldProceed() { 211 bool SupervisedUserInterstitial::ShouldProceed() {
211 Profile* profile = 212 Profile* profile =
212 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); 213 Profile::FromBrowserContext(web_contents_->GetBrowserContext());
213 ManagedUserService* managed_user_service = 214 SupervisedUserService* supervised_user_service =
214 ManagedUserServiceFactory::GetForProfile(profile); 215 SupervisedUserServiceFactory::GetForProfile(profile);
215 ManagedModeURLFilter* url_filter = 216 SupervisedUserURLFilter* url_filter =
216 managed_user_service->GetURLFilterForUIThread(); 217 supervised_user_service->GetURLFilterForUIThread();
217 return url_filter->GetFilteringBehaviorForURL(url_) != 218 return url_filter->GetFilteringBehaviorForURL(url_) !=
218 ManagedModeURLFilter::BLOCK; 219 SupervisedUserURLFilter::BLOCK;
219 } 220 }
220 221
221 void ManagedModeInterstitial::OnFilteringPrefsChanged() { 222 void SupervisedUserInterstitial::OnFilteringPrefsChanged() {
222 if (ShouldProceed()) 223 if (ShouldProceed())
223 interstitial_page_->Proceed(); 224 interstitial_page_->Proceed();
224 } 225 }
225 226
226 void ManagedModeInterstitial::DispatchContinueRequest(bool continue_request) { 227 void SupervisedUserInterstitial::DispatchContinueRequest(
228 bool continue_request) {
227 // If there is no history entry to go back to, close the tab instead. 229 // If there is no history entry to go back to, close the tab instead.
228 int nav_entry_count = web_contents_->GetController().GetEntryCount(); 230 int nav_entry_count = web_contents_->GetController().GetEntryCount();
229 if (!continue_request && nav_entry_count == 0) 231 if (!continue_request && nav_entry_count == 0)
230 web_contents_->Close(); 232 web_contents_->Close();
231 233
232 BrowserThread::PostTask( 234 BrowserThread::PostTask(
233 BrowserThread::IO, FROM_HERE, base::Bind(callback_, continue_request)); 235 BrowserThread::IO, FROM_HERE, base::Bind(callback_, continue_request));
234 } 236 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698