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