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_SCHEME_H_ 38 #define CEF_INCLUDE_CEF_SCHEME_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_handler.h" 46 #include "include/cef_response.h" 47 48 class CefSchemeHandlerFactory; 49 50 /// 51 // Register a scheme handler factory with the global request context. An empty 52 // |domain_name| value for a standard scheme will cause the factory to match all 53 // domain names. The |domain_name| value will be ignored for non-standard 54 // schemes. If |scheme_name| is a built-in scheme and no handler is returned by 55 // |factory| then the built-in scheme handler factory will be called. If 56 // |scheme_name| is a custom scheme then you must also implement the 57 // CefApp::OnRegisterCustomSchemes() method in all processes. This function may 58 // be called multiple times to change or remove the factory that matches the 59 // specified |scheme_name| and optional |domain_name|. Returns false if an error 60 // occurs. This function may be called on any thread in the browser process. 61 // Using this function is equivalent to calling 62 // CefRequestContext::GetGlobalContext()->RegisterSchemeHandlerFactory(). 63 /// 64 /*--cef(optional_param=domain_name,optional_param=factory)--*/ 65 bool CefRegisterSchemeHandlerFactory( 66 const CefString& scheme_name, 67 const CefString& domain_name, 68 CefRefPtr<CefSchemeHandlerFactory> factory); 69 70 /// 71 // Clear all scheme handler factories registered with the global request 72 // context. Returns false on error. This function may be called on any thread in 73 // the browser process. Using this function is equivalent to calling 74 // CefRequestContext::GetGlobalContext()->ClearSchemeHandlerFactories(). 75 /// 76 /*--cef()--*/ 77 bool CefClearSchemeHandlerFactories(); 78 79 /// 80 // Class that manages custom scheme registrations. 81 /// 82 /*--cef(source=library)--*/ 83 class CefSchemeRegistrar : public CefBaseScoped { 84 public: 85 /// 86 // Register a custom scheme. This method should not be called for the built-in 87 // HTTP, HTTPS, FILE, FTP, ABOUT and DATA schemes. 88 // 89 // See cef_scheme_options_t for possible values for |options|. 90 // 91 // This function may be called on any thread. It should only be called once 92 // per unique |scheme_name| value. If |scheme_name| is already registered or 93 // if an error occurs this method will return false. 94 /// 95 /*--cef()--*/ 96 virtual bool AddCustomScheme(const CefString& scheme_name, int options) = 0; 97 }; 98 99 /// 100 // Class that creates CefResourceHandler instances for handling scheme requests. 101 // The methods of this class will always be called on the IO thread. 102 /// 103 /*--cef(source=client,no_debugct_check)--*/ 104 class CefSchemeHandlerFactory : public virtual CefBaseRefCounted { 105 public: 106 /// 107 // Return a new resource handler instance to handle the request or an empty 108 // reference to allow default handling of the request. |browser| and |frame| 109 // will be the browser window and frame respectively that originated the 110 // request or NULL if the request did not originate from a browser window 111 // (for example, if the request came from CefURLRequest). The |request| object 112 // passed to this method cannot be modified. 113 /// 114 /*--cef(optional_param=browser,optional_param=frame)--*/ 115 virtual CefRefPtr<CefResourceHandler> Create( 116 CefRefPtr<CefBrowser> browser, 117 CefRefPtr<CefFrame> frame, 118 const CefString& scheme_name, 119 CefRefPtr<CefRequest> request) = 0; 120 }; 121 122 #endif // CEF_INCLUDE_CEF_SCHEME_H_ 123