diff --git a/CefSharp.Example/Browser.cs b/CefSharp.Example/Browser.cs index f52f0d822..57807a043 100644 --- a/CefSharp.Example/Browser.cs +++ b/CefSharp.Example/Browser.cs @@ -7,7 +7,7 @@ using CefSharp; namespace CefSharp.Example { - public partial class Browser : Form, IBeforeResourceLoad + public partial class Browser : Form, IBeforeCreated, IBeforeResourceLoad { private readonly CefWebBrowser _browserControl; private const string cefSharpHomeUrl = "https://github.com/chillitom/CefSharp"; @@ -19,7 +19,8 @@ namespace CefSharp.Example _browserControl = new CefWebBrowser(cefSharpHomeUrl); _browserControl.Dock = DockStyle.Fill; _browserControl.PropertyChanged += HandleBrowserPropertyChanged; - _browserControl.ConsoleMessage += HandleConsoleMessage; + _browserControl.ConsoleMessage += HandleConsoleMessage; + _browserControl.BeforeCreatedHandler = this; _browserControl.BeforeResourceLoadHandler = this; toolStripContainer.ContentPanel.Controls.Add(_browserControl); } @@ -93,11 +94,18 @@ namespace CefSharp.Example { _browserControl.Load(urlTextBox.Text); } + } + + public bool HandleBeforeCreated(bool popup, string url) + { + Console.WriteLine("HandleBeforeCreated: popup: {0}, url: {1}", popup, url); + + return true; } public void HandleBeforeResourceLoad(CefWebBrowser browserControl, IRequestResponse requestResponse) { - IRequest request = requestResponse.Request; + IRequest request = requestResponse.Request; if(request.Url.StartsWith("http://test/resource/load")) { Stream resourceStream = new MemoryStream(Encoding.UTF8.GetBytes( diff --git a/CefSharp/CefSharp.h b/CefSharp/CefSharp.h index becb0951f..3b0b63bfd 100644 --- a/CefSharp/CefSharp.h +++ b/CefSharp/CefSharp.h @@ -50,7 +50,7 @@ namespace CefSharp { String^ get() { - return "trunk r196"; + return "trunk r199"; } } @@ -73,17 +73,17 @@ namespace CefSharp return success; } - static bool RegisterScheme(String^ schemeName, String^ hostName, ISchemeHandlerFactory^ factory) + static bool RegisterScheme(String^ schemeName, String^ hostName, bool is_standard, ISchemeHandlerFactory^ factory) { hostName = hostName ? hostName : ""; CefRefPtr wrapper = new SchemeHandlerFactoryWrapper(factory); - return CefRegisterScheme(toNative(schemeName), toNative(hostName), static_cast>(wrapper)); + return CefRegisterScheme(toNative(schemeName), toNative(hostName), is_standard, static_cast>(wrapper)); } static bool RegisterScheme(String^ schemeName, ISchemeHandlerFactory^ factory) { - return RegisterScheme(schemeName, nullptr, factory); + return RegisterScheme(schemeName, nullptr, true, factory); } static bool RegisterJsObject(String^ name, Object^ objectToBind) diff --git a/CefSharp/CefSharp.vcproj b/CefSharp/CefSharp.vcproj index acb5b5153..742f721a2 100644 --- a/CefSharp/CefSharp.vcproj +++ b/CefSharp/CefSharp.vcproj @@ -301,6 +301,10 @@ RelativePath=".\HandlerAdapter.h" > + + diff --git a/CefSharp/CefWebBrowser.h b/CefSharp/CefWebBrowser.h index 1090e133c..ee6b013f8 100644 --- a/CefSharp/CefWebBrowser.h +++ b/CefSharp/CefWebBrowser.h @@ -3,6 +3,7 @@ #include "CefSharp.h" #include "HandlerAdapter.h" +#include "IBeforeCreated.h" #include "IBeforeResourceLoad.h" #include "ConsoleMessageEventArgs.h" #include "RtzCountdownEvent.h" @@ -25,7 +26,8 @@ namespace CefSharp String^ _jsResult; bool _jsError; - IBeforeResourceLoad^ _beforeResourceLoadHandler; + IBeforeCreated^ _beforeCreatedHandler; + IBeforeResourceLoad^ _beforeResourceLoadHandler; MCefRefPtr _handlerAdapter; AutoResetEvent^ _runJsFinished; @@ -103,6 +105,12 @@ namespace CefSharp String^ get() { return _address; } } + property IBeforeCreated^ BeforeCreatedHandler + { + IBeforeCreated^ get() { return _beforeCreatedHandler; } + void set(IBeforeCreated^ handler) { _beforeCreatedHandler = handler; } + } + property IBeforeResourceLoad^ BeforeResourceLoadHandler { IBeforeResourceLoad^ get() { return _beforeResourceLoadHandler; } diff --git a/CefSharp/HandlerAdapter.cpp b/CefSharp/HandlerAdapter.cpp index a89b3c446..520c4f481 100644 --- a/CefSharp/HandlerAdapter.cpp +++ b/CefSharp/HandlerAdapter.cpp @@ -68,6 +68,19 @@ namespace CefSharp return RV_CONTINUE; } + CefHandler::RetVal HandlerAdapter::HandleBeforeCreated(CefRefPtr parentBrowser, CefWindowInfo& createInfo, bool popup, const CefPopupFeatures& popupFeatures, CefRefPtr& handler, CefString& url, CefBrowserSettings& settings) + { + IBeforeCreated^ beforeCreatedHandler = _browserControl->BeforeCreatedHandler; + if (beforeCreatedHandler == nullptr || beforeCreatedHandler->HandleBeforeCreated(popup, toClr(url))) + { + return RV_CONTINUE; + } + else + { + return RV_HANDLED; + } + } + CefHandler::RetVal HandlerAdapter::HandleBeforeResourceLoad(CefRefPtr browser, CefRefPtr request, CefString& redirectUrl, CefRefPtr& resourceStream, CefString& mimeType, int loadFlags) { IBeforeResourceLoad^ handler = _browserControl->BeforeResourceLoadHandler; @@ -115,5 +128,4 @@ namespace CefSharp _browserControl->RaiseConsoleMessage(messageStr, sourceStr, line); return RV_CONTINUE; } - } \ No newline at end of file diff --git a/CefSharp/HandlerAdapter.h b/CefSharp/HandlerAdapter.h index ed18ae5fe..bcf02e453 100644 --- a/CefSharp/HandlerAdapter.h +++ b/CefSharp/HandlerAdapter.h @@ -37,10 +37,10 @@ namespace CefSharp virtual RetVal HandleLoadEnd(CefRefPtr browser, CefRefPtr frame, bool isMainContent, int httpStatusCode); virtual RetVal HandleJSBinding(CefRefPtr browser, CefRefPtr frame, CefRefPtr object); virtual RetVal HandleConsoleMessage(CefRefPtr browser, const CefString& message, const CefString& source, int line); - virtual RetVal HandleBeforeResourceLoad(CefRefPtr browser, CefRefPtr request, CefString& redirectUrl, CefRefPtr& resourceStream, CefString& mimeType,int loadFlags); + virtual RetVal HandleBeforeCreated(CefRefPtr parentBrowser, CefWindowInfo& createInfo, bool popup, const CefPopupFeatures& popupFeatures, CefRefPtr& handler, CefString& url, CefBrowserSettings& settings); + virtual RetVal HandleBeforeResourceLoad(CefRefPtr browser, CefRefPtr request, CefString& redirectUrl, CefRefPtr& resourceStream, CefString& mimeType,int loadFlags); - virtual RetVal HandleBeforeBrowse(CefRefPtr browser, CefRefPtr frame, CefRefPtr request, NavType navType, bool isRedirect) { return RV_CONTINUE; } - virtual RetVal HandleBeforeCreated(CefRefPtr parentBrowser, CefWindowInfo& createInfo, bool popup, const CefPopupFeatures& popupFeatures, CefRefPtr& handler, CefString& url, CefBrowserSettings& settings) { return RV_CONTINUE; } + virtual RetVal HandleBeforeBrowse(CefRefPtr browser, CefRefPtr frame, CefRefPtr request, NavType navType, bool isRedirect) { return RV_CONTINUE; } virtual RetVal HandleLoadError(CefRefPtr browser, CefRefPtr frame, ErrorCode errorCode, const CefString& failedUrl, CefString& errorText) { return RV_CONTINUE; } virtual RetVal HandleDownloadResponse(CefRefPtr browser, const CefString& mimeType, const CefString& fileName, int64 contentLength, CefRefPtr& handler) { return RV_CONTINUE; } virtual RetVal HandleAuthenticationRequest(CefRefPtr browser, bool isProxy, const CefString& host, const CefString& realm, const CefString& scheme, CefString& username, CefString& password) { return RV_HANDLED; } diff --git a/CefSharp/IBeforeCreated.h b/CefSharp/IBeforeCreated.h new file mode 100644 index 000000000..d3d8e3de4 --- /dev/null +++ b/CefSharp/IBeforeCreated.h @@ -0,0 +1,16 @@ +#include "stdafx.h" +#pragma once + +using namespace System; + +namespace CefSharp +{ + public interface class IBeforeCreated + { + public: + + /// called before a browser is created. + /// return false to prevent the browser from being created. + bool HandleBeforeCreated(bool popup, String^ url); + }; +} \ No newline at end of file diff --git a/include/cef.h b/include/cef.h index 066ef0bfa..fdac1d259 100644 --- a/include/cef.h +++ b/include/cef.h @@ -154,18 +154,40 @@ bool CefRegisterExtension(const CefString& extension_name, const CefString& javascript_code, CefRefPtr handler); - +// CEF supports two types of schemes, standard and non-standard. +// +// Standard schemes are subject to URL canonicalization and parsing rules as +// defined in the Common Internet Scheme Syntax RFC 1738 Section 3.1 available +// at http://www.ietf.org/rfc/rfc1738.txt +// +// In particular, the syntax for standard scheme URLs must be of the form: +// +// ://:@:/ +// +// Standard scheme URLs must have a host component that is a fully qualified +// domain name as defined in Section 3.5 of RFC 1034 [13] and Section 2.1 of RFC +// 1123. These URLs will be canonicalized to "scheme://host/path" in the +// simplest case and "scheme://username:password@host:port/path" in the most +// explicit case. For example, "scheme:host/path" and "scheme:///host/path" will +// both be canonicalized to "scheme://host/path". +// +// For non-standard scheme URLs only the "scheme:" component is parsed and +// canonicalized. The remainder of the URL will be passed to the handler as-is. +// For example, "scheme:///some%20text" will remain the same. Non-standard +// scheme URLs cannot be used as a target for form submission. +// // Register a custom scheme handler factory for the specified |scheme_name| and -// |host_name|. All URLs beginning with scheme_name://host_name/ can be handled -// by CefSchemeHandler instances returned by the factory. Specify an empty -// |host_name| value to match all host names. This function may be called on any -// thread. +// optional |host_name|. Specifying an empty |host_name| value for standard +// schemes will match all host names. The |host_name| value will be ignored for +// non-standard schemes. Set |is_standard| to true to register as a standard +// scheme or false to register a non-standard scheme. This function may be +// called on any thread. /*--cef()--*/ bool CefRegisterScheme(const CefString& scheme_name, const CefString& host_name, + bool is_standard, CefRefPtr factory); - typedef cef_thread_id_t CefThreadId; // CEF maintains multiple internal threads that are used for handling different diff --git a/include/cef_capi.h b/include/cef_capi.h index d418ab824..1fc59e527 100644 --- a/include/cef_capi.h +++ b/include/cef_capi.h @@ -123,13 +123,36 @@ CEF_EXPORT void cef_do_message_loop_work(); CEF_EXPORT int cef_register_extension(const cef_string_t* extension_name, const cef_string_t* javascript_code, struct _cef_v8handler_t* handler); +// CEF supports two types of schemes, standard and non-standard. +// +// Standard schemes are subject to URL canonicalization and parsing rules as +// defined in the Common Internet Scheme Syntax RFC 1738 Section 3.1 available +// at http://www.ietf.org/rfc/rfc1738.txt +// +// In particular, the syntax for standard scheme URLs must be of the form: +// +// ://:@:/ +// +// Standard scheme URLs must have a host component that is a fully qualified +// domain name as defined in Section 3.5 of RFC 1034 [13] and Section 2.1 of RFC +// 1123. These URLs will be canonicalized to "scheme://host/path" in the +// simplest case and "scheme://username:password@host:port/path" in the most +// explicit case. For example, "scheme:host/path" and "scheme:///host/path" will +// both be canonicalized to "scheme://host/path". +// +// For non-standard scheme URLs only the "scheme:" component is parsed and +// canonicalized. The remainder of the URL will be passed to the handler as-is. +// For example, "scheme:///some%20text" will remain the same. Non-standard +// scheme URLs cannot be used as a target for form submission. +// // Register a custom scheme handler factory for the specified |scheme_name| and -// |host_name|. All URLs beginning with scheme_name://host_name/ can be handled -// by cef_scheme_handler_t instances returned by the factory. Specify an NULL -// |host_name| value to match all host names. This function may be called on any -// thread. +// optional |host_name|. Specifying an NULL |host_name| value for standard +// schemes will match all host names. The |host_name| value will be ignored for +// non-standard schemes. Set |is_standard| to true (1) to register as a standard +// scheme or false (0) to register a non-standard scheme. This function may be +// called on any thread. CEF_EXPORT int cef_register_scheme(const cef_string_t* scheme_name, - const cef_string_t* host_name, + const cef_string_t* host_name, int is_standard, struct _cef_scheme_handler_factory_t* factory); // CEF maintains multiple internal threads that are used for handling different diff --git a/libs/Debug/libcef.lib b/libs/Debug/libcef.lib index 3751ef1b6..4a2ac245d 100644 Binary files a/libs/Debug/libcef.lib and b/libs/Debug/libcef.lib differ diff --git a/libs/Debug/libcef_dll_wrapper.lib b/libs/Debug/libcef_dll_wrapper.lib index 30169cabf..6fc8085bc 100644 Binary files a/libs/Debug/libcef_dll_wrapper.lib and b/libs/Debug/libcef_dll_wrapper.lib differ diff --git a/libs/Release/libcef.lib b/libs/Release/libcef.lib index dadd6d323..baa65af72 100644 Binary files a/libs/Release/libcef.lib and b/libs/Release/libcef.lib differ diff --git a/libs/Release/libcef_dll_wrapper.lib b/libs/Release/libcef_dll_wrapper.lib index 04b238cd6..c89bda380 100644 Binary files a/libs/Release/libcef_dll_wrapper.lib and b/libs/Release/libcef_dll_wrapper.lib differ diff --git a/patches/cef_5_url.patch b/patches/cef_5_url.patch new file mode 100644 index 000000000..a2f192ad3 --- /dev/null +++ b/patches/cef_5_url.patch @@ -0,0 +1,88 @@ +Index: patch/patches/5_url_fix.patch +=================================================================== +--- patch/patches/5_url_fix.patch (revision 0) ++++ patch/patches/5_url_fix.patch (revision 0) +@@ -0,0 +1,34 @@ ++Index: WebKit/Source/WebKit/chromium/src/ChromeClientImpl.cpp ++=================================================================== ++--- WebKit/Source/WebKit/chromium/src/ChromeClientImpl.cpp (revision 78450) +++++ WebKit/Source/WebKit/chromium/src/ChromeClientImpl.cpp (working copy) ++@@ -257,7 +257,7 @@ ++ } ++ ++ Page* ChromeClientImpl::createWindow( ++- Frame* frame, const FrameLoadRequest& r, const WindowFeatures& features, const NavigationAction&) +++ Frame* frame, const FrameLoadRequest& r, const WindowFeatures& features, const NavigationAction& action) ++ { ++ if (!m_webView->client()) ++ return 0; ++@@ -266,7 +266,7 @@ ++ if (!r.resourceRequest().isEmpty()) ++ request.bind(r.resourceRequest()); ++ WebViewImpl* newView = static_cast( ++- m_webView->client()->createView(WebFrameImpl::fromFrame(frame), request, features, r.frameName())); +++ m_webView->client()->createView(WebFrameImpl::fromFrame(frame), action.url(), request, features, r.frameName())); ++ if (!newView) ++ return 0; ++ ++Index: WebKit/Source/WebKit/chromium/public/WebViewClient.h ++=================================================================== ++--- WebKit/Source/WebKit/chromium/public/WebViewClient.h (revision 78450) +++++ WebKit/Source/WebKit/chromium/public/WebViewClient.h (working copy) ++@@ -88,6 +88,7 @@ ++ // The request parameter is only for the client to check if the request ++ // could be fulfilled. The client should not load the request. ++ virtual WebView* createView(WebFrame* creator, +++ const WebURL& url, ++ const WebURLRequest& request, ++ const WebWindowFeatures& features, ++ const WebString& name) { +Index: patch/patch_source.cfg +=================================================================== +--- patch/patch_source.cfg (revision 199) ++++ patch/patch_source.cfg (working copy) +@@ -3,4 +3,6 @@ + # file entry should be proceeded by the code review or bug report link that it + # relates to. + patches = { ++ # http://code.google.com/p/chromiumembedded/issues/detail?id=5 ++ '5_url_fix' : '../third_party/' + } +Index: libcef/browser_webview_delegate.cc +=================================================================== +--- libcef/browser_webview_delegate.cc (revision 199) ++++ libcef/browser_webview_delegate.cc (working copy) +@@ -166,15 +166,15 @@ + // WebViewClient ------------------------------------------------------------- + + WebView* BrowserWebViewDelegate::createView(WebFrame* creator, +- const WebURLRequest& request, const WebWindowFeatures& features, ++ const WebURL& url, const WebURLRequest& request, const WebWindowFeatures& features, + const WebString& name) { +- CefString url; +- if (!request.isNull()) +- url = request.url().spec().utf16(); ++ CefString cefUrl; ++ if (!url.isNull()) ++ cefUrl = url.spec().utf16(); + CefPopupFeatures cefFeatures; + TranslatePopupFeatures(features, cefFeatures); + CefRefPtr browser = +- browser_->UIT_CreatePopupWindow(url, cefFeatures); ++ browser_->UIT_CreatePopupWindow(cefUrl, cefFeatures); + return browser.get() ? browser->UIT_GetWebView() : NULL; + } + +Index: libcef/browser_webview_delegate.h +=================================================================== +--- libcef/browser_webview_delegate.h (revision 199) ++++ libcef/browser_webview_delegate.h (working copy) +@@ -52,7 +52,7 @@ + public: + // WebKit::WebViewClient + virtual WebKit::WebView* createView( +- WebKit::WebFrame* creator, const WebKit::WebURLRequest& request, ++ WebKit::WebFrame* creator, const WebKit::WebURL& url, const WebKit::WebURLRequest& request, + const WebKit::WebWindowFeatures& features, const WebKit::WebString& name); + virtual WebKit::WebWidget* createPopupMenu(WebKit::WebPopupType popup_type); + virtual WebKit::WebWidget* createPopupMenu(