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/ui/webui/options2/options_ui2.h" | 5 #include "chrome/browser/ui/webui/options2/options_ui2.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 #include "chrome/browser/ui/webui/options2/password_manager_handler2.h" | 35 #include "chrome/browser/ui/webui/options2/password_manager_handler2.h" |
36 #include "chrome/browser/ui/webui/options2/search_engine_manager_handler2.h" | 36 #include "chrome/browser/ui/webui/options2/search_engine_manager_handler2.h" |
37 #include "chrome/browser/ui/webui/options2/startup_pages_handler2.h" | 37 #include "chrome/browser/ui/webui/options2/startup_pages_handler2.h" |
38 #include "chrome/browser/ui/webui/options2/stop_syncing_handler2.h" | 38 #include "chrome/browser/ui/webui/options2/stop_syncing_handler2.h" |
39 #include "chrome/browser/ui/webui/options2/web_intents_settings_handler2.h" | 39 #include "chrome/browser/ui/webui/options2/web_intents_settings_handler2.h" |
40 #include "chrome/browser/ui/webui/theme_source.h" | 40 #include "chrome/browser/ui/webui/theme_source.h" |
41 #include "chrome/common/jstemplate_builder.h" | 41 #include "chrome/common/jstemplate_builder.h" |
42 #include "chrome/common/time_format.h" | 42 #include "chrome/common/time_format.h" |
43 #include "chrome/common/url_constants.h" | 43 #include "chrome/common/url_constants.h" |
44 #include "content/browser/renderer_host/render_view_host.h" | 44 #include "content/browser/renderer_host/render_view_host.h" |
| 45 #include "content/browser/webui/web_ui.h" |
45 #include "content/public/browser/browser_thread.h" | 46 #include "content/public/browser/browser_thread.h" |
46 #include "content/public/browser/notification_types.h" | 47 #include "content/public/browser/notification_types.h" |
47 #include "content/public/browser/web_contents.h" | 48 #include "content/public/browser/web_contents.h" |
48 #include "content/public/browser/web_contents_delegate.h" | 49 #include "content/public/browser/web_contents_delegate.h" |
49 #include "grit/chromium_strings.h" | 50 #include "grit/chromium_strings.h" |
50 #include "grit/generated_resources.h" | 51 #include "grit/generated_resources.h" |
51 #include "grit/locale_settings.h" | 52 #include "grit/locale_settings.h" |
52 #include "grit/options2_resources.h" | 53 #include "grit/options2_resources.h" |
53 #include "grit/theme_resources.h" | 54 #include "grit/theme_resources.h" |
54 #include "grit/theme_resources_standard.h" | 55 #include "grit/theme_resources_standard.h" |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE), | 190 l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE), |
190 l10n_util::GetStringUTF16(title_id))); | 191 l10n_util::GetStringUTF16(title_id))); |
191 } | 192 } |
192 | 193 |
193 //////////////////////////////////////////////////////////////////////////////// | 194 //////////////////////////////////////////////////////////////////////////////// |
194 // | 195 // |
195 // OptionsUI | 196 // OptionsUI |
196 // | 197 // |
197 //////////////////////////////////////////////////////////////////////////////// | 198 //////////////////////////////////////////////////////////////////////////////// |
198 | 199 |
199 OptionsUI::OptionsUI(WebContents* contents) | 200 OptionsUI::OptionsUI(WebUI* web_ui) |
200 : WebUI(contents, this), | 201 : WebUIController(web_ui), |
201 initialized_handlers_(false) { | 202 initialized_handlers_(false) { |
202 DictionaryValue* localized_strings = new DictionaryValue(); | 203 DictionaryValue* localized_strings = new DictionaryValue(); |
203 | 204 |
204 CoreOptionsHandler* core_handler; | 205 CoreOptionsHandler* core_handler; |
205 #if defined(OS_CHROMEOS) | 206 #if defined(OS_CHROMEOS) |
206 core_handler = new chromeos::options2::CoreChromeOSOptionsHandler(); | 207 core_handler = new chromeos::options2::CoreChromeOSOptionsHandler(); |
207 #else | 208 #else |
208 core_handler = new CoreOptionsHandler(); | 209 core_handler = new CoreOptionsHandler(); |
209 #endif | 210 #endif |
210 core_handler->set_handlers_host(this); | 211 core_handler->set_handlers_host(this); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 #if defined(USE_NSS) | 266 #if defined(USE_NSS) |
266 AddOptionsPageUIHandler(localized_strings, new CertificateManagerHandler()); | 267 AddOptionsPageUIHandler(localized_strings, new CertificateManagerHandler()); |
267 #endif | 268 #endif |
268 AddOptionsPageUIHandler(localized_strings, new HandlerOptionsHandler()); | 269 AddOptionsPageUIHandler(localized_strings, new HandlerOptionsHandler()); |
269 | 270 |
270 // |localized_strings| ownership is taken over by this constructor. | 271 // |localized_strings| ownership is taken over by this constructor. |
271 OptionsUIHTMLSource* html_source = | 272 OptionsUIHTMLSource* html_source = |
272 new OptionsUIHTMLSource(localized_strings); | 273 new OptionsUIHTMLSource(localized_strings); |
273 | 274 |
274 // Set up the chrome://settings-frame/ source. | 275 // Set up the chrome://settings-frame/ source. |
275 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); | 276 Profile* profile = Profile::FromBrowserContext( |
| 277 web_ui->web_contents()->GetBrowserContext()); |
276 profile->GetChromeURLDataManager()->AddDataSource(html_source); | 278 profile->GetChromeURLDataManager()->AddDataSource(html_source); |
277 | 279 |
278 // Set up the chrome://theme/ source. | 280 // Set up the chrome://theme/ source. |
279 ThemeSource* theme = new ThemeSource(profile); | 281 ThemeSource* theme = new ThemeSource(profile); |
280 profile->GetChromeURLDataManager()->AddDataSource(theme); | 282 profile->GetChromeURLDataManager()->AddDataSource(theme); |
281 | 283 |
282 #if defined(OS_CHROMEOS) | 284 #if defined(OS_CHROMEOS) |
283 // Set up the chrome://userimage/ source. | 285 // Set up the chrome://userimage/ source. |
284 chromeos::options2::UserImageSource* user_image_source = | 286 chromeos::options2::UserImageSource* user_image_source = |
285 new chromeos::options2::UserImageSource(); | 287 new chromeos::options2::UserImageSource(); |
286 profile->GetChromeURLDataManager()->AddDataSource(user_image_source); | 288 profile->GetChromeURLDataManager()->AddDataSource(user_image_source); |
287 #endif | 289 #endif |
288 } | 290 } |
289 | 291 |
290 OptionsUI::~OptionsUI() { | 292 OptionsUI::~OptionsUI() { |
291 // Uninitialize all registered handlers. The base class owns them and it will | 293 // Uninitialize all registered handlers. The base class owns them and it will |
292 // eventually delete them. Skip over the generic handler. | 294 // eventually delete them. Skip over the generic handler. |
293 for (std::vector<WebUIMessageHandler*>::iterator iter = handlers_.begin() + 1; | 295 for (size_t i = 0; i < handlers_.size(); ++i) |
294 iter != handlers_.end(); | 296 handlers_[i]->Uninitialize(); |
295 ++iter) { | |
296 static_cast<OptionsPageUIHandler*>(*iter)->Uninitialize(); | |
297 } | |
298 } | 297 } |
299 | 298 |
300 void OptionsUI::RenderViewCreated(RenderViewHost* render_view_host) { | 299 void OptionsUI::RenderViewCreated(RenderViewHost* render_view_host) { |
301 SetCommandLineString(render_view_host); | 300 SetCommandLineString(render_view_host); |
302 } | 301 } |
303 | 302 |
304 void OptionsUI::RenderViewReused(RenderViewHost* render_view_host) { | 303 void OptionsUI::RenderViewReused(RenderViewHost* render_view_host) { |
305 SetCommandLineString(render_view_host); | 304 SetCommandLineString(render_view_host); |
306 } | 305 } |
307 | 306 |
308 void OptionsUI::DidBecomeActiveForReusedRenderView() { | 307 void OptionsUI::DidBecomeActiveForReusedRenderView() { |
309 // When the renderer is re-used (e.g., for back/forward navigation within | 308 // When the renderer is re-used (e.g., for back/forward navigation within |
310 // options), the handlers are torn down and rebuilt, so are no longer | 309 // options), the handlers are torn down and rebuilt, so are no longer |
311 // initialized, but the web page's DOM may remain intact, in which case onload | 310 // initialized, but the web page's DOM may remain intact, in which case onload |
312 // won't fire to initilize the handlers. To make sure initialization always | 311 // won't fire to initilize the handlers. To make sure initialization always |
313 // happens, call reinitializeCore (which is a no-op unless the DOM was already | 312 // happens, call reinitializeCore (which is a no-op unless the DOM was already |
314 // initialized). | 313 // initialized). |
315 CallJavascriptFunction("OptionsPage.reinitializeCore"); | 314 web_ui()->CallJavascriptFunction("OptionsPage.reinitializeCore"); |
316 } | 315 } |
317 | 316 |
318 // static | 317 // static |
319 RefCountedMemory* OptionsUI::GetFaviconResourceBytes() { | 318 RefCountedMemory* OptionsUI::GetFaviconResourceBytes() { |
320 return ResourceBundle::GetSharedInstance(). | 319 return ResourceBundle::GetSharedInstance(). |
321 LoadDataResourceBytes(IDR_SETTINGS_FAVICON); | 320 LoadDataResourceBytes(IDR_SETTINGS_FAVICON); |
322 } | 321 } |
323 | 322 |
324 void OptionsUI::InitializeHandlers() { | 323 void OptionsUI::InitializeHandlers() { |
325 Profile* profile = | 324 Profile* profile = Profile::FromBrowserContext( |
326 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 325 web_ui()->web_contents()->GetBrowserContext()); |
327 DCHECK(!profile->IsOffTheRecord() || Profile::IsGuestSession()); | 326 DCHECK(!profile->IsOffTheRecord() || Profile::IsGuestSession()); |
328 | 327 |
329 // The reinitialize call from DidBecomeActiveForReusedRenderView end up being | 328 // The reinitialize call from DidBecomeActiveForReusedRenderView end up being |
330 // delivered after a new web page DOM has been brought up in an existing | 329 // delivered after a new web page DOM has been brought up in an existing |
331 // renderer (due to IPC delays), causing this method to be called twice. If | 330 // renderer (due to IPC delays), causing this method to be called twice. If |
332 // that happens, ignore the second call. | 331 // that happens, ignore the second call. |
333 if (initialized_handlers_) | 332 if (initialized_handlers_) |
334 return; | 333 return; |
335 initialized_handlers_ = true; | 334 initialized_handlers_ = true; |
336 | 335 |
337 std::vector<WebUIMessageHandler*>::iterator iter; | 336 std::vector<WebUIMessageHandler*>::iterator iter; |
338 // Skip over the generic handler. | 337 for (size_t i = 0; i < handlers_.size(); ++i) |
339 for (iter = handlers_.begin() + 1; iter != handlers_.end(); ++iter) { | 338 handlers_[i]->Initialize(); |
340 (static_cast<OptionsPageUIHandler*>(*iter))->Initialize(); | |
341 } | |
342 } | 339 } |
343 | 340 |
344 void OptionsUI::AddOptionsPageUIHandler(DictionaryValue* localized_strings, | 341 void OptionsUI::AddOptionsPageUIHandler(DictionaryValue* localized_strings, |
345 OptionsPageUIHandler* handler_raw) { | 342 OptionsPageUIHandler* handler_raw) { |
346 scoped_ptr<OptionsPageUIHandler> handler(handler_raw); | 343 scoped_ptr<OptionsPageUIHandler> handler(handler_raw); |
347 DCHECK(handler.get()); | 344 DCHECK(handler.get()); |
348 // Add only if handler's service is enabled. | 345 // Add only if handler's service is enabled. |
349 if (handler->IsEnabled()) { | 346 if (handler->IsEnabled()) { |
350 handler->GetLocalizedValues(localized_strings); | 347 handler->GetLocalizedValues(localized_strings); |
351 // Add handler to the list and also pass the ownership. | 348 // Add handler to the list and also pass the ownership. |
352 AddMessageHandler(handler.release()); | 349 web_ui()->AddMessageHandler(handler.release()); |
| 350 handlers_.push_back(handler_raw); |
353 } | 351 } |
354 } | 352 } |
355 | 353 |
356 void OptionsUI::SetCommandLineString(RenderViewHost* render_view_host) { | 354 void OptionsUI::SetCommandLineString(RenderViewHost* render_view_host) { |
357 std::string command_line_string; | 355 std::string command_line_string; |
358 | 356 |
359 #if defined(OS_WIN) | 357 #if defined(OS_WIN) |
360 command_line_string = | 358 command_line_string = |
361 WideToASCII(CommandLine::ForCurrentProcess()->GetCommandLineString()); | 359 WideToASCII(CommandLine::ForCurrentProcess()->GetCommandLineString()); |
362 #else | 360 #else |
363 command_line_string = | 361 command_line_string = |
364 CommandLine::ForCurrentProcess()->GetCommandLineString(); | 362 CommandLine::ForCurrentProcess()->GetCommandLineString(); |
365 #endif | 363 #endif |
366 | 364 |
367 render_view_host->SetWebUIProperty("commandLineString", command_line_string); | 365 render_view_host->SetWebUIProperty("commandLineString", command_line_string); |
368 } | 366 } |
369 | 367 |
370 } // namespace options2 | 368 } // namespace options2 |
OLD | NEW |