| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/webui/chromeos/enterprise_enrollment_ui.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/bind_helpers.h" | |
| 9 #include "base/memory/scoped_ptr.h" | |
| 10 #include "base/message_loop.h" | |
| 11 #include "base/utf_string_conversions.h" | |
| 12 #include "base/values.h" | |
| 13 #include "chrome/browser/chromeos/login/enrollment/enterprise_enrollment_screen_
actor.h" | |
| 14 #include "chrome/browser/profiles/profile.h" | |
| 15 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | |
| 16 #include "chrome/browser/ui/webui/chromeos/login/enterprise_enrollment_screen_ha
ndler.h" | |
| 17 #include "chrome/common/jstemplate_builder.h" | |
| 18 #include "chrome/common/url_constants.h" | |
| 19 #include "content/browser/renderer_host/render_view_host.h" | |
| 20 #include "content/browser/tab_contents/tab_contents.h" | |
| 21 #include "content/public/common/bindings_policy.h" | |
| 22 #include "grit/browser_resources.h" | |
| 23 #include "grit/chromium_strings.h" | |
| 24 #include "grit/generated_resources.h" | |
| 25 #include "ui/base/resource/resource_bundle.h" | |
| 26 | |
| 27 namespace chromeos { | |
| 28 | |
| 29 namespace { | |
| 30 | |
| 31 const char kEnterpriseEnrollmentGaiaLoginPath[] = "gaialogin"; | |
| 32 | |
| 33 } // namespace | |
| 34 | |
| 35 // Work around EnterpriseEnrollmentScreenHandler, which is suitable for the | |
| 36 // stand alone enterprise enrollment screen (views implementation). | |
| 37 class SingleEnterpriseEnrollmentScreenHandler | |
| 38 : public EnterpriseEnrollmentScreenHandler { | |
| 39 public: | |
| 40 SingleEnterpriseEnrollmentScreenHandler(); | |
| 41 virtual ~SingleEnterpriseEnrollmentScreenHandler() {} | |
| 42 | |
| 43 // Overridden from EnterpriseEnrollmentScreenHandler: | |
| 44 virtual void ShowConfirmationScreen() OVERRIDE; | |
| 45 virtual void SetController(Controller* controller_) OVERRIDE; | |
| 46 virtual void RegisterMessages() OVERRIDE; | |
| 47 | |
| 48 private: | |
| 49 // Handlers for WebUI messages. | |
| 50 void HandleScreenReady(const ListValue* args); | |
| 51 | |
| 52 bool show_when_controller_is_set_; | |
| 53 | |
| 54 DISALLOW_COPY_AND_ASSIGN(SingleEnterpriseEnrollmentScreenHandler); | |
| 55 }; | |
| 56 | |
| 57 SingleEnterpriseEnrollmentScreenHandler:: | |
| 58 SingleEnterpriseEnrollmentScreenHandler() | |
| 59 : show_when_controller_is_set_(false) { | |
| 60 } | |
| 61 | |
| 62 void SingleEnterpriseEnrollmentScreenHandler::ShowConfirmationScreen() { | |
| 63 RenderViewHost* render_view_host = | |
| 64 web_ui_->tab_contents()->render_view_host(); | |
| 65 render_view_host->ExecuteJavascriptInWebFrame( | |
| 66 string16(), | |
| 67 UTF8ToUTF16("enterpriseEnrollment.showScreen('confirmation-screen');")); | |
| 68 NotifyObservers(true); | |
| 69 } | |
| 70 | |
| 71 void SingleEnterpriseEnrollmentScreenHandler::SetController( | |
| 72 Controller* controller) { | |
| 73 EnterpriseEnrollmentScreenHandler::SetController(controller); | |
| 74 if (show_when_controller_is_set_) { | |
| 75 show_when_controller_is_set_ = false; | |
| 76 HandleScreenReady(NULL); | |
| 77 } | |
| 78 } | |
| 79 | |
| 80 void SingleEnterpriseEnrollmentScreenHandler::RegisterMessages() { | |
| 81 EnterpriseEnrollmentScreenHandler::RegisterMessages(); | |
| 82 web_ui_->RegisterMessageCallback( | |
| 83 "enrollmentScreenReady", | |
| 84 base::Bind(&SingleEnterpriseEnrollmentScreenHandler::HandleScreenReady, | |
| 85 base::Unretained(this))); | |
| 86 } | |
| 87 | |
| 88 void SingleEnterpriseEnrollmentScreenHandler::HandleScreenReady( | |
| 89 const ListValue* value) { | |
| 90 if (!controller_) { | |
| 91 show_when_controller_is_set_ = true; | |
| 92 return; | |
| 93 } | |
| 94 SetupGaiaStrings(); | |
| 95 web_ui_->CallJavascriptFunction("enterpriseEnrollment.showInitialScreen"); | |
| 96 } | |
| 97 | |
| 98 // A data source that provides the resources for the enterprise enrollment page. | |
| 99 // The enterprise enrollment page requests the HTML and other resources from | |
| 100 // this source. | |
| 101 class EnterpriseEnrollmentDataSource : public ChromeURLDataManager::DataSource { | |
| 102 public: | |
| 103 explicit EnterpriseEnrollmentDataSource(DictionaryValue* localized_strings); | |
| 104 | |
| 105 // DataSource implementation. | |
| 106 virtual void StartDataRequest(const std::string& path, | |
| 107 bool is_off_the_record, | |
| 108 int request_id) OVERRIDE; | |
| 109 virtual std::string GetMimeType(const std::string& path) const OVERRIDE; | |
| 110 | |
| 111 private: | |
| 112 virtual ~EnterpriseEnrollmentDataSource(); | |
| 113 | |
| 114 scoped_ptr<DictionaryValue> localized_strings_; | |
| 115 | |
| 116 DISALLOW_COPY_AND_ASSIGN(EnterpriseEnrollmentDataSource); | |
| 117 }; | |
| 118 | |
| 119 EnterpriseEnrollmentDataSource::EnterpriseEnrollmentDataSource( | |
| 120 DictionaryValue* localized_strings) | |
| 121 : DataSource(chrome::kChromeUIEnterpriseEnrollmentHost, | |
| 122 MessageLoop::current()), | |
| 123 localized_strings_(localized_strings) { | |
| 124 } | |
| 125 | |
| 126 void EnterpriseEnrollmentDataSource::StartDataRequest(const std::string& path, | |
| 127 bool is_off_the_record, | |
| 128 int request_id) { | |
| 129 ResourceBundle& resource_bundle = ResourceBundle::GetSharedInstance(); | |
| 130 | |
| 131 std::string response; | |
| 132 if (path.empty()) { | |
| 133 static const base::StringPiece html( | |
| 134 resource_bundle.GetRawDataResource(IDR_ENTERPRISE_ENROLLMENT_HTML)); | |
| 135 response = | |
| 136 jstemplate_builder::GetI18nTemplateHtml(html, localized_strings_.get()); | |
| 137 } else if (path == kEnterpriseEnrollmentGaiaLoginPath) { | |
| 138 static const base::StringPiece html(resource_bundle.GetRawDataResource( | |
| 139 IDR_GAIA_LOGIN_HTML)); | |
| 140 response = | |
| 141 jstemplate_builder::GetI18nTemplateHtml(html, localized_strings_.get()); | |
| 142 } | |
| 143 | |
| 144 SendResponse(request_id, base::RefCountedString::TakeString(&response)); | |
| 145 } | |
| 146 | |
| 147 std::string EnterpriseEnrollmentDataSource::GetMimeType( | |
| 148 const std::string& path) const { | |
| 149 return "text/html"; | |
| 150 } | |
| 151 | |
| 152 EnterpriseEnrollmentDataSource::~EnterpriseEnrollmentDataSource() {} | |
| 153 | |
| 154 EnterpriseEnrollmentUI::EnterpriseEnrollmentUI(TabContents* contents) | |
| 155 : ChromeWebUI(contents), handler_(NULL) {} | |
| 156 | |
| 157 EnterpriseEnrollmentUI::~EnterpriseEnrollmentUI() {} | |
| 158 | |
| 159 void EnterpriseEnrollmentUI::RenderViewCreated( | |
| 160 RenderViewHost* render_view_host) { | |
| 161 // Bail out early if web ui is disabled. | |
| 162 if (!(bindings_ & content::BINDINGS_POLICY_WEB_UI)) | |
| 163 return; | |
| 164 | |
| 165 handler_ = new SingleEnterpriseEnrollmentScreenHandler(); | |
| 166 AddMessageHandler(handler_->Attach(this)); | |
| 167 | |
| 168 scoped_ptr<DictionaryValue> localized_strings(new DictionaryValue); | |
| 169 handler_->GetLocalizedStrings(localized_strings.get()); | |
| 170 ChromeURLDataManager::DataSource::SetFontAndTextDirection( | |
| 171 localized_strings.get()); | |
| 172 // Set up the data source, so the enrollment page can be loaded. | |
| 173 Profile* profile = | |
| 174 Profile::FromBrowserContext(tab_contents()->browser_context()); | |
| 175 profile->GetChromeURLDataManager()->AddDataSource( | |
| 176 new EnterpriseEnrollmentDataSource(localized_strings.release())); | |
| 177 } | |
| 178 | |
| 179 EnterpriseEnrollmentScreenActor* EnterpriseEnrollmentUI::GetActor() { | |
| 180 return handler_; | |
| 181 } | |
| 182 | |
| 183 } // namespace chromeos | |
| OLD | NEW |