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_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/stringprintf.h" |
11 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
12 #include "base/values.h" | 13 #include "base/values.h" |
13 #include "chrome/browser/infobars/infobar_service.h" | 14 #include "chrome/browser/infobars/infobar_service.h" |
14 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/supervised_user/supervised_user_service.h" | 16 #include "chrome/browser/supervised_user/supervised_user_service.h" |
16 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" | 17 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" |
17 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
18 #include "chrome/grit/generated_resources.h" | 19 #include "chrome/grit/generated_resources.h" |
19 #include "components/infobars/core/infobar.h" | 20 #include "components/infobars/core/infobar.h" |
20 #include "components/infobars/core/infobar_delegate.h" | 21 #include "components/infobars/core/infobar_delegate.h" |
21 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
22 #include "content/public/browser/interstitial_page.h" | 23 #include "content/public/browser/interstitial_page.h" |
23 #include "content/public/browser/navigation_controller.h" | 24 #include "content/public/browser/navigation_controller.h" |
24 #include "content/public/browser/navigation_details.h" | 25 #include "content/public/browser/navigation_details.h" |
25 #include "content/public/browser/navigation_entry.h" | 26 #include "content/public/browser/navigation_entry.h" |
| 27 #include "content/public/browser/render_frame_host.h" |
| 28 #include "content/public/browser/render_view_host.h" |
26 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
27 #include "content/public/browser/web_contents_user_data.h" | 30 #include "content/public/browser/web_contents_user_data.h" |
28 #include "content/public/browser/web_ui.h" | 31 #include "content/public/browser/web_ui.h" |
29 #include "grit/browser_resources.h" | 32 #include "grit/browser_resources.h" |
30 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
31 #include "ui/base/resource/resource_bundle.h" | 34 #include "ui/base/resource/resource_bundle.h" |
32 #include "ui/base/webui/jstemplate_builder.h" | 35 #include "ui/base/webui/jstemplate_builder.h" |
33 #include "ui/base/webui/web_ui_util.h" | 36 #include "ui/base/webui/web_ui_util.h" |
34 | 37 |
35 #if !defined(OS_ANDROID) | 38 #if !defined(OS_ANDROID) |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 strings.SetString("feedbackLink", | 236 strings.SetString("feedbackLink", |
234 l10n_util::GetStringUTF16(IDS_BLOCK_INTERSTITIAL_SEND_FEEDBACK)); | 237 l10n_util::GetStringUTF16(IDS_BLOCK_INTERSTITIAL_SEND_FEEDBACK)); |
235 | 238 |
236 strings.SetString("backButton", l10n_util::GetStringUTF16(IDS_BACK_BUTTON)); | 239 strings.SetString("backButton", l10n_util::GetStringUTF16(IDS_BACK_BUTTON)); |
237 strings.SetString("requestAccessButton", l10n_util::GetStringUTF16( | 240 strings.SetString("requestAccessButton", l10n_util::GetStringUTF16( |
238 is_child_account | 241 is_child_account |
239 ? IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_ACCESS_BUTTON | 242 ? IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_ACCESS_BUTTON |
240 : IDS_BLOCK_INTERSTITIAL_REQUEST_ACCESS_BUTTON)); | 243 : IDS_BLOCK_INTERSTITIAL_REQUEST_ACCESS_BUTTON)); |
241 | 244 |
242 base::string16 request_sent_message; | 245 base::string16 request_sent_message; |
| 246 base::string16 request_failed_message; |
243 if (is_child_account) { | 247 if (is_child_account) { |
244 request_sent_message = l10n_util::GetStringUTF16( | 248 if (second_custodian.empty()) { |
245 second_custodian.empty() | 249 request_sent_message = l10n_util::GetStringUTF16( |
246 ? IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_SENT_MESSAGE_SINGLE_PARENT | 250 IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_SENT_MESSAGE_SINGLE_PARENT); |
247 : IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_SENT_MESSAGE_MULTI_PARENT); | 251 request_failed_message = l10n_util::GetStringUTF16( |
| 252 IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_FAILED_MESSAGE_SINGLE_PARENT); |
| 253 } else { |
| 254 request_sent_message = l10n_util::GetStringUTF16( |
| 255 IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_SENT_MESSAGE_MULTI_PARENT); |
| 256 request_failed_message = l10n_util::GetStringUTF16( |
| 257 IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_FAILED_MESSAGE_MULTI_PARENT); |
| 258 } |
248 } else { | 259 } else { |
249 request_sent_message = l10n_util::GetStringFUTF16( | 260 request_sent_message = l10n_util::GetStringFUTF16( |
250 IDS_BLOCK_INTERSTITIAL_REQUEST_SENT_MESSAGE, custodian); | 261 IDS_BLOCK_INTERSTITIAL_REQUEST_SENT_MESSAGE, custodian); |
| 262 request_failed_message = l10n_util::GetStringFUTF16( |
| 263 IDS_BLOCK_INTERSTITIAL_REQUEST_FAILED_MESSAGE, custodian); |
251 } | 264 } |
252 strings.SetString("requestSentMessage", request_sent_message); | 265 strings.SetString("requestSentMessage", request_sent_message); |
| 266 strings.SetString("requestFailedMessage", request_failed_message); |
253 | 267 |
254 webui::SetFontAndTextDirection(&strings); | 268 webui::SetFontAndTextDirection(&strings); |
255 | 269 |
256 base::StringPiece html(ResourceBundle::GetSharedInstance().GetRawDataResource( | 270 base::StringPiece html(ResourceBundle::GetSharedInstance().GetRawDataResource( |
257 IDR_SUPERVISED_USER_BLOCK_INTERSTITIAL_HTML)); | 271 IDR_SUPERVISED_USER_BLOCK_INTERSTITIAL_HTML)); |
258 | 272 |
259 return webui::GetI18nTemplateHtml(html, &strings); | 273 return webui::GetI18nTemplateHtml(html, &strings); |
260 } | 274 } |
261 | 275 |
262 void SupervisedUserInterstitial::CommandReceived(const std::string& command) { | 276 void SupervisedUserInterstitial::CommandReceived(const std::string& command) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 void SupervisedUserInterstitial::OnDontProceed() { | 336 void SupervisedUserInterstitial::OnDontProceed() { |
323 DispatchContinueRequest(false); | 337 DispatchContinueRequest(false); |
324 } | 338 } |
325 | 339 |
326 void SupervisedUserInterstitial::OnURLFilterChanged() { | 340 void SupervisedUserInterstitial::OnURLFilterChanged() { |
327 if (ShouldProceed()) | 341 if (ShouldProceed()) |
328 interstitial_page_->Proceed(); | 342 interstitial_page_->Proceed(); |
329 } | 343 } |
330 | 344 |
331 void SupervisedUserInterstitial::OnAccessRequestAdded(bool success) { | 345 void SupervisedUserInterstitial::OnAccessRequestAdded(bool success) { |
332 // TODO(akuegel): Figure out how to show the result of issuing the permission | |
333 // request in the UI. Currently, we assume the permission request was created | |
334 // successfully. | |
335 VLOG(1) << "Sent access request for " << url_.spec() | 346 VLOG(1) << "Sent access request for " << url_.spec() |
336 << (success ? " successfully" : " unsuccessfully"); | 347 << (success ? " successfully" : " unsuccessfully"); |
| 348 std::string jsFunc = |
| 349 base::StringPrintf("setRequestStatus(%s);", success ? "true" : "false"); |
| 350 interstitial_page_->GetRenderViewHost()->GetMainFrame()->ExecuteJavaScript( |
| 351 base::ASCIIToUTF16(jsFunc)); |
337 } | 352 } |
338 | 353 |
339 bool SupervisedUserInterstitial::ShouldProceed() { | 354 bool SupervisedUserInterstitial::ShouldProceed() { |
340 SupervisedUserService* supervised_user_service = | 355 SupervisedUserService* supervised_user_service = |
341 SupervisedUserServiceFactory::GetForProfile(profile_); | 356 SupervisedUserServiceFactory::GetForProfile(profile_); |
342 SupervisedUserURLFilter* url_filter = | 357 SupervisedUserURLFilter* url_filter = |
343 supervised_user_service->GetURLFilterForUIThread(); | 358 supervised_user_service->GetURLFilterForUIThread(); |
344 SupervisedUserURLFilter::FilteringBehavior behavior; | 359 SupervisedUserURLFilter::FilteringBehavior behavior; |
345 return (url_filter->GetManualFilteringBehaviorForURL(url_, &behavior) && | 360 return (url_filter->GetManualFilteringBehaviorForURL(url_, &behavior) && |
346 behavior != SupervisedUserURLFilter::BLOCK); | 361 behavior != SupervisedUserURLFilter::BLOCK); |
347 } | 362 } |
348 | 363 |
349 void SupervisedUserInterstitial::DispatchContinueRequest( | 364 void SupervisedUserInterstitial::DispatchContinueRequest( |
350 bool continue_request) { | 365 bool continue_request) { |
351 SupervisedUserService* supervised_user_service = | 366 SupervisedUserService* supervised_user_service = |
352 SupervisedUserServiceFactory::GetForProfile(profile_); | 367 SupervisedUserServiceFactory::GetForProfile(profile_); |
353 supervised_user_service->RemoveObserver(this); | 368 supervised_user_service->RemoveObserver(this); |
354 | 369 |
355 BrowserThread::PostTask( | 370 BrowserThread::PostTask( |
356 BrowserThread::IO, FROM_HERE, base::Bind(callback_, continue_request)); | 371 BrowserThread::IO, FROM_HERE, base::Bind(callback_, continue_request)); |
357 | 372 |
358 // After this, the WebContents may be destroyed. Make sure we don't try to use | 373 // After this, the WebContents may be destroyed. Make sure we don't try to use |
359 // it again. | 374 // it again. |
360 web_contents_ = NULL; | 375 web_contents_ = NULL; |
361 } | 376 } |
OLD | NEW |