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

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

Issue 789703004: Reflect the status of a request for accessing a blacklisted url. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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
OLDNEW
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_interstitial.h" 5 #include "chrome/browser/supervised_user/supervised_user_interstitial.h"
6 6
7 #include "base/memory/weak_ptr.h" 7 #include "base/memory/weak_ptr.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/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "chrome/browser/infobars/infobar_service.h" 13 #include "chrome/browser/infobars/infobar_service.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/supervised_user/supervised_user_service.h" 15 #include "chrome/browser/supervised_user/supervised_user_service.h"
16 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" 16 #include "chrome/browser/supervised_user/supervised_user_service_factory.h"
17 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
18 #include "chrome/grit/generated_resources.h" 18 #include "chrome/grit/generated_resources.h"
19 #include "components/infobars/core/infobar.h" 19 #include "components/infobars/core/infobar.h"
20 #include "components/infobars/core/infobar_delegate.h" 20 #include "components/infobars/core/infobar_delegate.h"
21 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
22 #include "content/public/browser/interstitial_page.h" 22 #include "content/public/browser/interstitial_page.h"
23 #include "content/public/browser/navigation_controller.h" 23 #include "content/public/browser/navigation_controller.h"
24 #include "content/public/browser/navigation_details.h" 24 #include "content/public/browser/navigation_details.h"
25 #include "content/public/browser/navigation_entry.h" 25 #include "content/public/browser/navigation_entry.h"
26 #include "content/public/browser/render_frame_host.h"
27 #include "content/public/browser/render_view_host.h"
26 #include "content/public/browser/web_contents.h" 28 #include "content/public/browser/web_contents.h"
27 #include "content/public/browser/web_contents_user_data.h" 29 #include "content/public/browser/web_contents_user_data.h"
28 #include "content/public/browser/web_ui.h" 30 #include "content/public/browser/web_ui.h"
29 #include "grit/browser_resources.h" 31 #include "grit/browser_resources.h"
30 #include "ui/base/l10n/l10n_util.h" 32 #include "ui/base/l10n/l10n_util.h"
31 #include "ui/base/resource/resource_bundle.h" 33 #include "ui/base/resource/resource_bundle.h"
32 #include "ui/base/webui/jstemplate_builder.h" 34 #include "ui/base/webui/jstemplate_builder.h"
33 #include "ui/base/webui/web_ui_util.h" 35 #include "ui/base/webui/web_ui_util.h"
34 36
35 #if !defined(OS_ANDROID) 37 #if !defined(OS_ANDROID)
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 ? l10n_util::GetStringUTF16( 224 ? l10n_util::GetStringUTF16(
223 SupervisedUserURLFilter::GetBlockMessageID(reason_)) 225 SupervisedUserURLFilter::GetBlockMessageID(reason_))
224 : base::string16()); 226 : base::string16());
225 227
226 strings.SetString("backButton", l10n_util::GetStringUTF16(IDS_BACK_BUTTON)); 228 strings.SetString("backButton", l10n_util::GetStringUTF16(IDS_BACK_BUTTON));
227 strings.SetString("requestAccessButton", l10n_util::GetStringUTF16( 229 strings.SetString("requestAccessButton", l10n_util::GetStringUTF16(
228 is_child_account 230 is_child_account
229 ? IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_ACCESS_BUTTON 231 ? IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_ACCESS_BUTTON
230 : IDS_BLOCK_INTERSTITIAL_REQUEST_ACCESS_BUTTON)); 232 : IDS_BLOCK_INTERSTITIAL_REQUEST_ACCESS_BUTTON));
231 233
232 base::string16 request_sent_message; 234 base::string16 request_sent_message, request_failed_message;
Bernhard Bauer 2014/12/17 17:05:18 Declare each variable on its own line.
khannan 2014/12/17 17:39:09 Done.
233 if (is_child_account) { 235 if (is_child_account) {
234 request_sent_message = l10n_util::GetStringUTF16( 236 request_sent_message = l10n_util::GetStringUTF16(
235 second_custodian.empty() 237 second_custodian.empty()
236 ? IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_SENT_MESSAGE_SINGLE_PARENT 238 ? IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_SENT_MESSAGE_SINGLE_PARENT
237 : IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_SENT_MESSAGE_MULTI_PARENT); 239 : IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_SENT_MESSAGE_MULTI_PARENT);
240 request_failed_message = l10n_util::GetStringUTF16(
Bernhard Bauer 2014/12/17 17:05:18 I think it starts making sense to add another case
khannan 2014/12/17 17:39:09 Done.
241 second_custodian.empty()
242 ? IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_FAILED_MESSAGE_SINGLE_PARENT
243 : IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_FAILED_MESSAGE_MULTI_PARENT);
238 } else { 244 } else {
239 request_sent_message = l10n_util::GetStringFUTF16( 245 request_sent_message = l10n_util::GetStringFUTF16(
240 IDS_BLOCK_INTERSTITIAL_REQUEST_SENT_MESSAGE, custodian); 246 IDS_BLOCK_INTERSTITIAL_REQUEST_SENT_MESSAGE, custodian);
247 request_failed_message = l10n_util::GetStringFUTF16(
248 IDS_BLOCK_INTERSTITIAL_REQUEST_FAILED_MESSAGE, custodian);
241 } 249 }
242 strings.SetString("requestSentMessage", request_sent_message); 250 strings.SetString("requestSentMessage", request_sent_message);
251 strings.SetString("requestFailedMessage", request_failed_message);
243 252
244 webui::SetFontAndTextDirection(&strings); 253 webui::SetFontAndTextDirection(&strings);
245 254
246 base::StringPiece html(ResourceBundle::GetSharedInstance().GetRawDataResource( 255 base::StringPiece html(ResourceBundle::GetSharedInstance().GetRawDataResource(
247 IDR_SUPERVISED_USER_BLOCK_INTERSTITIAL_HTML)); 256 IDR_SUPERVISED_USER_BLOCK_INTERSTITIAL_HTML));
248 257
249 return webui::GetI18nTemplateHtml(html, &strings); 258 return webui::GetI18nTemplateHtml(html, &strings);
250 } 259 }
251 260
252 void SupervisedUserInterstitial::CommandReceived(const std::string& command) { 261 void SupervisedUserInterstitial::CommandReceived(const std::string& command) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 void SupervisedUserInterstitial::OnDontProceed() { 305 void SupervisedUserInterstitial::OnDontProceed() {
297 DispatchContinueRequest(false); 306 DispatchContinueRequest(false);
298 } 307 }
299 308
300 void SupervisedUserInterstitial::OnURLFilterChanged() { 309 void SupervisedUserInterstitial::OnURLFilterChanged() {
301 if (ShouldProceed()) 310 if (ShouldProceed())
302 interstitial_page_->Proceed(); 311 interstitial_page_->Proceed();
303 } 312 }
304 313
305 void SupervisedUserInterstitial::OnAccessRequestAdded(bool success) { 314 void SupervisedUserInterstitial::OnAccessRequestAdded(bool success) {
306 // TODO(akuegel): Figure out how to show the result of issuing the permission
307 // request in the UI. Currently, we assume the permission request was created
308 // successfully.
309 VLOG(1) << "Sent access request for " << url_.spec() 315 VLOG(1) << "Sent access request for " << url_.spec()
310 << (success ? " successfully" : " unsuccessfully"); 316 << (success ? " successfully" : " unsuccessfully");
317 std::stringstream jsFunc;
Bernhard Bauer 2014/12/17 17:05:18 Don't use string streams. Just concatenate the str
khannan 2014/12/17 17:39:09 Done.
318 jsFunc << "requestStatus(" << success << ");";
319 interstitial_page_->GetRenderViewHostForTesting()
Bernhard Bauer 2014/12/17 17:05:18 I assume you are going to ensure this method will
khannan 2014/12/17 17:39:09 Yes.
320 ->GetMainFrame()
321 ->ExecuteJavaScript(base::ASCIIToUTF16(jsFunc.str()));
322 VLOG(1) << "Executed: " + jsFunc.str();
Bernhard Bauer 2014/12/17 17:05:18 I don't think this log statement is going to be us
khannan 2014/12/17 17:39:09 Yup. Test code.
311 } 323 }
312 324
313 bool SupervisedUserInterstitial::ShouldProceed() { 325 bool SupervisedUserInterstitial::ShouldProceed() {
314 SupervisedUserService* supervised_user_service = 326 SupervisedUserService* supervised_user_service =
315 SupervisedUserServiceFactory::GetForProfile(profile_); 327 SupervisedUserServiceFactory::GetForProfile(profile_);
316 SupervisedUserURLFilter* url_filter = 328 SupervisedUserURLFilter* url_filter =
317 supervised_user_service->GetURLFilterForUIThread(); 329 supervised_user_service->GetURLFilterForUIThread();
318 SupervisedUserURLFilter::FilteringBehavior behavior; 330 SupervisedUserURLFilter::FilteringBehavior behavior;
319 return (url_filter->GetManualFilteringBehaviorForURL(url_, &behavior) && 331 return (url_filter->GetManualFilteringBehaviorForURL(url_, &behavior) &&
320 behavior != SupervisedUserURLFilter::BLOCK); 332 behavior != SupervisedUserURLFilter::BLOCK);
321 } 333 }
322 334
323 void SupervisedUserInterstitial::DispatchContinueRequest( 335 void SupervisedUserInterstitial::DispatchContinueRequest(
324 bool continue_request) { 336 bool continue_request) {
325 SupervisedUserService* supervised_user_service = 337 SupervisedUserService* supervised_user_service =
326 SupervisedUserServiceFactory::GetForProfile(profile_); 338 SupervisedUserServiceFactory::GetForProfile(profile_);
327 supervised_user_service->RemoveObserver(this); 339 supervised_user_service->RemoveObserver(this);
328 340
329 BrowserThread::PostTask( 341 BrowserThread::PostTask(
330 BrowserThread::IO, FROM_HERE, base::Bind(callback_, continue_request)); 342 BrowserThread::IO, FROM_HERE, base::Bind(callback_, continue_request));
331 343
332 // After this, the WebContents may be destroyed. Make sure we don't try to use 344 // After this, the WebContents may be destroyed. Make sure we don't try to use
333 // it again. 345 // it again.
334 web_contents_ = NULL; 346 web_contents_ = NULL;
335 } 347 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698