• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2015 Marshall A. Greenblatt. All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 //    * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 //    * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 //    * Neither the name of Google Inc. nor the name Chromium Embedded
14 // Framework nor the names of its contributors may be used to endorse
15 // or promote products derived from this software without specific prior
16 // written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // ---------------------------------------------------------------------------
31 //
32 // The contents of this file must follow a specific format in order to
33 // support the CEF translator tool. See the translator.README.txt file in the
34 // tools directory for more information.
35 //
36 
37 #ifndef CEF_INCLUDE_CEF_RESPONSE_FILTER_H_
38 #define CEF_INCLUDE_CEF_RESPONSE_FILTER_H_
39 #pragma once
40 
41 #include "include/cef_base.h"
42 
43 ///
44 // Implement this interface to filter resource response content. The methods of
45 // this class will be called on the browser process IO thread.
46 ///
47 /*--cef(source=client)--*/
48 class CefResponseFilter : public virtual CefBaseRefCounted {
49  public:
50   typedef cef_response_filter_status_t FilterStatus;
51 
52   ///
53   // Initialize the response filter. Will only be called a single time. The
54   // filter will not be installed if this method returns false.
55   ///
56   /*--cef()--*/
57   virtual bool InitFilter() = 0;
58 
59   ///
60   // Called to filter a chunk of data. Expected usage is as follows:
61   //
62   //  A. Read input data from |data_in| and set |data_in_read| to the number of
63   //     bytes that were read up to a maximum of |data_in_size|. |data_in| will
64   //     be NULL if |data_in_size| is zero.
65   //  B. Write filtered output data to |data_out| and set |data_out_written| to
66   //     the number of bytes that were written up to a maximum of
67   //     |data_out_size|. If no output data was written then all data must be
68   //     read from |data_in| (user must set |data_in_read| = |data_in_size|).
69   //  C. Return RESPONSE_FILTER_DONE if all output data was written or
70   //     RESPONSE_FILTER_NEED_MORE_DATA if output data is still pending.
71   //
72   // This method will be called repeatedly until the input buffer has been
73   // fully read (user sets |data_in_read| = |data_in_size|) and there is no
74   // more input data to filter (the resource response is complete). This method
75   // may then be called an additional time with an empty input buffer if the
76   // user filled the output buffer (set |data_out_written| = |data_out_size|)
77   // and returned RESPONSE_FILTER_NEED_MORE_DATA to indicate that output data is
78   // still pending.
79   //
80   // Calls to this method will stop when one of the following conditions is met:
81   //
82   //  A. There is no more input data to filter (the resource response is
83   //     complete) and the user sets |data_out_written| = 0 or returns
84   //     RESPONSE_FILTER_DONE to indicate that all data has been written, or;
85   //  B. The user returns RESPONSE_FILTER_ERROR to indicate an error.
86   //
87   // Do not keep a reference to the buffers passed to this method.
88   ///
89   /*--cef(optional_param=data_in,default_retval=RESPONSE_FILTER_ERROR)--*/
90   virtual FilterStatus Filter(void* data_in,
91                               size_t data_in_size,
92                               size_t& data_in_read,
93                               void* data_out,
94                               size_t data_out_size,
95                               size_t& data_out_written) = 0;
96 };
97 
98 #endif  // CEF_INCLUDE_CEF_RESPONSE_FILTER_H_
99