| 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/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/tabs/tab_strip_model.h" | 10 #include "chrome/browser/tabs/tab_strip_model.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 BackgroundPrintingManager::~BackgroundPrintingManager() { | 24 BackgroundPrintingManager::~BackgroundPrintingManager() { |
| 25 DCHECK(CalledOnValidThread()); | 25 DCHECK(CalledOnValidThread()); |
| 26 // The might be some TabContentsWrappers still in |printing_contents_| at | 26 // The might be some TabContentsWrappers still in |printing_contents_| at |
| 27 // this point. E.g. when the last remaining tab is a print preview tab and | 27 // this point. E.g. when the last remaining tab is a print preview tab and |
| 28 // tries to print. In which case it will fail to print. | 28 // tries to print. In which case it will fail to print. |
| 29 // TODO(thestig) handle this case better. | 29 // TODO(thestig) handle this case better. |
| 30 } | 30 } |
| 31 | 31 |
| 32 void BackgroundPrintingManager::OwnTabContents(TabContentsWrapper* contents) { | 32 void BackgroundPrintingManager::OwnTabContents(TabContentsWrapper* contents) { |
| 33 DCHECK(CalledOnValidThread()); | 33 DCHECK(CalledOnValidThread()); |
| 34 DCHECK(printing::PrintPreviewTabController::IsPrintPreviewTab( | 34 DCHECK(PrintPreviewTabController::IsPrintPreviewTab(contents)); |
| 35 contents->tab_contents())); | |
| 36 CHECK(printing_contents_.find(contents) == printing_contents_.end()); | 35 CHECK(printing_contents_.find(contents) == printing_contents_.end()); |
| 37 | 36 |
| 38 printing_contents_.insert(contents); | 37 printing_contents_.insert(contents); |
| 39 | 38 |
| 40 registrar_.Add(this, chrome::NOTIFICATION_PRINT_JOB_RELEASED, | 39 registrar_.Add(this, chrome::NOTIFICATION_PRINT_JOB_RELEASED, |
| 41 Source<TabContentsWrapper>(contents)); | 40 Source<TabContentsWrapper>(contents)); |
| 42 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_DESTROYED, | 41 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_DESTROYED, |
| 43 Source<TabContents>(contents->tab_contents())); | 42 Source<TabContents>(contents->tab_contents())); |
| 44 | 43 |
| 45 // Detach |contents| from its tab strip. | 44 // Detach |contents| from its tab strip. |
| 46 Browser* browser = BrowserList::FindBrowserWithID( | 45 Browser* browser = BrowserList::FindBrowserWithID( |
| 47 contents->restore_tab_helper()->window_id().id()); | 46 contents->restore_tab_helper()->window_id().id()); |
| 48 DCHECK(browser); | 47 DCHECK(browser); |
| 49 | 48 |
| 50 TabStripModel* tabstrip = browser->tabstrip_model(); | 49 TabStripModel* tabstrip = browser->tabstrip_model(); |
| 51 tabstrip->DetachTabContentsAt(tabstrip->GetIndexOfTabContents(contents)); | 50 tabstrip->DetachTabContentsAt(tabstrip->GetIndexOfTabContents(contents)); |
| 52 | 51 |
| 53 // Activate the initiator tab. | 52 // Activate the initiator tab. |
| 54 printing::PrintPreviewTabController* tab_controller = | 53 PrintPreviewTabController* tab_controller = |
| 55 printing::PrintPreviewTabController::GetInstance(); | 54 PrintPreviewTabController::GetInstance(); |
| 56 if (!tab_controller) | 55 if (!tab_controller) |
| 57 return; | 56 return; |
| 58 TabContents* initiator_tab = tab_controller->GetInitiatorTab( | 57 TabContentsWrapper* initiator_tab = tab_controller->GetInitiatorTab(contents); |
| 59 contents->tab_contents()); | |
| 60 if (!initiator_tab) | 58 if (!initiator_tab) |
| 61 return; | 59 return; |
| 62 static_cast<RenderViewHostDelegate*>(initiator_tab)->Activate(); | 60 static_cast<RenderViewHostDelegate*>( |
| 61 initiator_tab->tab_contents())->Activate(); |
| 63 } | 62 } |
| 64 | 63 |
| 65 void BackgroundPrintingManager::Observe(int type, | 64 void BackgroundPrintingManager::Observe(int type, |
| 66 const NotificationSource& source, | 65 const NotificationSource& source, |
| 67 const NotificationDetails& details) { | 66 const NotificationDetails& details) { |
| 68 switch (type) { | 67 switch (type) { |
| 69 case chrome::NOTIFICATION_PRINT_JOB_RELEASED: { | 68 case chrome::NOTIFICATION_PRINT_JOB_RELEASED: { |
| 70 TabContentsWrapper* tab = Source<TabContentsWrapper>(source).ptr(); | 69 TabContentsWrapper* tab = Source<TabContentsWrapper>(source).ptr(); |
| 71 registrar_.Remove(this, chrome::NOTIFICATION_PRINT_JOB_RELEASED, | 70 registrar_.Remove(this, chrome::NOTIFICATION_PRINT_JOB_RELEASED, |
| 72 Source<TabContentsWrapper>(tab)); | 71 Source<TabContentsWrapper>(tab)); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 std::set<TabContentsWrapper*>::const_iterator | 104 std::set<TabContentsWrapper*>::const_iterator |
| 106 BackgroundPrintingManager::end() { | 105 BackgroundPrintingManager::end() { |
| 107 return printing_contents_.end(); | 106 return printing_contents_.end(); |
| 108 } | 107 } |
| 109 | 108 |
| 110 bool BackgroundPrintingManager::HasTabContents(TabContentsWrapper* entry) { | 109 bool BackgroundPrintingManager::HasTabContents(TabContentsWrapper* entry) { |
| 111 return printing_contents_.find(entry) != printing_contents_.end(); | 110 return printing_contents_.find(entry) != printing_contents_.end(); |
| 112 } | 111 } |
| 113 | 112 |
| 114 } // namespace printing | 113 } // namespace printing |
| OLD | NEW |