| 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 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 PrintPreviewTabMap::iterator it = preview_tab_map_.find(preview_tab); | 272 PrintPreviewTabMap::iterator it = preview_tab_map_.find(preview_tab); |
| 273 if (it != preview_tab_map_.end()) | 273 if (it != preview_tab_map_.end()) |
| 274 return preview_tab_map_[preview_tab]; | 274 return preview_tab_map_[preview_tab]; |
| 275 return NULL; | 275 return NULL; |
| 276 } | 276 } |
| 277 | 277 |
| 278 void PrintPreviewTabController::Observe( | 278 void PrintPreviewTabController::Observe( |
| 279 int type, | 279 int type, |
| 280 const content::NotificationSource& source, | 280 const content::NotificationSource& source, |
| 281 const content::NotificationDetails& details) { | 281 const content::NotificationDetails& details) { |
| 282 switch (type) { | 282 if (type == content::NOTIFICATION_RENDERER_PROCESS_CLOSED) { |
| 283 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: { | 283 OnRendererProcessClosed( |
| 284 OnRendererProcessClosed( | 284 content::Source<content::RenderProcessHost>(source).ptr()); |
| 285 content::Source<content::RenderProcessHost>(source).ptr()); | 285 } else if (type == chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED) { |
| 286 break; | 286 OnTabContentsDestroyed(content::Source<TabContents>(source).ptr()); |
| 287 } | 287 } else { |
| 288 case chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED: { | 288 DCHECK_EQ(content::NOTIFICATION_NAV_ENTRY_COMMITTED, type); |
| 289 OnTabContentsDestroyed(content::Source<TabContents>(source).ptr()); | 289 TabContents* tab = TabContents::FromWebContents( |
| 290 break; | 290 content::Source<NavigationController>(source)->GetWebContents()); |
| 291 } | 291 OnNavEntryCommitted(tab, |
| 292 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: { | 292 content::Details<content::LoadCommittedDetails>(details).ptr()); |
| 293 NavigationController* controller = | |
| 294 content::Source<NavigationController>(source).ptr(); | |
| 295 TabContents* tab = TabContents::FromWebContents( | |
| 296 controller->GetWebContents()); | |
| 297 content::LoadCommittedDetails* load_details = | |
| 298 content::Details<content::LoadCommittedDetails>(details).ptr(); | |
| 299 OnNavEntryCommitted(tab, load_details); | |
| 300 break; | |
| 301 } | |
| 302 default: { | |
| 303 NOTREACHED(); | |
| 304 break; | |
| 305 } | |
| 306 } | 293 } |
| 307 } | 294 } |
| 308 | 295 |
| 309 // static | 296 // static |
| 310 bool PrintPreviewTabController::IsPrintPreviewTab(TabContents* tab) { | 297 bool PrintPreviewTabController::IsPrintPreviewTab(TabContents* tab) { |
| 311 return IsPrintPreviewURL(tab->web_contents()->GetURL()); | 298 return IsPrintPreviewURL(tab->web_contents()->GetURL()); |
| 312 } | 299 } |
| 313 | 300 |
| 314 // static | 301 // static |
| 315 bool PrintPreviewTabController::IsPrintPreviewURL(const GURL& url) { | 302 bool PrintPreviewTabController::IsPrintPreviewURL(const GURL& url) { |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 if (initiator_tab && preview_tab->web_contents()->GetWebUI()) { | 451 if (initiator_tab && preview_tab->web_contents()->GetWebUI()) { |
| 465 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( | 452 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
| 466 preview_tab->web_contents()->GetWebUI()->GetController()); | 453 preview_tab->web_contents()->GetWebUI()->GetController()); |
| 467 print_preview_ui->SetInitiatorTabURLAndTitle( | 454 print_preview_ui->SetInitiatorTabURLAndTitle( |
| 468 initiator_tab->web_contents()->GetURL().spec(), | 455 initiator_tab->web_contents()->GetURL().spec(), |
| 469 initiator_tab->print_view_manager()->RenderSourceName()); | 456 initiator_tab->print_view_manager()->RenderSourceName()); |
| 470 } | 457 } |
| 471 } | 458 } |
| 472 | 459 |
| 473 void PrintPreviewTabController::AddObservers(TabContents* tab) { | 460 void PrintPreviewTabController::AddObservers(TabContents* tab) { |
| 474 WebContents* contents = tab->web_contents(); | 461 WebContents* web_contents = tab->web_contents(); |
| 475 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED, | 462 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED, |
| 476 content::Source<TabContents>(tab)); | 463 content::Source<TabContents>(tab)); |
| 477 registrar_.Add( | 464 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 478 this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 465 content::Source<NavigationController>(&web_contents->GetController())); |
| 479 content::Source<NavigationController>(&contents->GetController())); | |
| 480 | 466 |
| 481 // Multiple sites may share the same RenderProcessHost, so check if this | 467 // Multiple sites may share the same RenderProcessHost, so check if this |
| 482 // notification has already been added. | 468 // notification has already been added. |
| 483 content::RenderProcessHost* rph = tab->web_contents()->GetRenderProcessHost(); | 469 content::Source<content::RenderProcessHost> rph_source( |
| 470 web_contents->GetRenderProcessHost()); |
| 484 if (!registrar_.IsRegistered(this, | 471 if (!registrar_.IsRegistered(this, |
| 485 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 472 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, rph_source)) { |
| 486 content::Source<content::RenderProcessHost>( | |
| 487 rph))) { | |
| 488 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 473 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
| 489 content::Source<content::RenderProcessHost>(rph)); | 474 rph_source); |
| 490 } | 475 } |
| 491 } | 476 } |
| 492 | 477 |
| 493 void PrintPreviewTabController::RemoveObservers(TabContents* tab) { | 478 void PrintPreviewTabController::RemoveObservers(TabContents* tab) { |
| 494 WebContents* contents = tab->web_contents(); | 479 WebContents* web_contents = tab->web_contents(); |
| 495 registrar_.Remove(this, chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED, | 480 registrar_.Remove(this, chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED, |
| 496 content::Source<TabContents>(tab)); | 481 content::Source<TabContents>(tab)); |
| 497 registrar_.Remove( | 482 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 498 this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 483 content::Source<NavigationController>(&web_contents->GetController())); |
| 499 content::Source<NavigationController>(&contents->GetController())); | |
| 500 | 484 |
| 501 // Multiple sites may share the same RenderProcessHost, so check if this | 485 // Multiple sites may share the same RenderProcessHost, so check if this |
| 502 // notification has already been added. | 486 // notification has already been added. |
| 503 content::RenderProcessHost* rph = tab->web_contents()->GetRenderProcessHost(); | 487 content::Source<content::RenderProcessHost> rph_source( |
| 488 web_contents->GetRenderProcessHost()); |
| 504 if (registrar_.IsRegistered(this, | 489 if (registrar_.IsRegistered(this, |
| 505 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 490 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, rph_source)) { |
| 506 content::Source<content::RenderProcessHost>( | |
| 507 rph))) { | |
| 508 registrar_.Remove(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 491 registrar_.Remove(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
| 509 content::Source<content::RenderProcessHost>(rph)); | 492 rph_source); |
| 510 } | 493 } |
| 511 } | 494 } |
| 512 | 495 |
| 513 void PrintPreviewTabController::RemoveInitiatorTab(TabContents* initiator_tab) { | 496 void PrintPreviewTabController::RemoveInitiatorTab(TabContents* initiator_tab) { |
| 514 TabContents* preview_tab = GetPrintPreviewForTab(initiator_tab); | 497 TabContents* preview_tab = GetPrintPreviewForTab(initiator_tab); |
| 515 DCHECK(preview_tab); | 498 DCHECK(preview_tab); |
| 516 // Update the map entry first, so when the print preview tab gets destroyed | 499 // Update the map entry first, so when the print preview tab gets destroyed |
| 517 // and reaches RemovePreviewTab(), it does not attempt to also remove the | 500 // and reaches RemovePreviewTab(), it does not attempt to also remove the |
| 518 // initiator tab's observers. | 501 // initiator tab's observers. |
| 519 preview_tab_map_[preview_tab] = NULL; | 502 preview_tab_map_[preview_tab] = NULL; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 541 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( | 524 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
| 542 preview_tab->web_contents()->GetWebUI()->GetController()); | 525 preview_tab->web_contents()->GetWebUI()->GetController()); |
| 543 if (print_preview_ui) | 526 if (print_preview_ui) |
| 544 print_preview_ui->OnTabDestroyed(); | 527 print_preview_ui->OnTabDestroyed(); |
| 545 | 528 |
| 546 preview_tab_map_.erase(preview_tab); | 529 preview_tab_map_.erase(preview_tab); |
| 547 RemoveObservers(preview_tab); | 530 RemoveObservers(preview_tab); |
| 548 } | 531 } |
| 549 | 532 |
| 550 } // namespace printing | 533 } // namespace printing |
| OLD | NEW |