OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "headless/lib/browser/headless_devtools_manager_delegate.h" | 5 #include "headless/lib/browser/headless_devtools_manager_delegate.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 | 21 |
22 namespace headless { | 22 namespace headless { |
23 | 23 |
24 namespace { | 24 namespace { |
25 const char kIdParam[] = "id"; | 25 const char kIdParam[] = "id"; |
26 const char kResultParam[] = "result"; | 26 const char kResultParam[] = "result"; |
27 const char kErrorParam[] = "error"; | 27 const char kErrorParam[] = "error"; |
28 const char kErrorCodeParam[] = "code"; | 28 const char kErrorCodeParam[] = "code"; |
29 const char kErrorMessageParam[] = "message"; | 29 const char kErrorMessageParam[] = "message"; |
30 | 30 |
31 // The max and min value should match the ones in scaling_settings.html. | |
32 // Update both files at the same time. | |
33 const double kScaleMaxVal = 200; | |
34 const double kScaleMinVal = 10; | |
35 | |
36 // JSON RPC 2.0 spec: http://www.jsonrpc.org/specification#error_object | 31 // JSON RPC 2.0 spec: http://www.jsonrpc.org/specification#error_object |
37 enum Error { | 32 enum Error { |
38 kErrorInvalidParam = -32602, | 33 kErrorInvalidParam = -32602, |
39 kErrorServerError = -32000 | 34 kErrorServerError = -32000 |
40 }; | 35 }; |
41 | 36 |
42 std::unique_ptr<base::DictionaryValue> CreateSuccessResponse( | 37 std::unique_ptr<base::DictionaryValue> CreateSuccessResponse( |
43 int command_id, | 38 int command_id, |
44 std::unique_ptr<base::Value> result) { | 39 std::unique_ptr<base::Value> result) { |
45 if (!result) | 40 if (!result) |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 command_id, kErrorServerError, | 84 command_id, kErrorServerError, |
90 printing::HeadlessPrintManager::PrintResultToString(print_result)); | 85 printing::HeadlessPrintManager::PrintResultToString(print_result)); |
91 } | 86 } |
92 callback.Run(std::move(response)); | 87 callback.Run(std::move(response)); |
93 } | 88 } |
94 #endif | 89 #endif |
95 | 90 |
96 } // namespace | 91 } // namespace |
97 | 92 |
98 #if BUILDFLAG(ENABLE_BASIC_PRINTING) | 93 #if BUILDFLAG(ENABLE_BASIC_PRINTING) |
| 94 namespace { |
| 95 // The max and min value should match the ones in scaling_settings.html. |
| 96 // Update both files at the same time. |
| 97 const double kScaleMaxVal = 200; |
| 98 const double kScaleMinVal = 10; |
| 99 } |
| 100 |
99 std::unique_ptr<base::DictionaryValue> ParsePrintSettings( | 101 std::unique_ptr<base::DictionaryValue> ParsePrintSettings( |
100 int command_id, | 102 int command_id, |
101 const base::DictionaryValue* params, | 103 const base::DictionaryValue* params, |
102 printing::HeadlessPrintSettings* settings) { | 104 printing::HeadlessPrintSettings* settings) { |
103 // We can safely ignore the return values of the following Get methods since | 105 // We can safely ignore the return values of the following Get methods since |
104 // the defaults are already set in |settings|. | 106 // the defaults are already set in |settings|. |
105 params->GetBoolean("landscape", &settings->landscape); | 107 params->GetBoolean("landscape", &settings->landscape); |
106 params->GetBoolean("displayHeaderFooter", &settings->display_header_footer); | 108 params->GetBoolean("displayHeaderFooter", &settings->display_header_footer); |
107 params->GetBoolean("printBackground", &settings->should_print_backgrounds); | 109 params->GetBoolean("printBackground", &settings->should_print_backgrounds); |
108 params->GetDouble("scale", &settings->scale); | 110 params->GetDouble("scale", &settings->scale); |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 | 372 |
371 std::unique_ptr<base::Value> result( | 373 std::unique_ptr<base::Value> result( |
372 target::DisposeBrowserContextResult::Builder() | 374 target::DisposeBrowserContextResult::Builder() |
373 .SetSuccess(success) | 375 .SetSuccess(success) |
374 .Build() | 376 .Build() |
375 ->Serialize()); | 377 ->Serialize()); |
376 return CreateSuccessResponse(command_id, std::move(result)); | 378 return CreateSuccessResponse(command_id, std::move(result)); |
377 } | 379 } |
378 | 380 |
379 } // namespace headless | 381 } // namespace headless |
OLD | NEW |