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 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 } | 333 } |
334 | 334 |
335 void OptionsUI::RenderViewCreated(RenderViewHost* render_view_host) { | 335 void OptionsUI::RenderViewCreated(RenderViewHost* render_view_host) { |
336 SetCommandLineString(render_view_host); | 336 SetCommandLineString(render_view_host); |
337 } | 337 } |
338 | 338 |
339 void OptionsUI::RenderViewReused(RenderViewHost* render_view_host) { | 339 void OptionsUI::RenderViewReused(RenderViewHost* render_view_host) { |
340 SetCommandLineString(render_view_host); | 340 SetCommandLineString(render_view_host); |
341 } | 341 } |
342 | 342 |
343 void OptionsUI::DidBecomeActiveForReusedRenderView() { | |
344 // When the renderer is re-used (e.g., for back/forward navigation within | |
345 // options), the handlers are torn down and rebuilt, so are no longer | |
346 // initialized, but the web page's DOM may remain intact, in which case onload | |
347 // won't fire to initilize the handlers. To make sure initialization always | |
348 // happens, call reinitializeCore (which is a no-op unless the DOM was already | |
349 // initialized). | |
350 web_ui()->CallJavascriptFunction("OptionsPage.reinitializeCore"); | |
351 } | |
352 | |
353 // static | 343 // static |
354 void OptionsUI::ProcessAutocompleteSuggestions( | 344 void OptionsUI::ProcessAutocompleteSuggestions( |
355 const AutocompleteResult& autocompleteResult, | 345 const AutocompleteResult& autocompleteResult, |
356 ListValue * const suggestions) { | 346 ListValue * const suggestions) { |
357 for (size_t i = 0; i < autocompleteResult.size(); ++i) { | 347 for (size_t i = 0; i < autocompleteResult.size(); ++i) { |
358 const AutocompleteMatch& match = autocompleteResult.match_at(i); | 348 const AutocompleteMatch& match = autocompleteResult.match_at(i); |
359 AutocompleteMatch::Type type = match.type; | 349 AutocompleteMatch::Type type = match.type; |
360 if (type != AutocompleteMatch::HISTORY_URL && | 350 if (type != AutocompleteMatch::HISTORY_URL && |
361 type != AutocompleteMatch::HISTORY_TITLE && | 351 type != AutocompleteMatch::HISTORY_TITLE && |
362 type != AutocompleteMatch::HISTORY_BODY && | 352 type != AutocompleteMatch::HISTORY_BODY && |
(...skipping 11 matching lines...) Expand all Loading... |
374 // static | 364 // static |
375 RefCountedMemory* OptionsUI::GetFaviconResourceBytes() { | 365 RefCountedMemory* OptionsUI::GetFaviconResourceBytes() { |
376 return ResourceBundle::GetSharedInstance(). | 366 return ResourceBundle::GetSharedInstance(). |
377 LoadDataResourceBytes(IDR_SETTINGS_FAVICON); | 367 LoadDataResourceBytes(IDR_SETTINGS_FAVICON); |
378 } | 368 } |
379 | 369 |
380 void OptionsUI::InitializeHandlers() { | 370 void OptionsUI::InitializeHandlers() { |
381 Profile* profile = Profile::FromWebUI(web_ui()); | 371 Profile* profile = Profile::FromWebUI(web_ui()); |
382 DCHECK(!profile->IsOffTheRecord() || Profile::IsGuestSession()); | 372 DCHECK(!profile->IsOffTheRecord() || Profile::IsGuestSession()); |
383 | 373 |
384 // The reinitialize call from DidBecomeActiveForReusedRenderView end up being | 374 // A new web page DOM has been brought up in an existing renderer, causing |
385 // delivered after a new web page DOM has been brought up in an existing | 375 // this method to be called twice. If that happens, ignore the second call. |
386 // renderer (due to IPC delays), causing this method to be called twice. If | |
387 // that happens, ignore the second call. | |
388 if (!initialized_handlers_) { | 376 if (!initialized_handlers_) { |
389 for (size_t i = 0; i < handlers_.size(); ++i) | 377 for (size_t i = 0; i < handlers_.size(); ++i) |
390 handlers_[i]->InitializeHandler(); | 378 handlers_[i]->InitializeHandler(); |
391 initialized_handlers_ = true; | 379 initialized_handlers_ = true; |
| 380 |
| 381 #if defined(OS_CHROMEOS) |
| 382 pointer_device_observer_->Init(); |
| 383 #endif |
392 } | 384 } |
393 | 385 |
394 // Always initialize the page as when handlers are left over we still need to | 386 // Always initialize the page as when handlers are left over we still need to |
395 // do various things like show/hide sections and send data to the Javascript. | 387 // do various things like show/hide sections and send data to the Javascript. |
396 for (size_t i = 0; i < handlers_.size(); ++i) | 388 for (size_t i = 0; i < handlers_.size(); ++i) |
397 handlers_[i]->InitializePage(); | 389 handlers_[i]->InitializePage(); |
398 | |
399 #if defined(OS_CHROMEOS) | |
400 pointer_device_observer_->Init(); | |
401 #endif | |
402 } | 390 } |
403 | 391 |
404 void OptionsUI::AddOptionsPageUIHandler(DictionaryValue* localized_strings, | 392 void OptionsUI::AddOptionsPageUIHandler(DictionaryValue* localized_strings, |
405 OptionsPageUIHandler* handler_raw) { | 393 OptionsPageUIHandler* handler_raw) { |
406 scoped_ptr<OptionsPageUIHandler> handler(handler_raw); | 394 scoped_ptr<OptionsPageUIHandler> handler(handler_raw); |
407 DCHECK(handler.get()); | 395 DCHECK(handler.get()); |
408 // Add only if handler's service is enabled. | 396 // Add only if handler's service is enabled. |
409 if (handler->IsEnabled()) { | 397 if (handler->IsEnabled()) { |
410 // Add handler to the list and also pass the ownership. | 398 // Add handler to the list and also pass the ownership. |
411 web_ui()->AddMessageHandler(handler.release()); | 399 web_ui()->AddMessageHandler(handler.release()); |
(...skipping 10 matching lines...) Expand all Loading... |
422 WideToASCII(CommandLine::ForCurrentProcess()->GetCommandLineString()); | 410 WideToASCII(CommandLine::ForCurrentProcess()->GetCommandLineString()); |
423 #else | 411 #else |
424 command_line_string = | 412 command_line_string = |
425 CommandLine::ForCurrentProcess()->GetCommandLineString(); | 413 CommandLine::ForCurrentProcess()->GetCommandLineString(); |
426 #endif | 414 #endif |
427 | 415 |
428 render_view_host->SetWebUIProperty("commandLineString", command_line_string); | 416 render_view_host->SetWebUIProperty("commandLineString", command_line_string); |
429 } | 417 } |
430 | 418 |
431 } // namespace options2 | 419 } // namespace options2 |
OLD | NEW |