| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 using content::NavigationController; | 43 using content::NavigationController; |
| 44 using content::WebContents; | 44 using content::WebContents; |
| 45 using content::WebUIMessageHandler; | 45 using content::WebUIMessageHandler; |
| 46 | 46 |
| 47 namespace { | 47 namespace { |
| 48 | 48 |
| 49 void EnableInternalPDFPluginForTab(TabContentsWrapper* preview_tab) { | 49 void EnableInternalPDFPluginForTab(TabContentsWrapper* preview_tab) { |
| 50 // Always enable the internal PDF plugin for the print preview page. | 50 // Always enable the internal PDF plugin for the print preview page. |
| 51 ChromePluginServiceFilter::GetInstance()->OverridePluginForTab( | 51 ChromePluginServiceFilter::GetInstance()->OverridePluginForTab( |
| 52 preview_tab->web_contents()->GetRenderProcessHost()->GetID(), | 52 preview_tab->web_contents()->GetRenderProcessHost()->GetID(), |
| 53 preview_tab->web_contents()->GetRenderViewHost()->routing_id(), | 53 preview_tab->web_contents()->GetRenderViewHost()->GetRoutingID(), |
| 54 GURL(), | 54 GURL(), |
| 55 ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName)); | 55 ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName)); |
| 56 } | 56 } |
| 57 | 57 |
| 58 // HtmlDialogUIDelegate that specifies what the print preview dialog will look | 58 // HtmlDialogUIDelegate that specifies what the print preview dialog will look |
| 59 // like. | 59 // like. |
| 60 class PrintPreviewTabDelegate : public HtmlDialogUIDelegate { | 60 class PrintPreviewTabDelegate : public HtmlDialogUIDelegate { |
| 61 public: | 61 public: |
| 62 explicit PrintPreviewTabDelegate(TabContentsWrapper* initiator_tab); | 62 explicit PrintPreviewTabDelegate(TabContentsWrapper* initiator_tab); |
| 63 virtual ~PrintPreviewTabDelegate(); | 63 virtual ~PrintPreviewTabDelegate(); |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 TabContentsWrapper* PrintPreviewTabController::GetOrCreatePreviewTab( | 221 TabContentsWrapper* PrintPreviewTabController::GetOrCreatePreviewTab( |
| 222 TabContentsWrapper* initiator_tab) { | 222 TabContentsWrapper* initiator_tab) { |
| 223 DCHECK(initiator_tab); | 223 DCHECK(initiator_tab); |
| 224 | 224 |
| 225 // Get the print preview tab for |initiator_tab|. | 225 // Get the print preview tab for |initiator_tab|. |
| 226 TabContentsWrapper* preview_tab = GetPrintPreviewForTab(initiator_tab); | 226 TabContentsWrapper* preview_tab = GetPrintPreviewForTab(initiator_tab); |
| 227 if (!preview_tab) | 227 if (!preview_tab) |
| 228 return CreatePrintPreviewTab(initiator_tab); | 228 return CreatePrintPreviewTab(initiator_tab); |
| 229 | 229 |
| 230 // Show the initiator tab holding the existing preview tab. | 230 // Show the initiator tab holding the existing preview tab. |
| 231 initiator_tab->web_contents()->GetRenderViewHost()->delegate()->Activate(); | 231 initiator_tab->web_contents()->GetRenderViewHost()->GetDelegate()->Activate(); |
| 232 return preview_tab; | 232 return preview_tab; |
| 233 } | 233 } |
| 234 | 234 |
| 235 TabContentsWrapper* PrintPreviewTabController::GetPrintPreviewForTab( | 235 TabContentsWrapper* PrintPreviewTabController::GetPrintPreviewForTab( |
| 236 TabContentsWrapper* tab) const { | 236 TabContentsWrapper* tab) const { |
| 237 // |preview_tab_map_| is keyed by the preview tab, so if find() succeeds, then | 237 // |preview_tab_map_| is keyed by the preview tab, so if find() succeeds, then |
| 238 // |tab| is the preview tab. | 238 // |tab| is the preview tab. |
| 239 PrintPreviewTabMap::const_iterator it = preview_tab_map_.find(tab); | 239 PrintPreviewTabMap::const_iterator it = preview_tab_map_.find(tab); |
| 240 if (it != preview_tab_map_.end()) | 240 if (it != preview_tab_map_.end()) |
| 241 return tab; | 241 return tab; |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( | 537 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
| 538 preview_tab->web_contents()->GetWebUI()->GetController()); | 538 preview_tab->web_contents()->GetWebUI()->GetController()); |
| 539 if (print_preview_ui) | 539 if (print_preview_ui) |
| 540 print_preview_ui->OnTabDestroyed(); | 540 print_preview_ui->OnTabDestroyed(); |
| 541 | 541 |
| 542 preview_tab_map_.erase(preview_tab); | 542 preview_tab_map_.erase(preview_tab); |
| 543 RemoveObservers(preview_tab); | 543 RemoveObservers(preview_tab); |
| 544 } | 544 } |
| 545 | 545 |
| 546 } // namespace printing | 546 } // namespace printing |
| OLD | NEW |