| OLD | NEW |
| 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/chromeos/login/screens/eula_screen.h" | 5 #include "chrome/browser/chromeos/login/screens/eula_screen.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/chromeos/customization/customization_document.h" | 11 #include "chrome/browser/chromeos/customization/customization_document.h" |
| 12 #include "chrome/browser/chromeos/login/screens/base_screen_delegate.h" | 12 #include "chrome/browser/chromeos/login/screens/base_screen_delegate.h" |
| 13 #include "chrome/browser/chromeos/login/screens/eula_view.h" | 13 #include "chrome/browser/chromeos/login/screens/eula_view.h" |
| 14 #include "chrome/browser/chromeos/login/wizard_controller.h" |
| 14 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" | 15 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" |
| 15 #include "chromeos/dbus/cryptohome_client.h" | 16 #include "chromeos/dbus/cryptohome_client.h" |
| 16 #include "chromeos/dbus/dbus_method_call_status.h" | 17 #include "chromeos/dbus/dbus_method_call_status.h" |
| 17 #include "chromeos/dbus/dbus_thread_manager.h" | 18 #include "chromeos/dbus/dbus_thread_manager.h" |
| 18 | 19 |
| 19 namespace chromeos { | 20 namespace chromeos { |
| 21 namespace { |
| 22 |
| 23 constexpr const char kUserActionAcceptButtonClicked[] = "accept-button"; |
| 24 constexpr const char kUserActionBackButtonClicked[] = "back-button"; |
| 25 constexpr const char kContextKeyUsageStatsEnabled[] = "usageStatsEnabled"; |
| 26 |
| 27 } // namespace |
| 20 | 28 |
| 21 EulaScreen::EulaScreen(BaseScreenDelegate* base_screen_delegate, | 29 EulaScreen::EulaScreen(BaseScreenDelegate* base_screen_delegate, |
| 22 Delegate* delegate, | 30 Delegate* delegate, |
| 23 EulaView* view) | 31 EulaView* view) |
| 24 : EulaModel(base_screen_delegate), | 32 : BaseScreen(base_screen_delegate, OobeScreen::SCREEN_OOBE_EULA), |
| 25 delegate_(delegate), | 33 delegate_(delegate), |
| 26 view_(view), | 34 view_(view), |
| 27 password_fetcher_(this) { | 35 password_fetcher_(this) { |
| 28 DCHECK(view_); | 36 DCHECK(view_); |
| 29 DCHECK(delegate_); | 37 DCHECK(delegate_); |
| 30 if (view_) | 38 if (view_) |
| 31 view_->Bind(*this); | 39 view_->Bind(this); |
| 32 } | 40 } |
| 33 | 41 |
| 34 EulaScreen::~EulaScreen() { | 42 EulaScreen::~EulaScreen() { |
| 35 if (view_) | 43 if (view_) |
| 36 view_->Unbind(); | 44 view_->Unbind(); |
| 37 } | 45 } |
| 38 | 46 |
| 39 void EulaScreen::Show() { | |
| 40 // Command to own the TPM. | |
| 41 DBusThreadManager::Get()->GetCryptohomeClient()->TpmCanAttemptOwnership( | |
| 42 EmptyVoidDBusMethodCallback()); | |
| 43 if (policy::DeviceCloudPolicyManagerChromeOS::GetZeroTouchEnrollmentMode() == | |
| 44 policy::ZeroTouchEnrollmentMode::HANDS_OFF) | |
| 45 OnUserAction(EulaModel::kUserActionAcceptButtonClicked); | |
| 46 else if (view_) | |
| 47 view_->Show(); | |
| 48 } | |
| 49 | |
| 50 void EulaScreen::Hide() { | |
| 51 if (view_) | |
| 52 view_->Hide(); | |
| 53 } | |
| 54 | |
| 55 GURL EulaScreen::GetOemEulaUrl() const { | 47 GURL EulaScreen::GetOemEulaUrl() const { |
| 56 const StartupCustomizationDocument* customization = | 48 const StartupCustomizationDocument* customization = |
| 57 StartupCustomizationDocument::GetInstance(); | 49 StartupCustomizationDocument::GetInstance(); |
| 58 if (customization->IsReady()) { | 50 if (customization->IsReady()) { |
| 59 // Previously we're using "initial locale" that device initially | 51 // Previously we're using "initial locale" that device initially |
| 60 // booted with out-of-box. http://crbug.com/145142 | 52 // booted with out-of-box. http://crbug.com/145142 |
| 61 std::string locale = g_browser_process->GetApplicationLocale(); | 53 std::string locale = g_browser_process->GetApplicationLocale(); |
| 62 std::string eula_page = customization->GetEULAPage(locale); | 54 std::string eula_page = customization->GetEULAPage(locale); |
| 63 if (!eula_page.empty()) | 55 if (!eula_page.empty()) |
| 64 return GURL(eula_page); | 56 return GURL(eula_page); |
| 65 | 57 |
| 66 VLOG(1) << "No eula found for locale: " << locale; | 58 VLOG(1) << "No eula found for locale: " << locale; |
| 67 } else { | 59 } else { |
| 68 LOG(ERROR) << "No manifest found."; | 60 LOG(ERROR) << "No manifest found."; |
| 69 } | 61 } |
| 70 return GURL(); | 62 return GURL(); |
| 71 } | 63 } |
| 72 | 64 |
| 73 void EulaScreen::InitiatePasswordFetch() { | 65 void EulaScreen::InitiatePasswordFetch() { |
| 74 if (tpm_password_.empty()) { | 66 if (tpm_password_.empty()) { |
| 75 password_fetcher_.Fetch(); | 67 password_fetcher_.Fetch(); |
| 76 // Will call view after password has been fetched. | 68 // Will call view after password has been fetched. |
| 77 } else if (view_) { | 69 } else if (view_) { |
| 78 view_->OnPasswordFetched(tpm_password_); | 70 view_->OnPasswordFetched(tpm_password_); |
| 79 } | 71 } |
| 80 } | 72 } |
| 81 | 73 |
| 82 void EulaScreen::OnPasswordFetched(const std::string& tpm_password) { | |
| 83 tpm_password_ = tpm_password; | |
| 84 if (view_) | |
| 85 view_->OnPasswordFetched(tpm_password_); | |
| 86 } | |
| 87 | |
| 88 bool EulaScreen::IsUsageStatsEnabled() const { | 74 bool EulaScreen::IsUsageStatsEnabled() const { |
| 89 return delegate_ && delegate_->GetUsageStatisticsReporting(); | 75 return delegate_ && delegate_->GetUsageStatisticsReporting(); |
| 90 } | 76 } |
| 91 | 77 |
| 92 void EulaScreen::OnViewDestroyed(EulaView* view) { | 78 void EulaScreen::OnViewDestroyed(EulaView* view) { |
| 93 if (view_ == view) | 79 if (view_ == view) |
| 94 view_ = NULL; | 80 view_ = NULL; |
| 95 } | 81 } |
| 96 | 82 |
| 83 void EulaScreen::Show() { |
| 84 // Command to own the TPM. |
| 85 DBusThreadManager::Get()->GetCryptohomeClient()->TpmCanAttemptOwnership( |
| 86 EmptyVoidDBusMethodCallback()); |
| 87 if (policy::DeviceCloudPolicyManagerChromeOS::GetZeroTouchEnrollmentMode() == |
| 88 policy::ZeroTouchEnrollmentMode::HANDS_OFF) |
| 89 OnUserAction(kUserActionAcceptButtonClicked); |
| 90 else if (view_) |
| 91 view_->Show(); |
| 92 } |
| 93 |
| 94 void EulaScreen::Hide() { |
| 95 if (view_) |
| 96 view_->Hide(); |
| 97 } |
| 98 |
| 97 void EulaScreen::OnUserAction(const std::string& action_id) { | 99 void EulaScreen::OnUserAction(const std::string& action_id) { |
| 98 if (action_id == kUserActionAcceptButtonClicked) | 100 if (action_id == kUserActionAcceptButtonClicked) |
| 99 Finish(BaseScreenDelegate::EULA_ACCEPTED); | 101 Finish(BaseScreenDelegate::EULA_ACCEPTED); |
| 100 else if (action_id == kUserActionBackButtonClicked) | 102 else if (action_id == kUserActionBackButtonClicked) |
| 101 Finish(BaseScreenDelegate::EULA_BACK); | 103 Finish(BaseScreenDelegate::EULA_BACK); |
| 102 else | 104 else |
| 103 BaseScreen::OnUserAction(action_id); | 105 BaseScreen::OnUserAction(action_id); |
| 104 } | 106 } |
| 105 | 107 |
| 106 void EulaScreen::OnContextKeyUpdated( | 108 void EulaScreen::OnContextKeyUpdated( |
| 107 const ::login::ScreenContext::KeyType& key) { | 109 const ::login::ScreenContext::KeyType& key) { |
| 108 if (key == kContextKeyUsageStatsEnabled && delegate_) { | 110 if (key == kContextKeyUsageStatsEnabled && delegate_) { |
| 109 delegate_->SetUsageStatisticsReporting( | 111 delegate_->SetUsageStatisticsReporting( |
| 110 context_.GetBoolean(kContextKeyUsageStatsEnabled)); | 112 context_.GetBoolean(kContextKeyUsageStatsEnabled)); |
| 111 } | 113 } |
| 112 } | 114 } |
| 113 | 115 |
| 116 void EulaScreen::OnPasswordFetched(const std::string& tpm_password) { |
| 117 tpm_password_ = tpm_password; |
| 118 if (view_) |
| 119 view_->OnPasswordFetched(tpm_password_); |
| 120 } |
| 121 |
| 114 } // namespace chromeos | 122 } // namespace chromeos |
| OLD | NEW |