Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1247)

Side by Side Diff: chrome/browser/ui/webui/options2/options_ui2.cc

Issue 9994005: Separate handler initialization from page initialization (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: estade review Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 #endif 312 #endif
313
314 InitializeHandlers();
Dan Beam 2012/04/05 21:38:21 We could also simply call handler->InitializeHandl
313 } 315 }
314 316
315 OptionsUI::~OptionsUI() { 317 OptionsUI::~OptionsUI() {
316 // Uninitialize all registered handlers. Deleted by WebUIImpl. 318 // Uninitialize all registered handlers. Deleted by WebUIImpl.
317 for (size_t i = 0; i < handlers_.size(); ++i) 319 for (size_t i = 0; i < handlers_.size(); ++i)
318 handlers_[i]->Uninitialize(); 320 handlers_[i]->Uninitialize();
319 } 321 }
320 322
321 void OptionsUI::RenderViewCreated(RenderViewHost* render_view_host) { 323 void OptionsUI::RenderViewCreated(RenderViewHost* render_view_host) {
322 SetCommandLineString(render_view_host); 324 SetCommandLineString(render_view_host);
323 } 325 }
324 326
325 void OptionsUI::RenderViewReused(RenderViewHost* render_view_host) { 327 void OptionsUI::RenderViewReused(RenderViewHost* render_view_host) {
326 SetCommandLineString(render_view_host); 328 SetCommandLineString(render_view_host);
327 } 329 }
328 330
329 void OptionsUI::DidBecomeActiveForReusedRenderView() { 331 void OptionsUI::DidBecomeActiveForReusedRenderView() {
330 // When the renderer is re-used (e.g., for back/forward navigation within 332 // 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 333 // 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 334 // 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 335 // 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 336 // happens, call reinitializeCore (which is a no-op unless the DOM was already
335 // initialized). 337 // initialized).
336 web_ui()->CallJavascriptFunction("OptionsPage.reinitializeCore"); 338 web_ui()->CallJavascriptFunction("OptionsPage.reinitializeCore");
Tyler Breisacher (Chromium) 2012/04/05 20:57:40 I'm not sure whether we still need this.
Dan Beam 2012/04/05 21:38:21 I don't think we do.
337 } 339 }
338 340
339 // static 341 // static
340 void OptionsUI::ProcessAutocompleteSuggestions( 342 void OptionsUI::ProcessAutocompleteSuggestions(
341 const AutocompleteResult& autocompleteResult, 343 const AutocompleteResult& autocompleteResult,
342 ListValue * const suggestions) { 344 ListValue * const suggestions) {
343 for (size_t i = 0; i < autocompleteResult.size(); ++i) { 345 for (size_t i = 0; i < autocompleteResult.size(); ++i) {
344 const AutocompleteMatch& match = autocompleteResult.match_at(i); 346 const AutocompleteMatch& match = autocompleteResult.match_at(i);
345 AutocompleteMatch::Type type = match.type; 347 AutocompleteMatch::Type type = match.type;
346 if (type != AutocompleteMatch::HISTORY_URL && 348 if (type != AutocompleteMatch::HISTORY_URL &&
(...skipping 23 matching lines...) Expand all
370 // The reinitialize call from DidBecomeActiveForReusedRenderView end up being 372 // The reinitialize call from DidBecomeActiveForReusedRenderView end up being
371 // delivered after a new web page DOM has been brought up in an existing 373 // 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 374 // renderer (due to IPC delays), causing this method to be called twice. If
373 // that happens, ignore the second call. 375 // that happens, ignore the second call.
374 if (!initialized_handlers_) { 376 if (!initialized_handlers_) {
375 for (size_t i = 0; i < handlers_.size(); ++i) 377 for (size_t i = 0; i < handlers_.size(); ++i)
376 handlers_[i]->InitializeHandler(); 378 handlers_[i]->InitializeHandler();
377 initialized_handlers_ = true; 379 initialized_handlers_ = true;
378 } 380 }
379 381
380 // 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.
382 for (size_t i = 0; i < handlers_.size(); ++i)
383 handlers_[i]->InitializePage();
384
385 #if defined(OS_CHROMEOS) 382 #if defined(OS_CHROMEOS)
386 pointer_device_observer_->Init(); 383 pointer_device_observer_->Init();
387 #endif 384 #endif
388 } 385 }
389 386
387 void OptionsUI::InitializePages() {
388 // Always initialize the page as when handlers are left over we still need to
389 // do various things like show/hide sections and send data to the Javascript.
390 for (size_t i = 0; i < handlers_.size(); ++i)
391 handlers_[i]->InitializePage();
392 }
393
390 void OptionsUI::AddOptionsPageUIHandler(DictionaryValue* localized_strings, 394 void OptionsUI::AddOptionsPageUIHandler(DictionaryValue* localized_strings,
391 OptionsPageUIHandler* handler_raw) { 395 OptionsPageUIHandler* handler_raw) {
392 scoped_ptr<OptionsPageUIHandler> handler(handler_raw); 396 scoped_ptr<OptionsPageUIHandler> handler(handler_raw);
393 DCHECK(handler.get()); 397 DCHECK(handler.get());
394 // Add only if handler's service is enabled. 398 // Add only if handler's service is enabled.
395 if (handler->IsEnabled()) { 399 if (handler->IsEnabled()) {
396 // Add handler to the list and also pass the ownership. 400 // Add handler to the list and also pass the ownership.
397 web_ui()->AddMessageHandler(handler.release()); 401 web_ui()->AddMessageHandler(handler.release());
Dan Beam 2012/04/05 21:38:21 seeing .release() at the beginning here is weird..
Tyler Breisacher (Chromium) 2012/04/05 22:56:16 If IsEnabled is true, we release it because we wan
Dan Beam 2012/04/06 03:38:16 Use classes to do resource management, don't delet
Tyler Breisacher (Chromium) 2012/04/06 16:59:44 It *should* jump out at us. We *are* using a point
398 handler_raw->GetLocalizedValues(localized_strings); 402 handler_raw->GetLocalizedValues(localized_strings);
Dan Beam 2012/04/05 21:38:21 handler->InitializeHandler(); // here instead of
Tyler Breisacher (Chromium) 2012/04/05 22:56:16 +1 If we do it before it gets added to handlers_
Evan Stade 2012/04/06 22:14:30 yes, it would be fine to move this above AddMessag
399 handlers_.push_back(handler_raw); 403 handlers_.push_back(handler_raw);
Evan Stade 2012/04/06 22:14:30 I don't know why handlers_ exists. There's already
400 } 404 }
401 } 405 }
402 406
403 void OptionsUI::SetCommandLineString(RenderViewHost* render_view_host) { 407 void OptionsUI::SetCommandLineString(RenderViewHost* render_view_host) {
404 std::string command_line_string; 408 std::string command_line_string;
405 409
406 #if defined(OS_WIN) 410 #if defined(OS_WIN)
407 command_line_string = 411 command_line_string =
408 WideToASCII(CommandLine::ForCurrentProcess()->GetCommandLineString()); 412 WideToASCII(CommandLine::ForCurrentProcess()->GetCommandLineString());
409 #else 413 #else
410 command_line_string = 414 command_line_string =
411 CommandLine::ForCurrentProcess()->GetCommandLineString(); 415 CommandLine::ForCurrentProcess()->GetCommandLineString();
412 #endif 416 #endif
413 417
414 render_view_host->SetWebUIProperty("commandLineString", command_line_string); 418 render_view_host->SetWebUIProperty("commandLineString", command_line_string);
415 } 419 }
416 420
417 } // namespace options2 421 } // namespace options2
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698