| 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/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 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 } | 222 } |
| 223 | 223 |
| 224 // static | 224 // static |
| 225 void PrintPreviewTabController::PrintPreview(TabContents* tab) { | 225 void PrintPreviewTabController::PrintPreview(TabContents* tab) { |
| 226 if (tab->web_contents()->ShowingInterstitialPage()) | 226 if (tab->web_contents()->ShowingInterstitialPage()) |
| 227 return; | 227 return; |
| 228 | 228 |
| 229 PrintPreviewTabController* tab_controller = GetInstance(); | 229 PrintPreviewTabController* tab_controller = GetInstance(); |
| 230 if (!tab_controller) | 230 if (!tab_controller) |
| 231 return; | 231 return; |
| 232 if (!tab_controller->GetOrCreatePreviewTab(tab)) | 232 if (!tab_controller->GetOrCreatePreviewTab(tab)) { |
| 233 tab->print_view_manager()->PrintPreviewDone(); | 233 printing::PrintViewManager::FromWebContents(tab->web_contents())-> |
| 234 PrintPreviewDone(); |
| 235 } |
| 234 } | 236 } |
| 235 | 237 |
| 236 TabContents* PrintPreviewTabController::GetOrCreatePreviewTab( | 238 TabContents* PrintPreviewTabController::GetOrCreatePreviewTab( |
| 237 TabContents* initiator_tab) { | 239 TabContents* initiator_tab) { |
| 238 DCHECK(initiator_tab); | 240 DCHECK(initiator_tab); |
| 239 | 241 |
| 240 // Get the print preview tab for |initiator_tab|. | 242 // Get the print preview tab for |initiator_tab|. |
| 241 TabContents* preview_tab = GetPrintPreviewForTab(initiator_tab); | 243 TabContents* preview_tab = GetPrintPreviewForTab(initiator_tab); |
| 242 if (!preview_tab) | 244 if (!preview_tab) |
| 243 return CreatePrintPreviewTab(initiator_tab); | 245 return CreatePrintPreviewTab(initiator_tab); |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 } | 447 } |
| 446 | 448 |
| 447 void PrintPreviewTabController::SetInitiatorTabURLAndTitle( | 449 void PrintPreviewTabController::SetInitiatorTabURLAndTitle( |
| 448 TabContents* preview_tab) { | 450 TabContents* preview_tab) { |
| 449 TabContents* initiator_tab = GetInitiatorTab(preview_tab); | 451 TabContents* initiator_tab = GetInitiatorTab(preview_tab); |
| 450 if (initiator_tab && preview_tab->web_contents()->GetWebUI()) { | 452 if (initiator_tab && preview_tab->web_contents()->GetWebUI()) { |
| 451 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( | 453 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
| 452 preview_tab->web_contents()->GetWebUI()->GetController()); | 454 preview_tab->web_contents()->GetWebUI()->GetController()); |
| 453 print_preview_ui->SetInitiatorTabURLAndTitle( | 455 print_preview_ui->SetInitiatorTabURLAndTitle( |
| 454 initiator_tab->web_contents()->GetURL().spec(), | 456 initiator_tab->web_contents()->GetURL().spec(), |
| 455 initiator_tab->print_view_manager()->RenderSourceName()); | 457 printing::PrintViewManager::FromWebContents( |
| 458 initiator_tab->web_contents())->RenderSourceName()); |
| 456 } | 459 } |
| 457 } | 460 } |
| 458 | 461 |
| 459 void PrintPreviewTabController::AddObservers(TabContents* tab) { | 462 void PrintPreviewTabController::AddObservers(TabContents* tab) { |
| 460 WebContents* web_contents = tab->web_contents(); | 463 WebContents* web_contents = tab->web_contents(); |
| 461 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED, | 464 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED, |
| 462 content::Source<TabContents>(tab)); | 465 content::Source<TabContents>(tab)); |
| 463 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 466 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 464 content::Source<NavigationController>(&web_contents->GetController())); | 467 content::Source<NavigationController>(&web_contents->GetController())); |
| 465 | 468 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 494 | 497 |
| 495 void PrintPreviewTabController::RemoveInitiatorTab(TabContents* initiator_tab) { | 498 void PrintPreviewTabController::RemoveInitiatorTab(TabContents* initiator_tab) { |
| 496 TabContents* preview_tab = GetPrintPreviewForTab(initiator_tab); | 499 TabContents* preview_tab = GetPrintPreviewForTab(initiator_tab); |
| 497 DCHECK(preview_tab); | 500 DCHECK(preview_tab); |
| 498 // Update the map entry first, so when the print preview tab gets destroyed | 501 // Update the map entry first, so when the print preview tab gets destroyed |
| 499 // and reaches RemovePreviewTab(), it does not attempt to also remove the | 502 // and reaches RemovePreviewTab(), it does not attempt to also remove the |
| 500 // initiator tab's observers. | 503 // initiator tab's observers. |
| 501 preview_tab_map_[preview_tab] = NULL; | 504 preview_tab_map_[preview_tab] = NULL; |
| 502 RemoveObservers(initiator_tab); | 505 RemoveObservers(initiator_tab); |
| 503 | 506 |
| 504 initiator_tab->print_view_manager()->PrintPreviewDone(); | 507 printing::PrintViewManager::FromWebContents(initiator_tab->web_contents())-> |
| 508 PrintPreviewDone(); |
| 505 | 509 |
| 506 // Initiator tab is closed. Close the print preview tab too. | 510 // Initiator tab is closed. Close the print preview tab too. |
| 507 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( | 511 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
| 508 preview_tab->web_contents()->GetWebUI()->GetController()); | 512 preview_tab->web_contents()->GetWebUI()->GetController()); |
| 509 if (print_preview_ui) | 513 if (print_preview_ui) |
| 510 print_preview_ui->OnInitiatorTabClosed(); | 514 print_preview_ui->OnInitiatorTabClosed(); |
| 511 } | 515 } |
| 512 | 516 |
| 513 void PrintPreviewTabController::RemovePreviewTab(TabContents* preview_tab) { | 517 void PrintPreviewTabController::RemovePreviewTab(TabContents* preview_tab) { |
| 514 // Remove the initiator tab's observers before erasing the mapping. | 518 // Remove the initiator tab's observers before erasing the mapping. |
| 515 TabContents* initiator_tab = GetInitiatorTab(preview_tab); | 519 TabContents* initiator_tab = GetInitiatorTab(preview_tab); |
| 516 if (initiator_tab) { | 520 if (initiator_tab) { |
| 517 RemoveObservers(initiator_tab); | 521 RemoveObservers(initiator_tab); |
| 518 initiator_tab->print_view_manager()->PrintPreviewDone(); | 522 printing::PrintViewManager::FromWebContents(initiator_tab->web_contents())-> |
| 523 PrintPreviewDone(); |
| 519 } | 524 } |
| 520 | 525 |
| 521 // Print preview WebContents is destroyed. Notify |PrintPreviewUI| to abort | 526 // Print preview WebContents is destroyed. Notify |PrintPreviewUI| to abort |
| 522 // the initiator tab preview request. | 527 // the initiator tab preview request. |
| 523 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( | 528 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
| 524 preview_tab->web_contents()->GetWebUI()->GetController()); | 529 preview_tab->web_contents()->GetWebUI()->GetController()); |
| 525 if (print_preview_ui) | 530 if (print_preview_ui) |
| 526 print_preview_ui->OnTabDestroyed(); | 531 print_preview_ui->OnTabDestroyed(); |
| 527 | 532 |
| 528 preview_tab_map_.erase(preview_tab); | 533 preview_tab_map_.erase(preview_tab); |
| 529 RemoveObservers(preview_tab); | 534 RemoveObservers(preview_tab); |
| 530 } | 535 } |
| 531 | 536 |
| 532 } // namespace printing | 537 } // namespace printing |
| OLD | NEW |