mirror of
https://github.com/cefsharp/CefSharp.git
synced 2026-12-05 11:42:36 +00:00
update to CEF trunk r199, add IBeforeCreated
This commit is contained in:
@@ -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(
|
||||
|
||||
+4
-4
@@ -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<SchemeHandlerFactoryWrapper> wrapper = new SchemeHandlerFactoryWrapper(factory);
|
||||
return CefRegisterScheme(toNative(schemeName), toNative(hostName), static_cast<CefRefPtr<CefSchemeHandlerFactory>>(wrapper));
|
||||
return CefRegisterScheme(toNative(schemeName), toNative(hostName), is_standard, static_cast<CefRefPtr<CefSchemeHandlerFactory>>(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)
|
||||
|
||||
@@ -301,6 +301,10 @@
|
||||
RelativePath=".\HandlerAdapter.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\IBeforeCreated.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\IBeforeResourceLoad.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> _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; }
|
||||
|
||||
@@ -68,6 +68,19 @@ namespace CefSharp
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
CefHandler::RetVal HandlerAdapter::HandleBeforeCreated(CefRefPtr<CefBrowser> parentBrowser, CefWindowInfo& createInfo, bool popup, const CefPopupFeatures& popupFeatures, CefRefPtr<CefHandler>& 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<CefBrowser> browser, CefRefPtr<CefRequest> request, CefString& redirectUrl, CefRefPtr<CefStreamReader>& resourceStream, CefString& mimeType, int loadFlags)
|
||||
{
|
||||
IBeforeResourceLoad^ handler = _browserControl->BeforeResourceLoadHandler;
|
||||
@@ -115,5 +128,4 @@ namespace CefSharp
|
||||
_browserControl->RaiseConsoleMessage(messageStr, sourceStr, line);
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -37,10 +37,10 @@ namespace CefSharp
|
||||
virtual RetVal HandleLoadEnd(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, bool isMainContent, int httpStatusCode);
|
||||
virtual RetVal HandleJSBinding(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Value> object);
|
||||
virtual RetVal HandleConsoleMessage(CefRefPtr<CefBrowser> browser, const CefString& message, const CefString& source, int line);
|
||||
virtual RetVal HandleBeforeResourceLoad(CefRefPtr<CefBrowser> browser, CefRefPtr<CefRequest> request, CefString& redirectUrl, CefRefPtr<CefStreamReader>& resourceStream, CefString& mimeType,int loadFlags);
|
||||
virtual RetVal HandleBeforeCreated(CefRefPtr<CefBrowser> parentBrowser, CefWindowInfo& createInfo, bool popup, const CefPopupFeatures& popupFeatures, CefRefPtr<CefHandler>& handler, CefString& url, CefBrowserSettings& settings);
|
||||
virtual RetVal HandleBeforeResourceLoad(CefRefPtr<CefBrowser> browser, CefRefPtr<CefRequest> request, CefString& redirectUrl, CefRefPtr<CefStreamReader>& resourceStream, CefString& mimeType,int loadFlags);
|
||||
|
||||
virtual RetVal HandleBeforeBrowse(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefRequest> request, NavType navType, bool isRedirect) { return RV_CONTINUE; }
|
||||
virtual RetVal HandleBeforeCreated(CefRefPtr<CefBrowser> parentBrowser, CefWindowInfo& createInfo, bool popup, const CefPopupFeatures& popupFeatures, CefRefPtr<CefHandler>& handler, CefString& url, CefBrowserSettings& settings) { return RV_CONTINUE; }
|
||||
virtual RetVal HandleBeforeBrowse(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefRequest> request, NavType navType, bool isRedirect) { return RV_CONTINUE; }
|
||||
virtual RetVal HandleLoadError(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, ErrorCode errorCode, const CefString& failedUrl, CefString& errorText) { return RV_CONTINUE; }
|
||||
virtual RetVal HandleDownloadResponse(CefRefPtr<CefBrowser> browser, const CefString& mimeType, const CefString& fileName, int64 contentLength, CefRefPtr<CefDownloadHandler>& handler) { return RV_CONTINUE; }
|
||||
virtual RetVal HandleAuthenticationRequest(CefRefPtr<CefBrowser> browser, bool isProxy, const CefString& host, const CefString& realm, const CefString& scheme, CefString& username, CefString& password) { return RV_HANDLED; }
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
}
|
||||
+28
-6
@@ -154,18 +154,40 @@ bool CefRegisterExtension(const CefString& extension_name,
|
||||
const CefString& javascript_code,
|
||||
CefRefPtr<CefV8Handler> 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:
|
||||
//
|
||||
// <scheme>://<username>:<password>@<host>:<port>/<url-path>
|
||||
//
|
||||
// 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<CefSchemeHandlerFactory> factory);
|
||||
|
||||
|
||||
typedef cef_thread_id_t CefThreadId;
|
||||
|
||||
// CEF maintains multiple internal threads that are used for handling different
|
||||
|
||||
+28
-5
@@ -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:
|
||||
//
|
||||
// <scheme>://<username>:<password>@<host>:<port>/<url-path>
|
||||
//
|
||||
// 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
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -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<WebViewImpl*>(
|
||||
+- 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<CefBrowserImpl> 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(
|
||||
Reference in New Issue
Block a user