OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/printing/print_dialog_cloud.h" | 5 #include "chrome/browser/printing/print_dialog_cloud.h" |
6 #include "chrome/browser/printing/print_dialog_cloud_internal.h" | 6 #include "chrome/browser/printing/print_dialog_cloud_internal.h" |
7 | 7 |
8 #include "base/base64.h" | 8 #include "base/base64.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 // that the dialog should be closed, at which point things are torn | 92 // that the dialog should be closed, at which point things are torn |
93 // down and released. | 93 // down and released. |
94 | 94 |
95 // TODO(scottbyer): | 95 // TODO(scottbyer): |
96 // http://code.google.com/p/chromium/issues/detail?id=44093 The | 96 // http://code.google.com/p/chromium/issues/detail?id=44093 The |
97 // high-level flow (where the data is generated before even | 97 // high-level flow (where the data is generated before even |
98 // bringing up the dialog) isn't what we want. | 98 // bringing up the dialog) isn't what we want. |
99 | 99 |
100 namespace internal_cloud_print_helpers { | 100 namespace internal_cloud_print_helpers { |
101 | 101 |
102 bool GetDoubleOrInt(const DictionaryValue& dictionary, | |
103 const std::string& path, | |
104 double* out_value) { | |
105 if (!dictionary.GetDouble(path, out_value)) { | |
106 int int_value = 0; | |
107 if (!dictionary.GetInteger(path, &int_value)) | |
108 return false; | |
109 *out_value = int_value; | |
110 } | |
111 return true; | |
112 } | |
113 | |
114 // From the JSON parsed value, get the entries for the page setup | 102 // From the JSON parsed value, get the entries for the page setup |
115 // parameters. | 103 // parameters. |
116 bool GetPageSetupParameters(const std::string& json, | 104 bool GetPageSetupParameters(const std::string& json, |
117 PrintMsg_Print_Params& parameters) { | 105 PrintMsg_Print_Params& parameters) { |
118 scoped_ptr<Value> parsed_value(base::JSONReader::Read(json, false)); | 106 scoped_ptr<Value> parsed_value(base::JSONReader::Read(json, false)); |
119 DLOG_IF(ERROR, (!parsed_value.get() || | 107 DLOG_IF(ERROR, (!parsed_value.get() || |
120 !parsed_value->IsType(Value::TYPE_DICTIONARY))) | 108 !parsed_value->IsType(Value::TYPE_DICTIONARY))) |
121 << "PageSetup call didn't have expected contents"; | 109 << "PageSetup call didn't have expected contents"; |
122 if (!parsed_value.get() || !parsed_value->IsType(Value::TYPE_DICTIONARY)) | 110 if (!parsed_value.get() || !parsed_value->IsType(Value::TYPE_DICTIONARY)) |
123 return false; | 111 return false; |
124 | 112 |
125 bool result = true; | 113 bool result = true; |
126 DictionaryValue* params = static_cast<DictionaryValue*>(parsed_value.get()); | 114 DictionaryValue* params = static_cast<DictionaryValue*>(parsed_value.get()); |
127 result &= GetDoubleOrInt(*params, "dpi", ¶meters.dpi); | 115 result &= params->GetDouble("dpi", ¶meters.dpi); |
128 result &= GetDoubleOrInt(*params, "min_shrink", ¶meters.min_shrink); | 116 result &= params->GetDouble("min_shrink", ¶meters.min_shrink); |
129 result &= GetDoubleOrInt(*params, "max_shrink", ¶meters.max_shrink); | 117 result &= params->GetDouble("max_shrink", ¶meters.max_shrink); |
130 result &= params->GetBoolean("selection_only", ¶meters.selection_only); | 118 result &= params->GetBoolean("selection_only", ¶meters.selection_only); |
131 return result; | 119 return result; |
132 } | 120 } |
133 | 121 |
134 void CloudPrintDataSenderHelper::CallJavascriptFunction( | 122 void CloudPrintDataSenderHelper::CallJavascriptFunction( |
135 const std::wstring& function_name) { | 123 const std::wstring& function_name) { |
136 web_ui_->CallJavascriptFunction(WideToASCII(function_name)); | 124 web_ui_->CallJavascriptFunction(WideToASCII(function_name)); |
137 } | 125 } |
138 | 126 |
139 void CloudPrintDataSenderHelper::CallJavascriptFunction( | 127 void CloudPrintDataSenderHelper::CallJavascriptFunction( |
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 print_job_title, | 613 print_job_title, |
626 file_type, | 614 file_type, |
627 false); | 615 false); |
628 return true; | 616 return true; |
629 } | 617 } |
630 } | 618 } |
631 return false; | 619 return false; |
632 } | 620 } |
633 | 621 |
634 } // end namespace | 622 } // end namespace |
OLD | NEW |