Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: chrome/browser/ui/webui/chromeos/login/oobe_ui.cc

Issue 7076014: [cros] Initial implementation for OOBE WebUI. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix naming Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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/login/oobe_ui.h"
6
7 #include <string>
8
9 #include "base/logging.h"
10 #include "base/memory/weak_ptr.h"
11 #include "base/string_piece.h"
12 #include "base/values.h"
13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
15 #include "chrome/common/jstemplate_builder.h"
16 #include "chrome/common/url_constants.h"
17 #include "content/browser/browser_thread.h"
18 #include "content/browser/tab_contents/tab_contents.h"
19 #include "grit/browser_resources.h"
20 #include "grit/chromium_strings.h"
21 #include "grit/generated_resources.h"
22 #include "ui/base/l10n/l10n_util.h"
23 #include "ui/base/resource/resource_bundle.h"
24
25 namespace {
26
27 // JS API callbacks names.
28 const char kJsApiScreenStateInitialize[] = "screenStateInitialize";
29
30 // Page JS API function names.
31 const char kJsApiScreenStateChanged[] = "cr.ui.Oobe.screenStateChanged";
whywhat 2011/05/26 19:48:47 Oobe -> oobe?
Nikita (slow) 2011/05/27 12:23:24 JS class name should be capitalized.
32
33 // OOBE screen state variables which are passed to the page.
34 const char kState[] = "state";
35
36 } // namespace
37
38 namespace chromeos {
39
40 class OobeUIHTMLSource : public ChromeURLDataManager::DataSource {
41 public:
42 OobeUIHTMLSource();
43
44 // Called when the network layer has requested a resource underneath
45 // the path we registered.
46 virtual void StartDataRequest(const std::string& path,
47 bool is_incognito,
48 int request_id);
49 virtual std::string GetMimeType(const std::string&) const {
50 return "text/html";
51 }
52
53 private:
54 virtual ~OobeUIHTMLSource() {}
55
56 std::string service_path_;
57 DISALLOW_COPY_AND_ASSIGN(OobeUIHTMLSource);
58 };
59
60 // The handler for Javascript messages related to the "oobe" view.
61 class OobeHandler : public WebUIMessageHandler,
62 public base::SupportsWeakPtr<OobeHandler> {
63 public:
64 OobeHandler();
65 virtual ~OobeHandler();
66
67 // Init work after Attach.
68 void Init(TabContents* contents);
69
70 // WebUIMessageHandler implementation.
71 virtual WebUIMessageHandler* Attach(WebUI* web_ui);
72 virtual void RegisterMessages();
73
74 private:
75 // Should keep this state enum in sync with similar one in JS code.
76 typedef enum ScreenState {
77 SCREEN_LOADING = -1,
78 SCREEN_NONE = 0,
79 SCREEN_WELCOME = 1,
80 SCREEN_EULA = 2,
81 SCREEN_UPDATE = 3,
82 } ScreenState;
83
84 class TaskProxy : public base::RefCountedThreadSafe<TaskProxy> {
85 public:
86 explicit TaskProxy(const base::WeakPtr<OobeHandler>& handler)
87 : handler_(handler) {
88 }
89
90 void HandleInitialize() {
91 if (handler_)
92 handler_->InitializeScreenState();
93 }
94
95 private:
96 base::WeakPtr<OobeHandler> handler_;
97
98 DISALLOW_COPY_AND_ASSIGN(TaskProxy);
99 };
100
101 // Handlers for JS WebUI messages.
102 void HandleScreenStateInitialize(const ListValue* args);
103
104 // Initializes current OOBE state, passes that to page.
105 void InitializeScreenState();
106
107 // Updates page states.
108 void UpdatePage();
109
110 TabContents* tab_contents_;
111 ScreenState state_;
112
113 DISALLOW_COPY_AND_ASSIGN(OobeHandler);
114 };
115
116 // OobeUIHTMLSource -------------------------------------------------------
117
118 OobeUIHTMLSource::OobeUIHTMLSource()
119 : DataSource(chrome::kChromeUIOobeHost, MessageLoop::current()) {
120 }
121
122 void OobeUIHTMLSource::StartDataRequest(const std::string& path,
123 bool is_incognito,
124 int request_id) {
125 DictionaryValue strings;
126 // OOBE title is not actually seen in UI, use title of the welcome screen.
127 strings.SetString("title",
128 l10n_util::GetStringUTF16(IDS_NETWORK_SELECTION_TITLE));
129 strings.SetString("welcomeScreenTitle",
130 l10n_util::GetStringUTF16(IDS_WELCOME_SCREEN_TITLE));
131 strings.SetString("languageSelect",
132 l10n_util::GetStringUTF16(IDS_LANGUAGE_SELECTION_SELECT));
133 strings.SetString("keyboardSelect",
134 l10n_util::GetStringUTF16(IDS_KEYBOARD_SELECTION_SELECT));
135 strings.SetString("networkSelect",
136 l10n_util::GetStringUTF16(IDS_NETWORK_SELECTION_SELECT));
137 strings.SetString("continue",
138 l10n_util::GetStringUTF16(IDS_NETWORK_SELECTION_CONTINUE_BUTTON));
139 strings.SetString("eulaScreenTitle",
140 l10n_util::GetStringUTF16(IDS_EULA_SCREEN_TITLE));
141 strings.SetString("checkboxLogging",
142 l10n_util::GetStringUTF16(IDS_EULA_CHECKBOX_ENABLE_LOGGING));
143 strings.SetString("learnMore",
144 l10n_util::GetStringUTF16(IDS_LEARN_MORE));
145 strings.SetString("back",
146 l10n_util::GetStringUTF16(IDS_EULA_BACK_BUTTON));
147 strings.SetString("acceptAgreement",
148 l10n_util::GetStringUTF16(IDS_EULA_ACCEPT_AND_CONTINUE_BUTTON));
149 SetFontAndTextDirection(&strings);
150
151 static const base::StringPiece html(
152 ResourceBundle::GetSharedInstance().GetRawDataResource(IDR_OOBE_HTML));
153
154 const std::string& full_html = jstemplate_builder::GetI18nTemplateHtml(
155 html, &strings);
156
157 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes());
158 html_bytes->data.resize(full_html.size());
159 std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin());
160
161 SendResponse(request_id, html_bytes);
162 }
163
164 // OobeHandler ------------------------------------------------------------
165
166 OobeHandler::OobeHandler()
167 : tab_contents_(NULL),
168 state_(SCREEN_LOADING) {
169 }
170
171 OobeHandler::~OobeHandler() {
172 }
173
174 WebUIMessageHandler* OobeHandler::Attach(WebUI* web_ui) {
175 return WebUIMessageHandler::Attach(web_ui);
176 }
177
178 void OobeHandler::Init(TabContents* contents) {
179 tab_contents_ = contents;
180 }
181
182 void OobeHandler::RegisterMessages() {
183 web_ui_->RegisterMessageCallback(kJsApiScreenStateInitialize,
184 NewCallback(this, &OobeHandler::HandleScreenStateInitialize));
185 }
186
187 void OobeHandler::HandleScreenStateInitialize(const ListValue* args) {
188 const size_t kScreenStateInitializeParamCount = 0;
189 if (args->GetSize() != kScreenStateInitializeParamCount) {
190 NOTREACHED();
191 return;
192 }
193 scoped_refptr<TaskProxy> task = new TaskProxy(AsWeakPtr());
194 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
195 NewRunnableMethod(task.get(), &TaskProxy::HandleInitialize));
196 }
197
198 void OobeHandler::InitializeScreenState() {
199 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
200 // TODO(nkostylev): Integrated with OOBE flow, controllers.
201 UpdatePage();
202 }
203
204 void OobeHandler::UpdatePage() {
205 DictionaryValue screen_info_dict;
206 VLOG(1) << "New state: " << state_;
207 screen_info_dict.SetInteger(kState, state_);
208 web_ui_->CallJavascriptFunction(kJsApiScreenStateChanged, screen_info_dict);
209 }
210
211 // OobeUI ----------------------------------------------------------------------
212
213 OobeUI::OobeUI(TabContents* contents) : WebUI(contents) {
214 OobeHandler* handler = new OobeHandler();
215 AddMessageHandler((handler)->Attach(this));
216 handler->Init(contents);
217 OobeUIHTMLSource* html_source = new OobeUIHTMLSource();
218
219 // Set up the chrome://oobe/ source.
220 contents->profile()->GetChromeURLDataManager()->AddDataSource(html_source);
221 }
222
223 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698