| 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_dialog_controller.h" | 5 #include "chrome/browser/printing/print_preview_dialog_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/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/chrome_notification_types.h" | 15 #include "chrome/browser/chrome_notification_types.h" |
| 16 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" | 16 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" |
| 17 #include "chrome/browser/printing/print_view_manager.h" | 17 #include "chrome/browser/printing/print_view_manager.h" |
| 18 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
| 19 #include "chrome/browser/ui/browser_finder.h" | 19 #include "chrome/browser/ui/browser_finder.h" |
| 20 #include "chrome/browser/ui/browser_navigator.h" | 20 #include "chrome/browser/ui/browser_navigator.h" |
| 21 #include "chrome/browser/ui/browser_window.h" | 21 #include "chrome/browser/ui/browser_window.h" |
| 22 #include "chrome/browser/ui/host_desktop.h" | 22 #include "chrome/browser/ui/host_desktop.h" |
| 23 #include "chrome/browser/ui/webui/chrome_web_contents_handler.h" | 23 #include "chrome/browser/ui/webui/chrome_web_contents_handler.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/common/chrome_paths.h" | 26 #include "chrome/common/chrome_paths.h" |
| 27 #include "chrome/common/url_constants.h" | 27 #include "chrome/common/url_constants.h" |
| 28 #include "components/guest_view/browser/guest_view_base.h" |
| 28 #include "components/web_modal/web_contents_modal_dialog_host.h" | 29 #include "components/web_modal/web_contents_modal_dialog_host.h" |
| 29 #include "content/public/browser/host_zoom_map.h" | 30 #include "content/public/browser/host_zoom_map.h" |
| 30 #include "content/public/browser/navigation_controller.h" | 31 #include "content/public/browser/navigation_controller.h" |
| 31 #include "content/public/browser/navigation_details.h" | 32 #include "content/public/browser/navigation_details.h" |
| 32 #include "content/public/browser/navigation_entry.h" | 33 #include "content/public/browser/navigation_entry.h" |
| 33 #include "content/public/browser/notification_details.h" | 34 #include "content/public/browser/notification_details.h" |
| 34 #include "content/public/browser/notification_source.h" | 35 #include "content/public/browser/notification_source.h" |
| 35 #include "content/public/browser/render_view_host.h" | 36 #include "content/public/browser/render_view_host.h" |
| 36 #include "content/public/browser/web_contents.h" | 37 #include "content/public/browser/web_contents.h" |
| 37 #include "content/public/browser/web_contents_delegate.h" | 38 #include "content/public/browser/web_contents_delegate.h" |
| 38 #include "extensions/browser/guest_view/guest_view_base.h" | |
| 39 #include "ui/web_dialogs/web_dialog_delegate.h" | 39 #include "ui/web_dialogs/web_dialog_delegate.h" |
| 40 | 40 |
| 41 using content::NavigationController; | 41 using content::NavigationController; |
| 42 using content::WebContents; | 42 using content::WebContents; |
| 43 using content::WebUIMessageHandler; | 43 using content::WebUIMessageHandler; |
| 44 | 44 |
| 45 namespace { | 45 namespace { |
| 46 | 46 |
| 47 // A ui::WebDialogDelegate that specifies the print preview dialog appearance. | 47 // A ui::WebDialogDelegate that specifies the print preview dialog appearance. |
| 48 class PrintPreviewDialogDelegate : public ui::WebDialogDelegate { | 48 class PrintPreviewDialogDelegate : public ui::WebDialogDelegate { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 // PrintPreviewUI adds its own message handlers. | 94 // PrintPreviewUI adds its own message handlers. |
| 95 } | 95 } |
| 96 | 96 |
| 97 void PrintPreviewDialogDelegate::GetDialogSize(gfx::Size* size) const { | 97 void PrintPreviewDialogDelegate::GetDialogSize(gfx::Size* size) const { |
| 98 DCHECK(size); | 98 DCHECK(size); |
| 99 const gfx::Size kMinDialogSize(800, 480); | 99 const gfx::Size kMinDialogSize(800, 480); |
| 100 const int kBorder = 25; | 100 const int kBorder = 25; |
| 101 *size = kMinDialogSize; | 101 *size = kMinDialogSize; |
| 102 | 102 |
| 103 web_modal::WebContentsModalDialogHost* host = NULL; | 103 web_modal::WebContentsModalDialogHost* host = NULL; |
| 104 content::WebContents* outermost_web_contents = initiator_; | 104 content::WebContents* outermost_web_contents = |
| 105 const extensions::GuestViewBase* guest_view = | 105 guest_view::GuestViewBase::GetTopLevelWebContents(initiator_); |
| 106 extensions::GuestViewBase::FromWebContents(outermost_web_contents); | |
| 107 while (guest_view && guest_view->attached()) { | |
| 108 outermost_web_contents = guest_view->embedder_web_contents(); | |
| 109 guest_view = | |
| 110 extensions::GuestViewBase::FromWebContents(outermost_web_contents); | |
| 111 } | |
| 112 Browser* browser = chrome::FindBrowserWithWebContents(outermost_web_contents); | 106 Browser* browser = chrome::FindBrowserWithWebContents(outermost_web_contents); |
| 113 if (browser) | 107 if (browser) |
| 114 host = browser->window()->GetWebContentsModalDialogHost(); | 108 host = browser->window()->GetWebContentsModalDialogHost(); |
| 115 | 109 |
| 116 if (host) { | 110 if (host) { |
| 117 size->SetToMax(host->GetMaximumDialogSize()); | 111 size->SetToMax(host->GetMaximumDialogSize()); |
| 118 size->Enlarge(-2 * kBorder, -kBorder); | 112 size->Enlarge(-2 * kBorder, -kBorder); |
| 119 } else { | 113 } else { |
| 120 size->SetToMax(outermost_web_contents->GetContainerBounds().size()); | 114 size->SetToMax(outermost_web_contents->GetContainerBounds().size()); |
| 121 size->Enlarge(-2 * kBorder, -2 * kBorder); | 115 size->Enlarge(-2 * kBorder, -2 * kBorder); |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 static_cast<PrintPreviewUI*>(web_ui->GetController()); | 458 static_cast<PrintPreviewUI*>(web_ui->GetController()); |
| 465 if (print_preview_ui) | 459 if (print_preview_ui) |
| 466 print_preview_ui->OnPrintPreviewDialogDestroyed(); | 460 print_preview_ui->OnPrintPreviewDialogDestroyed(); |
| 467 } | 461 } |
| 468 | 462 |
| 469 preview_dialog_map_.erase(preview_dialog); | 463 preview_dialog_map_.erase(preview_dialog); |
| 470 RemoveObservers(preview_dialog); | 464 RemoveObservers(preview_dialog); |
| 471 } | 465 } |
| 472 | 466 |
| 473 } // namespace printing | 467 } // namespace printing |
| OLD | NEW |