diff options
author | tbarzic <tbarzic@chromium.org> | 2015-01-15 22:07:46 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-01-16 06:08:31 +0000 |
commit | 08c2178e8264a7eb87c36bf52cec587c19df6d6e (patch) | |
tree | c39b444ad099ca94db2bc3b7b8092078b907003c /extensions | |
parent | b7d295017977225179d790b7a5f498a36f341aa3 (diff) | |
download | chromium_src-08c2178e8264a7eb87c36bf52cec587c19df6d6e.zip chromium_src-08c2178e8264a7eb87c36bf52cec587c19df6d6e.tar.gz chromium_src-08c2178e8264a7eb87c36bf52cec587c19df6d6e.tar.bz2 |
Introduce printerProviderInternal API
The API will be used to implement callbacks for printerProvider API
events.
Just before dispatching an printerProvider event to listeners, in
custom bindings, the event argument list will be appended a callback
that wraps printerProviderInternal function. The function will run the
callback associated with the event (which will be cached in the API
event router). To identify the callback to be run, the event will be
added a requestId argument, which will be passed on to the internal
API function.
This cl only adds internal API idl and stub implementation (the rest to
follow).
Also, move printerProvider IDL file from chrome/ to extensions/ and enable
printerProvider permission/feature on dev channel.
BUG=408772
TEST=None (will be added in subsequent cls)
Review URL: https://codereview.chromium.org/812343003
Cr-Commit-Position: refs/heads/master@{#311846}
Diffstat (limited to 'extensions')
12 files changed, 313 insertions, 20 deletions
diff --git a/extensions/browser/BUILD.gn b/extensions/browser/BUILD.gn index fdead32..c043e73 100644 --- a/extensions/browser/BUILD.gn +++ b/extensions/browser/BUILD.gn @@ -164,6 +164,8 @@ source_set("browser") { "api/power/power_api.h", "api/power/power_api_manager.cc", "api/power/power_api_manager.h", + "api/printer_provider_internal/printer_provider_internal_api.cc", + "api/printer_provider_internal/printer_provider_internal_api.h", "api/runtime/runtime_api.cc", "api/runtime/runtime_api.h", "api/runtime/runtime_api_delegate.cc", diff --git a/extensions/browser/api/printer_provider_internal/OWNERS b/extensions/browser/api/printer_provider_internal/OWNERS new file mode 100644 index 0000000..0fa42c6 --- /dev/null +++ b/extensions/browser/api/printer_provider_internal/OWNERS @@ -0,0 +1,2 @@ +tbarzic@chromium.org +vitalybuka@chromium.org diff --git a/extensions/browser/api/printer_provider_internal/printer_provider_internal_api.cc b/extensions/browser/api/printer_provider_internal/printer_provider_internal_api.cc new file mode 100644 index 0000000..2f344a5 --- /dev/null +++ b/extensions/browser/api/printer_provider_internal/printer_provider_internal_api.cc @@ -0,0 +1,64 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "extensions/browser/api/printer_provider_internal/printer_provider_internal_api.h" + +#include "extensions/common/api/printer_provider_internal.h" + +namespace internal_api = extensions::core_api::printer_provider_internal; + +namespace extensions { + +PrinterProviderInternalReportPrintResultFunction:: + PrinterProviderInternalReportPrintResultFunction() { +} + +PrinterProviderInternalReportPrintResultFunction:: + ~PrinterProviderInternalReportPrintResultFunction() { +} + +ExtensionFunction::ResponseAction +PrinterProviderInternalReportPrintResultFunction::Run() { + scoped_ptr<internal_api::ReportPrintResult::Params> params( + internal_api::ReportPrintResult::Params::Create(*args_)); + EXTENSION_FUNCTION_VALIDATE(params.get()); + + return RespondNow(NoArguments()); +} + +PrinterProviderInternalReportPrinterCapabilityFunction:: + PrinterProviderInternalReportPrinterCapabilityFunction() { +} + +PrinterProviderInternalReportPrinterCapabilityFunction:: + ~PrinterProviderInternalReportPrinterCapabilityFunction() { +} + +ExtensionFunction::ResponseAction +PrinterProviderInternalReportPrinterCapabilityFunction::Run() { + scoped_ptr<internal_api::ReportPrinterCapability::Params> params( + internal_api::ReportPrinterCapability::Params::Create(*args_)); + EXTENSION_FUNCTION_VALIDATE(params.get()); + + return RespondNow(NoArguments()); +} + +PrinterProviderInternalReportPrintersFunction:: + PrinterProviderInternalReportPrintersFunction() { +} + +PrinterProviderInternalReportPrintersFunction:: + ~PrinterProviderInternalReportPrintersFunction() { +} + +ExtensionFunction::ResponseAction +PrinterProviderInternalReportPrintersFunction::Run() { + scoped_ptr<internal_api::ReportPrinters::Params> params( + internal_api::ReportPrinters::Params::Create(*args_)); + EXTENSION_FUNCTION_VALIDATE(params.get()); + + return RespondNow(NoArguments()); +} + +} // namespace extensions diff --git a/extensions/browser/api/printer_provider_internal/printer_provider_internal_api.h b/extensions/browser/api/printer_provider_internal/printer_provider_internal_api.h new file mode 100644 index 0000000..d24f0bb --- /dev/null +++ b/extensions/browser/api/printer_provider_internal/printer_provider_internal_api.h @@ -0,0 +1,65 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef EXTENSIONS_BROWSER_API_PRINTER_PROVIDER_INTERNAL_PRINTER_PROVIDER_INTERNAL_API_H_ +#define EXTENSIONS_BROWSER_API_PRINTER_PROVIDER_INTERNAL_PRINTER_PROVIDER_INTERNAL_API_H_ + +#include "extensions/browser/extension_function.h" + +namespace extensions { + +class PrinterProviderInternalReportPrintResultFunction + : public UIThreadExtensionFunction { + public: + PrinterProviderInternalReportPrintResultFunction(); + + protected: + ~PrinterProviderInternalReportPrintResultFunction() override; + + ExtensionFunction::ResponseAction Run() override; + + private: + DECLARE_EXTENSION_FUNCTION("printerProviderInternal.reportPrintResult", + PRINTERPROVIDERINTERNAL_REPORTPRINTRESULT) + + DISALLOW_COPY_AND_ASSIGN(PrinterProviderInternalReportPrintResultFunction); +}; + +class PrinterProviderInternalReportPrinterCapabilityFunction + : public UIThreadExtensionFunction { + public: + PrinterProviderInternalReportPrinterCapabilityFunction(); + + protected: + ~PrinterProviderInternalReportPrinterCapabilityFunction() override; + + ExtensionFunction::ResponseAction Run() override; + + private: + DECLARE_EXTENSION_FUNCTION("printerProviderInternal.reportPrinterCapability", + PRINTERPROVIDERINTERNAL_REPORTPRINTERCAPABILITY) + + DISALLOW_COPY_AND_ASSIGN( + PrinterProviderInternalReportPrinterCapabilityFunction); +}; + +class PrinterProviderInternalReportPrintersFunction + : public UIThreadExtensionFunction { + public: + PrinterProviderInternalReportPrintersFunction(); + + protected: + ~PrinterProviderInternalReportPrintersFunction() override; + ExtensionFunction::ResponseAction Run() override; + + private: + DECLARE_EXTENSION_FUNCTION("printerProviderInternal.reportPrinters", + PRINTERPROVIDERINTERNAL_REPORTPRINTERS) + + DISALLOW_COPY_AND_ASSIGN(PrinterProviderInternalReportPrintersFunction); +}; + +} // namespace extensions + +#endif // EXTENSIONS_BROWSER_API_PRINTER_PROVIDER_INTERNAL_PRINTER_PROVIDER_INTERNAL_API_H_ diff --git a/extensions/browser/extension_function_histogram_value.h b/extensions/browser/extension_function_histogram_value.h index ad9b627..413cf77 100644 --- a/extensions/browser/extension_function_histogram_value.h +++ b/extensions/browser/extension_function_histogram_value.h @@ -1006,6 +1006,9 @@ enum HistogramValue { USB_SETCONFIGURATION, EASYUNLOCKPRIVATE_GETCONNECTIONINFO, FILEMANAGERPRIVATE_COMPUTECHECKSUM, + PRINTERPROVIDERINTERNAL_REPORTPRINTRESULT, + PRINTERPROVIDERINTERNAL_REPORTPRINTERCAPABILITY, + PRINTERPROVIDERINTERNAL_REPORTPRINTERS, // Last entry: Add new entries above and ensure to update // tools/metrics/histograms/histograms.xml. ENUM_BOUNDARY diff --git a/extensions/common/api/_api_features.json b/extensions/common/api/_api_features.json index 11b7f0e..a69a117 100644 --- a/extensions/common/api/_api_features.json +++ b/extensions/common/api/_api_features.json @@ -193,6 +193,15 @@ "dependencies": ["permission:power"], "contexts": ["blessed_extension"] }, + "printerProvider": { + "dependencies": ["permission:printerProvider"], + "contexts": ["blessed_extension"] + }, + "printerProviderInternal": { + "internal": true, + "dependencies": ["permission:printerProvider"], + "contexts": ["blessed_extension"] + }, "runtime": { "channel": "stable", "extension_types": ["extension", "legacy_packaged_app", "platform_app"], diff --git a/extensions/common/api/_permission_features.json b/extensions/common/api/_permission_features.json index 4847910..4e185d9 100644 --- a/extensions/common/api/_permission_features.json +++ b/extensions/common/api/_permission_features.json @@ -206,6 +206,10 @@ "channel": "stable", "extension_types": [ "extension", "legacy_packaged_app", "platform_app" ] }, + "printerProvider": { + "channel": "dev", + "extension_types": ["extension", "platform_app" ] + }, // Note: runtime is not actually a permission, but some systems check these // values to verify restrictions. "runtime": { diff --git a/extensions/common/api/printer_provider.idl b/extensions/common/api/printer_provider.idl new file mode 100644 index 0000000..a3b1b23 --- /dev/null +++ b/extensions/common/api/printer_provider.idl @@ -0,0 +1,80 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This API exposes events used by print manager to query printers controlled +// by extensions, to query capabilities of them and to submit print jobs to +// these printers. +namespace printerProvider { + // Error codes used by providing extensions in response to requests. + enum PrintError { + // Operation completed successfully. + OK, + + // General failure. + FAILED, + + // Print ticket is invalid. For example, ticket is inconsistent with + // capabilities or extension is not able to handle all settings from the + // ticket. + INVALID_TICKET, + + // Document is invalid. For example, data may be corrupted or the format is + // incompatible with the Extension. + INVALID_DATA + }; + + // Printer description for $(ref:onGetPrintersRequested) event. + dictionary PrinterInfo { + // Unique ID of printer. + DOMString id; + + // Human readable display name of printer. + DOMString name; + + // Human readable description of printer. + DOMString? description; + }; + + // Parameters of $(ref:onPrintRequested). + dictionary PrintJob { + // ID of the printer to submit the job. + DOMString printerId; + + // print ticket in CJT format described at + // https://developers.google.com/cloud-print/docs/cdd#cjt + object ticket; + + // Content type of the document. Supported formats are "application/pdf" and + // "image/pwg-raster". + DOMString contentType; + + // Buffer with document to printer. Format must match |contentType|. + ArrayBuffer document; + }; + + callback PrintersCallback = void(PrinterInfo[] printerInfo); + callback CapabilitiesCallback = void(object capabilities); + callback PrintCallback = void(PrintError result); + + interface Events { + // Event fired when print manager requests printers provided by extension. + // |resultCallback| : callback to return printer list. Every listener must + // call callback exactly once. + static void onGetPrintersRequested(PrintersCallback resultCallback); + + // Event fired when print manager requests printer capabilities. + // |printerId| : unique ID of the printer. + // |resultCallback| : callback to return device capabilities in CDD format + // as described at https://developers.google.com/cloud-print/docs/cdd#cdd. + // The receiving listener must call callback exectly once. + static void onGetCapabilityRequested(DOMString printerId, + CapabilitiesCallback resultCallback); + + // Event fired when print manager requests printing. + // |printJob| : parameters of printing request. + static void onPrintRequested(PrintJob printJob, + PrintCallback resultCallback); + }; +}; + diff --git a/extensions/common/api/printer_provider_internal.idl b/extensions/common/api/printer_provider_internal.idl new file mode 100644 index 0000000..c2a962f --- /dev/null +++ b/extensions/common/api/printer_provider_internal.idl @@ -0,0 +1,36 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// printerProviderInternal +// Internal API used to run callbacks passed to chrome.printerProvider API +// events. +// When dispatching a chrome.printerProvider API event, its arguments will be +// massaged in custom bindings so a callback is added. The callback uses +// chrome.printerProviderInternal API to report the event results. +// In order to identify the event for which the callback is called, the event +// is internally dispatched having a requestId argument (which is removed from +// the argument list before the event actually reaches the event listeners). The +// requestId is forwarded to the chrome.printerProviderInternal API functions. +namespace printerProviderInternal { + interface Functions { + // Runs callback to printerProvider.onGetPrintersRequested event. + // |requestId|: Parameter identifying the event instance for which the + // callback is run. + // |printers|: List of printers reported by the extension. + void reportPrinters(long requestId, printerProvider.PrinterInfo[] printers); + + // Runs callback to printerProvider.onGetCapabilityRequested event. + // |requestId|: Parameter identifying the event instance for which the + // callback is run. + // |error|: The printer capability returned by the extension. + void reportPrinterCapability(long request_id, object capability); + + // Runs callback to printerProvider.onPrintRequested event. + // |requestId|: Parameter identifying the event instance for which the + // callback is run. + // |error|: The requested print job result. + void reportPrintResult(long request_id, printerProvider.PrintError error); + }; +}; + diff --git a/extensions/common/api/schemas.gypi b/extensions/common/api/schemas.gypi index 88c243f..a5711ef 100644 --- a/extensions/common/api/schemas.gypi +++ b/extensions/common/api/schemas.gypi @@ -31,6 +31,8 @@ 'mime_handler_view_guest_internal.json', 'mojo_private.idl', 'power.idl', + 'printer_provider.idl', + 'printer_provider_internal.idl', 'runtime.json', 'serial.idl', 'socket.idl', diff --git a/extensions/common/permissions/extensions_api_permissions.cc b/extensions/common/permissions/extensions_api_permissions.cc index 51cad23..0939c3b 100644 --- a/extensions/common/permissions/extensions_api_permissions.cc +++ b/extensions/common/permissions/extensions_api_permissions.cc @@ -33,13 +33,17 @@ std::vector<APIPermissionInfo*> ExtensionsAPIPermissions::GetAllPermissions() APIPermissionInfo::InitInfo permissions_to_register[] = { {APIPermission::kAlphaEnabled, "app.window.alpha"}, {APIPermission::kAlwaysOnTopWindows, "app.window.alwaysOnTop"}, - {APIPermission::kAppView, "appview", - APIPermissionInfo::kFlagCannotBeOptional}, + {APIPermission::kAppView, + "appview", + APIPermissionInfo::kFlagCannotBeOptional}, {APIPermission::kAudio, "audio"}, - {APIPermission::kAudioCapture, "audioCapture", - APIPermissionInfo::kFlagNone, IDS_EXTENSION_PROMPT_WARNING_AUDIO_CAPTURE, + {APIPermission::kAudioCapture, + "audioCapture", + APIPermissionInfo::kFlagNone, + IDS_EXTENSION_PROMPT_WARNING_AUDIO_CAPTURE, PermissionMessage::kAudioCapture}, - {APIPermission::kBluetoothPrivate, "bluetoothPrivate", + {APIPermission::kBluetoothPrivate, + "bluetoothPrivate", APIPermissionInfo::kFlagCannotBeOptional, IDS_EXTENSION_PROMPT_WARNING_BLUETOOTH_PRIVATE, PermissionMessage::kBluetoothPrivate}, @@ -51,7 +55,8 @@ std::vector<APIPermissionInfo*> ExtensionsAPIPermissions::GetAllPermissions() {APIPermission::kClipboardWrite, "clipboardWrite", APIPermissionInfo::kFlagSupportsContentCapabilities}, - {APIPermission::kDeclarativeWebRequest, "declarativeWebRequest", + {APIPermission::kDeclarativeWebRequest, + "declarativeWebRequest", APIPermissionInfo::kFlagNone, IDS_EXTENSION_PROMPT_WARNING_DECLARATIVE_WEB_REQUEST, PermissionMessage::kDeclarativeWebRequest}, @@ -64,14 +69,21 @@ std::vector<APIPermissionInfo*> ExtensionsAPIPermissions::GetAllPermissions() {APIPermission::kOverrideEscFullscreen, "app.window.fullscreen.overrideEsc"}, {APIPermission::kPower, "power"}, - {APIPermission::kSerial, "serial", APIPermissionInfo::kFlagNone, - IDS_EXTENSION_PROMPT_WARNING_SERIAL, PermissionMessage::kSerial}, + {APIPermission::kPrinterProvider, "printerProvider"}, + {APIPermission::kSerial, + "serial", + APIPermissionInfo::kFlagNone, + IDS_EXTENSION_PROMPT_WARNING_SERIAL, + PermissionMessage::kSerial}, // Because warning messages for the "socket" permission vary based // on the permissions parameters, no message ID or message text is // specified here. The message ID and text used will be // determined at run-time in the |SocketPermission| class. - {APIPermission::kSocket, "socket", - APIPermissionInfo::kFlagCannotBeOptional, 0, PermissionMessage::kNone, + {APIPermission::kSocket, + "socket", + APIPermissionInfo::kFlagCannotBeOptional, + 0, + PermissionMessage::kNone, &CreateAPIPermission<SocketPermission>}, {APIPermission::kStorage, "storage"}, {APIPermission::kSystemCpu, "system.cpu"}, @@ -79,33 +91,45 @@ std::vector<APIPermissionInfo*> ExtensionsAPIPermissions::GetAllPermissions() {APIPermission::kSystemNetwork, "system.network"}, {APIPermission::kSystemDisplay, "system.display"}, {APIPermission::kSystemStorage, "system.storage"}, - {APIPermission::kU2fDevices, "u2fDevices", APIPermissionInfo::kFlagNone, + {APIPermission::kU2fDevices, + "u2fDevices", + APIPermissionInfo::kFlagNone, IDS_EXTENSION_PROMPT_WARNING_U2F_DEVICES, PermissionMessage::kU2fDevices}, {APIPermission::kUnlimitedStorage, "unlimitedStorage", APIPermissionInfo::kFlagCannotBeOptional | - APIPermissionInfo::kFlagSupportsContentCapabilities}, + APIPermissionInfo::kFlagSupportsContentCapabilities}, {APIPermission::kUsb, "usb", APIPermissionInfo::kFlagNone}, - {APIPermission::kUsbDevice, "usbDevices", APIPermissionInfo::kFlagNone, 0, - PermissionMessage::kNone, &CreateAPIPermission<UsbDevicePermission>}, - {APIPermission::kVideoCapture, "videoCapture", - APIPermissionInfo::kFlagNone, IDS_EXTENSION_PROMPT_WARNING_VIDEO_CAPTURE, + {APIPermission::kUsbDevice, + "usbDevices", + APIPermissionInfo::kFlagNone, + 0, + PermissionMessage::kNone, + &CreateAPIPermission<UsbDevicePermission>}, + {APIPermission::kVideoCapture, + "videoCapture", + APIPermissionInfo::kFlagNone, + IDS_EXTENSION_PROMPT_WARNING_VIDEO_CAPTURE, PermissionMessage::kVideoCapture}, - {APIPermission::kVpnProvider, "vpnProvider", + {APIPermission::kVpnProvider, + "vpnProvider", APIPermissionInfo::kFlagCannotBeOptional, - IDS_EXTENSION_PROMPT_WARNING_VPN, PermissionMessage::kVpnProvider}, + IDS_EXTENSION_PROMPT_WARNING_VPN, + PermissionMessage::kVpnProvider}, // NOTE(kalman): This is provided by a manifest property but needs to // appear in the install permission dialogue, so we need a fake // permission for it. See http://crbug.com/247857. - {APIPermission::kWebConnectable, "webConnectable", + {APIPermission::kWebConnectable, + "webConnectable", APIPermissionInfo::kFlagCannotBeOptional | APIPermissionInfo::kFlagInternal, IDS_EXTENSION_PROMPT_WARNING_WEB_CONNECTABLE, PermissionMessage::kWebConnectable}, {APIPermission::kWebRequest, "webRequest"}, {APIPermission::kWebRequestBlocking, "webRequestBlocking"}, - {APIPermission::kWebView, "webview", + {APIPermission::kWebView, + "webview", APIPermissionInfo::kFlagCannotBeOptional}, {APIPermission::kWindowShape, "app.window.shape"}, }; diff --git a/extensions/extensions.gyp b/extensions/extensions.gyp index 18e157e..a31f302 100644 --- a/extensions/extensions.gyp +++ b/extensions/extensions.gyp @@ -454,6 +454,8 @@ 'browser/api/power/power_api.h', 'browser/api/power/power_api_manager.cc', 'browser/api/power/power_api_manager.h', + 'browser/api/printer_provider_internal/printer_provider_internal_api.cc', + 'browser/api/printer_provider_internal/printer_provider_internal_api.h', 'browser/api/runtime/runtime_api.cc', 'browser/api/runtime/runtime_api.h', 'browser/api/runtime/runtime_api_delegate.cc', |