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

Unified Diff: extensions/browser/api/printer_provider/printer_provider_api.cc

Issue 1144983002: Introduce concept of provisional destinations to print preview (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: extensions/browser/api/printer_provider/printer_provider_api.cc
diff --git a/extensions/browser/api/printer_provider/printer_provider_api.cc b/extensions/browser/api/printer_provider/printer_provider_api.cc
index 4d298e5f80b8fea6cde90dded690fc40fa998a13..02229960e0966bb5c0f4e0f22d9fc1cfd776ac33 100644
--- a/extensions/browser/api/printer_provider/printer_provider_api.cc
+++ b/extensions/browser/api/printer_provider/printer_provider_api.cc
@@ -16,6 +16,7 @@
#include "base/memory/ref_counted_memory.h"
#include "base/scoped_observer.h"
#include "base/strings/string16.h"
+#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "device/core/device_client.h"
@@ -59,6 +60,15 @@ std::string GeneratePrinterId(const std::string& extension_id,
return result;
}
+std::string GenerateUsbExtensionPrinterId(const std::string& extension_id,
+ int usb_device_id) {
+ std::string result("usb-");
+ result.append(
+ GeneratePrinterId(extension_id,
+ base::IntToString(usb_device_id)));
+ return result;
+}
+
// Parses an ID created using |GeneratePrinterId| to it's components:
// the extension ID and the printer ID internal to the extension.
// Returns whenter the ID was succesfully parsed.
@@ -222,7 +232,7 @@ class PendingUsbPrinterInfoRequests {
// Completes the request with the provided request id. It runs the request
// callback and removes the request from the set.
void Complete(int request_id,
- const core_api::printer_provider::PrinterInfo* printer_info);
+ const base::DictionaryValue* printer_info);
// Runs all pending callbacks with empty capability value and clears the
// set of pending requests.
@@ -505,7 +515,7 @@ int PendingUsbPrinterInfoRequests::Add(
void PendingUsbPrinterInfoRequests::Complete(
int request_id,
- const core_api::printer_provider::PrinterInfo* printer_info) {
+ const base::DictionaryValue* printer_info) {
auto it = pending_requests_.find(request_id);
if (it == pending_requests_.end()) {
return;
@@ -515,7 +525,7 @@ void PendingUsbPrinterInfoRequests::Complete(
pending_requests_.erase(it);
if (printer_info) {
- callback.Run(*printer_info->ToValue().get());
+ callback.Run(*printer_info);
} else {
callback.Run(base::DictionaryValue());
}
@@ -787,8 +797,34 @@ void PrinterProviderAPIImpl::OnUsbAccessGrantedResult(
const Extension* extension,
int request_id,
const core_api::printer_provider::PrinterInfo* printer_info) {
+ if (!printer_info) {
+ pending_usb_printer_info_requests_[extension->id()].Complete(
+ request_id, NULL);
+ return;
+ }
+
+ scoped_ptr<base::DictionaryValue> printer(printer_info->ToValue());
+ std::string internal_printer_id;
+ CHECK(printer->GetString("id", &internal_printer_id));
+ printer->SetString("id",
+ GeneratePrinterId(extension->id(), internal_printer_id));
+ printer->SetString("extensionId", extension->id());
+ printer->SetString("extensionName", extension->name());
+
+ base::string16 printer_name;
+ if (printer->GetString("name", &printer_name) &&
+ base::i18n::AdjustStringForLocaleDirection(&printer_name)) {
+ printer->SetString("name", printer_name);
+ }
+
+ base::string16 printer_description;
+ if (printer->GetString("description", &printer_description) &&
+ base::i18n::AdjustStringForLocaleDirection(&printer_description)) {
+ printer->SetString("description", printer_description);
+ }
+
pending_usb_printer_info_requests_[extension->id()].Complete(request_id,
- printer_info);
+ printer.get());
}
void PrinterProviderAPIImpl::OnExtensionUnloaded(
@@ -861,14 +897,20 @@ void PrinterProviderAPIImpl::OnUsbDevicesEnumerated(
ListBuilder printer_list;
for (const auto& map_entry : result_map) {
+ const scoped_refptr<UsbDevice>& device = map_entry.first;
+
ListBuilder extension_list;
for (const scoped_refptr<const Extension>& extension : map_entry.second) {
- extension_list.Append(DictionaryBuilder()
- .Set("extensionId", extension->id())
- .Set("extensionName", extension->name()));
+ extension_list.Append(
+ DictionaryBuilder()
+ .Set("extensionId", extension->id())
+ .Set("extensionName", extension->name())
+ .Set("printerId",
+ GenerateUsbExtensionPrinterId(
+ extension->id(),
+ static_cast<int>(device->unique_id()))));
}
- const scoped_refptr<UsbDevice>& device = map_entry.first;
printer_list.Append(
DictionaryBuilder()
.Set("name", DevicePermissionsManager::GetPermissionMessage(
@@ -876,7 +918,8 @@ void PrinterProviderAPIImpl::OnUsbDevicesEnumerated(
device->manufacturer_string(),
device->product_string(), base::string16(), false))
.Set("usbDevice", static_cast<int>(device->unique_id()))
- .Set("extensions", extension_list.Pass()));
+ .Set("extensions", extension_list.Pass())
+ .Set("needsUsbPermission", true));
}
pending_get_printers_requests_.CompleteUsbPrinters(

Powered by Google App Engine
This is Rietveld 408576698