OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 } else if (initiator_tab && | 248 } else if (initiator_tab && |
249 initiator_tab->tab_contents()->GetRenderProcessHost() == rph) { | 249 initiator_tab->tab_contents()->GetRenderProcessHost() == rph) { |
250 closed_initiator_tabs.push_back(initiator_tab); | 250 closed_initiator_tabs.push_back(initiator_tab); |
251 } | 251 } |
252 } | 252 } |
253 | 253 |
254 for (size_t i = 0; i < closed_preview_tabs.size(); ++i) { | 254 for (size_t i = 0; i < closed_preview_tabs.size(); ++i) { |
255 RemovePreviewTab(closed_preview_tabs[i]); | 255 RemovePreviewTab(closed_preview_tabs[i]); |
256 PrintPreviewUI* print_preview_ui = | 256 PrintPreviewUI* print_preview_ui = |
257 static_cast<PrintPreviewUI*>( | 257 static_cast<PrintPreviewUI*>( |
258 closed_preview_tabs[i]->tab_contents()->web_ui()); | 258 closed_preview_tabs[i]->tab_contents()->GetWebUI()); |
259 if (print_preview_ui) | 259 if (print_preview_ui) |
260 print_preview_ui->OnPrintPreviewTabClosed(); | 260 print_preview_ui->OnPrintPreviewTabClosed(); |
261 } | 261 } |
262 | 262 |
263 for (size_t i = 0; i < closed_initiator_tabs.size(); ++i) | 263 for (size_t i = 0; i < closed_initiator_tabs.size(); ++i) |
264 RemoveInitiatorTab(closed_initiator_tabs[i], false); | 264 RemoveInitiatorTab(closed_initiator_tabs[i], false); |
265 } | 265 } |
266 | 266 |
267 void PrintPreviewTabController::OnTabContentsDestroyed( | 267 void PrintPreviewTabController::OnTabContentsDestroyed( |
268 TabContentsWrapper* tab) { | 268 TabContentsWrapper* tab) { |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 | 388 |
389 AddObservers(initiator_tab); | 389 AddObservers(initiator_tab); |
390 AddObservers(preview_tab); | 390 AddObservers(preview_tab); |
391 | 391 |
392 return preview_tab; | 392 return preview_tab; |
393 } | 393 } |
394 | 394 |
395 void PrintPreviewTabController::SetInitiatorTabURLAndTitle( | 395 void PrintPreviewTabController::SetInitiatorTabURLAndTitle( |
396 TabContentsWrapper* preview_tab) { | 396 TabContentsWrapper* preview_tab) { |
397 TabContentsWrapper* initiator_tab = GetInitiatorTab(preview_tab); | 397 TabContentsWrapper* initiator_tab = GetInitiatorTab(preview_tab); |
398 if (initiator_tab && preview_tab->tab_contents()->web_ui()) { | 398 if (initiator_tab && preview_tab->tab_contents()->GetWebUI()) { |
399 PrintPreviewUI* print_preview_ui = | 399 PrintPreviewUI* print_preview_ui = |
400 static_cast<PrintPreviewUI*>(preview_tab->tab_contents()->web_ui()); | 400 static_cast<PrintPreviewUI*>(preview_tab->tab_contents()->GetWebUI()); |
401 print_preview_ui->SetInitiatorTabURLAndTitle( | 401 print_preview_ui->SetInitiatorTabURLAndTitle( |
402 initiator_tab->tab_contents()->GetURL().spec(), | 402 initiator_tab->tab_contents()->GetURL().spec(), |
403 initiator_tab->print_view_manager()->RenderSourceName()); | 403 initiator_tab->print_view_manager()->RenderSourceName()); |
404 } | 404 } |
405 } | 405 } |
406 | 406 |
407 void PrintPreviewTabController::AddObservers(TabContentsWrapper* tab) { | 407 void PrintPreviewTabController::AddObservers(TabContentsWrapper* tab) { |
408 TabContents* contents = tab->tab_contents(); | 408 TabContents* contents = tab->tab_contents(); |
409 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_DESTROYED, | 409 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_DESTROYED, |
410 content::Source<TabContents>(contents)); | 410 content::Source<TabContents>(contents)); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 preview_tab_map_[preview_tab] = NULL; | 454 preview_tab_map_[preview_tab] = NULL; |
455 RemoveObservers(initiator_tab); | 455 RemoveObservers(initiator_tab); |
456 | 456 |
457 // For the navigation case, PrintPreviewDone() has already been called in | 457 // For the navigation case, PrintPreviewDone() has already been called in |
458 // PrintPreviewMessageHandler::NavigateToPendingEntry(). | 458 // PrintPreviewMessageHandler::NavigateToPendingEntry(). |
459 if (!is_navigation) | 459 if (!is_navigation) |
460 initiator_tab->print_view_manager()->PrintPreviewDone(); | 460 initiator_tab->print_view_manager()->PrintPreviewDone(); |
461 | 461 |
462 // Initiator tab is closed. Close the print preview tab too. | 462 // Initiator tab is closed. Close the print preview tab too. |
463 PrintPreviewUI* print_preview_ui = | 463 PrintPreviewUI* print_preview_ui = |
464 static_cast<PrintPreviewUI*>(preview_tab->tab_contents()->web_ui()); | 464 static_cast<PrintPreviewUI*>(preview_tab->tab_contents()->GetWebUI()); |
465 if (print_preview_ui) | 465 if (print_preview_ui) |
466 print_preview_ui->OnInitiatorTabClosed(); | 466 print_preview_ui->OnInitiatorTabClosed(); |
467 } | 467 } |
468 | 468 |
469 void PrintPreviewTabController::RemovePreviewTab( | 469 void PrintPreviewTabController::RemovePreviewTab( |
470 TabContentsWrapper* preview_tab) { | 470 TabContentsWrapper* preview_tab) { |
471 // Remove the initiator tab's observers before erasing the mapping. | 471 // Remove the initiator tab's observers before erasing the mapping. |
472 TabContentsWrapper* initiator_tab = GetInitiatorTab(preview_tab); | 472 TabContentsWrapper* initiator_tab = GetInitiatorTab(preview_tab); |
473 if (initiator_tab) { | 473 if (initiator_tab) { |
474 RemoveObservers(initiator_tab); | 474 RemoveObservers(initiator_tab); |
475 initiator_tab->print_view_manager()->PrintPreviewDone(); | 475 initiator_tab->print_view_manager()->PrintPreviewDone(); |
476 } | 476 } |
477 | 477 |
478 // Print preview TabContents is destroyed. Notify |PrintPreviewUI| to abort | 478 // Print preview TabContents is destroyed. Notify |PrintPreviewUI| to abort |
479 // the initiator tab preview request. | 479 // the initiator tab preview request. |
480 PrintPreviewUI* print_preview_ui = | 480 PrintPreviewUI* print_preview_ui = |
481 static_cast<PrintPreviewUI*>(preview_tab->tab_contents()->web_ui()); | 481 static_cast<PrintPreviewUI*>(preview_tab->tab_contents()->GetWebUI()); |
482 if (print_preview_ui) | 482 if (print_preview_ui) |
483 print_preview_ui->OnTabDestroyed(); | 483 print_preview_ui->OnTabDestroyed(); |
484 | 484 |
485 preview_tab_map_.erase(preview_tab); | 485 preview_tab_map_.erase(preview_tab); |
486 RemoveObservers(preview_tab); | 486 RemoveObservers(preview_tab); |
487 } | 487 } |
488 | 488 |
489 } // namespace printing | 489 } // namespace printing |
OLD | NEW |