| 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 <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 if (preview_tab->web_contents()->GetRenderProcessHost() == rph) { | 253 if (preview_tab->web_contents()->GetRenderProcessHost() == rph) { |
| 254 closed_preview_tabs.push_back(preview_tab); | 254 closed_preview_tabs.push_back(preview_tab); |
| 255 } else if (initiator_tab && | 255 } else if (initiator_tab && |
| 256 initiator_tab->web_contents()->GetRenderProcessHost() == rph) { | 256 initiator_tab->web_contents()->GetRenderProcessHost() == rph) { |
| 257 closed_initiator_tabs.push_back(initiator_tab); | 257 closed_initiator_tabs.push_back(initiator_tab); |
| 258 } | 258 } |
| 259 } | 259 } |
| 260 | 260 |
| 261 for (size_t i = 0; i < closed_preview_tabs.size(); ++i) { | 261 for (size_t i = 0; i < closed_preview_tabs.size(); ++i) { |
| 262 RemovePreviewTab(closed_preview_tabs[i]); | 262 RemovePreviewTab(closed_preview_tabs[i]); |
| 263 PrintPreviewUI* print_preview_ui = | 263 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
| 264 static_cast<PrintPreviewUI*>( | 264 closed_preview_tabs[i]->web_contents()->GetWebUI()->GetController()); |
| 265 closed_preview_tabs[i]->web_contents()->GetWebUI()); | |
| 266 if (print_preview_ui) | 265 if (print_preview_ui) |
| 267 print_preview_ui->OnPrintPreviewTabClosed(); | 266 print_preview_ui->OnPrintPreviewTabClosed(); |
| 268 } | 267 } |
| 269 | 268 |
| 270 for (size_t i = 0; i < closed_initiator_tabs.size(); ++i) | 269 for (size_t i = 0; i < closed_initiator_tabs.size(); ++i) |
| 271 RemoveInitiatorTab(closed_initiator_tabs[i], false); | 270 RemoveInitiatorTab(closed_initiator_tabs[i], false); |
| 272 } | 271 } |
| 273 | 272 |
| 274 void PrintPreviewTabController::OnTabContentsDestroyed( | 273 void PrintPreviewTabController::OnTabContentsDestroyed( |
| 275 TabContentsWrapper* tab) { | 274 TabContentsWrapper* tab) { |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 AddObservers(initiator_tab); | 395 AddObservers(initiator_tab); |
| 397 AddObservers(preview_tab); | 396 AddObservers(preview_tab); |
| 398 | 397 |
| 399 return preview_tab; | 398 return preview_tab; |
| 400 } | 399 } |
| 401 | 400 |
| 402 void PrintPreviewTabController::SetInitiatorTabURLAndTitle( | 401 void PrintPreviewTabController::SetInitiatorTabURLAndTitle( |
| 403 TabContentsWrapper* preview_tab) { | 402 TabContentsWrapper* preview_tab) { |
| 404 TabContentsWrapper* initiator_tab = GetInitiatorTab(preview_tab); | 403 TabContentsWrapper* initiator_tab = GetInitiatorTab(preview_tab); |
| 405 if (initiator_tab && preview_tab->web_contents()->GetWebUI()) { | 404 if (initiator_tab && preview_tab->web_contents()->GetWebUI()) { |
| 406 PrintPreviewUI* print_preview_ui = | 405 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
| 407 static_cast<PrintPreviewUI*>(preview_tab->web_contents()->GetWebUI()); | 406 preview_tab->web_contents()->GetWebUI()->GetController()); |
| 408 print_preview_ui->SetInitiatorTabURLAndTitle( | 407 print_preview_ui->SetInitiatorTabURLAndTitle( |
| 409 initiator_tab->web_contents()->GetURL().spec(), | 408 initiator_tab->web_contents()->GetURL().spec(), |
| 410 initiator_tab->print_view_manager()->RenderSourceName()); | 409 initiator_tab->print_view_manager()->RenderSourceName()); |
| 411 } | 410 } |
| 412 } | 411 } |
| 413 | 412 |
| 414 void PrintPreviewTabController::AddObservers(TabContentsWrapper* tab) { | 413 void PrintPreviewTabController::AddObservers(TabContentsWrapper* tab) { |
| 415 WebContents* contents = tab->web_contents(); | 414 WebContents* contents = tab->web_contents(); |
| 416 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 415 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 417 content::Source<WebContents>(contents)); | 416 content::Source<WebContents>(contents)); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 // initiator tab's observers. | 459 // initiator tab's observers. |
| 461 preview_tab_map_[preview_tab] = NULL; | 460 preview_tab_map_[preview_tab] = NULL; |
| 462 RemoveObservers(initiator_tab); | 461 RemoveObservers(initiator_tab); |
| 463 | 462 |
| 464 // For the navigation case, PrintPreviewDone() has already been called in | 463 // For the navigation case, PrintPreviewDone() has already been called in |
| 465 // PrintPreviewMessageHandler::NavigateToPendingEntry(). | 464 // PrintPreviewMessageHandler::NavigateToPendingEntry(). |
| 466 if (!is_navigation) | 465 if (!is_navigation) |
| 467 initiator_tab->print_view_manager()->PrintPreviewDone(); | 466 initiator_tab->print_view_manager()->PrintPreviewDone(); |
| 468 | 467 |
| 469 // Initiator tab is closed. Close the print preview tab too. | 468 // Initiator tab is closed. Close the print preview tab too. |
| 470 PrintPreviewUI* print_preview_ui = | 469 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
| 471 static_cast<PrintPreviewUI*>(preview_tab->web_contents()->GetWebUI()); | 470 preview_tab->web_contents()->GetWebUI()->GetController()); |
| 472 if (print_preview_ui) | 471 if (print_preview_ui) |
| 473 print_preview_ui->OnInitiatorTabClosed(); | 472 print_preview_ui->OnInitiatorTabClosed(); |
| 474 } | 473 } |
| 475 | 474 |
| 476 void PrintPreviewTabController::RemovePreviewTab( | 475 void PrintPreviewTabController::RemovePreviewTab( |
| 477 TabContentsWrapper* preview_tab) { | 476 TabContentsWrapper* preview_tab) { |
| 478 // Remove the initiator tab's observers before erasing the mapping. | 477 // Remove the initiator tab's observers before erasing the mapping. |
| 479 TabContentsWrapper* initiator_tab = GetInitiatorTab(preview_tab); | 478 TabContentsWrapper* initiator_tab = GetInitiatorTab(preview_tab); |
| 480 if (initiator_tab) { | 479 if (initiator_tab) { |
| 481 RemoveObservers(initiator_tab); | 480 RemoveObservers(initiator_tab); |
| 482 initiator_tab->print_view_manager()->PrintPreviewDone(); | 481 initiator_tab->print_view_manager()->PrintPreviewDone(); |
| 483 } | 482 } |
| 484 | 483 |
| 485 // Print preview TabContents is destroyed. Notify |PrintPreviewUI| to abort | 484 // Print preview TabContents is destroyed. Notify |PrintPreviewUI| to abort |
| 486 // the initiator tab preview request. | 485 // the initiator tab preview request. |
| 487 PrintPreviewUI* print_preview_ui = | 486 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
| 488 static_cast<PrintPreviewUI*>(preview_tab->web_contents()->GetWebUI()); | 487 preview_tab->web_contents()->GetWebUI()->GetController()); |
| 489 if (print_preview_ui) | 488 if (print_preview_ui) |
| 490 print_preview_ui->OnTabDestroyed(); | 489 print_preview_ui->OnTabDestroyed(); |
| 491 | 490 |
| 492 preview_tab_map_.erase(preview_tab); | 491 preview_tab_map_.erase(preview_tab); |
| 493 RemoveObservers(preview_tab); | 492 RemoveObservers(preview_tab); |
| 494 } | 493 } |
| 495 | 494 |
| 496 } // namespace printing | 495 } // namespace printing |
| OLD | NEW |