| 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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 l10n_util::GetStringUTF16(title_id))); | 202 l10n_util::GetStringUTF16(title_id))); |
| 203 } | 203 } |
| 204 | 204 |
| 205 //////////////////////////////////////////////////////////////////////////////// | 205 //////////////////////////////////////////////////////////////////////////////// |
| 206 // | 206 // |
| 207 // OptionsUI | 207 // OptionsUI |
| 208 // | 208 // |
| 209 //////////////////////////////////////////////////////////////////////////////// | 209 //////////////////////////////////////////////////////////////////////////////// |
| 210 | 210 |
| 211 OptionsUI::OptionsUI(content::WebUI* web_ui) | 211 OptionsUI::OptionsUI(content::WebUI* web_ui) |
| 212 : WebUIController(web_ui), | 212 : WebUIController(web_ui) { |
| 213 initialized_handlers_(false) { | |
| 214 DictionaryValue* localized_strings = new DictionaryValue(); | 213 DictionaryValue* localized_strings = new DictionaryValue(); |
| 215 | 214 |
| 216 CoreOptionsHandler* core_handler; | 215 CoreOptionsHandler* core_handler; |
| 217 #if defined(OS_CHROMEOS) | 216 #if defined(OS_CHROMEOS) |
| 218 core_handler = new chromeos::options2::CoreChromeOSOptionsHandler(); | 217 core_handler = new chromeos::options2::CoreChromeOSOptionsHandler(); |
| 219 #else | 218 #else |
| 220 core_handler = new CoreOptionsHandler(); | 219 core_handler = new CoreOptionsHandler(); |
| 221 #endif | 220 #endif |
| 222 core_handler->set_handlers_host(this); | 221 core_handler->set_handlers_host(this); |
| 223 AddOptionsPageUIHandler(localized_strings, core_handler); | 222 AddOptionsPageUIHandler(localized_strings, core_handler); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 AddOptionsPageUIHandler(localized_strings, new CertificateManagerHandler()); | 290 AddOptionsPageUIHandler(localized_strings, new CertificateManagerHandler()); |
| 292 #endif | 291 #endif |
| 293 AddOptionsPageUIHandler(localized_strings, new HandlerOptionsHandler()); | 292 AddOptionsPageUIHandler(localized_strings, new HandlerOptionsHandler()); |
| 294 | 293 |
| 295 // |localized_strings| ownership is taken over by this constructor. | 294 // |localized_strings| ownership is taken over by this constructor. |
| 296 OptionsUIHTMLSource* html_source = | 295 OptionsUIHTMLSource* html_source = |
| 297 new OptionsUIHTMLSource(localized_strings); | 296 new OptionsUIHTMLSource(localized_strings); |
| 298 | 297 |
| 299 // Set up the chrome://settings-frame/ source. | 298 // Set up the chrome://settings-frame/ source. |
| 300 Profile* profile = Profile::FromWebUI(web_ui); | 299 Profile* profile = Profile::FromWebUI(web_ui); |
| 300 DCHECK(!profile->IsOffTheRecord() || Profile::IsGuestSession()); |
| 301 profile->GetChromeURLDataManager()->AddDataSource(html_source); | 301 profile->GetChromeURLDataManager()->AddDataSource(html_source); |
| 302 | 302 |
| 303 // Set up the chrome://theme/ source. | 303 // Set up the chrome://theme/ source. |
| 304 ThemeSource* theme = new ThemeSource(profile); | 304 ThemeSource* theme = new ThemeSource(profile); |
| 305 profile->GetChromeURLDataManager()->AddDataSource(theme); | 305 profile->GetChromeURLDataManager()->AddDataSource(theme); |
| 306 | 306 |
| 307 #if defined(OS_CHROMEOS) | 307 #if defined(OS_CHROMEOS) |
| 308 // Set up the chrome://userimage/ source. | 308 // Set up the chrome://userimage/ source. |
| 309 chromeos::options2::UserImageSource* user_image_source = | 309 chromeos::options2::UserImageSource* user_image_source = |
| 310 new chromeos::options2::UserImageSource(); | 310 new chromeos::options2::UserImageSource(); |
| 311 profile->GetChromeURLDataManager()->AddDataSource(user_image_source); | 311 profile->GetChromeURLDataManager()->AddDataSource(user_image_source); |
| 312 | 312 |
| 313 pointer_device_observer_.reset( | 313 pointer_device_observer_.reset( |
| 314 new chromeos::system::PointerDeviceObserver()); | 314 new chromeos::system::PointerDeviceObserver()); |
| 315 pointer_device_observer_->AddObserver(browser_options_handler); | 315 pointer_device_observer_->AddObserver(browser_options_handler); |
| 316 pointer_device_observer_->AddObserver(pointer_handler); | 316 pointer_device_observer_->AddObserver(pointer_handler); |
| 317 pointer_device_observer_->Init(); |
| 317 #endif | 318 #endif |
| 318 } | 319 } |
| 319 | 320 |
| 320 OptionsUI::~OptionsUI() { | 321 OptionsUI::~OptionsUI() { |
| 321 // Uninitialize all registered handlers. Deleted by WebUIImpl. | 322 // Uninitialize all registered handlers. Deleted by WebUIImpl. |
| 322 for (size_t i = 0; i < handlers_.size(); ++i) | 323 for (size_t i = 0; i < handlers_.size(); ++i) |
| 323 handlers_[i]->Uninitialize(); | 324 handlers_[i]->Uninitialize(); |
| 324 } | 325 } |
| 325 | 326 |
| 326 void OptionsUI::RenderViewCreated(RenderViewHost* render_view_host) { | 327 void OptionsUI::RenderViewCreated(RenderViewHost* render_view_host) { |
| 327 SetCommandLineString(render_view_host); | 328 SetCommandLineString(render_view_host); |
| 328 } | 329 } |
| 329 | 330 |
| 330 void OptionsUI::RenderViewReused(RenderViewHost* render_view_host) { | 331 void OptionsUI::RenderViewReused(RenderViewHost* render_view_host) { |
| 331 SetCommandLineString(render_view_host); | 332 SetCommandLineString(render_view_host); |
| 332 } | 333 } |
| 333 | 334 |
| 334 void OptionsUI::DidBecomeActiveForReusedRenderView() { | |
| 335 // When the renderer is re-used (e.g., for back/forward navigation within | |
| 336 // options), the handlers are torn down and rebuilt, so are no longer | |
| 337 // initialized, but the web page's DOM may remain intact, in which case onload | |
| 338 // won't fire to initilize the handlers. To make sure initialization always | |
| 339 // happens, call reinitializeCore (which is a no-op unless the DOM was already | |
| 340 // initialized). | |
| 341 web_ui()->CallJavascriptFunction("OptionsPage.reinitializeCore"); | |
| 342 } | |
| 343 | |
| 344 // static | 335 // static |
| 345 void OptionsUI::ProcessAutocompleteSuggestions( | 336 void OptionsUI::ProcessAutocompleteSuggestions( |
| 346 const AutocompleteResult& autocompleteResult, | 337 const AutocompleteResult& autocompleteResult, |
| 347 ListValue * const suggestions) { | 338 ListValue * const suggestions) { |
| 348 for (size_t i = 0; i < autocompleteResult.size(); ++i) { | 339 for (size_t i = 0; i < autocompleteResult.size(); ++i) { |
| 349 const AutocompleteMatch& match = autocompleteResult.match_at(i); | 340 const AutocompleteMatch& match = autocompleteResult.match_at(i); |
| 350 AutocompleteMatch::Type type = match.type; | 341 AutocompleteMatch::Type type = match.type; |
| 351 if (type != AutocompleteMatch::HISTORY_URL && | 342 if (type != AutocompleteMatch::HISTORY_URL && |
| 352 type != AutocompleteMatch::HISTORY_TITLE && | 343 type != AutocompleteMatch::HISTORY_TITLE && |
| 353 type != AutocompleteMatch::HISTORY_BODY && | 344 type != AutocompleteMatch::HISTORY_BODY && |
| 354 type != AutocompleteMatch::HISTORY_KEYWORD && | 345 type != AutocompleteMatch::HISTORY_KEYWORD && |
| 355 type != AutocompleteMatch::NAVSUGGEST) | 346 type != AutocompleteMatch::NAVSUGGEST) |
| 356 continue; | 347 continue; |
| 357 DictionaryValue* entry = new DictionaryValue(); | 348 DictionaryValue* entry = new DictionaryValue(); |
| 358 entry->SetString("title", match.description); | 349 entry->SetString("title", match.description); |
| 359 entry->SetString("displayURL", match.contents); | 350 entry->SetString("displayURL", match.contents); |
| 360 entry->SetString("url", match.destination_url.spec()); | 351 entry->SetString("url", match.destination_url.spec()); |
| 361 suggestions->Append(entry); | 352 suggestions->Append(entry); |
| 362 } | 353 } |
| 363 } | 354 } |
| 364 | 355 |
| 365 // static | 356 // static |
| 366 RefCountedMemory* OptionsUI::GetFaviconResourceBytes() { | 357 RefCountedMemory* OptionsUI::GetFaviconResourceBytes() { |
| 367 return ResourceBundle::GetSharedInstance(). | 358 return ResourceBundle::GetSharedInstance(). |
| 368 LoadDataResourceBytes(IDR_SETTINGS_FAVICON); | 359 LoadDataResourceBytes(IDR_SETTINGS_FAVICON); |
| 369 } | 360 } |
| 370 | 361 |
| 371 void OptionsUI::InitializeHandlers() { | 362 void OptionsUI::InitializePages() { |
| 372 Profile* profile = Profile::FromWebUI(web_ui()); | |
| 373 DCHECK(!profile->IsOffTheRecord() || Profile::IsGuestSession()); | |
| 374 | |
| 375 // The reinitialize call from DidBecomeActiveForReusedRenderView end up being | |
| 376 // delivered after a new web page DOM has been brought up in an existing | |
| 377 // renderer (due to IPC delays), causing this method to be called twice. If | |
| 378 // that happens, ignore the second call. | |
| 379 if (!initialized_handlers_) { | |
| 380 for (size_t i = 0; i < handlers_.size(); ++i) | |
| 381 handlers_[i]->InitializeHandler(); | |
| 382 initialized_handlers_ = true; | |
| 383 } | |
| 384 | |
| 385 // Always initialize the page as when handlers are left over we still need to | 363 // Always initialize the page as when handlers are left over we still need to |
| 386 // do various things like show/hide sections and send data to the Javascript. | 364 // do various things like show/hide sections and send data to the Javascript. |
| 387 for (size_t i = 0; i < handlers_.size(); ++i) | 365 for (size_t i = 0; i < handlers_.size(); ++i) |
| 388 handlers_[i]->InitializePage(); | 366 handlers_[i]->InitializePage(); |
| 367 } |
| 389 | 368 |
| 390 #if defined(OS_CHROMEOS) | 369 void OptionsUI::InitializeHandlers() { |
| 391 pointer_device_observer_->Init(); | 370 for (size_t i = 0; i < handlers_.size(); i++) |
| 392 #endif | 371 handlers_[i]->InitializeHandler(); |
| 393 } | 372 } |
| 394 | 373 |
| 395 void OptionsUI::AddOptionsPageUIHandler(DictionaryValue* localized_strings, | 374 void OptionsUI::AddOptionsPageUIHandler(DictionaryValue* localized_strings, |
| 396 OptionsPageUIHandler* handler_raw) { | 375 OptionsPageUIHandler* handler_raw) { |
| 397 scoped_ptr<OptionsPageUIHandler> handler(handler_raw); | 376 scoped_ptr<OptionsPageUIHandler> handler(handler_raw); |
| 398 DCHECK(handler.get()); | 377 DCHECK(handler.get()); |
| 399 // Add only if handler's service is enabled. | 378 // Add only if handler's service is enabled. |
| 400 if (handler->IsEnabled()) { | 379 if (handler->IsEnabled()) { |
| 401 // Add handler to the list and also pass the ownership. | 380 // Add handler to the list |
| 402 web_ui()->AddMessageHandler(handler.release()); | 381 web_ui()->AddMessageHandler(handler.get()); |
| 403 handler_raw->GetLocalizedValues(localized_strings); | 382 handler->GetLocalizedValues(localized_strings); |
| 404 handlers_.push_back(handler_raw); | 383 handlers_.push_back(handler.release()); |
| 405 } | 384 } |
| 406 } | 385 } |
| 407 | 386 |
| 408 void OptionsUI::SetCommandLineString(RenderViewHost* render_view_host) { | 387 void OptionsUI::SetCommandLineString(RenderViewHost* render_view_host) { |
| 409 std::string command_line_string; | 388 std::string command_line_string; |
| 410 | 389 |
| 411 #if defined(OS_WIN) | 390 #if defined(OS_WIN) |
| 412 command_line_string = | 391 command_line_string = |
| 413 WideToASCII(CommandLine::ForCurrentProcess()->GetCommandLineString()); | 392 WideToASCII(CommandLine::ForCurrentProcess()->GetCommandLineString()); |
| 414 #else | 393 #else |
| 415 command_line_string = | 394 command_line_string = |
| 416 CommandLine::ForCurrentProcess()->GetCommandLineString(); | 395 CommandLine::ForCurrentProcess()->GetCommandLineString(); |
| 417 #endif | 396 #endif |
| 418 | 397 |
| 419 render_view_host->SetWebUIProperty("commandLineString", command_line_string); | 398 render_view_host->SetWebUIProperty("commandLineString", command_line_string); |
| 420 } | 399 } |
| 421 | 400 |
| 422 } // namespace options2 | 401 } // namespace options2 |
| OLD | NEW |