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

Side by Side Diff: chrome/browser/printing/print_preview_tab_controller.cc

Issue 10829463: Print preview: Handle all tab navigations in PrintPreviewTabController instead of in two places. Ha… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 4 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/printing/print_preview_tab_controller.h" 5 #include "chrome/browser/printing/print_preview_tab_controller.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 353
354 for (size_t i = 0; i < closed_preview_tabs.size(); ++i) { 354 for (size_t i = 0; i < closed_preview_tabs.size(); ++i) {
355 RemovePreviewTab(closed_preview_tabs[i]); 355 RemovePreviewTab(closed_preview_tabs[i]);
356 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( 356 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(
357 closed_preview_tabs[i]->web_contents()->GetWebUI()->GetController()); 357 closed_preview_tabs[i]->web_contents()->GetWebUI()->GetController());
358 if (print_preview_ui) 358 if (print_preview_ui)
359 print_preview_ui->OnPrintPreviewTabClosed(); 359 print_preview_ui->OnPrintPreviewTabClosed();
360 } 360 }
361 361
362 for (size_t i = 0; i < closed_initiator_tabs.size(); ++i) 362 for (size_t i = 0; i < closed_initiator_tabs.size(); ++i)
363 RemoveInitiatorTab(closed_initiator_tabs[i], false); 363 RemoveInitiatorTab(closed_initiator_tabs[i]);
364 } 364 }
365 365
366 void PrintPreviewTabController::OnTabContentsDestroyed(TabContents* tab) { 366 void PrintPreviewTabController::OnTabContentsDestroyed(TabContents* tab) {
367 TabContents* preview_tab = GetPrintPreviewForTab(tab); 367 TabContents* preview_tab = GetPrintPreviewForTab(tab);
368 if (!preview_tab) { 368 if (!preview_tab) {
369 NOTREACHED(); 369 NOTREACHED();
370 return; 370 return;
371 } 371 }
372 372
373 if (tab == preview_tab) 373 if (tab == preview_tab)
374 RemovePreviewTab(tab); 374 RemovePreviewTab(tab);
375 else 375 else
376 RemoveInitiatorTab(tab, false); 376 RemoveInitiatorTab(tab);
377 } 377 }
378 378
379 void PrintPreviewTabController::OnNavEntryCommitted( 379 void PrintPreviewTabController::OnNavEntryCommitted(
380 TabContents* tab, content::LoadCommittedDetails* details) { 380 TabContents* tab, content::LoadCommittedDetails* details) {
381 TabContents* preview_tab = GetPrintPreviewForTab(tab); 381 TabContents* preview_tab = GetPrintPreviewForTab(tab);
382 if (!preview_tab) { 382 if (!preview_tab) {
383 NOTREACHED(); 383 NOTREACHED();
384 return; 384 return;
385 } 385 }
386 bool source_tab_is_preview_tab = (tab == preview_tab); 386 bool source_tab_is_preview_tab = (tab == preview_tab);
(...skipping 19 matching lines...) Expand all
406 transition_type == content::PAGE_TRANSITION_RELOAD && 406 transition_type == content::PAGE_TRANSITION_RELOAD &&
407 nav_type == content::NAVIGATION_TYPE_EXISTING_PAGE && 407 nav_type == content::NAVIGATION_TYPE_EXISTING_PAGE &&
408 IsPrintPreviewURL(details->previous_url)) { 408 IsPrintPreviewURL(details->previous_url)) {
409 return; 409 return;
410 } 410 }
411 } 411 }
412 NOTREACHED(); 412 NOTREACHED();
413 return; 413 return;
414 } 414 }
415 415
416 // Initiator tab navigated. 416 RemoveInitiatorTab(tab);
417 RemoveInitiatorTab(tab, true);
418 } 417 }
419 418
420 TabContents* PrintPreviewTabController::CreatePrintPreviewTab( 419 TabContents* PrintPreviewTabController::CreatePrintPreviewTab(
421 TabContents* initiator_tab) { 420 TabContents* initiator_tab) {
422 AutoReset<bool> auto_reset(&is_creating_print_preview_tab_, true); 421 AutoReset<bool> auto_reset(&is_creating_print_preview_tab_, true);
423 WebContents* web_contents = initiator_tab->web_contents(); 422 WebContents* web_contents = initiator_tab->web_contents();
424 Profile* profile = 423 Profile* profile =
425 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 424 Profile::FromBrowserContext(web_contents->GetBrowserContext());
426 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kChromeFrame)) { 425 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kChromeFrame)) {
427 Browser* current_browser = new Browser( 426 Browser* current_browser = new Browser(
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 content::RenderProcessHost* rph = tab->web_contents()->GetRenderProcessHost(); 503 content::RenderProcessHost* rph = tab->web_contents()->GetRenderProcessHost();
505 if (registrar_.IsRegistered(this, 504 if (registrar_.IsRegistered(this,
506 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, 505 content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
507 content::Source<content::RenderProcessHost>( 506 content::Source<content::RenderProcessHost>(
508 rph))) { 507 rph))) {
509 registrar_.Remove(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, 508 registrar_.Remove(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
510 content::Source<content::RenderProcessHost>(rph)); 509 content::Source<content::RenderProcessHost>(rph));
511 } 510 }
512 } 511 }
513 512
514 void PrintPreviewTabController::RemoveInitiatorTab(TabContents* initiator_tab, 513 void PrintPreviewTabController::RemoveInitiatorTab(TabContents* initiator_tab) {
515 bool is_navigation) {
516 TabContents* preview_tab = GetPrintPreviewForTab(initiator_tab); 514 TabContents* preview_tab = GetPrintPreviewForTab(initiator_tab);
517 DCHECK(preview_tab); 515 DCHECK(preview_tab);
518 // Update the map entry first, so when the print preview tab gets destroyed 516 // Update the map entry first, so when the print preview tab gets destroyed
519 // and reaches RemovePreviewTab(), it does not attempt to also remove the 517 // and reaches RemovePreviewTab(), it does not attempt to also remove the
520 // initiator tab's observers. 518 // initiator tab's observers.
521 preview_tab_map_[preview_tab] = NULL; 519 preview_tab_map_[preview_tab] = NULL;
522 RemoveObservers(initiator_tab); 520 RemoveObservers(initiator_tab);
523 521
524 // For the navigation case, PrintPreviewDone() has already been called in 522 initiator_tab->print_view_manager()->PrintPreviewDone();
525 // PrintPreviewMessageHandler::NavigateToPendingEntry().
526 if (!is_navigation)
527 initiator_tab->print_view_manager()->PrintPreviewDone();
528 523
529 // Initiator tab is closed. Close the print preview tab too. 524 // Initiator tab is closed. Close the print preview tab too.
530 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( 525 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(
531 preview_tab->web_contents()->GetWebUI()->GetController()); 526 preview_tab->web_contents()->GetWebUI()->GetController());
532 if (print_preview_ui) 527 if (print_preview_ui)
533 print_preview_ui->OnInitiatorTabClosed(); 528 print_preview_ui->OnInitiatorTabClosed();
534 } 529 }
535 530
536 void PrintPreviewTabController::RemovePreviewTab(TabContents* preview_tab) { 531 void PrintPreviewTabController::RemovePreviewTab(TabContents* preview_tab) {
537 // Remove the initiator tab's observers before erasing the mapping. 532 // Remove the initiator tab's observers before erasing the mapping.
538 TabContents* initiator_tab = GetInitiatorTab(preview_tab); 533 TabContents* initiator_tab = GetInitiatorTab(preview_tab);
539 if (initiator_tab) { 534 if (initiator_tab) {
540 RemoveObservers(initiator_tab); 535 RemoveObservers(initiator_tab);
541 initiator_tab->print_view_manager()->PrintPreviewDone(); 536 initiator_tab->print_view_manager()->PrintPreviewDone();
542 } 537 }
543 538
544 // Print preview WebContents is destroyed. Notify |PrintPreviewUI| to abort 539 // Print preview WebContents is destroyed. Notify |PrintPreviewUI| to abort
545 // the initiator tab preview request. 540 // the initiator tab preview request.
546 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( 541 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(
547 preview_tab->web_contents()->GetWebUI()->GetController()); 542 preview_tab->web_contents()->GetWebUI()->GetController());
548 if (print_preview_ui) 543 if (print_preview_ui)
549 print_preview_ui->OnTabDestroyed(); 544 print_preview_ui->OnTabDestroyed();
550 545
551 preview_tab_map_.erase(preview_tab); 546 preview_tab_map_.erase(preview_tab);
552 RemoveObservers(preview_tab); 547 RemoveObservers(preview_tab);
553 } 548 }
554 549
555 } // namespace printing 550 } // namespace printing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698