Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: chrome/browser/ui/webui/print_preview/extension_printer_handler.cc

Issue 1148383002: Add onGetUsbPrinterInfoRequested event to printerProvider API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Only include the permission granting part in this patch. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "chrome/browser/ui/webui/print_preview/extension_printer_handler.h" 5 #include "chrome/browser/ui/webui/print_preview/extension_printer_handler.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 return; 184 return;
185 } 185 }
186 186
187 print_job->content_type = kContentTypePWGRaster; 187 print_job->content_type = kContentTypePWGRaster;
188 ConvertToPWGRaster(print_data, printer_description, ticket, page_size, 188 ConvertToPWGRaster(print_data, printer_description, ticket, page_size,
189 print_job.Pass(), 189 print_job.Pass(),
190 base::Bind(&ExtensionPrinterHandler::DispatchPrintJob, 190 base::Bind(&ExtensionPrinterHandler::DispatchPrintJob,
191 weak_ptr_factory_.GetWeakPtr(), callback)); 191 weak_ptr_factory_.GetWeakPtr(), callback));
192 } 192 }
193 193
194 void ExtensionPrinterHandler::StartGrantUsbPrinterAccess(
195 const std::string& extension_id,
196 int device_id,
197 const GrantUsbPrinterAccessCallback& callback) {
198 extensions::PrinterProviderAPIFactory::GetInstance()
199 ->GetForBrowserContext(browser_context_)
200 ->DispatchGrantUsbPrinterAccess(
201 extension_id, device_id,
202 base::Bind(
203 &ExtensionPrinterHandler::WrapGrantUsbPrinterAccessCallback,
204 weak_ptr_factory_.GetWeakPtr(), callback));
205 }
206
194 void ExtensionPrinterHandler::SetPwgRasterConverterForTesting( 207 void ExtensionPrinterHandler::SetPwgRasterConverterForTesting(
195 scoped_ptr<local_discovery::PWGRasterConverter> pwg_raster_converter) { 208 scoped_ptr<local_discovery::PWGRasterConverter> pwg_raster_converter) {
196 pwg_raster_converter_ = pwg_raster_converter.Pass(); 209 pwg_raster_converter_ = pwg_raster_converter.Pass();
197 } 210 }
198 211
199 void ExtensionPrinterHandler::ConvertToPWGRaster( 212 void ExtensionPrinterHandler::ConvertToPWGRaster(
200 const scoped_refptr<base::RefCountedMemory>& data, 213 const scoped_refptr<base::RefCountedMemory>& data,
201 const cloud_devices::CloudDeviceDescription& printer_description, 214 const cloud_devices::CloudDeviceDescription& printer_description,
202 const cloud_devices::CloudDeviceDescription& ticket, 215 const cloud_devices::CloudDeviceDescription& ticket,
203 const gfx::Size& page_size, 216 const gfx::Size& page_size,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 callback.Run(destination_id, capability); 256 callback.Run(destination_id, capability);
244 } 257 }
245 258
246 void ExtensionPrinterHandler::WrapPrintCallback( 259 void ExtensionPrinterHandler::WrapPrintCallback(
247 const PrinterHandler::PrintCallback& callback, 260 const PrinterHandler::PrintCallback& callback,
248 bool success, 261 bool success,
249 const std::string& status) { 262 const std::string& status) {
250 callback.Run(success, status); 263 callback.Run(success, status);
251 } 264 }
252 265
266 void ExtensionPrinterHandler::WrapGrantUsbPrinterAccessCallback(
267 const GrantUsbPrinterAccessCallback& callback,
268 const base::DictionaryValue& printer_info) {
269 callback.Run(printer_info);
270 }
271
253 void ExtensionPrinterHandler::OnUsbDevicesEnumerated( 272 void ExtensionPrinterHandler::OnUsbDevicesEnumerated(
254 const GetUsbPrintersCallback& callback, 273 const GetUsbPrintersCallback& callback,
255 const std::vector<scoped_refptr<UsbDevice>>& devices) { 274 const std::vector<scoped_refptr<UsbDevice>>& devices) {
256 std::map<scoped_refptr<UsbDevice>, 275 std::map<scoped_refptr<UsbDevice>,
257 std::vector<scoped_refptr<const Extension>>> result_map; 276 std::vector<scoped_refptr<const Extension>>> result_map;
258 277
259 ExtensionRegistry* registry = ExtensionRegistry::Get(browser_context_); 278 ExtensionRegistry* registry = ExtensionRegistry::Get(browser_context_);
260 DevicePermissionsManager* permissions_manager = 279 DevicePermissionsManager* permissions_manager =
261 DevicePermissionsManager::Get(browser_context_); 280 DevicePermissionsManager::Get(browser_context_);
262 281
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 .Set("name", DevicePermissionsManager::GetPermissionMessage( 326 .Set("name", DevicePermissionsManager::GetPermissionMessage(
308 device->vendor_id(), device->product_id(), 327 device->vendor_id(), device->product_id(),
309 device->manufacturer_string(), 328 device->manufacturer_string(),
310 device->product_string(), base::string16(), false)) 329 device->product_string(), base::string16(), false))
311 .Set("usbDevice", static_cast<int>(device->unique_id())) 330 .Set("usbDevice", static_cast<int>(device->unique_id()))
312 .Set("extensions", extension_list.Pass())); 331 .Set("extensions", extension_list.Pass()));
313 } 332 }
314 333
315 callback.Run(*printer_list.Build().get()); 334 callback.Run(*printer_list.Build().get());
316 } 335 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698