1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654
|
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Use the <code>chrome.documentScan</code> API to discover and retrieve
// images from attached document scanners.
[platforms=("chromeos"),
implemented_in="chrome/browser/extensions/api/document_scan/document_scan_api.h"]
namespace documentScan {
dictionary ScanOptions {
// The MIME types that are accepted by the caller.
DOMString[]? mimeTypes;
// The number of scanned images allowed. The default is 1.
long? maxImages;
};
dictionary ScanResults {
// An array of data image URLs in a form that can be passed as the "src"
// value to an image tag.
DOMString[] dataUrls;
// The MIME type of the <code>dataUrls</code>.
DOMString mimeType;
};
// An enum that indicates the result of each operation.
enum OperationResult {
// An unknown or generic failure occurred.
UNKNOWN,
// The operation succeeded.
SUCCESS,
// The operation is not supported.
UNSUPPORTED,
// The operation was cancelled.
CANCELLED,
// The device is busy.
DEVICE_BUSY,
// Either the data or an argument passed to the method is not valid.
INVALID,
// The supplied value is the wrong data type for the underlying option.
WRONG_TYPE,
// No more data is available.
EOF,
// The document feeder is jammed.
ADF_JAMMED,
// The document feeder is empty.
ADF_EMPTY,
// The flatbed cover is open.
COVER_OPEN,
// An error occurred while communicating with the device.
IO_ERROR,
// The device requires authentication.
ACCESS_DENIED,
// Not enough memory is available on the Chromebook to complete the
// operation.
NO_MEMORY,
// The device is not reachable.
UNREACHABLE,
// The device is disconnected.
MISSING,
// An error has occurred somewhere other than the calling application.
INTERNAL_ERROR
};
// Indicates how the scanner is connected to the computer.
enum ConnectionType {
UNSPECIFIED,
USB,
NETWORK
};
// Contains general information about a scanner. It is
// intended for filtering and constructing user-facing information. to
// configure a scan, use $(ref:StartScanOptions).
dictionary ScannerInfo {
// The ID of a specific scanner.
DOMString scannerId;
// A human-readable name for the scanner to display in the UI.
DOMString name;
// The scanner manufacturer.
DOMString manufacturer;
// The scanner model if it is available, or a generic description.
DOMString model;
// For matching against other <code>ScannerInfo</code> entries that point
// to the same physical device.
DOMString deviceUuid;
// Indicates how the scanner is connected to the computer.
ConnectionType connectionType;
// If true, the scanner connection's transport cannot be intercepted by a
// passive listener, such as TLS or USB.
boolean secure;
// An array of MIME types that can be requested for returned scans.
DOMString[] imageFormats;
// A human-readable description of the protocol or driver used to
// access the scanner, such as Mopria, WSD, or epsonds. This is primarily
// useful for allowing a user to choose between protocols if a device
// supports multiple protocols.
DOMString protocolType;
};
// The data type of an option.
enum OptionType {
// The option's data type is unknown. The <code>value</code> property
// will be unset.
UNKNOWN,
// The <code>value</code> property will be one of <code>true</code or
// <code>false</code>.
BOOL,
// A signed 32-bit integer. The <code>value</code> property will be long or
// long[], depending on whether the option takes more than one value.
INT,
// A double in the range -32768-32767.9999 with a resolution of 1/65535.
// The <code>value</code> property will be double or double[] depending
// on whether the option takes more than one value. Double values that
// can't be exactly represented will be rounded to the available range
// and precision.
FIXED,
// A sequence of any bytes except NUL ('\0'). The <code>value</code>
// property will be a DOMString.
STRING,
// An option of this type has no value. Instead, setting an option of
// this type causes an option-specific side effect in the scanner
// driver. For example, a button-typed option could be used by a
// scanner driver to provide a means to select default values or to
// tell an automatic document feeder to advance to the next sheet of
// paper.
BUTTON,
// Grouping option. No value. This is included for compatibility, but
// will not normally be returned in <code>ScannerOption</code> values. Use
// <code>getOptionGroups()</code> to retrieve the list of groups with their
// member options.
GROUP
};
// Indicates the data type for $(ref:ScannerOption.unit).
enum OptionUnit {
// The value is a unitless number. For example, it can be a threshold.
UNITLESS,
// The value is a number of pixels, for example, scan dimensions.
PIXEL,
// The value is the number of bits, for example, color depth.
BIT,
// The value is measured in millimeters, for example, scan dimensions.
MM,
// The value is measured in dots per inch, for example, resolution.
DPI,
// The value is a percent, for example, brightness.
PERCENT,
// The value is measured in microseconds, for example, exposure time.
MICROSECOND
};
// The data type of constraint represented by an $(ref:OptionConstraint).
enum ConstraintType {
// The constraint on a range of <code>OptionType.INT</code> values.
// The <code>min</code>, <code>max</code>, and <code>quant</code> properties
// of <code>OptionConstraint</code> will be <code>long</code>, and its
// <code>list</code> propety will be unset.
INT_RANGE,
// The constraint on a range of <code>OptionType.FIXED</code> values.
// The <code>min</code>, <code>max</code>, and <code>quant</code> properties
// of <code>OptionConstraint</code> will be <code>double</code>, and its
// <code>list</code> property will be unset.
FIXED_RANGE,
// The constraint on a specific list of <code>OptionType.INT</code>
// values. The <code>OptionConstraint.list</code> property will contain
// <code>long</code> values, and the other properties will be unset.
INT_LIST,
// The constraint on a specific list of <code>OptionType.FIXED</code>
// values. The <code>OptionConstraint.list</code> property will contain
// <code>double</code> values, and the other properties will be unset.
FIXED_LIST,
// The constraint on a specific list of <code>OptionType.STRING</code>
// values. The <code>OptionConstraint.list</code> property will contain
// <code>DOMString</code> values, and the other properties will be unset.
STRING_LIST
};
// The specific values for the $(ref:ConstraintType) structure.
// An unconstrained value is represented by a lack of constraints;
// there is no separate <code>ConstraintType</code> value to indicate an
// unconstrained value.
dictionary OptionConstraint {
ConstraintType type;
(long or double)? min;
(long or double)? max;
(long or double)? quant;
(double[] or long[] or DOMString[])? list;
};
// How an option can be changed.
enum Configurability {
// The option is read-only.
NOT_CONFIGURABLE,
// The option can be set in software.
SOFTWARE_CONFIGURABLE,
// The option can be set by the user toggling or pushing a button on
// the scanner.
HARDWARE_CONFIGURABLE
};
// A self-describing configurable scanner option and its current value.
dictionary ScannerOption {
// The option name using lowercase ASCII letters, numbers, and dashes.
// Diacritics are not allowed.
DOMString name;
// A printable one-line title.
DOMString title;
// A longer description of the option.
DOMString description;
// The data type contained in the <code>value</code> property, which
// is needed for setting this option.
OptionType type;
// The unit of measurement for this option.
OptionUnit unit;
// The current value of the option, if relevant. Note that the data
// type of this property must match the data type specified in
// <code>type</code>.
(boolean or double or double[] or long or long[] or DOMString)? value;
// Defines $(ref:OptionConstraint) on the current scanner option.
OptionConstraint? constraint;
// Indicates that this option can be detected from software.
boolean isDetectable;
// Indicates whether and how the option can be changed.
Configurability configurability;
// Can be automatically set by the scanner driver.
boolean isAutoSettable;
// Emulated by the scanner driver if true.
boolean isEmulated;
// Indicates the option is active and can be set or retrieved. If false,
// the <code>value</code> property will not be set.
boolean isActive;
// Indicates that the UI should not display this option by default.
boolean isAdvanced;
// Indicates that the option is used for internal configuration and
// should never be displayed in the UI.
boolean isInternal;
};
// A set of criteria passed to <code>getScannerList()</code>. Only devices
// that match all of the criteria will be returned.
dictionary DeviceFilter {
// Only return scanners that are directly attached to the computer.
boolean? local;
// Only return scanners that use a secure transport, such as USB or TLS.
boolean? secure;
};
// Contains a list of option names. The groups and their contents are
// determined by the scanner driver and do not have any defined semantics
// or consistent membership. This structure is primarily intended
// for UI layout assistance; it does not affect individual option
// behaviors.
dictionary OptionGroup {
// Provides a printable title, for example "Geometry options".
DOMString title;
// An array of option names in driver-provided order.
DOMString[] members;
};
// The response from $(ref:getScannerList).
dictionary GetScannerListResponse {
// The enumeration result. Note that partial results could be
// returned even if this indicates an error.
OperationResult result;
// A possibly-empty list of scanners that match the provided
// $(ref:DeviceFilter).
ScannerInfo[] scanners;
};
// The response from $(ref:openScanner).
dictionary OpenScannerResponse {
// The scanner ID passed to <code>openScanner()</code>.
DOMString scannerId;
// The result of opening the scanner. If the value of this is
// <code>SUCCESS</code>, the <code>scannerHandle</code> and
// <code>options</code> properties will be populated.
OperationResult result;
// If <code>result</code> is <code>SUCCESS</code>, a
// handle to the scanner that can be used for further operations.
DOMString? scannerHandle;
// If <code>result</code> is <code>SUCCESS</code>,
// provides a key-value mapping where the key is a device-specific
// option and the value is an instance of $(ref:ScannerOption).
object? options;
};
// The response from $(ref:getOptionGroups).
dictionary GetOptionGroupsResponse {
// The same scanner handle as was passed to $(ref:getOptionGroups).
DOMString scannerHandle;
// The result of getting the option groups. If the value of this is
// <code>SUCCESS</code>, the <code>groups</code> property will be
// populated.
OperationResult result;
// If <code>result</code> is <code>SUCCESS</code>, provides a
// list of option groups in the order supplied by the scanner driver.
OptionGroup[]? groups;
};
// The response from <code>closeScanner()</code>.
dictionary CloseScannerResponse {
// The same scanner handle as was passed to $(ref:closeScanner).
DOMString scannerHandle;
// The result of closing the scanner. Even if this value is not
// <code>SUCCESS</code>, the handle will be invalid and
// should not be used for any further operations.
OperationResult result;
};
// Passed to $(ref:setOptions) to set an option to $(ref:ScannerOption) to
// a new value.
dictionary OptionSetting {
// Indicates the name of the option to set.
DOMString name;
// Indicates the data type of the option. The requested data type must
// match the real data type of the underlying option.
OptionType type;
// Indicates the value to set. Leave unset to request automatic setting for
// options that have <code>autoSettable</code> enabled. The data type
// supplied for <code>value</code> must match <code>type</code>.
(boolean or double or double[] or long or long[] or DOMString)? value;
};
// The result of setting an individual option. Each individual option
// supplied to <code>setOptions()</code> produces a separate result
// due to things like rounding and constraints.
dictionary SetOptionResult {
// Indicates the name of the option that was set.
DOMString name;
// Indicates the result of setting the option.
OperationResult result;
};
// The response from a call to $(ref:setOptions).
dictionary SetOptionsResponse {
// Provides the scanner handle passed to <code>setOptions()</code>.
DOMString scannerHandle;
// An array of results, one each for every passed-in
// <code>OptionSetting</code>.
SetOptionResult[] results;
// An updated key-value mapping from option names to
// $(ref:ScannerOption) values containing the new configuration after
// attempting to set all supplied options. This has the same structure as
// the <code>options</code> property in $(ref:OpenScannerResponse).
//
// This property will be set even if some options were not set successfully,
// but will be unset if retrieving the updated configuration fails (for
// example, if the scanner is disconnected in the middle of scanning).
object? options;
};
// Specifies options for $(ref:startScan).
dictionary StartScanOptions {
// Specifies the MIME type to return scanned data in.
DOMString format;
// If a non-zero value is specified, limits the maximum scanned bytes
// returned in a single $(ref:readScanData) response to that value. The
// smallest allowed value is 32768 (32 KB). If this property is not
// specified, the size of a returned chunk may be as large as the entire
// scanned image.
long? maxReadSize;
};
// The response from <code>startScan()</code>.
dictionary StartScanResponse {
// Provides the same scanner handle that was passed to
// <code>startScan()</code>.
DOMString scannerHandle;
// The result of starting a scan. If the value of this is
// <code>SUCCESS</code>, the <code>job</code> property will be populated.
OperationResult result;
// If <code>result</code> is <code>SUCCESS</code>, provides a
// handle that can be used to read scan data or cancel the job.
DOMString? job;
};
// The response from <code>cancelScan()</code>.
dictionary CancelScanResponse {
// Provides the same job handle that was passed to
// <code>cancelScan()</code>.
DOMString job;
// The backend's cancel scan result. If the result is
// <code>OperationResult.SUCCESS</code> or
// <code>OperationResult.CANCELLED</code>, the scan has been cancelled and
// the scanner is ready to start a new scan. If the result is
// <code>OperationResult.DEVICE_BUSY </code>, the scanner is still
// processing the requested cancellation; the caller should wait a short
// time and try the request again. Other result values indicate a permanent
// error that should not be retried.
OperationResult result;
};
// The response from $(ref:readScanData).
dictionary ReadScanDataResponse {
// Provides the job handle passed to <code>readScanData()</code>.
DOMString job;
// The result of reading data. If its value is
// <code>SUCCESS</code>, then <code>data</code> contains the
// <em>next</em> (possibly zero-length) chunk of image data that is ready
// for reading. If its value is <code>EOF</code>, the <code>data</code>
// contains the <em>last</em> chunk of image data.
OperationResult result;
// If <code>result</code> is <code>SUCCESS</code>, contains
// the <em>next</em> chunk of scanned image data. If <code>result</code> is
// <code>EOF</code>, contains the <em>last</em> chunk of
// scanned image data.
ArrayBuffer? data;
// If <code>result</code> is <code>SUCCESS</code>, an estimate of
// how much of the total scan data has been delivered so far, in the range
// 0 to 100.
long? estimatedCompletion;
};
// Callback from the $(ref:scan) method.
// |result| Provides the results from the scan, if successful.
// Otherwise, this value will be null and $(ref:runtime.lastError)
// will be set.
callback ScanCallback = void (ScanResults result);
// Callback from the $(ref:getScannerList) method.
// |response| The response from enumeration, if the call was valid.
// Otherwise, this value will be null and $(ref:runtime.lastError)
// will be set.
callback GetScannerListCallback = void (GetScannerListResponse response);
// Callback from the $(ref:openScanner) method.
// |response| The response from opening the scanner, if the call was valid.
// Otherwise, this value will be null and $(ref:runtime.lastError)
// will be set.
callback OpenScannerCallback = void (OpenScannerResponse response);
// Callback from the $(ref:getOptionGroups) method.
// |response| The response from getting the option groups, if the call was
// valid. Otherwise, this value will be null and $(ref:runtime.lastError)
// will be set.
callback GetOptionGroupsCallback =
void (GetOptionGroupsResponse response);
// Callback from the $(ref:closeScanner) method.
// |response| The response from closing the scanner, if the call was valid.
// Otherwise, this value will be null and $(ref:runtime.lastError)
// will be set.
callback CloseScannerCallback = void (CloseScannerResponse response);
// Callback from the $(ref:setOptions) method.
// |response| The response from setting the options, if the call was valid.
// Otherwise, this value will be null and $(ref:runtime.lastError)
// will be set.
callback SetOptionsCallback = void (SetOptionsResponse response);
// Callback from the $(ref:startScan) method.
// |response| The response from starting the scan, if the call was valid.
// Otherwise, this value will be null and $(ref:runtime.lastError)
// will be set.
callback StartScanCallback = void (StartScanResponse response);
// Callback from the $(ref:cancelScan) method.
// |response| The response from canceling the scan, if the call was valid.
// Otherwise, this value will be null and $(ref:runtime.lastError)
// will be set.
callback CancelScanCallback = void (CancelScanResponse response);
// Callback from the $(ref:readScanData) method.
// |response| The response from reading the next chunk of scanned image data,
// if the call was valid. Otherwise, this value will be null and
// $(ref:runtime.lastError) will be set.
callback ReadScanDataCallback = void (ReadScanDataResponse response);
interface Functions {
// Performs a document scan and returns a Promise that resolves
// with a $(ref:ScanResults) object. If a callback is passed to
// this function, the returned data is passed to it instead.
// |options| : An object containing scan parameters.
// |callback| : Called with the result and data from the scan.
static void scan(
ScanOptions options,
ScanCallback callback);
// Gets the list of available scanners and returns a Promise that
// resolves with a $(ref:GetScannerListResponse) object. If a callback
// is passed to this function, returned data is passed to it instead.
// |filter| : A $(ref:DeviceFilter) indicating which types of scanners
// should be returned.
// |callback| : Called with the result and list of scanners.
static void getScannerList(
DeviceFilter filter, GetScannerListCallback callback);
// Opens a scanner for exclusive access and returns a Promise that
// resolves with an $(ref:OpenScannerResponse) object. If a callback
// is passed to this function, returned data is passed to it instead.
// |scannerId| : The ID of a scanner to be opened. This value is one
// returned from a previous call to $(ref:getScannerList).
// |callback| : Called with the result.
static void openScanner(
DOMString scannerId, OpenScannerCallback callback);
// Gets the group names and member options from a scanner previously
// opened by $(ref:openScanner). This method returns a Promise that
// resolves with a $(ref:GetOptionGroupsResponse) object. If a callback
// is passed to this function, returned data is passed to it instead.
// |scannerHandle| : The handle of an open scanner returned from a call
// to $(ref:openScanner).
// |callback| : Called with the result.
static void getOptionGroups(
DOMString scannerHandle, GetOptionGroupsCallback callback);
// Closes the scanner with the passed in handle and returns a Promise
// that resolves with a $(ref:CloseScannerResponse) object. If a callback
// is used, the object is passed to it instead. Even if the response is
// not a success, the supplied handle becomes invalid and should not be
// used for further operations.
// |scannerHandle| : Specifies the handle of an open scanner that was
// previously returned from a call to $(ref:openScanner).
// |callback| : Called with the result.
static void closeScanner(
DOMString scannerHandle, CloseScannerCallback callback);
// Sets options on the specified scanner and returns a Promise that
// resolves with a $(ref:SetOptionsResponse) object containing the
// result of trying to set every value in the order of the passed-in
// $(ref:OptionSetting) object. If a callback is used, the object is
// passed to it instead.
// |scannerHandle| : The handle of the scanner to set options on. This
// should be a value previously returned from a call to $(ref:openScanner).
// |options| : A list of <code>OptionSetting</code> objects to be applied to
// the scanner.
// |callback| : Called with the result.
static void setOptions(
DOMString scannerHandle, OptionSetting[] options,
SetOptionsCallback callback);
// Starts a scan on the specified scanner and returns a Promise that
// resolves with a $(ref:StartScanResponse). If a callback is used,
// the object is passed to it instead. If the call was successful, the
// response includes a job handle that can be used in subsequent calls
// to read scan data or cancel a scan.
// |scannerHandle| : The handle of an open scanner. This should be a value
// previously returned from a call to $(ref:openScanner).
// |options| : A $(ref:StartScanOptions) object indicating the options to
// be used for the scan. The <code>StartScanOptions.format</code> property
// must match one of the entries returned in the scanner's
// <code>ScannerInfo</code>.
// |callback| : Called with the result.
static void startScan(
DOMString scannerHandle, StartScanOptions options,
StartScanCallback callback);
// Cancels a started scan and returns a Promise that resolves with a
// $(ref:CancelScanResponse) object. If a callback is used, the object
// is passed to it instead.
// |job| : The handle of an active scan job previously returned from a
// call to $(ref:startScan).
// |callback| : Called with the result.
static void cancelScan(
DOMString job, CancelScanCallback callback);
// Reads the next chunk of available image data from an active job handle,
// and returns a Promise that resolves with a $(ref:ReadScanDataResponse)
// object. If a callback is used, the object is passed to it instead.
//
// <aside class="note"><b>Note:</b>It is valid for a response result to be
// <code>SUCCESS</code> with a zero-length <code>data</code>
// member. This means the scanner is still working but does not yet have
// additional data ready. The caller should wait a short time and try again.
//
// When the scan job completes, the response will have the result value of
// <code>EOF</code>. This response may contain a final
// non-zero <code>data</code> member.</aside>
//
// |job| : Active job handle previously returned from
// $(ref:startScan).
// |callback| : Called with the result.
static void readScanData(
DOMString job, ReadScanDataCallback callback);
};
};
|