Chromium Code Reviews| 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" |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 37 PrintPreviewDialogController(); | 37 PrintPreviewDialogController(); |
| 38 | 38 |
| 39 static PrintPreviewDialogController* GetInstance(); | 39 static PrintPreviewDialogController* GetInstance(); |
| 40 | 40 |
| 41 // Initiate print preview for |initiator|. | 41 // Initiate print preview for |initiator|. |
| 42 // Call this instead of GetOrCreatePreviewDialog(). | 42 // Call this instead of GetOrCreatePreviewDialog(). |
| 43 static void PrintPreview(content::WebContents* initiator); | 43 static void PrintPreview(content::WebContents* initiator); |
| 44 | 44 |
| 45 // Get/Create the print preview dialog for |initiator|. | 45 // Get/Create the print preview dialog for |initiator|. |
| 46 // Exposed for unit tests. | 46 // Exposed for unit tests. |
| 47 content::WebContents* GetOrCreatePreviewDialog( | 47 virtual content::WebContents* GetOrCreatePreviewDialog( |
| 48 content::WebContents* initiator); | 48 content::WebContents* initiator); |
| 49 | 49 |
| 50 // Returns the preview dialog for |contents|. | 50 // Returns the preview dialog for |contents|. |
| 51 // Returns |contents| if |contents| is a preview dialog. | 51 // Returns |contents| if |contents| is a preview dialog. |
| 52 // Returns NULL if no preview dialog exists for |contents|. | 52 // Returns NULL if no preview dialog exists for |contents|. |
| 53 content::WebContents* GetPrintPreviewForContents( | 53 content::WebContents* GetPrintPreviewForContents( |
| 54 content::WebContents* contents) const; | 54 content::WebContents* contents) const; |
| 55 | 55 |
| 56 // Returns the initiator for |preview_dialog|. | 56 // Returns the initiator for |preview_dialog|. |
| 57 // Returns NULL if no initiator exists for |preview_dialog|. | 57 // Returns NULL if no initiator exists for |preview_dialog|. |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 72 // Returns true if |url| is a print preview url. | 72 // Returns true if |url| is a print preview url. |
| 73 static bool IsPrintPreviewURL(const GURL& url); | 73 static bool IsPrintPreviewURL(const GURL& url); |
| 74 | 74 |
| 75 // Erase the initiator info associated with |preview_dialog|. | 75 // Erase the initiator info associated with |preview_dialog|. |
| 76 void EraseInitiatorInfo(content::WebContents* preview_dialog); | 76 void EraseInitiatorInfo(content::WebContents* preview_dialog); |
| 77 | 77 |
| 78 bool is_creating_print_preview_dialog() const { | 78 bool is_creating_print_preview_dialog() const { |
| 79 return is_creating_print_preview_dialog_; | 79 return is_creating_print_preview_dialog_; |
| 80 } | 80 } |
| 81 | 81 |
| 82 private: | 82 protected: |
| 83 friend class base::RefCounted<PrintPreviewDialogController>; | 83 // Moved to this category so that testing subclass works |
|
Lei Zhang
2016/08/17 21:27:54
No need for the comment in the code to check in. M
| |
| 84 ~PrintPreviewDialogController() override; | |
| 84 | 85 |
| 85 // 1:1 relationship between a print preview dialog and its initiator tab. | 86 // 1:1 relationship between a print preview dialog and its initiator tab. |
| 86 // Key: Print preview dialog. | 87 // Key: Print preview dialog. |
| 87 // Value: Initiator. | 88 // Value: Initiator. |
| 88 using PrintPreviewDialogMap = | 89 using PrintPreviewDialogMap = |
| 89 std::map<content::WebContents*, content::WebContents*>; | 90 std::map<content::WebContents*, content::WebContents*>; |
| 90 | 91 |
| 91 ~PrintPreviewDialogController() override; | 92 // Mapping between print preview dialog and the corresponding initiator. |
| 93 PrintPreviewDialogMap preview_dialog_map_; | |
|
Lei Zhang
2016/08/17 21:27:54
Can we provide a setter method instead? Keep the m
| |
| 94 virtual void RemoveInitiator(content::WebContents* initiator); | |
| 92 | 95 |
| 96 // Adds/removes observers for notifications from |contents|. | |
| 97 void AddObservers(content::WebContents* contents); | |
| 98 void RemoveObservers(content::WebContents* contents); | |
| 99 | |
| 100 private: | |
| 101 friend class base::RefCounted<PrintPreviewDialogController>; | |
| 93 // Handler for the RENDERER_PROCESS_CLOSED notification. This is observed when | 102 // Handler for the RENDERER_PROCESS_CLOSED notification. This is observed when |
| 94 // the initiator renderer crashed. | 103 // the initiator renderer crashed. |
| 95 void OnRendererProcessClosed(content::RenderProcessHost* rph); | 104 void OnRendererProcessClosed(content::RenderProcessHost* rph); |
| 96 | 105 |
| 97 // Handler for the WEB_CONTENTS_DESTROYED notification. This is observed when | 106 // Handler for the WEB_CONTENTS_DESTROYED notification. This is observed when |
| 98 // either WebContents is closed. | 107 // either WebContents is closed. |
| 99 void OnWebContentsDestroyed(content::WebContents* contents); | 108 void OnWebContentsDestroyed(content::WebContents* contents); |
| 100 | 109 |
| 101 // Handler for the NAV_ENTRY_COMMITTED notification. This is observed when the | 110 // Handler for the NAV_ENTRY_COMMITTED notification. This is observed when the |
| 102 // renderer is navigated to a different page. | 111 // renderer is navigated to a different page. |
| 103 void OnNavEntryCommitted(content::WebContents* contents, | 112 void OnNavEntryCommitted(content::WebContents* contents, |
| 104 content::LoadCommittedDetails* details); | 113 content::LoadCommittedDetails* details); |
| 105 | 114 |
| 106 // Creates a new print preview dialog. | 115 // Creates a new print preview dialog. |
| 107 content::WebContents* CreatePrintPreviewDialog( | 116 content::WebContents* CreatePrintPreviewDialog( |
| 108 content::WebContents* initiator); | 117 content::WebContents* initiator); |
| 109 | 118 |
| 110 // Helper function to store the title of the initiator associated with | 119 // Helper function to store the title of the initiator associated with |
| 111 // |preview_dialog| in |preview_dialog|'s PrintPreviewUI. | 120 // |preview_dialog| in |preview_dialog|'s PrintPreviewUI. |
| 112 void SaveInitiatorTitle(content::WebContents* preview_dialog); | 121 void SaveInitiatorTitle(content::WebContents* preview_dialog); |
| 113 | 122 |
| 114 // Adds/Removes observers for notifications from |contents|. | |
| 115 void AddObservers(content::WebContents* contents); | |
| 116 void RemoveObservers(content::WebContents* contents); | |
| 117 | |
| 118 // Removes WebContents when they close/crash/navigate. | 123 // Removes WebContents when they close/crash/navigate. |
| 119 void RemoveInitiator(content::WebContents* initiator); | |
| 120 void RemovePreviewDialog(content::WebContents* preview_dialog); | 124 void RemovePreviewDialog(content::WebContents* preview_dialog); |
| 121 | 125 |
| 122 // Mapping between print preview dialog and the corresponding initiator. | |
| 123 PrintPreviewDialogMap preview_dialog_map_; | |
| 124 | |
| 125 // A registrar for listening to notifications. | 126 // A registrar for listening to notifications. |
| 126 content::NotificationRegistrar registrar_; | 127 content::NotificationRegistrar registrar_; |
| 127 | 128 |
| 128 // True if the controller is waiting for a new preview dialog via | 129 // True if the controller is waiting for a new preview dialog via |
| 129 // content::NAVIGATION_TYPE_NEW_PAGE. | 130 // content::NAVIGATION_TYPE_NEW_PAGE. |
| 130 bool waiting_for_new_preview_page_; | 131 bool waiting_for_new_preview_page_; |
| 131 | 132 |
| 132 // Whether the PrintPreviewDialogController is in the middle of creating a | 133 // Whether the PrintPreviewDialogController is in the middle of creating a |
| 133 // print preview dialog. | 134 // print preview dialog. |
| 134 bool is_creating_print_preview_dialog_; | 135 bool is_creating_print_preview_dialog_; |
| 135 | 136 |
| 136 DISALLOW_COPY_AND_ASSIGN(PrintPreviewDialogController); | 137 DISALLOW_COPY_AND_ASSIGN(PrintPreviewDialogController); |
| 137 }; | 138 }; |
| 138 | 139 |
| 139 } // namespace printing | 140 } // namespace printing |
| 140 | 141 |
| 141 #endif // CHROME_BROWSER_PRINTING_PRINT_PREVIEW_DIALOG_CONTROLLER_H_ | 142 #endif // CHROME_BROWSER_PRINTING_PRINT_PREVIEW_DIALOG_CONTROLLER_H_ |
| OLD | NEW |