| 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/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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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; |
| 235 base::string16 request_failed_message; |
| 233 if (is_child_account) { | 236 if (is_child_account) { |
| 234 request_sent_message = l10n_util::GetStringUTF16( | 237 if (second_custodian.empty()) { |
| 235 second_custodian.empty() | 238 request_sent_message = l10n_util::GetStringUTF16( |
| 236 ? IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_SENT_MESSAGE_SINGLE_PARENT | 239 IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_SENT_MESSAGE_SINGLE_PARENT); |
| 237 : IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_SENT_MESSAGE_MULTI_PARENT); | 240 request_failed_message = l10n_util::GetStringUTF16( |
| 241 IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_FAILED_MESSAGE_SINGLE_PARENT); |
| 242 } else { |
| 243 request_sent_message = l10n_util::GetStringUTF16( |
| 244 IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_SENT_MESSAGE_MULTI_PARENT); |
| 245 request_failed_message = l10n_util::GetStringUTF16( |
| 246 IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_FAILED_MESSAGE_MULTI_PARENT); |
| 247 } |
| 238 } else { | 248 } else { |
| 239 request_sent_message = l10n_util::GetStringFUTF16( | 249 request_sent_message = l10n_util::GetStringFUTF16( |
| 240 IDS_BLOCK_INTERSTITIAL_REQUEST_SENT_MESSAGE, custodian); | 250 IDS_BLOCK_INTERSTITIAL_REQUEST_SENT_MESSAGE, custodian); |
| 251 request_failed_message = l10n_util::GetStringFUTF16( |
| 252 IDS_BLOCK_INTERSTITIAL_REQUEST_FAILED_MESSAGE, custodian); |
| 241 } | 253 } |
| 242 strings.SetString("requestSentMessage", request_sent_message); | 254 strings.SetString("requestSentMessage", request_sent_message); |
| 255 strings.SetString("requestFailedMessage", request_failed_message); |
| 243 | 256 |
| 244 webui::SetFontAndTextDirection(&strings); | 257 webui::SetFontAndTextDirection(&strings); |
| 245 | 258 |
| 246 base::StringPiece html(ResourceBundle::GetSharedInstance().GetRawDataResource( | 259 base::StringPiece html(ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 247 IDR_SUPERVISED_USER_BLOCK_INTERSTITIAL_HTML)); | 260 IDR_SUPERVISED_USER_BLOCK_INTERSTITIAL_HTML)); |
| 248 | 261 |
| 249 return webui::GetI18nTemplateHtml(html, &strings); | 262 return webui::GetI18nTemplateHtml(html, &strings); |
| 250 } | 263 } |
| 251 | 264 |
| 252 void SupervisedUserInterstitial::CommandReceived(const std::string& command) { | 265 void SupervisedUserInterstitial::CommandReceived(const std::string& command) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 void SupervisedUserInterstitial::OnDontProceed() { | 309 void SupervisedUserInterstitial::OnDontProceed() { |
| 297 DispatchContinueRequest(false); | 310 DispatchContinueRequest(false); |
| 298 } | 311 } |
| 299 | 312 |
| 300 void SupervisedUserInterstitial::OnURLFilterChanged() { | 313 void SupervisedUserInterstitial::OnURLFilterChanged() { |
| 301 if (ShouldProceed()) | 314 if (ShouldProceed()) |
| 302 interstitial_page_->Proceed(); | 315 interstitial_page_->Proceed(); |
| 303 } | 316 } |
| 304 | 317 |
| 305 void SupervisedUserInterstitial::OnAccessRequestAdded(bool success) { | 318 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() | 319 VLOG(1) << "Sent access request for " << url_.spec() |
| 310 << (success ? " successfully" : " unsuccessfully"); | 320 << (success ? " successfully" : " unsuccessfully"); |
| 321 std::string jsFunc = base::StringPrintf("updateOnGettingRequestStatus(%s);", |
| 322 success ? "true" : "false"); |
| 323 interstitial_page_->GetRenderViewHostForTesting() |
| 324 ->GetMainFrame() |
| 325 ->ExecuteJavaScript(base::ASCIIToUTF16(jsFunc)); |
| 326 VLOG(1) << "Executed: " + jsFunc; |
| 311 } | 327 } |
| 312 | 328 |
| 313 bool SupervisedUserInterstitial::ShouldProceed() { | 329 bool SupervisedUserInterstitial::ShouldProceed() { |
| 314 SupervisedUserService* supervised_user_service = | 330 SupervisedUserService* supervised_user_service = |
| 315 SupervisedUserServiceFactory::GetForProfile(profile_); | 331 SupervisedUserServiceFactory::GetForProfile(profile_); |
| 316 SupervisedUserURLFilter* url_filter = | 332 SupervisedUserURLFilter* url_filter = |
| 317 supervised_user_service->GetURLFilterForUIThread(); | 333 supervised_user_service->GetURLFilterForUIThread(); |
| 318 SupervisedUserURLFilter::FilteringBehavior behavior; | 334 SupervisedUserURLFilter::FilteringBehavior behavior; |
| 319 return (url_filter->GetManualFilteringBehaviorForURL(url_, &behavior) && | 335 return (url_filter->GetManualFilteringBehaviorForURL(url_, &behavior) && |
| 320 behavior != SupervisedUserURLFilter::BLOCK); | 336 behavior != SupervisedUserURLFilter::BLOCK); |
| 321 } | 337 } |
| 322 | 338 |
| 323 void SupervisedUserInterstitial::DispatchContinueRequest( | 339 void SupervisedUserInterstitial::DispatchContinueRequest( |
| 324 bool continue_request) { | 340 bool continue_request) { |
| 325 SupervisedUserService* supervised_user_service = | 341 SupervisedUserService* supervised_user_service = |
| 326 SupervisedUserServiceFactory::GetForProfile(profile_); | 342 SupervisedUserServiceFactory::GetForProfile(profile_); |
| 327 supervised_user_service->RemoveObserver(this); | 343 supervised_user_service->RemoveObserver(this); |
| 328 | 344 |
| 329 BrowserThread::PostTask( | 345 BrowserThread::PostTask( |
| 330 BrowserThread::IO, FROM_HERE, base::Bind(callback_, continue_request)); | 346 BrowserThread::IO, FROM_HERE, base::Bind(callback_, continue_request)); |
| 331 | 347 |
| 332 // After this, the WebContents may be destroyed. Make sure we don't try to use | 348 // After this, the WebContents may be destroyed. Make sure we don't try to use |
| 333 // it again. | 349 // it again. |
| 334 web_contents_ = NULL; | 350 web_contents_ = NULL; |
| 335 } | 351 } |
| OLD | NEW |