• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2017 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_EXTENSION_HANDLER_H_
38 #define CEF_INCLUDE_CEF_EXTENSION_HANDLER_H_
39 #pragma once
40 
41 #include "include/cef_base.h"
42 #include "include/cef_browser.h"
43 #include "include/cef_extension.h"
44 #include "include/cef_stream.h"
45 
46 class CefClient;
47 
48 ///
49 // Callback interface used for asynchronous continuation of
50 // CefExtensionHandler::GetExtensionResource.
51 ///
52 /*--cef(source=library)--*/
53 class CefGetExtensionResourceCallback : public CefBaseRefCounted {
54  public:
55   ///
56   // Continue the request. Read the resource contents from |stream|.
57   ///
58   /*--cef(capi_name=cont,optional_param=stream)--*/
59   virtual void Continue(CefRefPtr<CefStreamReader> stream) = 0;
60 
61   ///
62   // Cancel the request.
63   ///
64   /*--cef()--*/
65   virtual void Cancel() = 0;
66 };
67 
68 ///
69 // Implement this interface to handle events related to browser extensions.
70 // The methods of this class will be called on the UI thread. See
71 // CefRequestContext::LoadExtension for information about extension loading.
72 ///
73 /*--cef(source=client)--*/
74 class CefExtensionHandler : public virtual CefBaseRefCounted {
75  public:
76   ///
77   // Called if the CefRequestContext::LoadExtension request fails. |result| will
78   // be the error code.
79   ///
80   /*--cef()--*/
OnExtensionLoadFailed(cef_errorcode_t result)81   virtual void OnExtensionLoadFailed(cef_errorcode_t result) {}
82 
83   ///
84   // Called if the CefRequestContext::LoadExtension request succeeds.
85   // |extension| is the loaded extension.
86   ///
87   /*--cef()--*/
OnExtensionLoaded(CefRefPtr<CefExtension> extension)88   virtual void OnExtensionLoaded(CefRefPtr<CefExtension> extension) {}
89 
90   ///
91   // Called after the CefExtension::Unload request has completed.
92   ///
93   /*--cef()--*/
OnExtensionUnloaded(CefRefPtr<CefExtension> extension)94   virtual void OnExtensionUnloaded(CefRefPtr<CefExtension> extension) {}
95 
96   ///
97   // Called when an extension needs a browser to host a background script
98   // specified via the "background" manifest key. The browser will have no
99   // visible window and cannot be displayed. |extension| is the extension that
100   // is loading the background script. |url| is an internally generated
101   // reference to an HTML page that will be used to load the background script
102   // via a <script> src attribute. To allow creation of the browser optionally
103   // modify |client| and |settings| and return false. To cancel creation of the
104   // browser (and consequently cancel load of the background script) return
105   // true. Successful creation will be indicated by a call to
106   // CefLifeSpanHandler::OnAfterCreated, and CefBrowserHost::IsBackgroundHost
107   // will return true for the resulting browser. See
108   // https://developer.chrome.com/extensions/event_pages for more information
109   // about extension background script usage.
110   ///
111   /*--cef()--*/
OnBeforeBackgroundBrowser(CefRefPtr<CefExtension> extension,const CefString & url,CefRefPtr<CefClient> & client,CefBrowserSettings & settings)112   virtual bool OnBeforeBackgroundBrowser(CefRefPtr<CefExtension> extension,
113                                          const CefString& url,
114                                          CefRefPtr<CefClient>& client,
115                                          CefBrowserSettings& settings) {
116     return false;
117   }
118 
119   ///
120   // Called when an extension API (e.g. chrome.tabs.create) requests creation of
121   // a new browser. |extension| and |browser| are the source of the API call.
122   // |active_browser| may optionally be specified via the windowId property or
123   // returned via the GetActiveBrowser() callback and provides the default
124   // |client| and |settings| values for the new browser. |index| is the position
125   // value optionally specified via the index property. |url| is the URL that
126   // will be loaded in the browser. |active| is true if the new browser should
127   // be active when opened.  To allow creation of the browser optionally modify
128   // |windowInfo|, |client| and |settings| and return false. To cancel creation
129   // of the browser return true. Successful creation will be indicated by a call
130   // to CefLifeSpanHandler::OnAfterCreated. Any modifications to |windowInfo|
131   // will be ignored if |active_browser| is wrapped in a CefBrowserView.
132   ///
133   /*--cef()--*/
OnBeforeBrowser(CefRefPtr<CefExtension> extension,CefRefPtr<CefBrowser> browser,CefRefPtr<CefBrowser> active_browser,int index,const CefString & url,bool active,CefWindowInfo & windowInfo,CefRefPtr<CefClient> & client,CefBrowserSettings & settings)134   virtual bool OnBeforeBrowser(CefRefPtr<CefExtension> extension,
135                                CefRefPtr<CefBrowser> browser,
136                                CefRefPtr<CefBrowser> active_browser,
137                                int index,
138                                const CefString& url,
139                                bool active,
140                                CefWindowInfo& windowInfo,
141                                CefRefPtr<CefClient>& client,
142                                CefBrowserSettings& settings) {
143     return false;
144   }
145 
146   ///
147   // Called when no tabId is specified to an extension API call that accepts a
148   // tabId parameter (e.g. chrome.tabs.*). |extension| and |browser| are the
149   // source of the API call. Return the browser that will be acted on by the API
150   // call or return NULL to act on |browser|. The returned browser must share
151   // the same CefRequestContext as |browser|. Incognito browsers should not be
152   // considered unless the source extension has incognito access enabled, in
153   // which case |include_incognito| will be true.
154   ///
155   /*--cef()--*/
GetActiveBrowser(CefRefPtr<CefExtension> extension,CefRefPtr<CefBrowser> browser,bool include_incognito)156   virtual CefRefPtr<CefBrowser> GetActiveBrowser(
157       CefRefPtr<CefExtension> extension,
158       CefRefPtr<CefBrowser> browser,
159       bool include_incognito) {
160     return nullptr;
161   }
162 
163   ///
164   // Called when the tabId associated with |target_browser| is specified to an
165   // extension API call that accepts a tabId parameter (e.g. chrome.tabs.*).
166   // |extension| and |browser| are the source of the API call. Return true
167   // to allow access of false to deny access. Access to incognito browsers
168   // should not be allowed unless the source extension has incognito access
169   // enabled, in which case |include_incognito| will be true.
170   ///
171   /*--cef()--*/
CanAccessBrowser(CefRefPtr<CefExtension> extension,CefRefPtr<CefBrowser> browser,bool include_incognito,CefRefPtr<CefBrowser> target_browser)172   virtual bool CanAccessBrowser(CefRefPtr<CefExtension> extension,
173                                 CefRefPtr<CefBrowser> browser,
174                                 bool include_incognito,
175                                 CefRefPtr<CefBrowser> target_browser) {
176     return true;
177   }
178 
179   ///
180   // Called to retrieve an extension resource that would normally be loaded from
181   // disk (e.g. if a file parameter is specified to chrome.tabs.executeScript).
182   // |extension| and |browser| are the source of the resource request. |file| is
183   // the requested relative file path. To handle the resource request return
184   // true and execute |callback| either synchronously or asynchronously. For the
185   // default behavior which reads the resource from the extension directory on
186   // disk return false. Localization substitutions will not be applied to
187   // resources handled via this method.
188   ///
189   /*--cef()--*/
GetExtensionResource(CefRefPtr<CefExtension> extension,CefRefPtr<CefBrowser> browser,const CefString & file,CefRefPtr<CefGetExtensionResourceCallback> callback)190   virtual bool GetExtensionResource(
191       CefRefPtr<CefExtension> extension,
192       CefRefPtr<CefBrowser> browser,
193       const CefString& file,
194       CefRefPtr<CefGetExtensionResourceCallback> callback) {
195     return false;
196   }
197 };
198 
199 #endif  // CEF_INCLUDE_CEF_EXTENSION_HANDLER_H_
200