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_UI_WEBUI_PRINT_PREVIEW_PRINT_PREVIEW_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_PRINT_PREVIEW_HANDLER_H_ |
6 #define CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_PRINT_PREVIEW_HANDLER_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_PRINT_PREVIEW_HANDLER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "chrome/common/features.h" | 16 #include "chrome/common/features.h" |
17 #include "components/signin/core/browser/gaia_cookie_manager_service.h" | 17 #include "components/signin/core/browser/gaia_cookie_manager_service.h" |
18 #include "content/public/browser/web_ui_message_handler.h" | 18 #include "content/public/browser/web_ui_message_handler.h" |
19 #include "ui/shell_dialogs/select_file_dialog.h" | 19 #include "ui/shell_dialogs/select_file_dialog.h" |
20 | 20 |
21 #if defined(ENABLE_SERVICE_DISCOVERY) | 21 #if BUILDFLAG(ENABLE_SERVICE_DISCOVERY) |
22 #include "chrome/browser/local_discovery/service_discovery_shared_client.h" | 22 #include "chrome/browser/local_discovery/service_discovery_shared_client.h" |
23 #include "chrome/browser/printing/cloud_print/privet_local_printer_lister.h" | 23 #include "chrome/browser/printing/cloud_print/privet_local_printer_lister.h" |
24 #endif // defined(ENABLE_SERVICE_DISCOVERY) | 24 #endif |
25 | 25 |
26 class PrinterHandler; | 26 class PrinterHandler; |
27 class PrintPreviewUI; | 27 class PrintPreviewUI; |
28 class PrintSystemTaskProxy; | 28 class PrintSystemTaskProxy; |
29 | 29 |
30 namespace base { | 30 namespace base { |
31 class DictionaryValue; | 31 class DictionaryValue; |
32 class RefCountedBytes; | 32 class RefCountedBytes; |
33 } | 33 } |
34 | 34 |
35 namespace content { | 35 namespace content { |
36 class WebContents; | 36 class WebContents; |
37 } | 37 } |
38 | 38 |
39 namespace gfx { | 39 namespace gfx { |
40 class Size; | 40 class Size; |
41 } | 41 } |
42 | 42 |
43 // The handler for Javascript messages related to the print preview dialog. | 43 // The handler for Javascript messages related to the print preview dialog. |
44 class PrintPreviewHandler | 44 class PrintPreviewHandler |
45 : public content::WebUIMessageHandler, | 45 : public content::WebUIMessageHandler, |
46 #if defined(ENABLE_SERVICE_DISCOVERY) | 46 #if BUILDFLAG(ENABLE_SERVICE_DISCOVERY) |
47 public cloud_print::PrivetLocalPrinterLister::Delegate, | 47 public cloud_print::PrivetLocalPrinterLister::Delegate, |
48 public cloud_print::PrivetLocalPrintOperation::Delegate, | 48 public cloud_print::PrivetLocalPrintOperation::Delegate, |
49 #endif | 49 #endif |
50 public ui::SelectFileDialog::Listener, | 50 public ui::SelectFileDialog::Listener, |
51 public GaiaCookieManagerService::Observer { | 51 public GaiaCookieManagerService::Observer { |
52 public: | 52 public: |
53 PrintPreviewHandler(); | 53 PrintPreviewHandler(); |
54 ~PrintPreviewHandler() override; | 54 ~PrintPreviewHandler() override; |
55 | 55 |
56 // WebUIMessageHandler implementation. | 56 // WebUIMessageHandler implementation. |
(...skipping 12 matching lines...) Expand all Loading... |
69 | 69 |
70 // Called when print preview failed. | 70 // Called when print preview failed. |
71 void OnPrintPreviewFailed(); | 71 void OnPrintPreviewFailed(); |
72 | 72 |
73 #if defined(ENABLE_BASIC_PRINTING) | 73 #if defined(ENABLE_BASIC_PRINTING) |
74 // Called when the user press ctrl+shift+p to display the native system | 74 // Called when the user press ctrl+shift+p to display the native system |
75 // dialog. | 75 // dialog. |
76 void ShowSystemDialog(); | 76 void ShowSystemDialog(); |
77 #endif // defined(ENABLE_BASIC_PRINTING) | 77 #endif // defined(ENABLE_BASIC_PRINTING) |
78 | 78 |
79 #if defined(ENABLE_SERVICE_DISCOVERY) | 79 #if BUILDFLAG(ENABLE_SERVICE_DISCOVERY) |
80 // PrivetLocalPrinterLister::Delegate implementation. | 80 // PrivetLocalPrinterLister::Delegate implementation. |
81 void LocalPrinterChanged( | 81 void LocalPrinterChanged( |
82 const std::string& name, | 82 const std::string& name, |
83 bool has_local_printing, | 83 bool has_local_printing, |
84 const cloud_print::DeviceDescription& description) override; | 84 const cloud_print::DeviceDescription& description) override; |
85 void LocalPrinterRemoved(const std::string& name) override; | 85 void LocalPrinterRemoved(const std::string& name) override; |
86 void LocalPrinterCacheFlushed() override; | 86 void LocalPrinterCacheFlushed() override; |
87 | 87 |
88 // PrivetLocalPrintOperation::Delegate implementation. | 88 // PrivetLocalPrintOperation::Delegate implementation. |
89 void OnPrivetPrintingDone( | 89 void OnPrivetPrintingDone( |
90 const cloud_print::PrivetLocalPrintOperation* print_operation) override; | 90 const cloud_print::PrivetLocalPrintOperation* print_operation) override; |
91 void OnPrivetPrintingError( | 91 void OnPrivetPrintingError( |
92 const cloud_print::PrivetLocalPrintOperation* print_operation, | 92 const cloud_print::PrivetLocalPrintOperation* print_operation, |
93 int http_code) override; | 93 int http_code) override; |
94 #endif // defined(ENABLE_SERVICE_DISCOVERY) | 94 #endif |
95 | 95 |
96 int regenerate_preview_request_count() const { | 96 int regenerate_preview_request_count() const { |
97 return regenerate_preview_request_count_; | 97 return regenerate_preview_request_count_; |
98 } | 98 } |
99 | 99 |
100 // Sets |pdf_file_saved_closure_| to |closure|. | 100 // Sets |pdf_file_saved_closure_| to |closure|. |
101 void SetPdfSavedClosureForTesting(const base::Closure& closure); | 101 void SetPdfSavedClosureForTesting(const base::Closure& closure); |
102 | 102 |
103 private: | 103 private: |
104 friend class PrintPreviewPdfGeneratedBrowserTest; | 104 friend class PrintPreviewPdfGeneratedBrowserTest; |
105 FRIEND_TEST_ALL_PREFIXES(PrintPreviewPdfGeneratedBrowserTest, | 105 FRIEND_TEST_ALL_PREFIXES(PrintPreviewPdfGeneratedBrowserTest, |
106 MANUAL_DummyTest); | 106 MANUAL_DummyTest); |
107 class AccessTokenService; | 107 class AccessTokenService; |
108 | 108 |
109 static bool PrivetPrintingEnabled(); | |
110 | |
111 content::WebContents* preview_web_contents() const; | 109 content::WebContents* preview_web_contents() const; |
112 | 110 |
113 PrintPreviewUI* print_preview_ui() const; | 111 PrintPreviewUI* print_preview_ui() const; |
114 | 112 |
115 // Gets the list of printers. |args| is unused. | 113 // Gets the list of printers. |args| is unused. |
116 void HandleGetPrinters(const base::ListValue* args); | 114 void HandleGetPrinters(const base::ListValue* args); |
117 | 115 |
118 // Starts getting all local privet printers. |args| is unused. | 116 // Starts getting all local privet printers. |args| is unused. |
119 void HandleGetPrivetPrinters(const base::ListValue* args); | 117 void HandleGetPrivetPrinters(const base::ListValue* args); |
120 | 118 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 // the user. Just an adaptor for FileSelected(). | 253 // the user. Just an adaptor for FileSelected(). |
256 void OnGotUniqueFileName(const base::FilePath& path); | 254 void OnGotUniqueFileName(const base::FilePath& path); |
257 | 255 |
258 #if defined(USE_CUPS) | 256 #if defined(USE_CUPS) |
259 void SaveCUPSColorSetting(const base::DictionaryValue* settings); | 257 void SaveCUPSColorSetting(const base::DictionaryValue* settings); |
260 | 258 |
261 void ConvertColorSettingToCUPSColorModel( | 259 void ConvertColorSettingToCUPSColorModel( |
262 base::DictionaryValue* settings) const; | 260 base::DictionaryValue* settings) const; |
263 #endif | 261 #endif |
264 | 262 |
265 #if defined(ENABLE_SERVICE_DISCOVERY) | 263 #if BUILDFLAG(ENABLE_SERVICE_DISCOVERY) |
266 void StartPrivetLister(const scoped_refptr< | 264 void StartPrivetLister(const scoped_refptr< |
267 local_discovery::ServiceDiscoverySharedClient>& client); | 265 local_discovery::ServiceDiscoverySharedClient>& client); |
268 void OnPrivetCapabilities(const base::DictionaryValue* capabilities); | 266 void OnPrivetCapabilities(const base::DictionaryValue* capabilities); |
269 void PrivetCapabilitiesUpdateClient( | 267 void PrivetCapabilitiesUpdateClient( |
270 std::unique_ptr<cloud_print::PrivetHTTPClient> http_client); | 268 std::unique_ptr<cloud_print::PrivetHTTPClient> http_client); |
271 void PrivetLocalPrintUpdateClient( | 269 void PrivetLocalPrintUpdateClient( |
272 std::string print_ticket, | 270 std::string print_ticket, |
273 std::string capabilities, | 271 std::string capabilities, |
274 gfx::Size page_size, | 272 gfx::Size page_size, |
275 std::unique_ptr<cloud_print::PrivetHTTPClient> http_client); | 273 std::unique_ptr<cloud_print::PrivetHTTPClient> http_client); |
276 bool PrivetUpdateClient( | 274 bool PrivetUpdateClient( |
277 std::unique_ptr<cloud_print::PrivetHTTPClient> http_client); | 275 std::unique_ptr<cloud_print::PrivetHTTPClient> http_client); |
278 void StartPrivetLocalPrint(const std::string& print_ticket, | 276 void StartPrivetLocalPrint(const std::string& print_ticket, |
279 const std::string& capabilities, | 277 const std::string& capabilities, |
280 const gfx::Size& page_size); | 278 const gfx::Size& page_size); |
281 void SendPrivetCapabilitiesError(const std::string& id); | 279 void SendPrivetCapabilitiesError(const std::string& id); |
282 void PrintToPrivetPrinter(const std::string& printer_name, | 280 void PrintToPrivetPrinter(const std::string& printer_name, |
283 const std::string& print_ticket, | 281 const std::string& print_ticket, |
284 const std::string& capabilities, | 282 const std::string& capabilities, |
285 const gfx::Size& page_size); | 283 const gfx::Size& page_size); |
286 bool CreatePrivetHTTP( | 284 bool CreatePrivetHTTP( |
287 const std::string& name, | 285 const std::string& name, |
288 const cloud_print::PrivetHTTPAsynchronousFactory::ResultCallback& | 286 const cloud_print::PrivetHTTPAsynchronousFactory::ResultCallback& |
289 callback); | 287 callback); |
290 void FillPrinterDescription( | 288 void FillPrinterDescription( |
291 const std::string& name, | 289 const std::string& name, |
292 const cloud_print::DeviceDescription& description, | 290 const cloud_print::DeviceDescription& description, |
293 bool has_local_printing, | 291 bool has_local_printing, |
294 base::DictionaryValue* printer_value); | 292 base::DictionaryValue* printer_value); |
295 #endif // defined(ENABLE_SERVICE_DISCOVERY) | 293 #endif |
296 | 294 |
297 // Lazily creates |extension_printer_handler_| that can be used to handle | 295 // Lazily creates |extension_printer_handler_| that can be used to handle |
298 // extension printers requests. | 296 // extension printers requests. |
299 void EnsureExtensionPrinterHandlerSet(); | 297 void EnsureExtensionPrinterHandlerSet(); |
300 | 298 |
301 // Called when a list of printers is reported by an extension. | 299 // Called when a list of printers is reported by an extension. |
302 // |printers|: The list of printers managed by the extension. | 300 // |printers|: The list of printers managed by the extension. |
303 // |done|: Whether all the extensions have reported the list of printers | 301 // |done|: Whether all the extensions have reported the list of printers |
304 // they manage. | 302 // they manage. |
305 void OnGotPrintersForExtension(const base::ListValue& printers, bool done); | 303 void OnGotPrintersForExtension(const base::ListValue& printers, bool done); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 // exists. | 349 // exists. |
352 base::FilePath print_to_pdf_path_; | 350 base::FilePath print_to_pdf_path_; |
353 | 351 |
354 // Holds token service to get OAuth2 access tokens. | 352 // Holds token service to get OAuth2 access tokens. |
355 std::unique_ptr<AccessTokenService> token_service_; | 353 std::unique_ptr<AccessTokenService> token_service_; |
356 | 354 |
357 // Pointer to cookie manager service so that print preview can listen for GAIA | 355 // Pointer to cookie manager service so that print preview can listen for GAIA |
358 // cookie changes. | 356 // cookie changes. |
359 GaiaCookieManagerService* gaia_cookie_manager_service_; | 357 GaiaCookieManagerService* gaia_cookie_manager_service_; |
360 | 358 |
361 #if defined(ENABLE_SERVICE_DISCOVERY) | 359 #if BUILDFLAG(ENABLE_SERVICE_DISCOVERY) |
362 scoped_refptr<local_discovery::ServiceDiscoverySharedClient> | 360 scoped_refptr<local_discovery::ServiceDiscoverySharedClient> |
363 service_discovery_client_; | 361 service_discovery_client_; |
364 std::unique_ptr<cloud_print::PrivetLocalPrinterLister> printer_lister_; | 362 std::unique_ptr<cloud_print::PrivetLocalPrinterLister> printer_lister_; |
365 | 363 |
366 std::unique_ptr<cloud_print::PrivetHTTPAsynchronousFactory> | 364 std::unique_ptr<cloud_print::PrivetHTTPAsynchronousFactory> |
367 privet_http_factory_; | 365 privet_http_factory_; |
368 std::unique_ptr<cloud_print::PrivetHTTPResolution> privet_http_resolution_; | 366 std::unique_ptr<cloud_print::PrivetHTTPResolution> privet_http_resolution_; |
369 std::unique_ptr<cloud_print::PrivetV1HTTPClient> privet_http_client_; | 367 std::unique_ptr<cloud_print::PrivetV1HTTPClient> privet_http_client_; |
370 std::unique_ptr<cloud_print::PrivetJSONOperation> | 368 std::unique_ptr<cloud_print::PrivetJSONOperation> |
371 privet_capabilities_operation_; | 369 privet_capabilities_operation_; |
372 std::unique_ptr<cloud_print::PrivetLocalPrintOperation> | 370 std::unique_ptr<cloud_print::PrivetLocalPrintOperation> |
373 privet_local_print_operation_; | 371 privet_local_print_operation_; |
374 #endif // defined(ENABLE_SERVICE_DISCOVERY) | 372 #endif |
375 | 373 |
376 // Handles requests for extension printers. Created lazily by calling | 374 // Handles requests for extension printers. Created lazily by calling |
377 // |EnsureExtensionPrinterHandlerSet|. | 375 // |EnsureExtensionPrinterHandlerSet|. |
378 std::unique_ptr<PrinterHandler> extension_printer_handler_; | 376 std::unique_ptr<PrinterHandler> extension_printer_handler_; |
379 | 377 |
380 // Notifies tests that want to know if the PDF has been saved. This doesn't | 378 // Notifies tests that want to know if the PDF has been saved. This doesn't |
381 // notify the test if it was a successful save, only that it was attempted. | 379 // notify the test if it was a successful save, only that it was attempted. |
382 base::Closure pdf_file_saved_closure_; | 380 base::Closure pdf_file_saved_closure_; |
383 | 381 |
384 base::WeakPtrFactory<PrintPreviewHandler> weak_factory_; | 382 base::WeakPtrFactory<PrintPreviewHandler> weak_factory_; |
385 | 383 |
386 DISALLOW_COPY_AND_ASSIGN(PrintPreviewHandler); | 384 DISALLOW_COPY_AND_ASSIGN(PrintPreviewHandler); |
387 }; | 385 }; |
388 | 386 |
389 #endif // CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_PRINT_PREVIEW_HANDLER_H_ | 387 #endif // CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_PRINT_PREVIEW_HANDLER_H_ |
OLD | NEW |