| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "extensions/browser/api/printer_provider_internal/printer_provider_inte
rnal_api.h" | 5 #include "extensions/browser/api/printer_provider_internal/printer_provider_inte
rnal_api.h" |
| 6 | 6 |
| 7 #include <memory> |
| 7 #include <string> | 8 #include <string> |
| 8 #include <utility> | 9 #include <utility> |
| 9 #include <vector> | 10 #include <vector> |
| 10 | 11 |
| 11 #include "base/bind.h" | 12 #include "base/bind.h" |
| 12 #include "base/guid.h" | 13 #include "base/guid.h" |
| 13 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
| 14 #include "base/location.h" | 15 #include "base/location.h" |
| 15 #include "base/memory/ref_counted_memory.h" | 16 #include "base/memory/ref_counted_memory.h" |
| 16 #include "base/memory/scoped_ptr.h" | |
| 17 #include "base/values.h" | 17 #include "base/values.h" |
| 18 #include "content/public/browser/blob_handle.h" | 18 #include "content/public/browser/blob_handle.h" |
| 19 #include "content/public/browser/browser_context.h" | 19 #include "content/public/browser/browser_context.h" |
| 20 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 21 #include "content/public/browser/render_frame_host.h" | 21 #include "content/public/browser/render_frame_host.h" |
| 22 #include "content/public/browser/render_process_host.h" | 22 #include "content/public/browser/render_process_host.h" |
| 23 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
| 24 #include "extensions/browser/api/printer_provider/printer_provider_api.h" | 24 #include "extensions/browser/api/printer_provider/printer_provider_api.h" |
| 25 #include "extensions/browser/api/printer_provider/printer_provider_api_factory.h
" | 25 #include "extensions/browser/api/printer_provider/printer_provider_api_factory.h
" |
| 26 #include "extensions/browser/api/printer_provider/printer_provider_print_job.h" | 26 #include "extensions/browser/api/printer_provider/printer_provider_print_job.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 PrinterProviderInternalReportPrintResultFunction:: | 99 PrinterProviderInternalReportPrintResultFunction:: |
| 100 PrinterProviderInternalReportPrintResultFunction() { | 100 PrinterProviderInternalReportPrintResultFunction() { |
| 101 } | 101 } |
| 102 | 102 |
| 103 PrinterProviderInternalReportPrintResultFunction:: | 103 PrinterProviderInternalReportPrintResultFunction:: |
| 104 ~PrinterProviderInternalReportPrintResultFunction() { | 104 ~PrinterProviderInternalReportPrintResultFunction() { |
| 105 } | 105 } |
| 106 | 106 |
| 107 ExtensionFunction::ResponseAction | 107 ExtensionFunction::ResponseAction |
| 108 PrinterProviderInternalReportPrintResultFunction::Run() { | 108 PrinterProviderInternalReportPrintResultFunction::Run() { |
| 109 scoped_ptr<internal_api::ReportPrintResult::Params> params( | 109 std::unique_ptr<internal_api::ReportPrintResult::Params> params( |
| 110 internal_api::ReportPrintResult::Params::Create(*args_)); | 110 internal_api::ReportPrintResult::Params::Create(*args_)); |
| 111 EXTENSION_FUNCTION_VALIDATE(params.get()); | 111 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 112 | 112 |
| 113 PrinterProviderInternalAPI::GetFactoryInstance() | 113 PrinterProviderInternalAPI::GetFactoryInstance() |
| 114 ->Get(browser_context()) | 114 ->Get(browser_context()) |
| 115 ->NotifyPrintResult(extension(), params->request_id, params->error); | 115 ->NotifyPrintResult(extension(), params->request_id, params->error); |
| 116 return RespondNow(NoArguments()); | 116 return RespondNow(NoArguments()); |
| 117 } | 117 } |
| 118 | 118 |
| 119 PrinterProviderInternalReportPrinterCapabilityFunction:: | 119 PrinterProviderInternalReportPrinterCapabilityFunction:: |
| 120 PrinterProviderInternalReportPrinterCapabilityFunction() { | 120 PrinterProviderInternalReportPrinterCapabilityFunction() { |
| 121 } | 121 } |
| 122 | 122 |
| 123 PrinterProviderInternalReportPrinterCapabilityFunction:: | 123 PrinterProviderInternalReportPrinterCapabilityFunction:: |
| 124 ~PrinterProviderInternalReportPrinterCapabilityFunction() { | 124 ~PrinterProviderInternalReportPrinterCapabilityFunction() { |
| 125 } | 125 } |
| 126 | 126 |
| 127 ExtensionFunction::ResponseAction | 127 ExtensionFunction::ResponseAction |
| 128 PrinterProviderInternalReportPrinterCapabilityFunction::Run() { | 128 PrinterProviderInternalReportPrinterCapabilityFunction::Run() { |
| 129 scoped_ptr<internal_api::ReportPrinterCapability::Params> params( | 129 std::unique_ptr<internal_api::ReportPrinterCapability::Params> params( |
| 130 internal_api::ReportPrinterCapability::Params::Create(*args_)); | 130 internal_api::ReportPrinterCapability::Params::Create(*args_)); |
| 131 EXTENSION_FUNCTION_VALIDATE(params.get()); | 131 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 132 | 132 |
| 133 if (params->capability) { | 133 if (params->capability) { |
| 134 PrinterProviderInternalAPI::GetFactoryInstance() | 134 PrinterProviderInternalAPI::GetFactoryInstance() |
| 135 ->Get(browser_context()) | 135 ->Get(browser_context()) |
| 136 ->NotifyGetCapabilityResult(extension(), params->request_id, | 136 ->NotifyGetCapabilityResult(extension(), params->request_id, |
| 137 params->capability->additional_properties); | 137 params->capability->additional_properties); |
| 138 } else { | 138 } else { |
| 139 PrinterProviderInternalAPI::GetFactoryInstance() | 139 PrinterProviderInternalAPI::GetFactoryInstance() |
| 140 ->Get(browser_context()) | 140 ->Get(browser_context()) |
| 141 ->NotifyGetCapabilityResult(extension(), params->request_id, | 141 ->NotifyGetCapabilityResult(extension(), params->request_id, |
| 142 base::DictionaryValue()); | 142 base::DictionaryValue()); |
| 143 } | 143 } |
| 144 return RespondNow(NoArguments()); | 144 return RespondNow(NoArguments()); |
| 145 } | 145 } |
| 146 | 146 |
| 147 PrinterProviderInternalReportPrintersFunction:: | 147 PrinterProviderInternalReportPrintersFunction:: |
| 148 PrinterProviderInternalReportPrintersFunction() { | 148 PrinterProviderInternalReportPrintersFunction() { |
| 149 } | 149 } |
| 150 | 150 |
| 151 PrinterProviderInternalReportPrintersFunction:: | 151 PrinterProviderInternalReportPrintersFunction:: |
| 152 ~PrinterProviderInternalReportPrintersFunction() { | 152 ~PrinterProviderInternalReportPrintersFunction() { |
| 153 } | 153 } |
| 154 | 154 |
| 155 ExtensionFunction::ResponseAction | 155 ExtensionFunction::ResponseAction |
| 156 PrinterProviderInternalReportPrintersFunction::Run() { | 156 PrinterProviderInternalReportPrintersFunction::Run() { |
| 157 scoped_ptr<internal_api::ReportPrinters::Params> params( | 157 std::unique_ptr<internal_api::ReportPrinters::Params> params( |
| 158 internal_api::ReportPrinters::Params::Create(*args_)); | 158 internal_api::ReportPrinters::Params::Create(*args_)); |
| 159 EXTENSION_FUNCTION_VALIDATE(params.get()); | 159 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 160 | 160 |
| 161 base::ListValue printers; | 161 base::ListValue printers; |
| 162 if (params->printers) { | 162 if (params->printers) { |
| 163 PrinterProviderInternalAPI::GetFactoryInstance() | 163 PrinterProviderInternalAPI::GetFactoryInstance() |
| 164 ->Get(browser_context()) | 164 ->Get(browser_context()) |
| 165 ->NotifyGetPrintersResult(extension(), params->request_id, | 165 ->NotifyGetPrintersResult(extension(), params->request_id, |
| 166 *params->printers); | 166 *params->printers); |
| 167 } else { | 167 } else { |
| 168 PrinterProviderInternalAPI::GetFactoryInstance() | 168 PrinterProviderInternalAPI::GetFactoryInstance() |
| 169 ->Get(browser_context()) | 169 ->Get(browser_context()) |
| 170 ->NotifyGetPrintersResult( | 170 ->NotifyGetPrintersResult( |
| 171 extension(), params->request_id, | 171 extension(), params->request_id, |
| 172 PrinterProviderInternalAPIObserver::PrinterInfoVector()); | 172 PrinterProviderInternalAPIObserver::PrinterInfoVector()); |
| 173 } | 173 } |
| 174 return RespondNow(NoArguments()); | 174 return RespondNow(NoArguments()); |
| 175 } | 175 } |
| 176 | 176 |
| 177 PrinterProviderInternalGetPrintDataFunction:: | 177 PrinterProviderInternalGetPrintDataFunction:: |
| 178 PrinterProviderInternalGetPrintDataFunction() { | 178 PrinterProviderInternalGetPrintDataFunction() { |
| 179 } | 179 } |
| 180 | 180 |
| 181 PrinterProviderInternalGetPrintDataFunction:: | 181 PrinterProviderInternalGetPrintDataFunction:: |
| 182 ~PrinterProviderInternalGetPrintDataFunction() { | 182 ~PrinterProviderInternalGetPrintDataFunction() { |
| 183 } | 183 } |
| 184 | 184 |
| 185 ExtensionFunction::ResponseAction | 185 ExtensionFunction::ResponseAction |
| 186 PrinterProviderInternalGetPrintDataFunction::Run() { | 186 PrinterProviderInternalGetPrintDataFunction::Run() { |
| 187 scoped_ptr<internal_api::GetPrintData::Params> params( | 187 std::unique_ptr<internal_api::GetPrintData::Params> params( |
| 188 internal_api::GetPrintData::Params::Create(*args_)); | 188 internal_api::GetPrintData::Params::Create(*args_)); |
| 189 EXTENSION_FUNCTION_VALIDATE(params.get()); | 189 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 190 | 190 |
| 191 const PrinterProviderPrintJob* job = | 191 const PrinterProviderPrintJob* job = |
| 192 PrinterProviderAPIFactory::GetInstance() | 192 PrinterProviderAPIFactory::GetInstance() |
| 193 ->GetForBrowserContext(browser_context()) | 193 ->GetForBrowserContext(browser_context()) |
| 194 ->GetPrintJob(extension(), params->request_id); | 194 ->GetPrintJob(extension(), params->request_id); |
| 195 if (!job) | 195 if (!job) |
| 196 return RespondNow(Error("Print request not found.")); | 196 return RespondNow(Error("Print request not found.")); |
| 197 | 197 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 214 } else { | 214 } else { |
| 215 return RespondNow(Error("Job data not set")); | 215 return RespondNow(Error("Job data not set")); |
| 216 } | 216 } |
| 217 return RespondLater(); | 217 return RespondLater(); |
| 218 } | 218 } |
| 219 | 219 |
| 220 void PrinterProviderInternalGetPrintDataFunction::OnBlob( | 220 void PrinterProviderInternalGetPrintDataFunction::OnBlob( |
| 221 const std::string& type, | 221 const std::string& type, |
| 222 int size, | 222 int size, |
| 223 const scoped_refptr<base::RefCountedMemory>& data, | 223 const scoped_refptr<base::RefCountedMemory>& data, |
| 224 scoped_ptr<content::BlobHandle> blob) { | 224 std::unique_ptr<content::BlobHandle> blob) { |
| 225 if (!blob) { | 225 if (!blob) { |
| 226 SetError("Unable to create the blob."); | 226 SetError("Unable to create the blob."); |
| 227 SendResponse(false); | 227 SendResponse(false); |
| 228 return; | 228 return; |
| 229 } | 229 } |
| 230 | 230 |
| 231 internal_api::BlobInfo info; | 231 internal_api::BlobInfo info; |
| 232 info.blob_uuid = blob->GetUUID(); | 232 info.blob_uuid = blob->GetUUID(); |
| 233 info.type = type; | 233 info.type = type; |
| 234 info.size = size; | 234 info.size = size; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 249 PrinterProviderInternalReportUsbPrinterInfoFunction:: | 249 PrinterProviderInternalReportUsbPrinterInfoFunction:: |
| 250 PrinterProviderInternalReportUsbPrinterInfoFunction() { | 250 PrinterProviderInternalReportUsbPrinterInfoFunction() { |
| 251 } | 251 } |
| 252 | 252 |
| 253 PrinterProviderInternalReportUsbPrinterInfoFunction:: | 253 PrinterProviderInternalReportUsbPrinterInfoFunction:: |
| 254 ~PrinterProviderInternalReportUsbPrinterInfoFunction() { | 254 ~PrinterProviderInternalReportUsbPrinterInfoFunction() { |
| 255 } | 255 } |
| 256 | 256 |
| 257 ExtensionFunction::ResponseAction | 257 ExtensionFunction::ResponseAction |
| 258 PrinterProviderInternalReportUsbPrinterInfoFunction::Run() { | 258 PrinterProviderInternalReportUsbPrinterInfoFunction::Run() { |
| 259 scoped_ptr<internal_api::ReportUsbPrinterInfo::Params> params( | 259 std::unique_ptr<internal_api::ReportUsbPrinterInfo::Params> params( |
| 260 internal_api::ReportUsbPrinterInfo::Params::Create(*args_)); | 260 internal_api::ReportUsbPrinterInfo::Params::Create(*args_)); |
| 261 EXTENSION_FUNCTION_VALIDATE(params.get()); | 261 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 262 | 262 |
| 263 PrinterProviderInternalAPI::GetFactoryInstance() | 263 PrinterProviderInternalAPI::GetFactoryInstance() |
| 264 ->Get(browser_context()) | 264 ->Get(browser_context()) |
| 265 ->NotifyGetUsbPrinterInfoResult(extension(), params->request_id, | 265 ->NotifyGetUsbPrinterInfoResult(extension(), params->request_id, |
| 266 params->printer_info.get()); | 266 params->printer_info.get()); |
| 267 return RespondNow(NoArguments()); | 267 return RespondNow(NoArguments()); |
| 268 } | 268 } |
| 269 | 269 |
| 270 } // namespace extensions | 270 } // namespace extensions |
| OLD | NEW |