| 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 #ifndef CHROME_BROWSER_PRINTING_PRINT_PREVIEW_DIALOG_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_PRINTING_PRINT_PREVIEW_DIALOG_CONTROLLER_H_ |
| 6 #define CHROME_BROWSER_PRINTING_PRINT_PREVIEW_DIALOG_CONTROLLER_H_ | 6 #define CHROME_BROWSER_PRINTING_PRINT_PREVIEW_DIALOG_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h" |
| 13 #include "components/sessions/core/session_id.h" | 14 #include "components/sessions/core/session_id.h" |
| 14 #include "content/public/browser/notification_observer.h" | 15 #include "content/public/browser/notification_observer.h" |
| 15 #include "content/public/browser/notification_registrar.h" | 16 #include "content/public/browser/notification_registrar.h" |
| 17 #include "ui/web_dialogs/web_dialog_delegate.h" |
| 16 | 18 |
| 17 class GURL; | 19 class GURL; |
| 18 | 20 |
| 19 namespace content { | 21 namespace content { |
| 20 struct LoadCommittedDetails; | 22 struct LoadCommittedDetails; |
| 21 class RenderProcessHost; | 23 class RenderProcessHost; |
| 22 class WebContents; | 24 class WebContents; |
| 23 } | 25 } |
| 24 | 26 |
| 25 namespace printing { | 27 namespace printing { |
| 28 ui::WebDialogDelegate * GetPrintPreviewDialogDelegate( |
| 29 content::WebContents * initiator); |
| 26 | 30 |
| 27 // For print preview, the WebContents that initiates the printing operation is | 31 // For print preview, the WebContents that initiates the printing operation is |
| 28 // the initiator, and the constrained dialog that shows the print preview is the | 32 // the initiator, and the constrained dialog that shows the print preview is the |
| 29 // print preview dialog. | 33 // print preview dialog. |
| 30 // This class manages print preview dialog creation and destruction, and keeps | 34 // This class manages print preview dialog creation and destruction, and keeps |
| 31 // track of the 1:1 relationship between initiator tabs and print preview | 35 // track of the 1:1 relationship between initiator tabs and print preview |
| 32 // dialogs. | 36 // dialogs. |
| 33 class PrintPreviewDialogController | 37 class PrintPreviewDialogController |
| 34 : public base::RefCounted<PrintPreviewDialogController>, | 38 : public base::RefCounted<PrintPreviewDialogController>, |
| 35 public content::NotificationObserver { | 39 public content::NotificationObserver { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 | 75 |
| 72 // Returns true if |url| is a print preview url. | 76 // Returns true if |url| is a print preview url. |
| 73 static bool IsPrintPreviewURL(const GURL& url); | 77 static bool IsPrintPreviewURL(const GURL& url); |
| 74 | 78 |
| 75 // Erase the initiator info associated with |preview_dialog|. | 79 // Erase the initiator info associated with |preview_dialog|. |
| 76 void EraseInitiatorInfo(content::WebContents* preview_dialog); | 80 void EraseInitiatorInfo(content::WebContents* preview_dialog); |
| 77 | 81 |
| 78 bool is_creating_print_preview_dialog() const { | 82 bool is_creating_print_preview_dialog() const { |
| 79 return is_creating_print_preview_dialog_; | 83 return is_creating_print_preview_dialog_; |
| 80 } | 84 } |
| 85 protected: |
| 86 ~PrintPreviewDialogController() override; |
| 87 |
| 88 virtual ConstrainedWebDialogDelegate * GetWebDialogDelegate( |
| 89 content::WebContents* initiator); |
| 81 | 90 |
| 82 private: | 91 private: |
| 83 friend class base::RefCounted<PrintPreviewDialogController>; | 92 friend class base::RefCounted<PrintPreviewDialogController>; |
| 84 | 93 |
| 85 // 1:1 relationship between a print preview dialog and its initiator tab. | 94 // 1:1 relationship between a print preview dialog and its initiator tab. |
| 86 // Key: Print preview dialog. | 95 // Key: Print preview dialog. |
| 87 // Value: Initiator. | 96 // Value: Initiator. |
| 88 using PrintPreviewDialogMap = | 97 using PrintPreviewDialogMap = |
| 89 std::map<content::WebContents*, content::WebContents*>; | 98 std::map<content::WebContents*, content::WebContents*>; |
| 90 | 99 |
| 91 ~PrintPreviewDialogController() override; | |
| 92 | |
| 93 // Handler for the RENDERER_PROCESS_CLOSED notification. This is observed when | 100 // Handler for the RENDERER_PROCESS_CLOSED notification. This is observed when |
| 94 // the initiator renderer crashed. | 101 // the initiator renderer crashed. |
| 95 void OnRendererProcessClosed(content::RenderProcessHost* rph); | 102 void OnRendererProcessClosed(content::RenderProcessHost* rph); |
| 96 | 103 |
| 97 // Handler for the WEB_CONTENTS_DESTROYED notification. This is observed when | 104 // Handler for the WEB_CONTENTS_DESTROYED notification. This is observed when |
| 98 // either WebContents is closed. | 105 // either WebContents is closed. |
| 99 void OnWebContentsDestroyed(content::WebContents* contents); | 106 void OnWebContentsDestroyed(content::WebContents* contents); |
| 100 | 107 |
| 101 // Handler for the NAV_ENTRY_COMMITTED notification. This is observed when the | 108 // Handler for the NAV_ENTRY_COMMITTED notification. This is observed when the |
| 102 // renderer is navigated to a different page. | 109 // renderer is navigated to a different page. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 // NOTIFICATION_RENDERER_PROCESS_CLOSED notification should be removed from | 145 // NOTIFICATION_RENDERER_PROCESS_CLOSED notification should be removed from |
| 139 // the registrar. | 146 // the registrar. |
| 140 std::map<content::RenderProcessHost*, int> host_contents_count_map_; | 147 std::map<content::RenderProcessHost*, int> host_contents_count_map_; |
| 141 | 148 |
| 142 DISALLOW_COPY_AND_ASSIGN(PrintPreviewDialogController); | 149 DISALLOW_COPY_AND_ASSIGN(PrintPreviewDialogController); |
| 143 }; | 150 }; |
| 144 | 151 |
| 145 } // namespace printing | 152 } // namespace printing |
| 146 | 153 |
| 147 #endif // CHROME_BROWSER_PRINTING_PRINT_PREVIEW_DIALOG_CONTROLLER_H_ | 154 #endif // CHROME_BROWSER_PRINTING_PRINT_PREVIEW_DIALOG_CONTROLLER_H_ |
| OLD | NEW |