| 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/background_printing_manager.h" | 5 #include "chrome/browser/printing/background_printing_manager.h" |
| 6 | 6 |
| 7 #include "chrome/browser/printing/print_job.h" | 7 #include "chrome/browser/printing/print_job.h" |
| 8 #include "chrome/browser/printing/print_preview_tab_controller.h" | 8 #include "chrome/browser/printing/print_preview_tab_controller.h" |
| 9 #include "chrome/browser/sessions/restore_tab_helper.h" | 9 #include "chrome/browser/sessions/restore_tab_helper.h" |
| 10 #include "chrome/browser/ui/browser_list.h" | 10 #include "chrome/browser/ui/browser_list.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED, preview_source)) { | 50 chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED, preview_source)) { |
| 51 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED, | 51 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED, |
| 52 preview_source); | 52 preview_source); |
| 53 } | 53 } |
| 54 | 54 |
| 55 // If a tab that is printing crashes, the user cannot destroy it since it is | 55 // If a tab that is printing crashes, the user cannot destroy it since it is |
| 56 // not in any tab strip. Thus listen for crashes here and delete the tab. | 56 // not in any tab strip. Thus listen for crashes here and delete the tab. |
| 57 // | 57 // |
| 58 // Multiple sites may share the same RenderProcessHost, so check if this | 58 // Multiple sites may share the same RenderProcessHost, so check if this |
| 59 // notification has already been added. | 59 // notification has already been added. |
| 60 content::RenderProcessHost* rph = | 60 content::Source<content::RenderProcessHost> rph_source( |
| 61 preview_tab->web_contents()->GetRenderProcessHost(); | 61 preview_tab->web_contents()->GetRenderProcessHost()); |
| 62 if (!registrar_.IsRegistered(this, | 62 if (!registrar_.IsRegistered(this, |
| 63 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 63 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, rph_source)) { |
| 64 content::Source<content::RenderProcessHost>( | |
| 65 rph))) { | |
| 66 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 64 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
| 67 content::Source<content::RenderProcessHost>(rph)); | 65 rph_source); |
| 68 } | 66 } |
| 69 | 67 |
| 70 // Activate the initiator tab. | 68 // Activate the initiator tab. |
| 71 PrintPreviewTabController* tab_controller = | 69 PrintPreviewTabController* tab_controller = |
| 72 PrintPreviewTabController::GetInstance(); | 70 PrintPreviewTabController::GetInstance(); |
| 73 if (!tab_controller) | 71 if (!tab_controller) |
| 74 return; | 72 return; |
| 75 TabContents* initiator_tab = tab_controller->GetInitiatorTab(preview_tab); | 73 TabContents* initiator_tab = tab_controller->GetInitiatorTab(preview_tab); |
| 76 if (!initiator_tab) | 74 if (!initiator_tab) |
| 77 return; | 75 return; |
| 78 WebContents* web_contents = initiator_tab->web_contents(); | 76 WebContents* web_contents = initiator_tab->web_contents(); |
| 79 web_contents->GetDelegate()->ActivateContents(web_contents); | 77 web_contents->GetDelegate()->ActivateContents(web_contents); |
| 80 } | 78 } |
| 81 | 79 |
| 82 void BackgroundPrintingManager::Observe( | 80 void BackgroundPrintingManager::Observe( |
| 83 int type, | 81 int type, |
| 84 const content::NotificationSource& source, | 82 const content::NotificationSource& source, |
| 85 const content::NotificationDetails& details) { | 83 const content::NotificationDetails& details) { |
| 86 switch (type) { | 84 if (type == content::NOTIFICATION_RENDERER_PROCESS_CLOSED) { |
| 87 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: { | 85 OnRendererProcessClosed( |
| 88 OnRendererProcessClosed( | 86 content::Source<content::RenderProcessHost>(source).ptr()); |
| 89 content::Source<content::RenderProcessHost>(source).ptr()); | 87 } else if (type == chrome::NOTIFICATION_PRINT_JOB_RELEASED) { |
| 90 break; | 88 OnPrintJobReleased(content::Source<TabContents>(source).ptr()); |
| 91 } | 89 } else { |
| 92 case chrome::NOTIFICATION_PRINT_JOB_RELEASED: { | 90 DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED, type); |
| 93 OnPrintJobReleased(content::Source<TabContents>(source).ptr()); | 91 OnTabContentsDestroyed(content::Source<TabContents>(source).ptr()); |
| 94 break; | |
| 95 } | |
| 96 case chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED: { | |
| 97 OnTabContentsDestroyed(content::Source<TabContents>(source).ptr()); | |
| 98 break; | |
| 99 } | |
| 100 default: { | |
| 101 NOTREACHED(); | |
| 102 break; | |
| 103 } | |
| 104 } | 92 } |
| 105 } | 93 } |
| 106 | 94 |
| 107 void BackgroundPrintingManager::OnRendererProcessClosed( | 95 void BackgroundPrintingManager::OnRendererProcessClosed( |
| 108 content::RenderProcessHost* rph) { | 96 content::RenderProcessHost* rph) { |
| 109 TabContentsSet preview_tabs_pending_deletion; | 97 TabContentsSet preview_tabs_pending_deletion; |
| 110 TabContentsSet::const_iterator it; | 98 TabContentsSet::const_iterator it; |
| 111 for (it = begin(); it != end(); ++it) { | 99 for (it = begin(); it != end(); ++it) { |
| 112 TabContents* preview_tab = *it; | 100 TabContents* preview_tab = *it; |
| 113 if (preview_tab->web_contents()->GetRenderProcessHost() == rph) { | 101 if (preview_tab->web_contents()->GetRenderProcessHost() == rph) { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 | 181 |
| 194 bool BackgroundPrintingManager::HasPrintPreviewTab( | 182 bool BackgroundPrintingManager::HasPrintPreviewTab( |
| 195 TabContents* preview_tab) { | 183 TabContents* preview_tab) { |
| 196 if (printing_tabs_.find(preview_tab) != printing_tabs_.end()) | 184 if (printing_tabs_.find(preview_tab) != printing_tabs_.end()) |
| 197 return true; | 185 return true; |
| 198 return printing_tabs_pending_deletion_.find(preview_tab) != | 186 return printing_tabs_pending_deletion_.find(preview_tab) != |
| 199 printing_tabs_pending_deletion_.end(); | 187 printing_tabs_pending_deletion_.end(); |
| 200 } | 188 } |
| 201 | 189 |
| 202 } // namespace printing | 190 } // namespace printing |
| OLD | NEW |