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 #include "chrome/browser/printing/print_dialog_cloud.h" | 5 #include "chrome/browser/printing/print_dialog_cloud.h" |
6 | 6 |
7 | 7 |
8 #include "base/base64.h" | 8 #include "base/base64.h" |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
30 #include "content/public/browser/navigation_controller.h" | 30 #include "content/public/browser/navigation_controller.h" |
31 #include "content/public/browser/navigation_entry.h" | 31 #include "content/public/browser/navigation_entry.h" |
32 #include "content/public/browser/notification_registrar.h" | 32 #include "content/public/browser/notification_registrar.h" |
33 #include "content/public/browser/notification_source.h" | 33 #include "content/public/browser/notification_source.h" |
34 #include "content/public/browser/notification_types.h" | 34 #include "content/public/browser/notification_types.h" |
35 #include "content/public/browser/render_view_host.h" | 35 #include "content/public/browser/render_view_host.h" |
36 #include "content/public/browser/web_contents.h" | 36 #include "content/public/browser/web_contents.h" |
37 #include "content/public/browser/web_contents_view.h" | 37 #include "content/public/browser/web_contents_view.h" |
38 #include "content/public/browser/web_ui.h" | 38 #include "content/public/browser/web_ui.h" |
39 #include "grit/generated_resources.h" | |
40 #include "ui/base/l10n/l10n_util.h" | |
41 #include "webkit/common/webpreferences.h" | 39 #include "webkit/common/webpreferences.h" |
42 | 40 |
43 #if defined(USE_AURA) | 41 #if defined(USE_AURA) |
44 #include "ui/aura/root_window.h" | 42 #include "ui/aura/root_window.h" |
45 #include "ui/aura/window.h" | 43 #include "ui/aura/window.h" |
46 #endif | 44 #endif |
47 | 45 |
48 #if defined(OS_WIN) | 46 #if defined(OS_WIN) |
49 #include "ui/base/win/foreground_helper.h" | 47 #include "ui/base/win/foreground_helper.h" |
50 #endif | 48 #endif |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 | 131 |
134 bool result = true; | 132 bool result = true; |
135 DictionaryValue* params = static_cast<DictionaryValue*>(parsed_value.get()); | 133 DictionaryValue* params = static_cast<DictionaryValue*>(parsed_value.get()); |
136 result &= params->GetDouble("dpi", ¶meters.dpi); | 134 result &= params->GetDouble("dpi", ¶meters.dpi); |
137 result &= params->GetDouble("min_shrink", ¶meters.min_shrink); | 135 result &= params->GetDouble("min_shrink", ¶meters.min_shrink); |
138 result &= params->GetDouble("max_shrink", ¶meters.max_shrink); | 136 result &= params->GetDouble("max_shrink", ¶meters.max_shrink); |
139 result &= params->GetBoolean("selection_only", ¶meters.selection_only); | 137 result &= params->GetBoolean("selection_only", ¶meters.selection_only); |
140 return result; | 138 return result; |
141 } | 139 } |
142 | 140 |
143 string16 GetSwitchValueString16(const CommandLine& command_line, | 141 base::string16 GetSwitchValueString16(const CommandLine& command_line, |
144 const char* switchName) { | 142 const char* switchName) { |
145 #if defined(OS_WIN) | 143 #if defined(OS_WIN) |
146 CommandLine::StringType native_switch_val; | 144 return command_line.GetSwitchValueNative(switchName); |
147 native_switch_val = command_line.GetSwitchValueNative(switchName); | |
148 return string16(native_switch_val); | |
149 #elif defined(OS_POSIX) | 145 #elif defined(OS_POSIX) |
150 // POSIX Command line string types are different. | 146 // POSIX Command line string types are different. |
151 CommandLine::StringType native_switch_val; | 147 CommandLine::StringType native_switch_val; |
152 native_switch_val = command_line.GetSwitchValueASCII(switchName); | 148 native_switch_val = command_line.GetSwitchValueASCII(switchName); |
153 // Convert the ASCII string to UTF16 to prepare to pass. | 149 // Convert the ASCII string to UTF16 to prepare to pass. |
154 return string16(ASCIIToUTF16(native_switch_val)); | 150 return base::ASCIIToUTF16(native_switch_val); |
155 #endif | 151 #endif |
156 } | 152 } |
157 | 153 |
158 void CloudPrintDataSenderHelper::CallJavascriptFunction( | 154 void CloudPrintDataSenderHelper::CallJavascriptFunction( |
159 const std::wstring& function_name) { | 155 const std::string& function_name, const Value& arg1, const Value& arg2) { |
160 web_ui_->CallJavascriptFunction(WideToASCII(function_name)); | 156 web_ui_->CallJavascriptFunction(function_name, arg1, arg2); |
161 } | |
162 | |
163 void CloudPrintDataSenderHelper::CallJavascriptFunction( | |
164 const std::wstring& function_name, const Value& arg) { | |
165 web_ui_->CallJavascriptFunction(WideToASCII(function_name), arg); | |
166 } | |
167 | |
168 void CloudPrintDataSenderHelper::CallJavascriptFunction( | |
169 const std::wstring& function_name, const Value& arg1, const Value& arg2) { | |
170 web_ui_->CallJavascriptFunction(WideToASCII(function_name), arg1, arg2); | |
171 } | |
172 | |
173 void CloudPrintDataSenderHelper::CallJavascriptFunction( | |
174 const std::wstring& function_name, | |
175 const Value& arg1, | |
176 const Value& arg2, | |
177 const Value& arg3) { | |
178 web_ui_->CallJavascriptFunction( | |
179 WideToASCII(function_name), arg1, arg2, arg3); | |
180 } | 157 } |
181 | 158 |
182 // Clears out the pointer we're using to communicate. Either routine is | 159 // Clears out the pointer we're using to communicate. Either routine is |
183 // potentially expensive enough that stopping whatever is in progress | 160 // potentially expensive enough that stopping whatever is in progress |
184 // is worth it. | 161 // is worth it. |
185 void CloudPrintDataSender::CancelPrintDataFile() { | 162 void CloudPrintDataSender::CancelPrintDataFile() { |
186 base::AutoLock lock(lock_); | 163 base::AutoLock lock(lock_); |
187 // We don't own helper, it was passed in to us, so no need to | 164 // We don't own helper, it was passed in to us, so no need to |
188 // delete, just let it go. | 165 // delete, just let it go. |
189 helper_ = NULL; | 166 helper_ = NULL; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 base::StringPiece(reinterpret_cast<const char*>(data_->front()), | 198 base::StringPiece(reinterpret_cast<const char*>(data_->front()), |
222 data_->size()), | 199 data_->size()), |
223 &base64_data); | 200 &base64_data); |
224 std::string header("data:"); | 201 std::string header("data:"); |
225 header.append(file_type_); | 202 header.append(file_type_); |
226 header.append(";base64,"); | 203 header.append(";base64,"); |
227 base64_data.insert(0, header); | 204 base64_data.insert(0, header); |
228 | 205 |
229 base::AutoLock lock(lock_); | 206 base::AutoLock lock(lock_); |
230 if (helper_) { | 207 if (helper_) { |
231 StringValue title(print_job_title_); | 208 base::StringValue title(print_job_title_); |
232 StringValue ticket(print_ticket_); | 209 base::StringValue ticket(print_ticket_); |
233 // TODO(abodenha): Change Javascript call to pass in print ticket | 210 // TODO(abodenha): Change Javascript call to pass in print ticket |
234 // after server side support is added. Add test for it. | 211 // after server side support is added. Add test for it. |
235 | 212 |
236 // Send the print data to the dialog contents. The JavaScript | 213 // Send the print data to the dialog contents. The JavaScript |
237 // function is a preliminary API for prototyping purposes and is | 214 // function is a preliminary API for prototyping purposes and is |
238 // subject to change. | 215 // subject to change. |
239 const_cast<CloudPrintDataSenderHelper*>(helper_)->CallJavascriptFunction( | 216 helper_->CallJavascriptFunction( |
240 L"printApp._printDataUrl", StringValue(base64_data), title); | 217 "printApp._printDataUrl", base::StringValue(base64_data), title); |
241 } | 218 } |
242 } | 219 } |
243 | 220 |
244 | 221 |
245 CloudPrintFlowHandler::CloudPrintFlowHandler(const base::RefCountedMemory* data, | 222 CloudPrintFlowHandler::CloudPrintFlowHandler(const base::RefCountedMemory* data, |
246 const string16& print_job_title, | 223 const string16& print_job_title, |
247 const string16& print_ticket, | 224 const string16& print_ticket, |
248 const std::string& file_type, | 225 const std::string& file_type, |
249 bool close_after_signin, | 226 bool close_after_signin, |
250 const base::Closure& callback) | 227 const base::Closure& callback) |
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
781 print_job_print_ticket, | 758 print_job_print_ticket, |
782 file_type, | 759 file_type, |
783 delete_on_close); | 760 delete_on_close); |
784 return true; | 761 return true; |
785 } | 762 } |
786 } | 763 } |
787 return false; | 764 return false; |
788 } | 765 } |
789 | 766 |
790 } // namespace print_dialog_cloud | 767 } // namespace print_dialog_cloud |
OLD | NEW |