Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/enterprise_enrollment_view.h" | 5 #include "chrome/browser/chromeos/login/enterprise_enrollment_view.h" |
| 6 | 6 |
| 7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "chrome/browser/chromeos/cros/cros_library.h" | |
| 10 #include "chrome/browser/chromeos/cros/cryptohome_library.h" | |
| 9 #include "chrome/browser/chromeos/login/enterprise_enrollment_screen.h" | 11 #include "chrome/browser/chromeos/login/enterprise_enrollment_screen.h" |
| 10 #include "chrome/browser/chromeos/login/helper.h" | 12 #include "chrome/browser/chromeos/login/helper.h" |
| 11 #include "chrome/browser/chromeos/login/rounded_rect_painter.h" | 13 #include "chrome/browser/chromeos/login/rounded_rect_painter.h" |
| 12 #include "chrome/browser/profiles/profile_manager.h" | 14 #include "chrome/browser/profiles/profile_manager.h" |
| 13 #include "chrome/browser/ui/webui/chromeos/enterprise_enrollment_ui.h" | 15 #include "chrome/browser/ui/webui/chromeos/enterprise_enrollment_ui.h" |
| 14 #include "chrome/common/url_constants.h" | 16 #include "chrome/common/url_constants.h" |
| 15 #include "content/browser/renderer_host/render_view_host.h" | 17 #include "content/browser/renderer_host/render_view_host.h" |
| 16 #include "content/browser/site_instance.h" | 18 #include "content/browser/site_instance.h" |
| 17 #include "content/browser/tab_contents/tab_contents_delegate.h" | 19 #include "content/browser/tab_contents/tab_contents_delegate.h" |
| 18 #include "grit/generated_resources.h" | 20 #include "grit/generated_resources.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 68 NavigationType::Type navigation_type) { | 70 NavigationType::Type navigation_type) { |
| 69 return false; | 71 return false; |
| 70 } | 72 } |
| 71 virtual void MoveContents(TabContents* source, const gfx::Rect& pos) {} | 73 virtual void MoveContents(TabContents* source, const gfx::Rect& pos) {} |
| 72 virtual void ToolbarSizeChanged(TabContents* source, bool is_animating) {} | 74 virtual void ToolbarSizeChanged(TabContents* source, bool is_animating) {} |
| 73 virtual bool HandleContextMenu(const ContextMenuParams& params) { | 75 virtual bool HandleContextMenu(const ContextMenuParams& params) { |
| 74 return true; | 76 return true; |
| 75 } | 77 } |
| 76 | 78 |
| 77 private: | 79 private: |
| 80 | |
| 78 DISALLOW_COPY_AND_ASSIGN(EnrollmentDomView); | 81 DISALLOW_COPY_AND_ASSIGN(EnrollmentDomView); |
| 79 }; | 82 }; |
| 80 | 83 |
| 81 } // namespace | 84 } // namespace |
| 82 | 85 |
| 83 EnterpriseEnrollmentView::EnterpriseEnrollmentView( | 86 EnterpriseEnrollmentView::EnterpriseEnrollmentView( |
| 84 EnterpriseEnrollmentController* controller) | 87 EnterpriseEnrollmentController* controller) |
| 85 : controller_(controller) {} | 88 : controller_(controller), |
| 89 editable_user_(true) {} | |
| 86 | 90 |
| 87 EnterpriseEnrollmentView::~EnterpriseEnrollmentView() {} | 91 EnterpriseEnrollmentView::~EnterpriseEnrollmentView() {} |
| 88 | 92 |
| 89 void EnterpriseEnrollmentView::Init() { | 93 void EnterpriseEnrollmentView::Init() { |
| 90 // Use rounded rect background. | 94 // Use rounded rect background. |
| 91 views::Painter* painter = | 95 views::Painter* painter = |
| 92 CreateWizardPainter(&BorderDefinition::kScreenBorder); | 96 CreateWizardPainter(&BorderDefinition::kScreenBorder); |
| 93 set_background(views::Background::CreateBackgroundPainter(true, painter)); | 97 set_background(views::Background::CreateBackgroundPainter(true, painter)); |
| 94 | 98 |
| 95 // Create the view that hosts the enrollment page. | 99 // Create the view that hosts the enrollment page. |
| 96 enrollment_page_view_ = new EnrollmentDomView(); | 100 enrollment_page_view_ = new EnrollmentDomView(); |
| 97 enrollment_page_view_->set_border( | 101 enrollment_page_view_->set_border( |
| 98 views::Border::CreateEmptyBorder(kBorderSize, kBorderSize, | 102 views::Border::CreateEmptyBorder(kBorderSize, kBorderSize, |
| 99 kBorderSize, kBorderSize)); | 103 kBorderSize, kBorderSize)); |
| 100 | 104 |
| 101 AddChildView(enrollment_page_view_); | 105 AddChildView(enrollment_page_view_); |
| 102 | 106 |
| 103 // Load the enrollment page. | 107 // Load the enrollment page. |
| 104 Profile* profile = ProfileManager::GetDefaultProfile(); | 108 Profile* profile = ProfileManager::GetDefaultProfile(); |
| 105 GURL url(chrome::kChromeUIEnterpriseEnrollmentURL); | 109 GURL url(chrome::kChromeUIEnterpriseEnrollmentURL); |
| 106 enrollment_page_view_->Init( | 110 enrollment_page_view_->Init( |
| 107 profile, SiteInstance::CreateSiteInstanceForURL(profile, url)); | 111 profile, SiteInstance::CreateSiteInstanceForURL(profile, url)); |
| 108 EnterpriseEnrollmentUI::SetController(enrollment_page_view_->tab_contents(), | 112 EnterpriseEnrollmentUI::SetController(enrollment_page_view_->tab_contents(), |
| 109 this); | 113 this); |
| 110 enrollment_page_view_->LoadURL(url); | 114 enrollment_page_view_->LoadURL(url); |
| 115 | |
| 116 // Check lockbox data and update the view if needed. | |
| 117 chromeos::CryptohomeLibrary* cryptohome = | |
| 118 chromeos::CrosLibrary::Get()->GetCryptohomeLibrary(); | |
| 119 // TODO(pastarmovj): This is being done either on the eula screen or on first | |
| 120 // login so maybe we should do it already here? If not remove. | |
| 121 if (cryptohome) { | |
| 122 if (cryptohome->TpmIsEnabled() && !cryptohome->TpmIsBeingOwned()) { | |
| 123 if (cryptohome->TpmIsOwned()) | |
| 124 cryptohome->TpmClearStoredPassword(); | |
| 125 else | |
| 126 cryptohome->TpmCanAttemptOwnership(); | |
| 127 } | |
| 128 | |
| 129 if (cryptohome->InstallAttributesIsReady() && | |
| 130 !cryptohome->InstallAttributesIsFirstInstall()) { | |
| 131 std::string value; | |
| 132 if (cryptohome->InstallAttributesGet("enterprise.owned", &value) && | |
| 133 0 == value.compare("true")) { | |
| 134 if (cryptohome->InstallAttributesGet("enterprise.user", &value)) { | |
| 135 DictionaryValue args; | |
| 136 args.SetString("user", value); | |
| 137 args.SetBoolean("editable_user", false); | |
| 138 editable_user_ = false; | |
| 139 UpdateGaiaLogin(args); | |
|
Will Drewry
2011/04/15 02:38:19
Is this only used during enrollment or will enterp
| |
| 140 } else { | |
| 141 // TODO(pastarmovj): Put some new error message here! | |
| 142 ShowError(IDS_ENTERPRISE_ENROLLMENT_FATAL_ENROLLMENT_ERROR); | |
| 143 } | |
| 144 } | |
| 145 } | |
| 146 } else { | |
| 147 // TODO(pastarmovj): Put some new error message here! | |
| 148 ShowError(IDS_ENTERPRISE_ENROLLMENT_FATAL_ENROLLMENT_ERROR); | |
| 149 } | |
| 111 } | 150 } |
| 112 | 151 |
| 113 void EnterpriseEnrollmentView::ShowConfirmationScreen() { | 152 void EnterpriseEnrollmentView::ShowConfirmationScreen() { |
| 114 RenderViewHost* render_view_host = | 153 RenderViewHost* render_view_host = |
| 115 enrollment_page_view_->tab_contents()->render_view_host(); | 154 enrollment_page_view_->tab_contents()->render_view_host(); |
| 116 render_view_host->ExecuteJavascriptInWebFrame( | 155 render_view_host->ExecuteJavascriptInWebFrame( |
| 117 string16(), | 156 string16(), |
| 118 UTF8ToUTF16("enterpriseEnrollment.showScreen('confirmation-screen');")); | 157 UTF8ToUTF16("enterpriseEnrollment.showScreen('confirmation-screen');")); |
| 119 } | 158 } |
| 120 | 159 |
| 121 void EnterpriseEnrollmentView::ShowAuthError( | 160 void EnterpriseEnrollmentView::ShowAuthError( |
| 122 const GoogleServiceAuthError& error) { | 161 const GoogleServiceAuthError& error) { |
| 123 DictionaryValue args; | 162 DictionaryValue args; |
| 124 args.SetInteger("error", error.state()); | 163 args.SetInteger("error", error.state()); |
| 125 args.SetBoolean("editable_user", true); | 164 args.SetBoolean("editable_user", editable_user_); |
| 126 args.SetString("captchaUrl", error.captcha().image_url.spec()); | 165 args.SetString("captchaUrl", error.captcha().image_url.spec()); |
| 127 UpdateGaiaLogin(args); | 166 UpdateGaiaLogin(args); |
| 128 } | 167 } |
| 129 | 168 |
| 130 void EnterpriseEnrollmentView::ShowAccountError() { | 169 void EnterpriseEnrollmentView::ShowAccountError() { |
| 131 ShowError(IDS_ENTERPRISE_ENROLLMENT_ACCOUNT_ERROR); | 170 ShowError(IDS_ENTERPRISE_ENROLLMENT_ACCOUNT_ERROR); |
| 132 } | 171 } |
| 133 | 172 |
| 134 void EnterpriseEnrollmentView::ShowFatalAuthError() { | 173 void EnterpriseEnrollmentView::ShowFatalAuthError() { |
| 135 ShowError(IDS_ENTERPRISE_ENROLLMENT_FATAL_AUTH_ERROR); | 174 ShowError(IDS_ENTERPRISE_ENROLLMENT_FATAL_AUTH_ERROR); |
| 136 } | 175 } |
| 137 | 176 |
| 138 void EnterpriseEnrollmentView::ShowFatalEnrollmentError() { | 177 void EnterpriseEnrollmentView::ShowFatalEnrollmentError() { |
| 139 ShowError(IDS_ENTERPRISE_ENROLLMENT_FATAL_ENROLLMENT_ERROR); | 178 ShowError(IDS_ENTERPRISE_ENROLLMENT_FATAL_ENROLLMENT_ERROR); |
| 140 } | 179 } |
| 141 | 180 |
| 142 void EnterpriseEnrollmentView::ShowNetworkEnrollmentError() { | 181 void EnterpriseEnrollmentView::ShowNetworkEnrollmentError() { |
| 143 ShowError(IDS_ENTERPRISE_ENROLLMENT_NETWORK_ENROLLMENT_ERROR); | 182 ShowError(IDS_ENTERPRISE_ENROLLMENT_NETWORK_ENROLLMENT_ERROR); |
| 144 } | 183 } |
| 145 | 184 |
| 146 void EnterpriseEnrollmentView::OnAuthSubmitted(const std::string& user, | 185 void EnterpriseEnrollmentView::OnAuthSubmitted(const std::string& user, |
| 147 const std::string& password, | 186 const std::string& password, |
| 148 const std::string& captcha, | 187 const std::string& captcha, |
| 149 const std::string& access_code) { | 188 const std::string& access_code) { |
| 189 user_ = user; | |
| 150 controller_->Authenticate(user, password, captcha, access_code); | 190 controller_->Authenticate(user, password, captcha, access_code); |
| 151 } | 191 } |
| 152 | 192 |
| 153 void EnterpriseEnrollmentView::OnAuthCancelled() { | 193 void EnterpriseEnrollmentView::OnAuthCancelled() { |
| 154 controller_->CancelEnrollment(); | 194 controller_->CancelEnrollment(); |
| 155 } | 195 } |
| 156 | 196 |
| 157 void EnterpriseEnrollmentView::OnConfirmationClosed() { | 197 void EnterpriseEnrollmentView::OnConfirmationClosed() { |
| 158 controller_->CloseConfirmation(); | 198 controller_->CloseConfirmation(); |
| 159 } | 199 } |
| 160 | 200 |
| 161 void EnterpriseEnrollmentView::UpdateGaiaLogin(const DictionaryValue& args) { | 201 void EnterpriseEnrollmentView::UpdateGaiaLogin(const DictionaryValue& args) { |
| 162 std::string json; | 202 std::string json; |
| 163 base::JSONWriter::Write(&args, false, &json); | 203 base::JSONWriter::Write(&args, false, &json); |
| 164 | 204 |
| 165 RenderViewHost* render_view_host = | 205 RenderViewHost* render_view_host = |
| 166 enrollment_page_view_->tab_contents()->render_view_host(); | 206 enrollment_page_view_->tab_contents()->render_view_host(); |
| 167 render_view_host->ExecuteJavascriptInWebFrame( | 207 render_view_host->ExecuteJavascriptInWebFrame( |
| 168 ASCIIToUTF16("//iframe[@id='gaialogin']"), | 208 ASCIIToUTF16("//iframe[@id='gaialogin']"), |
| 169 UTF8ToUTF16("showGaiaLogin(" + json + ");")); | 209 UTF8ToUTF16("showGaiaLogin(" + json + ");")); |
| 170 } | 210 } |
| 171 | 211 |
| 172 void EnterpriseEnrollmentView::ShowError(int message_id) { | 212 void EnterpriseEnrollmentView::ShowError(int message_id) { |
| 173 DictionaryValue args; | 213 DictionaryValue args; |
| 174 args.SetInteger("error", GoogleServiceAuthError::NONE); | 214 args.SetInteger("error", GoogleServiceAuthError::NONE); |
| 175 args.SetBoolean("editable_user", true); | 215 args.SetBoolean("editable_user", editable_user_); |
| 176 args.SetString("error_message", l10n_util::GetStringUTF16(message_id)); | 216 args.SetString("error_message", l10n_util::GetStringUTF16(message_id)); |
| 177 UpdateGaiaLogin(args); | 217 UpdateGaiaLogin(args); |
| 178 } | 218 } |
| 179 | 219 |
| 180 void EnterpriseEnrollmentView::Layout() { | 220 void EnterpriseEnrollmentView::Layout() { |
| 181 enrollment_page_view_->SetBoundsRect(GetContentsBounds()); | 221 enrollment_page_view_->SetBoundsRect(GetContentsBounds()); |
| 182 } | 222 } |
| 183 | 223 |
| 184 } // namespace chromeos | 224 } // namespace chromeos |
| OLD | NEW |