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