| 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 |
| 11 #include "base/auto_reset.h" | 11 #include "base/auto_reset.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/chrome_plugin_service_filter.h" | 15 #include "chrome/browser/chrome_plugin_service_filter.h" |
| 16 #include "chrome/browser/printing/print_view_manager.h" | 16 #include "chrome/browser/printing/print_view_manager.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/tabs/tab_strip_model.h" | 18 #include "chrome/browser/tabs/tab_strip_model.h" |
| 19 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
| 20 #include "chrome/browser/ui/browser_list.h" | 20 #include "chrome/browser/ui/browser_list.h" |
| 21 #include "chrome/browser/ui/browser_navigator.h" | 21 #include "chrome/browser/ui/browser_navigator.h" |
| 22 #include "chrome/browser/ui/browser_window.h" | 22 #include "chrome/browser/ui/browser_window.h" |
| 23 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 23 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 24 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h" | 24 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h" |
| 25 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" | 25 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" |
| 26 #include "chrome/browser/ui/webui/web_dialog_delegate.h" | 26 #include "chrome/browser/ui/webui/chrome_web_dialog_web_contents_delegate.h" |
| 27 #include "chrome/browser/ui/webui/web_dialog_web_contents_delegate.h" | |
| 28 #include "chrome/common/chrome_content_client.h" | 27 #include "chrome/common/chrome_content_client.h" |
| 29 #include "chrome/common/chrome_switches.h" | 28 #include "chrome/common/chrome_switches.h" |
| 30 #include "chrome/common/url_constants.h" | 29 #include "chrome/common/url_constants.h" |
| 31 #include "content/public/browser/navigation_controller.h" | 30 #include "content/public/browser/navigation_controller.h" |
| 32 #include "content/public/browser/navigation_details.h" | 31 #include "content/public/browser/navigation_details.h" |
| 33 #include "content/public/browser/navigation_entry.h" | 32 #include "content/public/browser/navigation_entry.h" |
| 34 #include "content/public/browser/notification_details.h" | 33 #include "content/public/browser/notification_details.h" |
| 35 #include "content/public/browser/notification_source.h" | 34 #include "content/public/browser/notification_source.h" |
| 36 #include "content/public/browser/notification_types.h" | 35 #include "content/public/browser/notification_types.h" |
| 37 #include "content/public/browser/render_process_host.h" | 36 #include "content/public/browser/render_process_host.h" |
| 38 #include "content/public/browser/render_view_host.h" | 37 #include "content/public/browser/render_view_host.h" |
| 39 #include "content/public/browser/render_view_host_delegate.h" | 38 #include "content/public/browser/render_view_host_delegate.h" |
| 40 #include "content/public/browser/web_contents.h" | 39 #include "content/public/browser/web_contents.h" |
| 40 #include "ui/web_dialogs/web_dialog_delegate.h" |
| 41 #include "ui/web_dialogs/web_dialog_ui.h" |
| 41 #include "webkit/plugins/webplugininfo.h" | 42 #include "webkit/plugins/webplugininfo.h" |
| 42 | 43 |
| 43 using content::NavigationController; | 44 using content::NavigationController; |
| 44 using content::WebContents; | 45 using content::WebContents; |
| 45 using content::WebUIMessageHandler; | 46 using content::WebUIMessageHandler; |
| 46 | 47 |
| 47 namespace { | 48 namespace { |
| 48 | 49 |
| 49 void EnableInternalPDFPluginForTab(TabContentsWrapper* preview_tab) { | 50 void EnableInternalPDFPluginForTab(TabContentsWrapper* preview_tab) { |
| 50 // Always enable the internal PDF plugin for the print preview page. | 51 // Always enable the internal PDF plugin for the print preview page. |
| 51 ChromePluginServiceFilter::GetInstance()->OverridePluginForTab( | 52 ChromePluginServiceFilter::GetInstance()->OverridePluginForTab( |
| 52 preview_tab->web_contents()->GetRenderProcessHost()->GetID(), | 53 preview_tab->web_contents()->GetRenderProcessHost()->GetID(), |
| 53 preview_tab->web_contents()->GetRenderViewHost()->GetRoutingID(), | 54 preview_tab->web_contents()->GetRenderViewHost()->GetRoutingID(), |
| 54 GURL(), | 55 GURL(), |
| 55 ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName)); | 56 ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName)); |
| 56 } | 57 } |
| 57 | 58 |
| 58 // WebDialogDelegate that specifies what the print preview dialog | 59 // WebDialogDelegate that specifies what the print preview dialog |
| 59 // will look like. | 60 // will look like. |
| 60 class PrintPreviewTabDelegate : public WebDialogDelegate { | 61 class PrintPreviewTabDelegate : public web_dialogs::WebDialogDelegate { |
| 61 public: | 62 public: |
| 62 explicit PrintPreviewTabDelegate(TabContentsWrapper* initiator_tab); | 63 explicit PrintPreviewTabDelegate(TabContentsWrapper* initiator_tab); |
| 63 virtual ~PrintPreviewTabDelegate(); | 64 virtual ~PrintPreviewTabDelegate(); |
| 64 | 65 |
| 65 // Overridden from WebDialogDelegate: | 66 // Overridden from WebDialogDelegate: |
| 66 virtual ui::ModalType GetDialogModalType() const OVERRIDE; | 67 virtual ui::ModalType GetDialogModalType() const OVERRIDE; |
| 67 virtual string16 GetDialogTitle() const OVERRIDE; | 68 virtual string16 GetDialogTitle() const OVERRIDE; |
| 68 virtual GURL GetDialogContentURL() const OVERRIDE; | 69 virtual GURL GetDialogContentURL() const OVERRIDE; |
| 69 virtual void GetWebUIMessageHandlers( | 70 virtual void GetWebUIMessageHandlers( |
| 70 std::vector<WebUIMessageHandler*>* handlers) const OVERRIDE; | 71 std::vector<WebUIMessageHandler*>* handlers) const OVERRIDE; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 } | 143 } |
| 143 | 144 |
| 144 bool PrintPreviewTabDelegate::ShouldShowDialogTitle() const { | 145 bool PrintPreviewTabDelegate::ShouldShowDialogTitle() const { |
| 145 // Not used, returning dummy value. | 146 // Not used, returning dummy value. |
| 146 NOTREACHED(); | 147 NOTREACHED(); |
| 147 return false; | 148 return false; |
| 148 } | 149 } |
| 149 | 150 |
| 150 // WebContentsDelegate that forwards shortcut keys in the print preview | 151 // WebContentsDelegate that forwards shortcut keys in the print preview |
| 151 // renderer to the browser. | 152 // renderer to the browser. |
| 152 class PrintPreviewWebContentDelegate : public WebDialogWebContentsDelegate { | 153 class PrintPreviewWebContentDelegate |
| 154 : public ChromeWebDialogWebContentsDelegate { |
| 153 public: | 155 public: |
| 154 PrintPreviewWebContentDelegate(Profile* profile, | 156 PrintPreviewWebContentDelegate(Profile* profile, |
| 155 TabContentsWrapper* initiator_tab); | 157 TabContentsWrapper* initiator_tab); |
| 156 virtual ~PrintPreviewWebContentDelegate(); | 158 virtual ~PrintPreviewWebContentDelegate(); |
| 157 | 159 |
| 158 virtual bool CanReloadContents(WebContents* source) const OVERRIDE; | 160 virtual bool CanReloadContents(WebContents* source) const OVERRIDE; |
| 159 virtual void HandleKeyboardEvent( | 161 virtual void HandleKeyboardEvent( |
| 160 const NativeWebKeyboardEvent& event) OVERRIDE; | 162 const NativeWebKeyboardEvent& event) OVERRIDE; |
| 161 | 163 |
| 162 private: | 164 private: |
| 163 TabContentsWrapper* tab_; | 165 TabContentsWrapper* tab_; |
| 164 | 166 |
| 165 DISALLOW_COPY_AND_ASSIGN(PrintPreviewWebContentDelegate); | 167 DISALLOW_COPY_AND_ASSIGN(PrintPreviewWebContentDelegate); |
| 166 }; | 168 }; |
| 167 | 169 |
| 168 PrintPreviewWebContentDelegate::PrintPreviewWebContentDelegate( | 170 PrintPreviewWebContentDelegate::PrintPreviewWebContentDelegate( |
| 169 Profile* profile, | 171 Profile* profile, |
| 170 TabContentsWrapper* initiator_tab) | 172 TabContentsWrapper* initiator_tab) |
| 171 : WebDialogWebContentsDelegate(profile), | 173 : ChromeWebDialogWebContentsDelegate(profile), |
| 172 tab_(initiator_tab) {} | 174 tab_(initiator_tab) {} |
| 173 | 175 |
| 174 PrintPreviewWebContentDelegate::~PrintPreviewWebContentDelegate() {} | 176 PrintPreviewWebContentDelegate::~PrintPreviewWebContentDelegate() {} |
| 175 | 177 |
| 176 bool PrintPreviewWebContentDelegate::CanReloadContents( | 178 bool PrintPreviewWebContentDelegate::CanReloadContents( |
| 177 WebContents* source) const { | 179 WebContents* source) const { |
| 178 return false; | 180 return false; |
| 179 } | 181 } |
| 180 | 182 |
| 181 void PrintPreviewWebContentDelegate::HandleKeyboardEvent( | 183 void PrintPreviewWebContentDelegate::HandleKeyboardEvent( |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 NOTREACHED() << "Failed to create popup browser window"; | 423 NOTREACHED() << "Failed to create popup browser window"; |
| 422 return NULL; | 424 return NULL; |
| 423 } | 425 } |
| 424 } else { | 426 } else { |
| 425 return NULL; | 427 return NULL; |
| 426 } | 428 } |
| 427 } | 429 } |
| 428 | 430 |
| 429 // |web_dialog_ui_delegate| deletes itself in | 431 // |web_dialog_ui_delegate| deletes itself in |
| 430 // PrintPreviewTabDelegate::OnDialogClosed(). | 432 // PrintPreviewTabDelegate::OnDialogClosed(). |
| 431 WebDialogDelegate* web_dialog_delegate = | 433 web_dialogs::WebDialogDelegate* web_dialog_delegate = |
| 432 new PrintPreviewTabDelegate(initiator_tab); | 434 new PrintPreviewTabDelegate(initiator_tab); |
| 433 // |web_tab_content_delegate|'s owner is |constrained_web_ui_delegate|. | 435 // |web_tab_content_delegate|'s owner is |constrained_web_ui_delegate|. |
| 434 PrintPreviewWebContentDelegate* pp_wcd = | 436 PrintPreviewWebContentDelegate* pp_wcd = |
| 435 new PrintPreviewWebContentDelegate(current_browser->profile(), | 437 new PrintPreviewWebContentDelegate(current_browser->profile(), |
| 436 initiator_tab); | 438 initiator_tab); |
| 437 ConstrainedWebDialogDelegate* constrained_delegate = | 439 ConstrainedWebDialogDelegate* constrained_delegate = |
| 438 ConstrainedWebDialogUI::CreateConstrainedWebDialog( | 440 ConstrainedWebDialogUI::CreateConstrainedWebDialog( |
| 439 current_browser->profile(), | 441 current_browser->profile(), |
| 440 web_dialog_delegate, | 442 web_dialog_delegate, |
| 441 pp_wcd, | 443 pp_wcd, |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( | 543 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
| 542 preview_tab->web_contents()->GetWebUI()->GetController()); | 544 preview_tab->web_contents()->GetWebUI()->GetController()); |
| 543 if (print_preview_ui) | 545 if (print_preview_ui) |
| 544 print_preview_ui->OnTabDestroyed(); | 546 print_preview_ui->OnTabDestroyed(); |
| 545 | 547 |
| 546 preview_tab_map_.erase(preview_tab); | 548 preview_tab_map_.erase(preview_tab); |
| 547 RemoveObservers(preview_tab); | 549 RemoveObservers(preview_tab); |
| 548 } | 550 } |
| 549 | 551 |
| 550 } // namespace printing | 552 } // namespace printing |
| OLD | NEW |