| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_UI_H_ | |
| 6 #define CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_UI_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/memory/ref_counted.h" | |
| 12 #include "base/memory/ref_counted_memory.h" | |
| 13 #include "base/time.h" | |
| 14 #include "chrome/browser/printing/print_preview_data_service.h" | |
| 15 #include "chrome/browser/ui/webui/constrained_html_ui.h" | |
| 16 | |
| 17 class PrintPreviewDataService; | |
| 18 class PrintPreviewHandler; | |
| 19 struct PrintHostMsg_DidGetPreviewPageCount_Params; | |
| 20 | |
| 21 namespace printing { | |
| 22 struct PageSizeMargins; | |
| 23 } | |
| 24 | |
| 25 class PrintPreviewUI : public ConstrainedHtmlUI { | |
| 26 public: | |
| 27 explicit PrintPreviewUI(content::WebContents* contents); | |
| 28 virtual ~PrintPreviewUI(); | |
| 29 | |
| 30 // Gets the print preview |data|. |index| is zero-based, and can be | |
| 31 // |printing::COMPLETE_PREVIEW_DOCUMENT_INDEX| to get the entire preview | |
| 32 // document. | |
| 33 void GetPrintPreviewDataForIndex(int index, | |
| 34 scoped_refptr<RefCountedBytes>* data); | |
| 35 | |
| 36 // Sets the print preview |data|. |index| is zero-based, and can be | |
| 37 // |printing::COMPLETE_PREVIEW_DOCUMENT_INDEX| to set the entire preview | |
| 38 // document. | |
| 39 void SetPrintPreviewDataForIndex(int index, const RefCountedBytes* data); | |
| 40 | |
| 41 // Clear the existing print preview data. | |
| 42 void ClearAllPreviewData(); | |
| 43 | |
| 44 // Returns the available draft page count. | |
| 45 int GetAvailableDraftPageCount(); | |
| 46 | |
| 47 // Setters | |
| 48 void SetInitiatorTabURLAndTitle(const std::string& initiator_url, | |
| 49 const string16& initiator_tab_title); | |
| 50 | |
| 51 string16 initiator_tab_title() { return initiator_tab_title_; } | |
| 52 | |
| 53 bool source_is_modifiable() { return source_is_modifiable_; } | |
| 54 | |
| 55 // Set |source_is_modifiable_| for |print_preview_tab|'s PrintPreviewUI. | |
| 56 static void SetSourceIsModifiable(TabContentsWrapper* print_preview_tab, | |
| 57 bool source_is_modifiable); | |
| 58 | |
| 59 // Determines whether to cancel a print preview request based on | |
| 60 // |preview_ui_addr| and |request_id|. | |
| 61 // Can be called from any thread. | |
| 62 static void GetCurrentPrintPreviewStatus(const std::string& preview_ui_addr, | |
| 63 int request_id, | |
| 64 bool* cancel); | |
| 65 | |
| 66 // Returns a string to uniquely identify this PrintPreviewUI. | |
| 67 std::string GetPrintPreviewUIAddress() const; | |
| 68 | |
| 69 // Notifies the Web UI of a print preview request with |request_id|. | |
| 70 void OnPrintPreviewRequest(int request_id); | |
| 71 | |
| 72 // Notifies the Web UI to show the system dialog. | |
| 73 void OnShowSystemDialog(); | |
| 74 | |
| 75 // Notifies the Web UI about the page count of the request preview. | |
| 76 void OnDidGetPreviewPageCount( | |
| 77 const PrintHostMsg_DidGetPreviewPageCount_Params& params); | |
| 78 | |
| 79 // Notifies the Web UI of the default page layout according to the currently | |
| 80 // selected printer and page size. | |
| 81 void OnDidGetDefaultPageLayout( | |
| 82 const printing::PageSizeMargins& page_layout, | |
| 83 bool has_custom_page_size_style); | |
| 84 | |
| 85 // Notifies the Web UI that the 0-based page |page_number| has been rendered. | |
| 86 // |preview_request_id| indicates wich request resulted in this response. | |
| 87 void OnDidPreviewPage(int page_number, int preview_request_id); | |
| 88 | |
| 89 // Notifies the Web UI renderer that preview data is available. | |
| 90 // |expected_pages_count| specifies the total number of pages. | |
| 91 // |preview_request_id| indicates which request resulted in this response. | |
| 92 void OnPreviewDataIsAvailable(int expected_pages_count, | |
| 93 int preview_request_id); | |
| 94 | |
| 95 // Notifies the Web UI renderer to reuse the preview data. | |
| 96 // |preview_request_id| indicates which request resulted in this response. | |
| 97 void OnReusePreviewData(int preview_request_id); | |
| 98 | |
| 99 // Notifies the Web UI that preview tab is destroyed. This is the last chance | |
| 100 // to communicate with the source tab before the association is erased. | |
| 101 void OnTabDestroyed(); | |
| 102 | |
| 103 // Notifies the Web UI that the print preview failed to render. | |
| 104 void OnPrintPreviewFailed(); | |
| 105 | |
| 106 // Notified the Web UI that this print preview tab's RenderProcess has been | |
| 107 // closed, which may occur for several reasons, e.g. tab closure or crash. | |
| 108 void OnPrintPreviewTabClosed(); | |
| 109 | |
| 110 // Notifies the Web UI that initiator tab is closed, so we can disable all the | |
| 111 // controls that need the initiator tab for generating the preview data. | |
| 112 void OnInitiatorTabClosed(); | |
| 113 | |
| 114 // Notifies the Web UI renderer that file selection has been cancelled. | |
| 115 void OnFileSelectionCancelled(); | |
| 116 | |
| 117 // Notifies the Web UI that the printer is unavailable or its settings are | |
| 118 // invalid. | |
| 119 void OnInvalidPrinterSettings(); | |
| 120 | |
| 121 // Notifies the Web UI to cancel the pending preview request. | |
| 122 void OnCancelPendingPreviewRequest(); | |
| 123 | |
| 124 // Hides the print preview tab. | |
| 125 void OnHidePreviewTab(); | |
| 126 | |
| 127 // Closes the print preview tab. | |
| 128 void OnClosePrintPreviewTab(); | |
| 129 | |
| 130 // Reload the printers list. | |
| 131 void OnReloadPrintersList(); | |
| 132 | |
| 133 private: | |
| 134 friend class PrintPreviewHandlerTest; | |
| 135 FRIEND_TEST_ALL_PREFIXES(PrintPreviewHandlerTest, StickyMarginsCustom); | |
| 136 FRIEND_TEST_ALL_PREFIXES(PrintPreviewHandlerTest, StickyMarginsDefault); | |
| 137 FRIEND_TEST_ALL_PREFIXES(PrintPreviewHandlerTest, | |
| 138 StickyMarginsCustomThenDefault); | |
| 139 FRIEND_TEST_ALL_PREFIXES(PrintPreviewHandlerTest, | |
| 140 GetLastUsedMarginSettingsCustom); | |
| 141 FRIEND_TEST_ALL_PREFIXES(PrintPreviewHandlerTest, | |
| 142 GetLastUsedMarginSettingsDefault); | |
| 143 FRIEND_TEST_ALL_PREFIXES(PrintPreviewTabControllerUnitTest, | |
| 144 TitleAfterReload); | |
| 145 | |
| 146 // Returns the Singleton instance of the PrintPreviewDataService. | |
| 147 PrintPreviewDataService* print_preview_data_service(); | |
| 148 | |
| 149 base::TimeTicks initial_preview_start_time_; | |
| 150 | |
| 151 // Store the PrintPreviewUI address string. | |
| 152 std::string preview_ui_addr_str_; | |
| 153 | |
| 154 // Weak pointer to the WebUI handler. | |
| 155 PrintPreviewHandler* handler_; | |
| 156 | |
| 157 // Store the |initiator_url| in order to display an accurate error message | |
| 158 // when the initiator tab is closed/crashed. | |
| 159 std::string initiator_url_; | |
| 160 | |
| 161 // Indicates whether the source document can be modified. | |
| 162 bool source_is_modifiable_; | |
| 163 | |
| 164 // Store the initiator tab title, used for populating the print preview tab | |
| 165 // title. | |
| 166 string16 initiator_tab_title_; | |
| 167 | |
| 168 // Keeps track of whether OnClosePrintPreviewTab() has been called or not. | |
| 169 bool tab_closed_; | |
| 170 | |
| 171 // True if the user visited the page directly, false if it's a live UI. | |
| 172 bool is_dummy_; | |
| 173 | |
| 174 DISALLOW_COPY_AND_ASSIGN(PrintPreviewUI); | |
| 175 }; | |
| 176 | |
| 177 #endif // CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_UI_H_ | |
| OLD | NEW |