• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 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_COOKIE_H_
38 #define CEF_INCLUDE_CEF_COOKIE_H_
39 #pragma once
40 
41 #include <vector>
42 #include "include/cef_base.h"
43 #include "include/cef_callback.h"
44 
45 class CefCookieVisitor;
46 class CefSetCookieCallback;
47 class CefDeleteCookiesCallback;
48 
49 ///
50 // Class used for managing cookies. The methods of this class may be called on
51 // any thread unless otherwise indicated.
52 ///
53 /*--cef(source=library,no_debugct_check)--*/
54 class CefCookieManager : public virtual CefBaseRefCounted {
55  public:
56   ///
57   // Returns the global cookie manager. By default data will be stored at
58   // CefSettings.cache_path if specified or in memory otherwise. If |callback|
59   // is non-NULL it will be executed asnychronously on the UI thread after the
60   // manager's storage has been initialized. Using this method is equivalent to
61   // calling CefRequestContext::GetGlobalContext()->GetDefaultCookieManager().
62   ///
63   /*--cef(optional_param=callback)--*/
64   static CefRefPtr<CefCookieManager> GetGlobalManager(
65       CefRefPtr<CefCompletionCallback> callback);
66 
67   ///
68   // Visit all cookies on the UI thread. The returned cookies are ordered by
69   // longest path, then by earliest creation date. Returns false if cookies
70   // cannot be accessed.
71   ///
72   /*--cef()--*/
73   virtual bool VisitAllCookies(CefRefPtr<CefCookieVisitor> visitor) = 0;
74 
75   ///
76   // Visit a subset of cookies on the UI thread. The results are filtered by the
77   // given url scheme, host, domain and path. If |includeHttpOnly| is true
78   // HTTP-only cookies will also be included in the results. The returned
79   // cookies are ordered by longest path, then by earliest creation date.
80   // Returns false if cookies cannot be accessed.
81   ///
82   /*--cef()--*/
83   virtual bool VisitUrlCookies(const CefString& url,
84                                bool includeHttpOnly,
85                                CefRefPtr<CefCookieVisitor> visitor) = 0;
86 
87   ///
88   // Sets a cookie given a valid URL and explicit user-provided cookie
89   // attributes. This function expects each attribute to be well-formed. It will
90   // check for disallowed characters (e.g. the ';' character is disallowed
91   // within the cookie value attribute) and fail without setting the cookie if
92   // such characters are found. If |callback| is non-NULL it will be executed
93   // asnychronously on the UI thread after the cookie has been set. Returns
94   // false if an invalid URL is specified or if cookies cannot be accessed.
95   ///
96   /*--cef(optional_param=callback)--*/
97   virtual bool SetCookie(const CefString& url,
98                          const CefCookie& cookie,
99                          CefRefPtr<CefSetCookieCallback> callback) = 0;
100 
101   ///
102   // Delete all cookies that match the specified parameters. If both |url| and
103   // |cookie_name| values are specified all host and domain cookies matching
104   // both will be deleted. If only |url| is specified all host cookies (but not
105   // domain cookies) irrespective of path will be deleted. If |url| is empty all
106   // cookies for all hosts and domains will be deleted. If |callback| is
107   // non-NULL it will be executed asnychronously on the UI thread after the
108   // cookies have been deleted. Returns false if a non-empty invalid URL is
109   // specified or if cookies cannot be accessed. Cookies can alternately be
110   // deleted using the Visit*Cookies() methods.
111   ///
112   /*--cef(optional_param=url,optional_param=cookie_name,
113           optional_param=callback)--*/
114   virtual bool DeleteCookies(const CefString& url,
115                              const CefString& cookie_name,
116                              CefRefPtr<CefDeleteCookiesCallback> callback) = 0;
117 
118   ///
119   // Flush the backing store (if any) to disk. If |callback| is non-NULL it will
120   // be executed asnychronously on the UI thread after the flush is complete.
121   // Returns false if cookies cannot be accessed.
122   ///
123   /*--cef(optional_param=callback)--*/
124   virtual bool FlushStore(CefRefPtr<CefCompletionCallback> callback) = 0;
125 };
126 
127 ///
128 // Interface to implement for visiting cookie values. The methods of this class
129 // will always be called on the UI thread.
130 ///
131 /*--cef(source=client)--*/
132 class CefCookieVisitor : public virtual CefBaseRefCounted {
133  public:
134   ///
135   // Method that will be called once for each cookie. |count| is the 0-based
136   // index for the current cookie. |total| is the total number of cookies.
137   // Set |deleteCookie| to true to delete the cookie currently being visited.
138   // Return false to stop visiting cookies. This method may never be called if
139   // no cookies are found.
140   ///
141   /*--cef()--*/
142   virtual bool Visit(const CefCookie& cookie,
143                      int count,
144                      int total,
145                      bool& deleteCookie) = 0;
146 };
147 
148 ///
149 // Interface to implement to be notified of asynchronous completion via
150 // CefCookieManager::SetCookie().
151 ///
152 /*--cef(source=client)--*/
153 class CefSetCookieCallback : public virtual CefBaseRefCounted {
154  public:
155   ///
156   // Method that will be called upon completion. |success| will be true if the
157   // cookie was set successfully.
158   ///
159   /*--cef()--*/
160   virtual void OnComplete(bool success) = 0;
161 };
162 
163 ///
164 // Interface to implement to be notified of asynchronous completion via
165 // CefCookieManager::DeleteCookies().
166 ///
167 /*--cef(source=client)--*/
168 class CefDeleteCookiesCallback : public virtual CefBaseRefCounted {
169  public:
170   ///
171   // Method that will be called upon completion. |num_deleted| will be the
172   // number of cookies that were deleted.
173   ///
174   /*--cef()--*/
175   virtual void OnComplete(int num_deleted) = 0;
176 };
177 
178 #endif  // CEF_INCLUDE_CEF_COOKIE_H_
179