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 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(); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 324 } | 324 } |
| 325 | 325 |
| 326 void OptionsUI::RenderViewCreated(RenderViewHost* render_view_host) { | 326 void OptionsUI::RenderViewCreated(RenderViewHost* render_view_host) { |
| 327 SetCommandLineString(render_view_host); | 327 SetCommandLineString(render_view_host); |
| 328 } | 328 } |
| 329 | 329 |
| 330 void OptionsUI::RenderViewReused(RenderViewHost* render_view_host) { | 330 void OptionsUI::RenderViewReused(RenderViewHost* render_view_host) { |
| 331 SetCommandLineString(render_view_host); | 331 SetCommandLineString(render_view_host); |
| 332 } | 332 } |
| 333 | 333 |
| 334 void OptionsUI::DidBecomeActiveForReusedRenderView() { | |
|
Tyler Breisacher (Chromium)
2012/04/10 22:01:47
Since we took this out, does that mean it's no lon
| |
| 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 | 334 // static |
| 345 void OptionsUI::ProcessAutocompleteSuggestions( | 335 void OptionsUI::ProcessAutocompleteSuggestions( |
| 346 const AutocompleteResult& autocompleteResult, | 336 const AutocompleteResult& autocompleteResult, |
| 347 ListValue * const suggestions) { | 337 ListValue * const suggestions) { |
| 348 for (size_t i = 0; i < autocompleteResult.size(); ++i) { | 338 for (size_t i = 0; i < autocompleteResult.size(); ++i) { |
| 349 const AutocompleteMatch& match = autocompleteResult.match_at(i); | 339 const AutocompleteMatch& match = autocompleteResult.match_at(i); |
| 350 AutocompleteMatch::Type type = match.type; | 340 AutocompleteMatch::Type type = match.type; |
| 351 if (type != AutocompleteMatch::HISTORY_URL && | 341 if (type != AutocompleteMatch::HISTORY_URL && |
| 352 type != AutocompleteMatch::HISTORY_TITLE && | 342 type != AutocompleteMatch::HISTORY_TITLE && |
| 353 type != AutocompleteMatch::HISTORY_BODY && | 343 type != AutocompleteMatch::HISTORY_BODY && |
| 354 type != AutocompleteMatch::HISTORY_KEYWORD && | 344 type != AutocompleteMatch::HISTORY_KEYWORD && |
| 355 type != AutocompleteMatch::NAVSUGGEST) | 345 type != AutocompleteMatch::NAVSUGGEST) |
| 356 continue; | 346 continue; |
| 357 DictionaryValue* entry = new DictionaryValue(); | 347 DictionaryValue* entry = new DictionaryValue(); |
| 358 entry->SetString("title", match.description); | 348 entry->SetString("title", match.description); |
| 359 entry->SetString("displayURL", match.contents); | 349 entry->SetString("displayURL", match.contents); |
| 360 entry->SetString("url", match.destination_url.spec()); | 350 entry->SetString("url", match.destination_url.spec()); |
| 361 suggestions->Append(entry); | 351 suggestions->Append(entry); |
| 362 } | 352 } |
| 363 } | 353 } |
| 364 | 354 |
| 365 // static | 355 // static |
| 366 RefCountedMemory* OptionsUI::GetFaviconResourceBytes() { | 356 RefCountedMemory* OptionsUI::GetFaviconResourceBytes() { |
| 367 return ResourceBundle::GetSharedInstance(). | 357 return ResourceBundle::GetSharedInstance(). |
| 368 LoadDataResourceBytes(IDR_SETTINGS_FAVICON); | 358 LoadDataResourceBytes(IDR_SETTINGS_FAVICON); |
| 369 } | 359 } |
| 370 | 360 |
| 371 void OptionsUI::InitializeHandlers() { | 361 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 | 362 // 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. | 363 // do various things like show/hide sections and send data to the Javascript. |
| 387 for (size_t i = 0; i < handlers_.size(); ++i) | 364 for (size_t i = 0; i < handlers_.size(); ++i) |
| 388 handlers_[i]->InitializePage(); | 365 handlers_[i]->InitializePage(); |
| 389 | 366 |
| 390 #if defined(OS_CHROMEOS) | 367 #if defined(OS_CHROMEOS) |
| 391 pointer_device_observer_->Init(); | 368 pointer_device_observer_->Init(); |
| 392 #endif | 369 #endif |
| 393 } | 370 } |
| 394 | 371 |
| 395 void OptionsUI::AddOptionsPageUIHandler(DictionaryValue* localized_strings, | 372 void OptionsUI::AddOptionsPageUIHandler(DictionaryValue* localized_strings, |
| 396 OptionsPageUIHandler* handler_raw) { | 373 OptionsPageUIHandler* handler_raw) { |
| 397 scoped_ptr<OptionsPageUIHandler> handler(handler_raw); | 374 scoped_ptr<OptionsPageUIHandler> handler(handler_raw); |
| 398 DCHECK(handler.get()); | 375 DCHECK(handler.get()); |
| 399 // Add only if handler's service is enabled. | 376 // Add only if handler's service is enabled. |
| 400 if (handler->IsEnabled()) { | 377 if (handler->IsEnabled()) { |
| 401 // Add handler to the list and also pass the ownership. | 378 // Add handler to the list |
| 402 web_ui()->AddMessageHandler(handler.release()); | 379 web_ui()->AddMessageHandler(handler.get()); |
| 403 handler_raw->GetLocalizedValues(localized_strings); | 380 handler->InitializeHandler(); |
| 404 handlers_.push_back(handler_raw); | 381 handler->GetLocalizedValues(localized_strings); |
| 382 handlers_.push_back(handler.release()); | |
| 405 } | 383 } |
| 406 } | 384 } |
| 407 | 385 |
| 408 void OptionsUI::SetCommandLineString(RenderViewHost* render_view_host) { | 386 void OptionsUI::SetCommandLineString(RenderViewHost* render_view_host) { |
| 409 std::string command_line_string; | 387 std::string command_line_string; |
| 410 | 388 |
| 411 #if defined(OS_WIN) | 389 #if defined(OS_WIN) |
| 412 command_line_string = | 390 command_line_string = |
| 413 WideToASCII(CommandLine::ForCurrentProcess()->GetCommandLineString()); | 391 WideToASCII(CommandLine::ForCurrentProcess()->GetCommandLineString()); |
| 414 #else | 392 #else |
| 415 command_line_string = | 393 command_line_string = |
| 416 CommandLine::ForCurrentProcess()->GetCommandLineString(); | 394 CommandLine::ForCurrentProcess()->GetCommandLineString(); |
| 417 #endif | 395 #endif |
| 418 | 396 |
| 419 render_view_host->SetWebUIProperty("commandLineString", command_line_string); | 397 render_view_host->SetWebUIProperty("commandLineString", command_line_string); |
| 420 } | 398 } |
| 421 | 399 |
| 422 } // namespace options2 | 400 } // namespace options2 |
| OLD | NEW |