summaryrefslogtreecommitdiffstats
path: root/dom/webidl/StreamFilter.webidl
blob: a45b392dc06a2635edd7c736bf8156e8cbb3e026 (plain)
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
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/.
 */

/**
 * This is a Mozilla-specific WebExtension API, which is not available to web
 * content. It allows monitoring and filtering of HTTP response stream data.
 *
 * This API should currently be considered experimental, and is not defined by
 * any standard.
 */

enum StreamFilterStatus {
  /**
   * The StreamFilter is not fully initialized. No methods may be called until
   * a "start" event has been received.
   */
  "uninitialized",
  /**
   * The underlying channel is currently transferring data, which will be
   * dispatched via "data" events.
   */
  "transferringdata",
  /**
   * The underlying channel has finished transferring data. Data may still be
   * written via write() calls at this point.
   */
  "finishedtransferringdata",
  /**
   * Data transfer is currently suspended. It may be resumed by a call to
   * resume(). Data may still be written via write() calls in this state.
   */
  "suspended",
  /**
   * The channel has been closed by a call to close(). No further data wlil be
   * delivered via "data" events, and no further data may be written via
   * write() calls.
   */
  "closed",
  /**
   * The channel has been disconnected by a call to disconnect(). All further
   * data will be delivered directly, without passing through the filter. No
   * further events will be dispatched, and no further data may be written by
   * write() calls.
   */
  "disconnected",
  /**
   * An error has occurred and the channel is disconnected. The `error`
   * property contains the details of the error.
   */
  "failed",
};

/**
 * An interface which allows an extension to intercept, and optionally modify,
 * response data from an HTTP request.
 */
[Exposed=Window,
 Func="mozilla::extensions::StreamFilter::IsAllowedInContext"]
interface StreamFilter : EventTarget {
  /**
   * Creates a stream filter for the given add-on and the given extension ID.
   */
  [ChromeOnly]
  static StreamFilter create(unsigned long long requestId, DOMString addonId);

  /**
   * Suspends processing of the request. After this is called, no further data
   * will be delivered until the request is resumed.
   */
  [Throws]
  undefined suspend();

  /**
   * Resumes delivery of data for a suspended request.
   */
  [Throws]
  undefined resume();

  /**
   * Closes the request. After this is called, no more data may be written to
   * the stream, and no further data will be delivered.
   *
   * This *must* be called after the consumer is finished writing data, unless
   * disconnect() has already been called.
   */
  [Throws]
  undefined close();

  /**
   * Disconnects the stream filter from the request. After this is called, no
   * further data will be delivered to the filter, and any unprocessed data
   * will be written directly to the output stream.
   */
  [Throws]
  undefined disconnect();

  /**
   * Writes a chunk of data to the output stream. This may not be called
   * before the "start" event has been received.
   */
  [Throws]
  undefined write((ArrayBuffer or Uint8Array) data);

  /**
   * Returns the current status of the stream.
   */
  [Pure]
  readonly attribute StreamFilterStatus status;

  /**
   * After an "error" event has been dispatched, this contains a message
   * describing the error.
   */
  [Pure]
  readonly attribute DOMString error;

  /**
   * Dispatched with a StreamFilterDataEvent whenever incoming data is
   * available on the stream. This data will not be delivered to the output
   * stream unless it is explicitly written via a write() call.
   */
  attribute EventHandler ondata;

  /**
   * Dispatched when the stream is opened, and is about to begin delivering
   * data.
   */
  attribute EventHandler onstart;

  /**
   * Dispatched when the stream has closed, and has no more data to deliver.
   * The output stream remains open and writable until close() is called.
   */
  attribute EventHandler onstop;

  /**
   * Dispatched when an error has occurred. No further data may be read or
   * written after this point.
   */
  attribute EventHandler onerror;
};