1 // Copyright (c) 2013 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_REQUEST_CONTEXT_HANDLER_H_ 38 #define CEF_INCLUDE_CEF_REQUEST_CONTEXT_HANDLER_H_ 39 #pragma once 40 41 #include "include/cef_base.h" 42 #include "include/cef_browser.h" 43 #include "include/cef_frame.h" 44 #include "include/cef_request.h" 45 #include "include/cef_resource_request_handler.h" 46 #include "include/cef_web_plugin.h" 47 48 /// 49 // Implement this interface to provide handler implementations. The handler 50 // instance will not be released until all objects related to the context have 51 // been destroyed. 52 /// 53 /*--cef(source=client,no_debugct_check)--*/ 54 class CefRequestContextHandler : public virtual CefBaseRefCounted { 55 public: 56 typedef cef_plugin_policy_t PluginPolicy; 57 58 /// 59 // Called on the browser process UI thread immediately after the request 60 // context has been initialized. 61 /// 62 /*--cef()--*/ OnRequestContextInitialized(CefRefPtr<CefRequestContext> request_context)63 virtual void OnRequestContextInitialized( 64 CefRefPtr<CefRequestContext> request_context) {} 65 66 /// 67 // Called on multiple browser process threads before a plugin instance is 68 // loaded. |mime_type| is the mime type of the plugin that will be loaded. 69 // |plugin_url| is the content URL that the plugin will load and may be empty. 70 // |is_main_frame| will be true if the plugin is being loaded in the main 71 // (top-level) frame, |top_origin_url| is the URL for the top-level frame that 72 // contains the plugin when loading a specific plugin instance or empty when 73 // building the initial list of enabled plugins for 'navigator.plugins' 74 // JavaScript state. |plugin_info| includes additional information about the 75 // plugin that will be loaded. |plugin_policy| is the recommended policy. 76 // Modify |plugin_policy| and return true to change the policy. Return false 77 // to use the recommended policy. The default plugin policy can be set at 78 // runtime using the `--plugin-policy=[allow|detect|block]` command-line flag. 79 // Decisions to mark a plugin as disabled by setting |plugin_policy| to 80 // PLUGIN_POLICY_DISABLED may be cached when |top_origin_url| is empty. To 81 // purge the plugin list cache and potentially trigger new calls to this 82 // method call CefRequestContext::PurgePluginListCache. 83 /// 84 /*--cef(optional_param=plugin_url,optional_param=top_origin_url)--*/ OnBeforePluginLoad(const CefString & mime_type,const CefString & plugin_url,bool is_main_frame,const CefString & top_origin_url,CefRefPtr<CefWebPluginInfo> plugin_info,PluginPolicy * plugin_policy)85 virtual bool OnBeforePluginLoad(const CefString& mime_type, 86 const CefString& plugin_url, 87 bool is_main_frame, 88 const CefString& top_origin_url, 89 CefRefPtr<CefWebPluginInfo> plugin_info, 90 PluginPolicy* plugin_policy) { 91 return false; 92 } 93 94 /// 95 // Called on the browser process IO thread before a resource request is 96 // initiated. The |browser| and |frame| values represent the source of the 97 // request, and may be NULL for requests originating from service workers or 98 // CefURLRequest. |request| represents the request contents and cannot be 99 // modified in this callback. |is_navigation| will be true if the resource 100 // request is a navigation. |is_download| will be true if the resource request 101 // is a download. |request_initiator| is the origin (scheme + domain) of the 102 // page that initiated the request. Set |disable_default_handling| to true to 103 // disable default handling of the request, in which case it will need to be 104 // handled via CefResourceRequestHandler::GetResourceHandler or it will be 105 // canceled. To allow the resource load to proceed with default handling 106 // return NULL. To specify a handler for the resource return a 107 // CefResourceRequestHandler object. This method will not be called if the 108 // client associated with |browser| returns a non-NULL value from 109 // CefRequestHandler::GetResourceRequestHandler for the same request 110 // (identified by CefRequest::GetIdentifier). 111 /// 112 /*--cef(optional_param=browser,optional_param=frame, 113 optional_param=request_initiator)--*/ GetResourceRequestHandler(CefRefPtr<CefBrowser> browser,CefRefPtr<CefFrame> frame,CefRefPtr<CefRequest> request,bool is_navigation,bool is_download,const CefString & request_initiator,bool & disable_default_handling)114 virtual CefRefPtr<CefResourceRequestHandler> GetResourceRequestHandler( 115 CefRefPtr<CefBrowser> browser, 116 CefRefPtr<CefFrame> frame, 117 CefRefPtr<CefRequest> request, 118 bool is_navigation, 119 bool is_download, 120 const CefString& request_initiator, 121 bool& disable_default_handling) { 122 return nullptr; 123 } 124 }; 125 126 #endif // CEF_INCLUDE_CEF_REQUEST_CONTEXT_HANDLER_H_ 127