diff --git a/CefSharp.BrowserSubprocess.Core/Async/JavascriptAsyncMethodHandler.cpp b/CefSharp.BrowserSubprocess.Core/Async/JavascriptAsyncMethodHandler.cpp index 10ee3da576..525f6626f0 100644 --- a/CefSharp.BrowserSubprocess.Core/Async/JavascriptAsyncMethodHandler.cpp +++ b/CefSharp.BrowserSubprocess.Core/Async/JavascriptAsyncMethodHandler.cpp @@ -21,7 +21,7 @@ namespace CefSharp bool JavascriptAsyncMethodHandler::Execute(const CefString& name, CefRefPtr object, const CefV8ValueList& arguments, CefRefPtr& retval, CefString& exception) { auto context = CefV8Context::GetCurrentContext(); - auto browser = context->GetBrowser(); + auto frame = context->GetFrame(); CefRefPtr promiseData; CefRefPtr promiseException; @@ -59,13 +59,13 @@ namespace CefSharp SerializeV8Object(arguments[i], params, i, _callbackRegistry); } - SetInt64(argList, 0, context->GetFrame()->GetIdentifier()); + SetInt64(argList, 0, frame->GetIdentifier()); SetInt64(argList, 1, _objectId); SetInt64(argList, 2, callbackId); argList->SetString(3, name); argList->SetList(4, params); - browser->SendProcessMessage(CefProcessId::PID_BROWSER, request); + frame->SendProcessMessage(CefProcessId::PID_BROWSER, request); return true; } diff --git a/CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.cpp b/CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.cpp index 7ff7a54e66..4a7136db43 100644 --- a/CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.cpp +++ b/CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.cpp @@ -46,7 +46,7 @@ namespace CefSharp }; // CefRenderProcessHandler - void CefAppUnmanagedWrapper::OnBrowserCreated(CefRefPtr browser) + void CefAppUnmanagedWrapper::OnBrowserCreated(CefRefPtr browser, CefRefPtr extraInfo) { auto wrapper = gcnew CefBrowserWrapper(browser); _onBrowserCreated->Invoke(wrapper); @@ -125,7 +125,7 @@ namespace CefSharp SetInt64(contextCreatedMessage->GetArgumentList(), 0, frame->GetIdentifier()); - browser->SendProcessMessage(CefProcessId::PID_BROWSER, contextCreatedMessage); + frame->SendProcessMessage(CefProcessId::PID_BROWSER, contextCreatedMessage); }; void CefAppUnmanagedWrapper::OnContextReleased(CefRefPtr browser, CefRefPtr frame, CefRefPtr context) @@ -143,7 +143,7 @@ namespace CefSharp SetInt64(contextReleasedMessage->GetArgumentList(), 0, frame->GetIdentifier()); - browser->SendProcessMessage(CefProcessId::PID_BROWSER, contextReleasedMessage); + frame->SendProcessMessage(CefProcessId::PID_BROWSER, contextReleasedMessage); auto browserWrapper = FindBrowserWrapper(browser->GetIdentifier()); @@ -202,7 +202,7 @@ namespace CefSharp list->SetBool(1, false); } - browser->SendProcessMessage(CefProcessId::PID_BROWSER, focusedNodeChangedMessage); + frame->SendProcessMessage(CefProcessId::PID_BROWSER, focusedNodeChangedMessage); } void CefAppUnmanagedWrapper::OnUncaughtException(CefRefPtr browser, CefRefPtr frame, CefRefPtr context, CefRefPtr exception, CefRefPtr stackTrace) @@ -230,7 +230,7 @@ namespace CefSharp list->SetList(2, frames); - browser->SendProcessMessage(CefProcessId::PID_BROWSER, uncaughtExceptionMessage); + frame->SendProcessMessage(CefProcessId::PID_BROWSER, uncaughtExceptionMessage); } JavascriptRootObjectWrapper^ CefAppUnmanagedWrapper::GetJsRootObjectWrapper(int browserId, int64 frameId) @@ -269,7 +269,7 @@ namespace CefSharp return wrapper; } - bool CefAppUnmanagedWrapper::OnProcessMessageReceived(CefRefPtr browser, CefProcessId sourceProcessId, CefRefPtr message) + bool CefAppUnmanagedWrapper::OnProcessMessageReceived(CefRefPtr browser, CefRefPtr frame, CefProcessId sourceProcessId, CefRefPtr message) { auto handled = false; auto name = message->GetName(); @@ -313,7 +313,7 @@ namespace CefSharp responseArgList->SetBool(0, false); SetInt64(responseArgList, 1, callbackId); responseArgList->SetString(2, StringUtils::ToNative(errorMessage)); - browser->SendProcessMessage(sourceProcessId, response); + frame->SendProcessMessage(sourceProcessId, response); return true; } @@ -471,7 +471,7 @@ namespace CefSharp { responseArgList->SetString(2, errorMessage); } - browser->SendProcessMessage(sourceProcessId, response); + frame->SendProcessMessage(sourceProcessId, response); handled = true; } @@ -594,7 +594,7 @@ namespace CefSharp args->SetList(0, boundObjects); - browser->SendProcessMessage(CefProcessId::PID_BROWSER, msg); + frame->SendProcessMessage(CefProcessId::PID_BROWSER, msg); } } finally diff --git a/CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.h b/CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.h index ef037e6d19..65929e80d8 100644 --- a/CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.h +++ b/CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.h @@ -72,11 +72,11 @@ namespace CefSharp JavascriptRootObjectWrapper^ GetJsRootObjectWrapper(int browserId, int64 frameId); virtual DECL CefRefPtr GetRenderProcessHandler() OVERRIDE; - virtual DECL void OnBrowserCreated(CefRefPtr browser) OVERRIDE; + virtual DECL void OnBrowserCreated(CefRefPtr browser, CefRefPtr extraInfo) OVERRIDE; virtual DECL void OnBrowserDestroyed(CefRefPtr browser) OVERRIDE; virtual DECL void OnContextCreated(CefRefPtr browser, CefRefPtr frame, CefRefPtr context) OVERRIDE; virtual DECL void OnContextReleased(CefRefPtr browser, CefRefPtr frame, CefRefPtr context) OVERRIDE; - virtual DECL bool OnProcessMessageReceived(CefRefPtr browser, CefProcessId sourceProcessId, CefRefPtr message) OVERRIDE; + virtual DECL bool OnProcessMessageReceived(CefRefPtr browser, CefRefPtr frame, CefProcessId sourceProcessId, CefRefPtr message) OVERRIDE; virtual DECL void OnRenderThreadCreated(CefRefPtr extraInfo) OVERRIDE; virtual DECL void OnWebKitInitialized() OVERRIDE; virtual DECL void OnRegisterCustomSchemes(CefRawPtr registrar) OVERRIDE; diff --git a/CefSharp.BrowserSubprocess.Core/CefSharp.BrowserSubprocess.Core.vcxproj b/CefSharp.BrowserSubprocess.Core/CefSharp.BrowserSubprocess.Core.vcxproj index e1e0843d22..0341bb7ea7 100644 --- a/CefSharp.BrowserSubprocess.Core/CefSharp.BrowserSubprocess.Core.vcxproj +++ b/CefSharp.BrowserSubprocess.Core/CefSharp.BrowserSubprocess.Core.vcxproj @@ -1,6 +1,6 @@  - + Debug diff --git a/CefSharp.BrowserSubprocess.Core/JavascriptPostMessageHandler.h b/CefSharp.BrowserSubprocess.Core/JavascriptPostMessageHandler.h index 87f4da786d..33d352079b 100644 --- a/CefSharp.BrowserSubprocess.Core/JavascriptPostMessageHandler.h +++ b/CefSharp.BrowserSubprocess.Core/JavascriptPostMessageHandler.h @@ -42,7 +42,7 @@ namespace CefSharp auto context = CefV8Context::GetCurrentContext(); if (context.get()) { - auto browser = context->GetBrowser(); + auto frame = context->GetFrame(); if (context.get() && context->Enter()) { @@ -53,7 +53,7 @@ namespace CefSharp auto request = CefProcessMessage::Create(kJavascriptMessageReceived); auto argList = request->GetArgumentList(); - SetInt64(argList, 0, context->GetFrame()->GetIdentifier()); + SetInt64(argList, 0, frame->GetIdentifier()); auto params = CefListValue::Create(); SerializeV8Object(arguments[0], params, 0, _javascriptCallbackRegistry); @@ -64,7 +64,7 @@ namespace CefSharp argList->SetValue(1, params->GetValue(0)); } - browser->SendProcessMessage(CefProcessId::PID_BROWSER, request); + frame->SendProcessMessage(CefProcessId::PID_BROWSER, request); retval = CefV8Value::CreateNull(); } diff --git a/CefSharp.BrowserSubprocess.Core/RegisterBoundObjectHandler.h b/CefSharp.BrowserSubprocess.Core/RegisterBoundObjectHandler.h index e0d26eb4a8..64da2d6985 100644 --- a/CefSharp.BrowserSubprocess.Core/RegisterBoundObjectHandler.h +++ b/CefSharp.BrowserSubprocess.Core/RegisterBoundObjectHandler.h @@ -240,6 +240,7 @@ namespace CefSharp if (cachedObjects->Count == objectCount && ignoreCache == false) { auto frame = context->GetFrame(); + if (frame.get()) { if (Object::ReferenceEquals(_browserWrapper, nullptr)) @@ -268,45 +269,54 @@ namespace CefSharp response->SetValue("Message", CefV8Value::CreateString("OK"), CefV8Value::PropertyAttribute::V8_PROPERTY_ATTRIBUTE_READONLY); callback->Success(response); - NotifyObjectBound(browser, objectNamesWithBoundStatus); + NotifyObjectBound(frame, objectNamesWithBoundStatus); } } } else { - //Obtain a callbackId then send off the Request for objects - auto callbackId = _callbackRegistry->SaveMethodCallback(callback); + auto frame = context->GetFrame(); + if (frame.get()) + { + //Obtain a callbackId then send off the Request for objects + auto callbackId = _callbackRegistry->SaveMethodCallback(callback); - argList->SetInt(0, browser->GetIdentifier()); - SetInt64(argList, 1, context->GetFrame()->GetIdentifier()); - SetInt64(argList, 2, callbackId); - argList->SetList(3, params); + argList->SetInt(0, browser->GetIdentifier()); + SetInt64(argList, 1, frame->GetIdentifier()); + SetInt64(argList, 2, callbackId); + argList->SetList(3, params); - browser->SendProcessMessage(CefProcessId::PID_BROWSER, request); + frame->SendProcessMessage(CefProcessId::PID_BROWSER, request); + } } } else { - //Objects already bound or ignore cache + auto frame = context->GetFrame(); - //Response object has no Accessor or Interceptor - auto response = CefV8Value::CreateObject(NULL, NULL); + if (frame.get()) + { + //Objects already bound or ignore cache - //Objects already bound so we immediately resolve the Promise - response->SetValue("Success", CefV8Value::CreateBool(false), CefV8Value::PropertyAttribute::V8_PROPERTY_ATTRIBUTE_READONLY); - response->SetValue("Count", CefV8Value::CreateInt(0), CefV8Value::PropertyAttribute::V8_PROPERTY_ATTRIBUTE_READONLY); - response->SetValue("Message", CefV8Value::CreateString("Object(s) already bound"), CefV8Value::PropertyAttribute::V8_PROPERTY_ATTRIBUTE_READONLY); + //Response object has no Accessor or Interceptor + auto response = CefV8Value::CreateObject(NULL, NULL); - CefV8ValueList returnArgs; - returnArgs.push_back(response); - //If all the requested objects are bound then we immediately execute resolve - //with Success true and Count of 0 - resolve->ExecuteFunctionWithContext(context, nullptr, returnArgs); + //Objects already bound so we immediately resolve the Promise + response->SetValue("Success", CefV8Value::CreateBool(false), CefV8Value::PropertyAttribute::V8_PROPERTY_ATTRIBUTE_READONLY); + response->SetValue("Count", CefV8Value::CreateInt(0), CefV8Value::PropertyAttribute::V8_PROPERTY_ATTRIBUTE_READONLY); + response->SetValue("Message", CefV8Value::CreateString("Object(s) already bound"), CefV8Value::PropertyAttribute::V8_PROPERTY_ATTRIBUTE_READONLY); - if (notifyIfAlreadyBound) - { - NotifyObjectBound(browser, objectNamesWithBoundStatus); + CefV8ValueList returnArgs; + returnArgs.push_back(response); + //If all the requested objects are bound then we immediately execute resolve + //with Success true and Count of 0 + resolve->ExecuteFunctionWithContext(context, nullptr, returnArgs); + + if (notifyIfAlreadyBound) + { + NotifyObjectBound(frame, objectNamesWithBoundStatus); + } } } } @@ -331,7 +341,7 @@ namespace CefSharp } private: - void NotifyObjectBound(const CefRefPtr browser, List^>^ objectNamesWithBoundStatus) + void NotifyObjectBound(const CefRefPtr frame, List^>^ objectNamesWithBoundStatus) { //Send message notifying Browser Process of which objects were bound //We do this after the objects have been created in the V8Context to gurantee @@ -358,7 +368,7 @@ namespace CefSharp args->SetList(0, boundObjects); - browser->SendProcessMessage(CefProcessId::PID_BROWSER, msg); + frame->SendProcessMessage(CefProcessId::PID_BROWSER, msg); } diff --git a/CefSharp.BrowserSubprocess.Core/packages.config b/CefSharp.BrowserSubprocess.Core/packages.config index 4cbdc1e94e..e020d81652 100644 --- a/CefSharp.BrowserSubprocess.Core/packages.config +++ b/CefSharp.BrowserSubprocess.Core/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file diff --git a/CefSharp.Core/AbstractCefSettings.h b/CefSharp.Core/AbstractCefSettings.h index 73f11422ec..c00242986a 100644 --- a/CefSharp.Core/AbstractCefSettings.h +++ b/CefSharp.Core/AbstractCefSettings.h @@ -162,6 +162,20 @@ namespace CefSharp void set(String^ value) { StringUtils::AssignNativeFromClr(_cefSettings->cache_path, value); } } + /// + /// The root directory that all CefSettings.CachePath and + /// RequestContextSettings.CachePath values must have in common. If this + /// value is empty and CefSettings.CachePath is non-empty then this value will + /// default to the CefSettings.CachePath value. Failure to set this value + /// correctly may result in the sandbox blocking read/write access to the + /// CachePath directory. NOTE: CefSharp does not implement the CHROMIUM SANDBOX. + /// + property String^ RootCachePath + { + String^ get() { return StringUtils::ToClr(_cefSettings->root_cache_path); } + void set(String^ value) { StringUtils::AssignNativeFromClr(_cefSettings->root_cache_path, value); } + } + /// /// The location where user data such as spell checking dictionary files will /// be stored on disk. If empty then the default platform-specific user data @@ -384,6 +398,18 @@ namespace CefSharp void set(uint32 value) { _cefSettings->background_color = value; } } + /// + /// GUID string used for identifying the application. This is passed to the + /// system AV function for scanning downloaded files. By default, the GUID + /// will be an empty string and the file will be treated as an untrusted + /// file when the GUID is empty. + /// + property String^ ApplicationClientIdForFileScanning + { + String^ get() { return StringUtils::ToClr(_cefSettings->application_client_id_for_file_scanning); } + void set(String^ value) { StringUtils::AssignNativeFromClr(_cefSettings->application_client_id_for_file_scanning, value); } + } + /// /// Registers a custom scheme using the provided settings. /// diff --git a/CefSharp.Core/Cef.h b/CefSharp.Core/Cef.h index b16495a54a..9f02a350ce 100644 --- a/CefSharp.Core/Cef.h +++ b/CefSharp.Core/Cef.h @@ -367,7 +367,7 @@ namespace CefSharp /// /// Returns the global cookie manager. By default data will be stored at CefSettings.CachePath if specified or in memory otherwise. - /// Using this method is equivalent to calling Cef.GetGlobalRequestContext().GetDefaultCookieManager() + /// Using this method is equivalent to calling Cef.GetGlobalRequestContext().GetCookieManager() /// The earlier possible place to access the ICookieManager is in IBrowserProcessHandler.OnContextInitialized. /// Alternative use the ChromiumWebBrowser BrowserInitialized (OffScreen) or IsBrowserInitializedChanged (WinForms/WPF) events. /// @@ -383,26 +383,6 @@ namespace CefSharp return nullptr; } - /// - /// Returns a cookie manager that neither stores nor retrieves cookies. All - /// usage of cookies will be blocked including cookies accessed via the network - /// (request/response headers), via JavaScript (document.cookie), and via - /// CefCookieManager methods. No cookies will be displayed in DevTools. If you - /// wish to only block cookies sent via the network use the IRequestHandler - /// CanGetCookies and CanSetCookie methods instead. - /// - /// A blocking cookie manager - static ICookieManager^ GetBlockingCookieManager() - { - auto cookieManager = CefCookieManager::GetBlockingManager(); - if (cookieManager.get()) - { - return gcnew CookieManager(cookieManager); - } - - return nullptr; - } - /// /// Shuts down CefSharp and the underlying CEF infrastructure. This method is safe to call multiple times; it will only /// shut down CEF on the first call (all subsequent calls will be ignored). diff --git a/CefSharp.Core/CefSharp.Core.vcxproj b/CefSharp.Core/CefSharp.Core.vcxproj index b9d6908f53..540462640c 100644 --- a/CefSharp.Core/CefSharp.Core.vcxproj +++ b/CefSharp.Core/CefSharp.Core.vcxproj @@ -1,6 +1,6 @@  - + Debug @@ -264,6 +264,7 @@ + diff --git a/CefSharp.Core/CefSharp.Core.vcxproj.filters b/CefSharp.Core/CefSharp.Core.vcxproj.filters index 7bf38ab352..1e85ecb4cb 100644 --- a/CefSharp.Core/CefSharp.Core.vcxproj.filters +++ b/CefSharp.Core/CefSharp.Core.vcxproj.filters @@ -301,6 +301,9 @@ Header Files + + Header Files + diff --git a/CefSharp.Core/CookieManager.cpp b/CefSharp.Core/CookieManager.cpp index 60a6e2003d..0de990c3bd 100644 --- a/CefSharp.Core/CookieManager.cpp +++ b/CefSharp.Core/CookieManager.cpp @@ -57,22 +57,13 @@ namespace CefSharp return _cookieManager->SetCookie(StringUtils::ToNative(url), c, wrapper); } - bool CookieManager::SetStoragePath(String^ path, bool persistSessionCookies, ICompletionCallback^ callback) + void CookieManager::SetSupportedSchemes(cli::array^ schemes, bool includeDefaults, ICompletionCallback^ callback) { ThrowIfDisposed(); CefRefPtr wrapper = callback == nullptr ? NULL : new CefCompletionCallbackAdapter(callback); - return _cookieManager->SetStoragePath(StringUtils::ToNative(path), persistSessionCookies, wrapper); - } - - void CookieManager::SetSupportedSchemes(cli::array^ schemes, ICompletionCallback^ callback) - { - ThrowIfDisposed(); - - CefRefPtr wrapper = callback == nullptr ? NULL : new CefCompletionCallbackAdapter(callback); - - _cookieManager->SetSupportedSchemes(StringUtils::ToNative(schemes), wrapper); + _cookieManager->SetSupportedSchemes(StringUtils::ToNative(schemes), includeDefaults, wrapper); } bool CookieManager::VisitAllCookies(ICookieVisitor^ visitor) diff --git a/CefSharp.Core/CookieManager.h b/CefSharp.Core/CookieManager.h index f3ffc646c5..6bfd34e87b 100644 --- a/CefSharp.Core/CookieManager.h +++ b/CefSharp.Core/CookieManager.h @@ -35,23 +35,6 @@ namespace CefSharp } public: - /// - // Creates a new cookie manager. If |path| is empty data will be stored in - // memory only. Otherwise, data will be stored at the specified |path|. To - // persist session cookies (cookies without an expiry date or validity - // interval) set |persist_session_cookies| to true. Session cookies are - // generally intended to be transient and most Web browsers do not persist - // them. If |callback| is non-NULL it will be executed asnychronously on the - // IO thread after the manager's storage has been initialized. - /// - /*--cef(optional_param=path,optional_param=callback)--*/ - CookieManager(String^ path, bool persistSessionCookies, ICompletionCallback^ callback) - { - CefRefPtr wrapper = callback == nullptr ? NULL : new CefCompletionCallbackAdapter(callback); - - _cookieManager = CefCookieManager::CreateManager(StringUtils::ToNative(path), persistSessionCookies, wrapper); - } - !CookieManager() { this->_cookieManager = nullptr; @@ -64,8 +47,7 @@ namespace CefSharp virtual bool DeleteCookies(String^ url, String^ name, IDeleteCookiesCallback^ callback); virtual bool SetCookie(String^ url, Cookie^ cookie, ISetCookieCallback^ callback); - virtual bool SetStoragePath(String^ path, bool persistSessionSookies, ICompletionCallback^ callback); - virtual void SetSupportedSchemes(cli::array^ schemes, ICompletionCallback^ callback); + virtual void SetSupportedSchemes(cli::array^ schemes, bool includeDefaults, ICompletionCallback^ callback); virtual bool VisitAllCookies(ICookieVisitor^ visitor); virtual bool VisitUrlCookies(String^ url, bool includeHttpOnly, ICookieVisitor^ visitor); virtual bool FlushStore(ICompletionCallback^ callback); @@ -78,4 +60,4 @@ namespace CefSharp } } }; -} \ No newline at end of file +} diff --git a/CefSharp.Core/Internals/CefRequestContextHandlerAdapter.cpp b/CefSharp.Core/Internals/CefRequestContextHandlerAdapter.cpp index 0ace48ffff..6331debc4c 100644 --- a/CefSharp.Core/Internals/CefRequestContextHandlerAdapter.cpp +++ b/CefSharp.Core/Internals/CefRequestContextHandlerAdapter.cpp @@ -14,33 +14,6 @@ namespace CefSharp { namespace Internals { - CefRefPtr CefRequestContextHandlerAdapter::GetCookieManager() - { - if (Object::ReferenceEquals(_requestContextHandler, nullptr)) - { - return NULL; - } - - auto cookieManager = _requestContextHandler->GetCookieManager(); - - if (cookieManager == nullptr) - { - return NULL; - } - - //Cookie manager can only be our managed wrapper - if (cookieManager->GetType() == CookieManager::typeid) - { - return (CookieManager^)cookieManager; - } - - //Report the exception on the thread pool so it can be caught in AppDomain::UnhandledException - auto msg = gcnew String(L"ICookieManager must be of type " + CookieManager::typeid + ". CEF does not support custom implementation"); - ReportUnhandledExceptions::Report(msg, gcnew NotSupportedException(msg)); - - return NULL; - } - bool CefRequestContextHandlerAdapter::OnBeforePluginLoad(const CefString& mime_type, const CefString& plugin_url, bool is_main_frame, @@ -78,4 +51,4 @@ namespace CefSharp } } } -} \ No newline at end of file +} diff --git a/CefSharp.Core/Internals/CefRequestContextHandlerAdapter.h b/CefSharp.Core/Internals/CefRequestContextHandlerAdapter.h index 8b17ada5e8..0938ad9bda 100644 --- a/CefSharp.Core/Internals/CefRequestContextHandlerAdapter.h +++ b/CefSharp.Core/Internals/CefRequestContextHandlerAdapter.h @@ -31,8 +31,6 @@ namespace CefSharp _requestContextHandler = nullptr; } - virtual CefRefPtr GetCookieManager() OVERRIDE; - virtual bool OnBeforePluginLoad(const CefString& mime_type, const CefString& plugin_url, bool is_main_frame, diff --git a/CefSharp.Core/Internals/CefResourceRequestHandlerAdapter.h b/CefSharp.Core/Internals/CefResourceRequestHandlerAdapter.h new file mode 100644 index 0000000000..be786c9a13 --- /dev/null +++ b/CefSharp.Core/Internals/CefResourceRequestHandlerAdapter.h @@ -0,0 +1,225 @@ +// Copyright © 2019 The CefSharp Authors. All rights reserved. +// +// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. + +#pragma once + +#include "Stdafx.h" + +#include "include\cef_resource_request_handler.h" +#include "include\wrapper\cef_stream_resource_handler.h" + +#include "CefResponseWrapper.h" +#include "CefRequestWrapper.h" +#include "CefFrameWrapper.h" +#include "CefSharpBrowserWrapper.h" +#include "ResourceHandlerWrapper.h" +#include "CefResponseFilterAdapter.h" +#include "CefRequestCallbackWrapper.h" + +namespace CefSharp +{ + namespace Internals + { + //TODO: NetworkService + // Deal with browser/frame null for serviceworker + //fix Ibrowser reference + private class CefResourceRequestHandlerAdapter : public CefResourceRequestHandler + { + private: + gcroot _handler; + gcroot _browserControl; + + public: + CefResourceRequestHandlerAdapter(IWebBrowser^ browserControl, IResourceRequestHandler^ handler) : + _handler(handler), _browserControl(browserControl) + { + + } + + ~CefResourceRequestHandlerAdapter() + { + delete _handler; + _handler = nullptr; + } + + CefRefPtr GetCookieAccessFilter(CefRefPtr browser, CefRefPtr frame, CefRefPtr request) OVERRIDE + { + if (!Object::ReferenceEquals(_handler, nullptr)) + { + return NULL; + } + + //TODO: We previously used GetBrowserWrapper - investigate passing in reference to this adapter + CefSharpBrowserWrapper browserWrapper(browser); + CefFrameWrapper frameWrapper(frame); + CefRequestWrapper requestWrapper(request); + + auto resourceHandler = _handler->GetCookieAccessFilter(_browserControl, %browserWrapper, %frameWrapper, %requestWrapper); + + if (resourceHandler == nullptr) + { + return NULL; + } + + throw gcnew NotImplementedException("Implement CefCookieAccessFilter wrapper"); + } + + cef_return_value_t OnBeforeResourceLoad(CefRefPtr browser, CefRefPtr frame, CefRefPtr request, CefRefPtr callback) OVERRIDE + { + if (!Object::ReferenceEquals(_handler, nullptr)) + { + return cef_return_value_t::RV_CONTINUE; + } + + //TODO: We previously used GetBrowserWrapper - investigate passing in reference to this adapter + CefSharpBrowserWrapper browserWrapper(browser); + //We pass the frame and request wrappers to CefRequestCallbackWrapper so they can be disposed of + //when the callback is executed + auto frameWrapper = gcnew CefFrameWrapper(frame); + auto requestWrapper = gcnew CefRequestWrapper(request); + auto requestCallback = gcnew CefRequestCallbackWrapper(callback, frameWrapper, requestWrapper); + + return (cef_return_value_t)_handler->OnBeforeResourceLoad(_browserControl, %browserWrapper, frameWrapper, requestWrapper, requestCallback); + } + + CefRefPtr GetResourceHandler(CefRefPtr browser, CefRefPtr frame, CefRefPtr request) OVERRIDE + { + if (!Object::ReferenceEquals(_handler, nullptr)) + { + return NULL; + } + + //TODO: We previously used GetBrowserWrapper - investigate passing in reference to this adapter + CefSharpBrowserWrapper browserWrapper(browser); + CefFrameWrapper frameWrapper(frame); + CefRequestWrapper requestWrapper(request); + + auto resourceHandler = _handler->GetResourceHandler(_browserControl, %browserWrapper, %frameWrapper, %requestWrapper); + + if (resourceHandler == nullptr) + { + return NULL; + } + + if (resourceHandler->GetType() == FileResourceHandler::typeid) + { + auto fileResourceHandler = static_cast(resourceHandler); + + auto streamReader = CefStreamReader::CreateForFile(StringUtils::ToNative(fileResourceHandler->FilePath)); + + if (streamReader.get()) + { + return new CefStreamResourceHandler(StringUtils::ToNative(fileResourceHandler->MimeType), streamReader); + } + else + { + auto msg = "Unable to load resource CefStreamReader::CreateForFile returned NULL for file:" + fileResourceHandler->FilePath; + LOG(ERROR) << StringUtils::ToNative(msg).ToString(); + + return NULL; + } + } + else if (resourceHandler->GetType() == ByteArrayResourceHandler::typeid) + { + auto byteArrayResourceHandler = static_cast(resourceHandler); + + //NOTE: Prefix with cli:: namespace as VS2015 gets confused with std::array + cli::array^ buffer = byteArrayResourceHandler->Data; + pin_ptr src = &buffer[0]; + + auto streamReader = CefStreamReader::CreateForData(static_cast(src), buffer->Length); + + return new CefStreamResourceHandler(StringUtils::ToNative(byteArrayResourceHandler->MimeType), streamReader); + } + + return new ResourceHandlerWrapper(resourceHandler); + } + + void OnResourceRedirect(CefRefPtr browser, CefRefPtr frame, CefRefPtr request, CefRefPtr response, CefString& newUrl) OVERRIDE + { + if (!Object::ReferenceEquals(_handler, nullptr)) + { + auto managedNewUrl = StringUtils::ToClr(newUrl); + //TODO: We previously used GetBrowserWrapper - investigate passing in reference to this adapter + CefSharpBrowserWrapper browserWrapper(browser); + CefFrameWrapper frameWrapper(frame); + CefRequestWrapper requestWrapper(request); + CefResponseWrapper responseWrapper(response); + + _handler->OnResourceRedirect(_browserControl, %browserWrapper, %frameWrapper, %requestWrapper, %responseWrapper, managedNewUrl); + + newUrl = StringUtils::ToNative(managedNewUrl); + } + } + + bool OnResourceResponse(CefRefPtr browser, CefRefPtr frame, CefRefPtr request, CefRefPtr response) OVERRIDE + { + if (!Object::ReferenceEquals(_handler, nullptr)) + { + return false; + } + + //TODO: We previously used GetBrowserWrapper - investigate passing in reference to this adapter + CefSharpBrowserWrapper browserWrapper(browser); + CefFrameWrapper frameWrapper(frame); + CefRequestWrapper requestWrapper(request); + CefResponseWrapper responseWrapper(response); + + return _handler->OnResourceResponse(_browserControl, %browserWrapper, %frameWrapper, %requestWrapper, %responseWrapper); + } + + CefRefPtr GetResourceResponseFilter(CefRefPtr browser, CefRefPtr frame, CefRefPtr request, CefRefPtr response) OVERRIDE + { + if (!Object::ReferenceEquals(_handler, nullptr)) + { + return NULL; + } + + //TODO: We previously used GetBrowserWrapper - investigate passing in reference to this adapter + CefSharpBrowserWrapper browserWrapper(browser); + CefFrameWrapper frameWrapper(frame); + CefRequestWrapper requestWrapper(request); + CefResponseWrapper responseWrapper(response); + + auto filter = _handler->GetResourceResponseFilter(_browserControl, %browserWrapper, %frameWrapper, %requestWrapper, %responseWrapper); + + if (filter == nullptr) + { + return NULL; + } + + return new CefResponseFilterAdapter(filter); + } + + void OnResourceLoadComplete(CefRefPtr browser, CefRefPtr frame, CefRefPtr request, CefRefPtr response, URLRequestStatus status, int64 receivedContentLength) OVERRIDE + { + if (!Object::ReferenceEquals(_handler, nullptr)) + { + //TODO: We previously used GetBrowserWrapper - investigate passing in reference to this adapter + CefSharpBrowserWrapper browserWrapper(browser); + CefFrameWrapper frameWrapper(frame); + CefRequestWrapper requestWrapper(request); + CefResponseWrapper responseWrapper(response); + + _handler->OnResourceLoadComplete(_browserControl, %browserWrapper, %frameWrapper, %requestWrapper, %responseWrapper, (UrlRequestStatus)status, receivedContentLength); + } + } + + void OnProtocolExecution(CefRefPtr browser, CefRefPtr frame, CefRefPtr request, bool& allowOSExecution) OVERRIDE + { + if (!Object::ReferenceEquals(_handler, nullptr)) + { + //TODO: We previously used GetBrowserWrapper - investigate passing in reference to this adapter + CefSharpBrowserWrapper browserWrapper(browser); + CefFrameWrapper frameWrapper(frame); + CefRequestWrapper requestWrapper(request); + + allowOSExecution = _handler->OnProtocolExecution(_browserControl, %browserWrapper, %frameWrapper, %requestWrapper); + } + } + + IMPLEMENT_REFCOUNTING(CefResourceRequestHandlerAdapter); + }; + } +} diff --git a/CefSharp.Core/Internals/CefSharpBrowserWrapper.cpp b/CefSharp.Core/Internals/CefSharpBrowserWrapper.cpp index b078629aad..9a0b162ee0 100644 --- a/CefSharp.Core/Internals/CefSharpBrowserWrapper.cpp +++ b/CefSharp.Core/Internals/CefSharpBrowserWrapper.cpp @@ -245,18 +245,7 @@ List^ CefSharpBrowserWrapper::GetFrameNames() return StringUtils::ToClr(names); } -// -// Send a message to the specified |target_process|. Returns true if the -// message was sent successfully. -/// -/*--cef()--*/ -bool CefSharpBrowserWrapper::SendProcessMessage(CefProcessId targetProcess, CefRefPtr message) -{ - ThrowIfDisposed(); - return _browser->SendProcessMessage(targetProcess, message); -} - MCefRefPtr CefSharpBrowserWrapper::Browser::get() { return _browser; -} \ No newline at end of file +} diff --git a/CefSharp.Core/Internals/CefSharpBrowserWrapper.h b/CefSharp.Core/Internals/CefSharpBrowserWrapper.h index 92479beea1..76b6338d4e 100644 --- a/CefSharp.Core/Internals/CefSharpBrowserWrapper.h +++ b/CefSharp.Core/Internals/CefSharpBrowserWrapper.h @@ -186,13 +186,6 @@ namespace CefSharp /// /*--cef()--*/ virtual List^ GetFrameNames(); - - // - // Send a message to the specified |target_process|. Returns true if the - // message was sent successfully. - /// - /*--cef()--*/ - virtual bool SendProcessMessage(CefProcessId targetProcess, CefRefPtr message); }; } -} \ No newline at end of file +} diff --git a/CefSharp.Core/Internals/ClientAdapter.cpp b/CefSharp.Core/Internals/ClientAdapter.cpp index c561f84229..baa14efea0 100644 --- a/CefSharp.Core/Internals/ClientAdapter.cpp +++ b/CefSharp.Core/Internals/ClientAdapter.cpp @@ -19,8 +19,7 @@ #include "CefJSDialogCallbackWrapper.h" #include "CefMenuModelWrapper.h" #include "CefRequestWrapper.h" -#include "CefResponseWrapper.h" -#include "CefResponseFilterAdapter.h" +#include "CefResourceRequestHandlerAdapter.h" #include "CefRequestCallbackWrapper.h" #include "CefRunContextMenuCallbackWrapper.h" #include "CefSslInfoWrapper.h" @@ -28,13 +27,11 @@ #include "ManagedCefBrowserAdapter.h" #include "Messaging\Messages.h" #include "PopupFeatures.h" -#include "ResourceHandlerWrapper.h" #include "Serialization\Primitives.h" #include "Serialization\V8Serialization.h" #include "Serialization\JsObjectsSerialization.h" #include "Serialization\ObjectsSerialization.h" #include "TypeConversion.h" - #include "WindowInfo.h" using namespace CefSharp::Internals::Messaging; @@ -103,7 +100,7 @@ namespace CefSharp bool ClientAdapter::OnBeforePopup(CefRefPtr browser, CefRefPtr frame, const CefString& target_url, const CefString& target_frame_name, CefLifeSpanHandler::WindowOpenDisposition target_disposition, bool user_gesture, const CefPopupFeatures& popupFeatures, CefWindowInfo& windowInfo, - CefRefPtr& client, CefBrowserSettings& settings, bool* no_javascript_access) + CefRefPtr& client, CefBrowserSettings& settings, CefRefPtr& extraInfo, bool* no_javascript_access) { auto handler = _browserControl->LifeSpanHandler; @@ -539,56 +536,62 @@ namespace CefSharp return handler->OnOpenUrlFromTab(_browserControl, browserWrapper, %frameWrapper, StringUtils::ToClr(targetUrl), (CefSharp::WindowOpenDisposition)targetDisposition, userGesture); } - bool ClientAdapter::OnCertificateError(CefRefPtr browser, cef_errorcode_t cert_error, const CefString& request_url, CefRefPtr ssl_info, CefRefPtr callback) + CefRefPtr ClientAdapter::GetResourceRequestHandler(CefRefPtr browser, + CefRefPtr frame, CefRefPtr request, bool isNavigation, bool isDownload, const CefString& requestInitiator, bool& disableDefaultHandling) { auto handler = _browserControl->RequestHandler; if (handler == nullptr) { - return false; + return NULL; } - // If callback is empty the error cannot be recovered from and the request will be canceled automatically. - // Still notify the user of the certificate error just don't provide a callback. - auto requestCallback = callback == NULL ? nullptr : gcnew CefRequestCallbackWrapper(callback); auto browserWrapper = GetBrowserWrapper(browser->GetIdentifier(), browser->IsPopup()); - auto sslInfoWrapper = gcnew CefSslInfoWrapper(ssl_info); + CefFrameWrapper frameWrapper(frame); + CefRequestWrapper requestWrapper(request); - return handler->OnCertificateError(_browserControl, browserWrapper, (CefErrorCode)cert_error, StringUtils::ToClr(request_url), sslInfoWrapper, requestCallback); - } + //TODO: Simplify this code - bool ClientAdapter::CanGetCookies(CefRefPtr browser, CefRefPtr frame, CefRefPtr request) - { - auto handler = _browserControl->RequestHandler; + auto resourceRequestHandler = handler->GetResourceRequestHandler(_browserControl, browserWrapper, %frameWrapper, + %requestWrapper, isNavigation, isDownload, StringUtils::ToClr(requestInitiator), disableDefaultHandling); - if (handler == nullptr) + if (resourceRequestHandler != nullptr) { - return true; + return new CefResourceRequestHandlerAdapter(_browserControl, resourceRequestHandler); } - auto browserWrapper = GetBrowserWrapper(browser->GetIdentifier(), browser->IsPopup()); - CefFrameWrapper frameWrapper(frame); - CefRequestWrapper requestWrapper(request); + auto resourceRequestHandlerFactory = _browserControl->ResourceRequestHandlerFactory; - return handler->CanGetCookies(_browserControl, browserWrapper, %frameWrapper, %requestWrapper); + if (resourceRequestHandlerFactory != nullptr) + { + auto factoryHandler = resourceRequestHandlerFactory->GetResourceRequestHandler(_browserControl, browserWrapper, %frameWrapper, + %requestWrapper, isNavigation, isDownload, StringUtils::ToClr(requestInitiator), disableDefaultHandling); + + if (factoryHandler != nullptr) + { + return new CefResourceRequestHandlerAdapter(_browserControl, factoryHandler); + } + } + + return NULL; } - bool ClientAdapter::CanSetCookie(CefRefPtr browser, CefRefPtr frame, CefRefPtr request, const CefCookie& cefCookie) + bool ClientAdapter::OnCertificateError(CefRefPtr browser, cef_errorcode_t cert_error, const CefString& request_url, CefRefPtr ssl_info, CefRefPtr callback) { auto handler = _browserControl->RequestHandler; if (handler == nullptr) { - return true; + return false; } + // If callback is empty the error cannot be recovered from and the request will be canceled automatically. + // Still notify the user of the certificate error just don't provide a callback. + auto requestCallback = callback == NULL ? nullptr : gcnew CefRequestCallbackWrapper(callback); auto browserWrapper = GetBrowserWrapper(browser->GetIdentifier(), browser->IsPopup()); - CefFrameWrapper frameWrapper(frame); - CefRequestWrapper requestWrapper(request); - - auto cookie = TypeConversion::FromNative(cefCookie); + auto sslInfoWrapper = gcnew CefSslInfoWrapper(ssl_info); - return handler->CanSetCookie(_browserControl, browserWrapper, %frameWrapper, %requestWrapper, cookie); + return handler->OnCertificateError(_browserControl, browserWrapper, (CefErrorCode)cert_error, StringUtils::ToClr(request_url), sslInfoWrapper, requestCallback); } bool ClientAdapter::OnQuotaRequest(CefRefPtr browser, const CefString& originUrl, int64 newSize, CefRefPtr callback) @@ -636,7 +639,8 @@ namespace CefSharp SetInt64(responseArgList, 2, 0); //FrameId SetInt64(responseArgList, 3, 0); //CallbackId SerializeJsObjects(objectRepository->GetObjects(nullptr), responseArgList, 4); - browser->SendProcessMessage(CefProcessId::PID_RENDERER, msg); + + browser->GetMainFrame()->SendProcessMessage(CefProcessId::PID_RENDERER, msg); } } } @@ -663,167 +667,6 @@ namespace CefSharp } } - void ClientAdapter::OnResourceRedirect(CefRefPtr browser, CefRefPtr frame, CefRefPtr request, CefRefPtr response, CefString& newUrl) - { - auto handler = _browserControl->RequestHandler; - - if (handler != nullptr) - { - auto managedNewUrl = StringUtils::ToClr(newUrl); - auto browserWrapper = GetBrowserWrapper(browser->GetIdentifier(), browser->IsPopup()); - CefFrameWrapper frameWrapper(frame); - CefRequestWrapper requestWrapper(request); - CefResponseWrapper responseWrapper(response); - - handler->OnResourceRedirect(_browserControl, browserWrapper, %frameWrapper, %requestWrapper, %responseWrapper, managedNewUrl); - - newUrl = StringUtils::ToNative(managedNewUrl); - } - } - - bool ClientAdapter::OnResourceResponse(CefRefPtr browser, CefRefPtr frame, CefRefPtr request, CefRefPtr response) - { - auto handler = _browserControl->RequestHandler; - - if (handler == nullptr) - { - return false; - } - - auto browserWrapper = GetBrowserWrapper(browser->GetIdentifier(), browser->IsPopup()); - CefFrameWrapper frameWrapper(frame); - CefRequestWrapper requestWrapper(request); - CefResponseWrapper responseWrapper(response); - - return handler->OnResourceResponse(_browserControl, browserWrapper, %frameWrapper, %requestWrapper, %responseWrapper); - } - - CefRefPtr ClientAdapter::GetResourceResponseFilter(CefRefPtr browser, CefRefPtr frame, CefRefPtr request, CefRefPtr response) - { - auto handler = _browserControl->RequestHandler; - - if (handler == nullptr) - { - return NULL; - } - - auto browserWrapper = GetBrowserWrapper(browser->GetIdentifier(), browser->IsPopup()); - CefFrameWrapper frameWrapper(frame); - CefRequestWrapper requestWrapper(request); - CefResponseWrapper responseWrapper(response); - - auto filter = handler->GetResourceResponseFilter(_browserControl, browserWrapper, %frameWrapper, %requestWrapper, %responseWrapper); - - if (filter == nullptr) - { - return NULL; - } - - return new CefResponseFilterAdapter(filter); - } - - void ClientAdapter::OnResourceLoadComplete(CefRefPtr browser, CefRefPtr frame, CefRefPtr request, CefRefPtr response, URLRequestStatus status, int64 receivedContentLength) - { - auto handler = _browserControl->RequestHandler; - - if (handler != nullptr) - { - auto browserWrapper = GetBrowserWrapper(browser->GetIdentifier(), browser->IsPopup()); - CefFrameWrapper frameWrapper(frame); - CefRequestWrapper requestWrapper(request); - CefResponseWrapper responseWrapper(response); - - handler->OnResourceLoadComplete(_browserControl, browserWrapper, %frameWrapper, %requestWrapper, %responseWrapper, (UrlRequestStatus)status, receivedContentLength); - } - } - - void ClientAdapter::OnProtocolExecution(CefRefPtr browser, const CefString& url, bool& allowOSExecution) - { - auto handler = _browserControl->RequestHandler; - - if (handler != nullptr) - { - auto browserWrapper = GetBrowserWrapper(browser->GetIdentifier(), browser->IsPopup()); - - allowOSExecution = handler->OnProtocolExecution(_browserControl, browserWrapper, StringUtils::ToClr(url)); - } - } - - // Called on the IO thread before a resource is loaded. To allow the resource - // to load normally return NULL. To specify a handler for the resource return - // a CefResourceHandler object. The |request| object should not be modified in - // this callback. - CefRefPtr ClientAdapter::GetResourceHandler(CefRefPtr browser, CefRefPtr frame, CefRefPtr request) - { - auto factory = _browserControl->ResourceHandlerFactory; - - if (factory == nullptr || !factory->HasHandlers) - { - return NULL; - } - - auto browserWrapper = GetBrowserWrapper(browser->GetIdentifier(), browser->IsPopup()); - CefFrameWrapper frameWrapper(frame); - CefRequestWrapper requestWrapper(request); - - auto handler = factory->GetResourceHandler(_browserControl, browserWrapper, %frameWrapper, %requestWrapper); - - if (handler == nullptr) - { - return NULL; - } - - if (handler->GetType() == FileResourceHandler::typeid) - { - auto resourceHandler = static_cast(handler); - - auto streamReader = CefStreamReader::CreateForFile(StringUtils::ToNative(resourceHandler->FilePath)); - - if (streamReader.get()) - { - return new CefStreamResourceHandler(StringUtils::ToNative(resourceHandler->MimeType), streamReader); - } - else - { - auto msg = "Unable to load resource CefStreamReader::CreateForFile returned NULL for file:" + resourceHandler->FilePath; - LOG(ERROR) << StringUtils::ToNative(msg).ToString(); - - return NULL; - } - } - else if (handler->GetType() == ByteArrayResourceHandler::typeid) - { - auto resourceHandler = static_cast(handler); - - //NOTE: Prefix with cli:: namespace as VS2015 gets confused with std::array - cli::array^ buffer = resourceHandler->Data; - pin_ptr src = &buffer[0]; - - auto streamReader = CefStreamReader::CreateForData(static_cast(src), buffer->Length); - - return new CefStreamResourceHandler(StringUtils::ToNative(resourceHandler->MimeType), streamReader); - } - - return new ResourceHandlerWrapper(handler); - } - - cef_return_value_t ClientAdapter::OnBeforeResourceLoad(CefRefPtr browser, CefRefPtr frame, CefRefPtr request, CefRefPtr callback) - { - auto handler = _browserControl->RequestHandler; - - if (handler == nullptr) - { - return cef_return_value_t::RV_CONTINUE; - } - - auto frameWrapper = gcnew CefFrameWrapper(frame); - auto browserWrapper = GetBrowserWrapper(browser->GetIdentifier(), browser->IsPopup()); - auto requestWrapper = gcnew CefRequestWrapper(request); - auto requestCallback = gcnew CefRequestCallbackWrapper(callback, frameWrapper, requestWrapper); - - return (cef_return_value_t)handler->OnBeforeResourceLoad(_browserControl, browserWrapper, frameWrapper, requestWrapper, requestCallback); - } - bool ClientAdapter::GetAuthCredentials(CefRefPtr browser, CefRefPtr frame, bool isProxy, const CefString& host, int port, const CefString& realm, const CefString& scheme, CefRefPtr callback) { @@ -1099,7 +942,7 @@ namespace CefSharp return handler->OnDragEnter(_browserControl, browserWrapper, %dragDataWrapper, (CefSharp::Enums::DragOperationsMask)mask); } - void ClientAdapter::OnDraggableRegionsChanged(CefRefPtr browser, const std::vector& regions) + void ClientAdapter::OnDraggableRegionsChanged(CefRefPtr browser, CefRefPtr frame, const std::vector& regions) { auto handler = _browserControl->DragHandler; @@ -1107,8 +950,9 @@ namespace CefSharp { auto regionsList = TypeConversion::FromNative(regions); auto browserWrapper = GetBrowserWrapper(browser->GetIdentifier(), browser->IsPopup()); + CefFrameWrapper frameWrapper(frame); - return handler->OnDraggableRegionsChanged(_browserControl, browserWrapper, regionsList); + return handler->OnDraggableRegionsChanged(_browserControl, browserWrapper, %frameWrapper, regionsList); } } @@ -1192,7 +1036,7 @@ namespace CefSharp } } - bool ClientAdapter::OnProcessMessageReceived(CefRefPtr browser, CefProcessId source_process, CefRefPtr message) + bool ClientAdapter::OnProcessMessageReceived(CefRefPtr browser, CefRefPtr frame, CefProcessId source_process, CefRefPtr message) { auto handled = false; auto name = message->GetName(); @@ -1229,7 +1073,7 @@ namespace CefSharp SetInt64(responseArgList, 2, frameId); SetInt64(responseArgList, 3, callbackId); SerializeJsObjects(objs, responseArgList, 4); - browser->SendProcessMessage(CefProcessId::PID_RENDERER, msg); + frame->SendProcessMessage(CefProcessId::PID_RENDERER, msg); } handled = true; @@ -1452,6 +1296,7 @@ namespace CefSharp } auto browserWrapper = static_cast(browser); + auto cefBrowser = browserWrapper->Browser; //create a new taskcompletionsource auto idAndComplectionSource = _pendingTaskRepository->CreatePendingTask(timeout); @@ -1464,7 +1309,9 @@ namespace CefSharp argList->SetString(3, StringUtils::ToNative(scriptUrl)); argList->SetInt(4, startLine); - browserWrapper->SendProcessMessage(CefProcessId::PID_RENDERER, message); + auto frame = cefBrowser->GetFrame(frameId); + + frame->SendProcessMessage(CefProcessId::PID_RENDERER, message); return idAndComplectionSource.Value->Task; } @@ -1497,8 +1344,9 @@ namespace CefSharp if (browser != nullptr) { auto wrapper = static_cast(browser); + auto frame = wrapper->Browser->GetFrame(result->FrameId); - wrapper->Browser->SendProcessMessage(CefProcessId::PID_RENDERER, message); + frame->SendProcessMessage(CefProcessId::PID_RENDERER, message); } } } diff --git a/CefSharp.Core/Internals/ClientAdapter.h b/CefSharp.Core/Internals/ClientAdapter.h index 93ba97a5e6..d5ff0c54cb 100644 --- a/CefSharp.Core/Internals/ClientAdapter.h +++ b/CefSharp.Core/Internals/ClientAdapter.h @@ -112,7 +112,7 @@ namespace CefSharp return this; } - virtual DECL bool OnProcessMessageReceived(CefRefPtr browser, CefProcessId source_process, CefRefPtr message) OVERRIDE; + virtual DECL bool OnProcessMessageReceived(CefRefPtr browser, CefRefPtr frame, CefProcessId source_process, CefRefPtr message) OVERRIDE; // CefLifeSpanHandler @@ -120,7 +120,7 @@ namespace CefSharp const CefString& target_url, const CefString& target_frame_name, CefLifeSpanHandler::WindowOpenDisposition target_disposition, bool user_gesture, const CefPopupFeatures& popupFeatures, - CefWindowInfo& windowInfo, CefRefPtr& client, CefBrowserSettings& settings, bool* no_javascript_access) OVERRIDE; + CefWindowInfo& windowInfo, CefRefPtr& client, CefBrowserSettings& settings, CefRefPtr& extraInfo, bool* no_javascript_access) OVERRIDE; virtual DECL void OnAfterCreated(CefRefPtr browser) OVERRIDE; virtual DECL bool DoClose(CefRefPtr browser) OVERRIDE; virtual DECL void OnBeforeClose(CefRefPtr browser) OVERRIDE; @@ -131,27 +131,20 @@ namespace CefSharp virtual DECL void OnLoadError(CefRefPtr browser, CefRefPtr frame, ErrorCode errorCode, const CefString& errorText, const CefString& failedUrl) OVERRIDE; // CefRequestHandler - virtual DECL CefRefPtr GetResourceHandler(CefRefPtr browser, CefRefPtr frame, CefRefPtr request) OVERRIDE; - virtual DECL cef_return_value_t OnBeforeResourceLoad(CefRefPtr browser, CefRefPtr frame, CefRefPtr request, CefRefPtr callback) OVERRIDE; - virtual DECL bool GetAuthCredentials(CefRefPtr browser, CefRefPtr frame, bool isProxy, - const CefString& host, int port, const CefString& realm, const CefString& scheme, CefRefPtr callback) OVERRIDE; virtual DECL bool OnBeforeBrowse(CefRefPtr browser, CefRefPtr frame, CefRefPtr request, bool userGesture, bool isRedirect) OVERRIDE; virtual DECL bool OnOpenURLFromTab(CefRefPtr browser, CefRefPtr frame, const CefString& targetUrl, CefRequestHandler::WindowOpenDisposition targetDisposition, bool userGesture) OVERRIDE; - virtual DECL bool OnCertificateError(CefRefPtr browser, cef_errorcode_t cert_error, const CefString& request_url, CefRefPtr ssl_info, CefRefPtr callback) OVERRIDE; - virtual DECL bool CanGetCookies(CefRefPtr browser, CefRefPtr frame, CefRefPtr request) OVERRIDE; - virtual DECL bool CanSetCookie(CefRefPtr browser, CefRefPtr frame, CefRefPtr request, const CefCookie& cookie) OVERRIDE; + virtual DECL CefRefPtr GetResourceRequestHandler(CefRefPtr browser, + CefRefPtr frame, CefRefPtr request, bool isNavigation, bool isDownload, const CefString& requestInitiator, bool& disableDefaultHandling) OVERRIDE; + virtual DECL bool GetAuthCredentials(CefRefPtr browser, CefRefPtr frame, bool isProxy, + const CefString& host, int port, const CefString& realm, const CefString& scheme, CefRefPtr callback) OVERRIDE; virtual DECL bool OnQuotaRequest(CefRefPtr browser, const CefString& originUrl, int64 newSize, CefRefPtr callback) OVERRIDE; - virtual DECL void OnResourceRedirect(CefRefPtr browser, CefRefPtr frame, CefRefPtr request, CefRefPtr response, CefString& newUrl) OVERRIDE; - virtual DECL bool OnResourceResponse(CefRefPtr browser, CefRefPtr frame, CefRefPtr request, CefRefPtr response) OVERRIDE; - virtual DECL CefRefPtr GetResourceResponseFilter(CefRefPtr browser, CefRefPtr frame, CefRefPtr request, CefRefPtr response) OVERRIDE; - virtual DECL void OnResourceLoadComplete(CefRefPtr browser, CefRefPtr frame, CefRefPtr request, CefRefPtr response, URLRequestStatus status, int64 receivedContentLength) OVERRIDE; - virtual DECL void OnProtocolExecution(CefRefPtr browser, const CefString& url, bool& allowOSExecution) OVERRIDE; + virtual DECL bool OnCertificateError(CefRefPtr browser, cef_errorcode_t cert_error, const CefString& request_url, CefRefPtr ssl_info, CefRefPtr callback) OVERRIDE; + virtual DECL bool OnSelectClientCertificate(CefRefPtr browser, bool isProxy, const CefString& host, int port, + const CefRequestHandler::X509CertificateList& certificates, CefRefPtr callback) OVERRIDE; virtual DECL void OnPluginCrashed(CefRefPtr browser, const CefString& plugin_path) OVERRIDE; virtual DECL void OnRenderViewReady(CefRefPtr browser) OVERRIDE; virtual DECL void OnRenderProcessTerminated(CefRefPtr browser, TerminationStatus status) OVERRIDE; - virtual DECL bool OnSelectClientCertificate(CefRefPtr browser, bool isProxy, const CefString& host, int port, - const CefRequestHandler::X509CertificateList& certificates, CefRefPtr callback) OVERRIDE; // CefDisplayHandler virtual DECL void OnLoadingStateChange(CefRefPtr browser, bool isLoading, bool canGoBack, bool canGoForward) OVERRIDE; @@ -198,7 +191,7 @@ namespace CefSharp //CefDragHandler virtual DECL bool OnDragEnter(CefRefPtr browser, CefRefPtr dragData, DragOperationsMask mask) OVERRIDE; - virtual DECL void OnDraggableRegionsChanged(CefRefPtr browser, const std::vector& regions) OVERRIDE; + virtual DECL void OnDraggableRegionsChanged(CefRefPtr browser, CefRefPtr frame, const std::vector& regions) OVERRIDE; //CefDownloadHandler virtual DECL void OnBeforeDownload(CefRefPtr browser, CefRefPtr download_item, diff --git a/CefSharp.Core/Internals/JavascriptCallbackProxy.cpp b/CefSharp.Core/Internals/JavascriptCallbackProxy.cpp index b725f105b0..90ca9edcac 100644 --- a/CefSharp.Core/Internals/JavascriptCallbackProxy.cpp +++ b/CefSharp.Core/Internals/JavascriptCallbackProxy.cpp @@ -42,9 +42,22 @@ namespace CefSharp } argList->SetList(3, paramList); - browserWrapper->SendProcessMessage(CefProcessId::PID_RENDERER, callbackMessage); + auto frame = browserWrapper->Browser->GetFrame(_callback->FrameId); - return doneCallback.Value->Task; + if (frame.get() && frame->IsValid()) + { + frame->SendProcessMessage(CefProcessId::PID_RENDERER, callbackMessage); + + return doneCallback.Value->Task; + } + else + { + auto invalidFrameResponse = gcnew JavascriptResponse(); + invalidFrameResponse->Success = false; + invalidFrameResponse->Message = "Frame with Id:" + _callback->FrameId + " is no longer valid."; + + Task::FromResult(invalidFrameResponse); + } } CefRefPtr JavascriptCallbackProxy::CreateDestroyMessage() diff --git a/CefSharp.Core/Internals/JavascriptCallbackProxy.h b/CefSharp.Core/Internals/JavascriptCallbackProxy.h index 5ac0369804..81df1d3030 100644 --- a/CefSharp.Core/Internals/JavascriptCallbackProxy.h +++ b/CefSharp.Core/Internals/JavascriptCallbackProxy.h @@ -45,8 +45,12 @@ namespace CefSharp auto browser = GetBrowser(); if (browser != nullptr && !browser->IsDisposed) { - auto browserWrapper = static_cast(browser); - browserWrapper->SendProcessMessage(CefProcessId::PID_RENDERER, CreateDestroyMessage()); + auto browserWrapper = static_cast(browser)->Browser; + auto frame = browserWrapper->GetFrame(_callback->FrameId); + if (frame.get() && frame->IsValid()) + { + frame->SendProcessMessage(CefProcessId::PID_RENDERER, CreateDestroyMessage()); + } } _disposed = true; } @@ -69,4 +73,4 @@ namespace CefSharp } }; } -} \ No newline at end of file +} diff --git a/CefSharp.Core/ManagedCefBrowserAdapter.cpp b/CefSharp.Core/ManagedCefBrowserAdapter.cpp index 920fc1bec2..7868cdcf6a 100644 --- a/CefSharp.Core/ManagedCefBrowserAdapter.cpp +++ b/CefSharp.Core/ManagedCefBrowserAdapter.cpp @@ -35,7 +35,7 @@ void ManagedCefBrowserAdapter::CreateBrowser(IWindowInfo^ windowInfo, BrowserSet } if (!CefBrowserHost::CreateBrowser(*cefWindowInfoWrapper->GetWindowInfo(), _clientAdapter.get(), addressNative, - *browserSettings->_browserSettings, static_cast>(requestContext))) + *browserSettings->_browserSettings, NULL, static_cast>(requestContext))) { throw gcnew InvalidOperationException("CefBrowserHost::CreateBrowser call failed, review the CEF log file for more details."); } diff --git a/CefSharp.Core/RequestContext.cpp b/CefSharp.Core/RequestContext.cpp index 1b3cb672f3..bae40d7364 100644 --- a/CefSharp.Core/RequestContext.cpp +++ b/CefSharp.Core/RequestContext.cpp @@ -49,13 +49,13 @@ namespace CefSharp return _requestContext->IsSharingWith(requestContext); } - ICookieManager^ RequestContext::GetDefaultCookieManager(ICompletionCallback^ callback) + ICookieManager^ RequestContext::GetCookieManager(ICompletionCallback^ callback) { ThrowIfDisposed(); CefRefPtr wrapper = callback == nullptr ? NULL : new CefCompletionCallbackAdapter(callback); - auto cookieManager = _requestContext->GetDefaultCookieManager(wrapper); + auto cookieManager = _requestContext->GetCookieManager(wrapper); if (cookieManager.get()) { return gcnew CookieManager(cookieManager); diff --git a/CefSharp.Core/RequestContext.h b/CefSharp.Core/RequestContext.h index 3471fd76a5..31752cf2d7 100644 --- a/CefSharp.Core/RequestContext.h +++ b/CefSharp.Core/RequestContext.h @@ -134,14 +134,12 @@ namespace CefSharp /// /// Returns the default cookie manager for this object. This will be the global - /// cookie manager if this object is the global request context. Otherwise, - /// this will be the default cookie manager used when this request context does - /// not receive a value via IRequestContextHandler.GetCookieManager(). + /// cookie manager if this object is the global request context. /// /// If callback is non-NULL it will be executed asnychronously on the CEF IO thread /// after the manager's storage has been initialized. /// Returns the default cookie manager for this object - virtual ICookieManager^ GetDefaultCookieManager(ICompletionCallback^ callback); + virtual ICookieManager^ GetCookieManager(ICompletionCallback^ callback); /// /// Returns true if this object is the global context. The global context is diff --git a/CefSharp.Core/ResourceHandlerWrapper.cpp b/CefSharp.Core/ResourceHandlerWrapper.cpp index d5581d2bc4..3e021d3cc3 100644 --- a/CefSharp.Core/ResourceHandlerWrapper.cpp +++ b/CefSharp.Core/ResourceHandlerWrapper.cpp @@ -42,22 +42,6 @@ namespace CefSharp return _handler->ReadResponse(%writeStream, bytesRead, callbackWrapper); } - bool ResourceHandlerWrapper::CanGetCookie(const CefCookie& cefCookie) - { - auto cookie = GetCookie(cefCookie); - - //Default value is true - return _handler->CanGetCookie(cookie); - } - - bool ResourceHandlerWrapper::CanSetCookie(const CefCookie& cefCookie) - { - auto cookie = GetCookie(cefCookie); - - //Default value is true - return _handler->CanSetCookie(cookie); - } - void ResourceHandlerWrapper::Cancel() { _handler->Cancel(); diff --git a/CefSharp.Core/ResourceHandlerWrapper.h b/CefSharp.Core/ResourceHandlerWrapper.h index a2d91df88e..105050b5b7 100644 --- a/CefSharp.Core/ResourceHandlerWrapper.h +++ b/CefSharp.Core/ResourceHandlerWrapper.h @@ -38,10 +38,8 @@ namespace CefSharp virtual bool ProcessRequest(CefRefPtr request, CefRefPtr callback) OVERRIDE; virtual void GetResponseHeaders(CefRefPtr response, int64& response_length, CefString& redirectUrl) OVERRIDE; virtual bool ReadResponse(void* data_out, int bytes_to_read, int& bytes_read, CefRefPtr callback) OVERRIDE; - virtual bool CanGetCookie(const CefCookie& cookie) OVERRIDE; - virtual bool CanSetCookie(const CefCookie& cookie) OVERRIDE; virtual void Cancel() OVERRIDE; IMPLEMENT_REFCOUNTING(ResourceHandlerWrapper); }; -} \ No newline at end of file +} diff --git a/CefSharp.Core/packages.config b/CefSharp.Core/packages.config index 4cbdc1e94e..e020d81652 100644 --- a/CefSharp.Core/packages.config +++ b/CefSharp.Core/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file diff --git a/CefSharp.Example/CefExample.cs b/CefSharp.Example/CefExample.cs index 5ee6f40205..1a86b83161 100644 --- a/CefSharp.Example/CefExample.cs +++ b/CefSharp.Example/CefExample.cs @@ -217,7 +217,7 @@ public static void Init(AbstractCefSettings settings, IBrowserProcessHandler bro public static async void RegisterTestResources(IWebBrowser browser) { - var handler = browser.ResourceHandlerFactory as DefaultResourceHandlerFactory; + var handler = browser.ResourceRequestHandlerFactory as DefaultResourceRequestHandlerFactory; if (handler != null) { const string renderProcessCrashedBody = "

Render Process Crashed

Your seeing this message as the render process has crashed

"; diff --git a/CefSharp.Example/CefSharp.Example.csproj b/CefSharp.Example/CefSharp.Example.csproj index a6603eec02..8c20ed71d1 100644 --- a/CefSharp.Example/CefSharp.Example.csproj +++ b/CefSharp.Example/CefSharp.Example.csproj @@ -82,10 +82,9 @@ - - + diff --git a/CefSharp.Example/FlashResourceHandlerFactory.cs b/CefSharp.Example/FlashResourceHandlerFactory.cs deleted file mode 100644 index 22ebbe0249..0000000000 --- a/CefSharp.Example/FlashResourceHandlerFactory.cs +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright © 2016 The CefSharp Authors. All rights reserved. -// -// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. - -namespace CefSharp.Example -{ - public class FlashResourceHandlerFactory : IResourceHandlerFactory - { - bool IResourceHandlerFactory.HasHandlers - { - get { return true; } - } - - IResourceHandler IResourceHandlerFactory.GetResourceHandler(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request) - { - if (request.Url.Contains("zeldaADPCM5bit.swf")) - { - return new FlashResourceHandler(); - } - return null; - } - } -} diff --git a/CefSharp.Example/Handlers/BrowserProcessHandler.cs b/CefSharp.Example/Handlers/BrowserProcessHandler.cs index 17f5859f8c..f483cd6784 100644 --- a/CefSharp.Example/Handlers/BrowserProcessHandler.cs +++ b/CefSharp.Example/Handlers/BrowserProcessHandler.cs @@ -24,8 +24,7 @@ void IBrowserProcessHandler.OnContextInitialized() { //The Global CookieManager has been initialized, you can now set cookies var cookieManager = Cef.GetGlobalCookieManager(); - cookieManager.SetStoragePath("cookies", true); - cookieManager.SetSupportedSchemes(new string[] { "custom" }); + cookieManager.SetSupportedSchemes(new string[] { "custom" }, true); if (cookieManager.SetCookie("custom://cefsharp/home.html", new Cookie { Name = "CefSharpTestCookie", diff --git a/CefSharp.Example/Handlers/RequestHandler.cs b/CefSharp.Example/Handlers/RequestHandler.cs index 564cf05688..36c9b91c2b 100644 --- a/CefSharp.Example/Handlers/RequestHandler.cs +++ b/CefSharp.Example/Handlers/RequestHandler.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Security.Cryptography.X509Certificates; -using System.Text; using CefSharp.Example.Filters; using CefSharp.Handler; @@ -22,7 +21,7 @@ public class RequestHandler : DefaultRequestHandler public static readonly string VersionNumberString = String.Format("Chromium: {0}, CEF: {1}, CefSharp: {2}", Cef.ChromiumVersion, Cef.CefVersion, Cef.CefSharpVersion); - private Dictionary responseDictionary = new Dictionary(); + private readonly Dictionary responseDictionary = new Dictionary(); public override bool OnBeforeBrowse(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, bool userGesture, bool isRedirect) { @@ -60,79 +59,79 @@ public override void OnPluginCrashed(IWebBrowser browserControl, IBrowser browse // TODO: Add your own code here for handling scenarios where a plugin crashed, for one reason or another. } - public override CefReturnValue OnBeforeResourceLoad(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IRequestCallback callback) - { - Uri url; - if (Uri.TryCreate(request.Url, UriKind.Absolute, out url) == false) - { - //If we're unable to parse the Uri then cancel the request - // avoid throwing any exceptions here as we're being called by unmanaged code - return CefReturnValue.Cancel; - } - - //Example of how to set Referer - // Same should work when setting any header - - // For this example only set Referer when using our custom scheme - if (url.Scheme == CefSharpSchemeHandlerFactory.SchemeName) - { - //Referrer is now set using it's own method (was previously set in headers before) - request.SetReferrer("http://google.com", ReferrerPolicy.Default); - } - - //Example of setting User-Agent in every request. - //var headers = request.Headers; - - //var userAgent = headers["User-Agent"]; - //headers["User-Agent"] = userAgent + " CefSharp"; - - //request.Headers = headers; - - //NOTE: If you do not wish to implement this method returning false is the default behaviour - // We also suggest you explicitly Dispose of the callback as it wraps an unmanaged resource. - //callback.Dispose(); - //return false; - - //NOTE: When executing the callback in an async fashion need to check to see if it's disposed - if (!callback.IsDisposed) - { - using (callback) - { - if (request.Method == "POST") - { - using (var postData = request.PostData) - { - if (postData != null) - { - var elements = postData.Elements; - - var charSet = request.GetCharSet(); - - foreach (var element in elements) - { - if (element.Type == PostDataElementType.Bytes) - { - var body = element.GetBody(charSet); - } - } - } - } - } - - //Note to Redirect simply set the request Url - //if (request.Url.StartsWith("https://www.google.com", StringComparison.OrdinalIgnoreCase)) - //{ - // request.Url = "https://github.com/"; - //} - - //Callback in async fashion - //callback.Continue(true); - //return CefReturnValue.ContinueAsync; - } - } - - return CefReturnValue.Continue; - } + //public override CefReturnValue OnBeforeResourceLoad(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IRequestCallback callback) + //{ + // Uri url; + // if (Uri.TryCreate(request.Url, UriKind.Absolute, out url) == false) + // { + // //If we're unable to parse the Uri then cancel the request + // // avoid throwing any exceptions here as we're being called by unmanaged code + // return CefReturnValue.Cancel; + // } + + // //Example of how to set Referer + // // Same should work when setting any header + + // // For this example only set Referer when using our custom scheme + // if (url.Scheme == CefSharpSchemeHandlerFactory.SchemeName) + // { + // //Referrer is now set using it's own method (was previously set in headers before) + // request.SetReferrer("http://google.com", ReferrerPolicy.Default); + // } + + // //Example of setting User-Agent in every request. + // //var headers = request.Headers; + + // //var userAgent = headers["User-Agent"]; + // //headers["User-Agent"] = userAgent + " CefSharp"; + + // //request.Headers = headers; + + // //NOTE: If you do not wish to implement this method returning false is the default behaviour + // // We also suggest you explicitly Dispose of the callback as it wraps an unmanaged resource. + // //callback.Dispose(); + // //return false; + + // //NOTE: When executing the callback in an async fashion need to check to see if it's disposed + // if (!callback.IsDisposed) + // { + // using (callback) + // { + // if (request.Method == "POST") + // { + // using (var postData = request.PostData) + // { + // if (postData != null) + // { + // var elements = postData.Elements; + + // var charSet = request.GetCharSet(); + + // foreach (var element in elements) + // { + // if (element.Type == PostDataElementType.Bytes) + // { + // var body = element.GetBody(charSet); + // } + // } + // } + // } + // } + + // //Note to Redirect simply set the request Url + // //if (request.Url.StartsWith("https://www.google.com", StringComparison.OrdinalIgnoreCase)) + // //{ + // // request.Url = "https://github.com/"; + // //} + + // //Callback in async fashion + // //callback.Continue(true); + // //return CefReturnValue.ContinueAsync; + // } + // } + + // return CefReturnValue.Continue; + //} public override bool GetAuthCredentials(IWebBrowser browserControl, IBrowser browser, IFrame frame, bool isProxy, string host, int port, string realm, string scheme, IAuthCallback callback) { @@ -178,74 +177,74 @@ public override bool OnQuotaRequest(IWebBrowser browserControl, IBrowser browser return false; } - public override void OnResourceRedirect(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response, ref string newUrl) - { - //Example of how to redirect - need to check `newUrl` in the second pass - //if (request.Url.StartsWith("https://www.google.com", StringComparison.OrdinalIgnoreCase) && !newUrl.Contains("github")) - //{ - // newUrl = "https://github.com"; - //} - } + //public override void OnResourceRedirect(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response, ref string newUrl) + //{ + // //Example of how to redirect - need to check `newUrl` in the second pass + // //if (request.Url.StartsWith("https://www.google.com", StringComparison.OrdinalIgnoreCase) && !newUrl.Contains("github")) + // //{ + // // newUrl = "https://github.com"; + // //} + //} - public override bool OnProtocolExecution(IWebBrowser browserControl, IBrowser browser, string url) - { - return url.StartsWith("mailto"); - } + //public override bool OnProtocolExecution(IWebBrowser browserControl, IBrowser browser, string url) + //{ + // return url.StartsWith("mailto"); + //} public override void OnRenderViewReady(IWebBrowser browserControl, IBrowser browser) { } - public override bool OnResourceResponse(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response) - { - //NOTE: You cannot modify the response, only the request - // You can now access the headers - //var headers = response.Headers; - - return false; - } - - public override IResponseFilter GetResourceResponseFilter(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response) - { - var url = new Uri(request.Url); - if (url.Scheme == CefSharpSchemeHandlerFactory.SchemeName) - { - if (request.Url.Equals(CefExample.ResponseFilterTestUrl, StringComparison.OrdinalIgnoreCase)) - { - return new FindReplaceResponseFilter("REPLACE_THIS_STRING", "This is the replaced string!"); - } - - if (request.Url.Equals("custom://cefsharp/assets/js/jquery.js", StringComparison.OrdinalIgnoreCase)) - { - return new AppendResponseFilter(System.Environment.NewLine + "//CefSharp Appended this comment."); - } - - //Only called for our customScheme - var dataFilter = new MemoryStreamResponseFilter(); - responseDictionary.Add(request.Identifier, dataFilter); - return dataFilter; - } - - //return new PassThruResponseFilter(); - return null; - } - - public override void OnResourceLoadComplete(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response, UrlRequestStatus status, long receivedContentLength) - { - var url = new Uri(request.Url); - if (url.Scheme == CefSharpSchemeHandlerFactory.SchemeName) - { - MemoryStreamResponseFilter filter; - if (responseDictionary.TryGetValue(request.Identifier, out filter)) - { - //TODO: Do something with the data here - var data = filter.Data; - var dataLength = filter.Data.Length; - //NOTE: You may need to use a different encoding depending on the request - var dataAsUtf8String = Encoding.UTF8.GetString(data); - } - } - } + //public override bool OnResourceResponse(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response) + //{ + // //NOTE: You cannot modify the response, only the request + // // You can now access the headers + // //var headers = response.Headers; + + // return false; + //} + + //public override IResponseFilter GetResourceResponseFilter(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response) + //{ + // var url = new Uri(request.Url); + // if (url.Scheme == CefSharpSchemeHandlerFactory.SchemeName) + // { + // if (request.Url.Equals(CefExample.ResponseFilterTestUrl, StringComparison.OrdinalIgnoreCase)) + // { + // return new FindReplaceResponseFilter("REPLACE_THIS_STRING", "This is the replaced string!"); + // } + + // if (request.Url.Equals("custom://cefsharp/assets/js/jquery.js", StringComparison.OrdinalIgnoreCase)) + // { + // return new AppendResponseFilter(System.Environment.NewLine + "//CefSharp Appended this comment."); + // } + + // //Only called for our customScheme + // var dataFilter = new MemoryStreamResponseFilter(); + // responseDictionary.Add(request.Identifier, dataFilter); + // return dataFilter; + // } + + // //return new PassThruResponseFilter(); + // return null; + //} + + //public override void OnResourceLoadComplete(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response, UrlRequestStatus status, long receivedContentLength) + //{ + // var url = new Uri(request.Url); + // if (url.Scheme == CefSharpSchemeHandlerFactory.SchemeName) + // { + // MemoryStreamResponseFilter filter; + // if (responseDictionary.TryGetValue(request.Identifier, out filter)) + // { + // //TODO: Do something with the data here + // var data = filter.Data; + // var dataLength = filter.Data.Length; + // //NOTE: You may need to use a different encoding depending on the request + // var dataAsUtf8String = Encoding.UTF8.GetString(data); + // } + // } + //} } } diff --git a/CefSharp.Example/InMemorySchemeAndResourceHandlerFactory.cs b/CefSharp.Example/InMemorySchemeHandlerFactory.cs similarity index 62% rename from CefSharp.Example/InMemorySchemeAndResourceHandlerFactory.cs rename to CefSharp.Example/InMemorySchemeHandlerFactory.cs index a892a2e5df..667522f570 100644 --- a/CefSharp.Example/InMemorySchemeAndResourceHandlerFactory.cs +++ b/CefSharp.Example/InMemorySchemeHandlerFactory.cs @@ -10,18 +10,18 @@ namespace CefSharp.Example { /// - /// Demo ISchemeHandlerFactory and IResourceHandlerFactory, reads that from resource in memory, could just + /// Demo ISchemeHandlerFactory reads that from resource in memory, could just /// as easily be from files on disk - only use this method if you already have pre loaded data, don't perform /// any web requests here or database lookups, best for static data only. /// - public class InMemorySchemeAndResourceHandlerFactory : ISchemeHandlerFactory, IResourceHandlerFactory + public class InMemorySchemeHandlerFactory : ISchemeHandlerFactory { /// /// Just a simple dictionary for resource lookup /// private static readonly IDictionary ResourceDictionary; - static InMemorySchemeAndResourceHandlerFactory() + static InMemorySchemeHandlerFactory() { ResourceDictionary = new Dictionary { @@ -81,46 +81,5 @@ IResourceHandler ISchemeHandlerFactory.Create(IBrowser browser, IFrame frame, st return null; } - - /// - /// This is typically required for the internal implementation and is here for performance reasons, - /// in general you'd just return true - /// - bool IResourceHandlerFactory.HasHandlers - { - get { return true; } - } - - /// - /// The main method when implementing an IResourceHandlerFactory, use for standard schemes like http/https - /// - /// the ChromiumWebBrowser instance this handler is assocated with - /// browser - /// frame - /// request, we'll use this to check the Url and load the appropriate resource - /// - /// return null to invoke the default behaviour, this is important when you want to only intercept a few specific requests - /// if we have a string that represents our resource in the lookup dictionary then return it as an IResourceHandler - /// - IResourceHandler IResourceHandlerFactory.GetResourceHandler(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request) - { - var uri = new Uri(request.Url); - //Compare scheme and host - if (string.Equals(uri.Scheme, "http", StringComparison.OrdinalIgnoreCase) && string.Equals(uri.Host, "cefsharp", StringComparison.OrdinalIgnoreCase)) - { - var fileName = uri.AbsolutePath; - var extension = Path.GetExtension(fileName); - - string resource; - if (ResourceDictionary.TryGetValue(fileName, out resource) && !string.IsNullOrEmpty(resource)) - { - //For css/js/etc it's important to specify a mime/type, here we use the file extension to perform a lookup - //there are overloads where you can specify more options including Encoding, mimeType - return ResourceHandler.FromString(resource, extension); - } - } - - return null; - } } } diff --git a/CefSharp.Example/RequestEventHandler/RequestEventHandler.cs b/CefSharp.Example/RequestEventHandler/RequestEventHandler.cs index 632d3f4940..cb69f2609e 100644 --- a/CefSharp.Example/RequestEventHandler/RequestEventHandler.cs +++ b/CefSharp.Example/RequestEventHandler/RequestEventHandler.cs @@ -75,15 +75,15 @@ void IRequestHandler.OnPluginCrashed(IWebBrowser browserControl, IBrowser browse OnPluginCrashedEvent?.Invoke(this, args); } - CefReturnValue IRequestHandler.OnBeforeResourceLoad(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IRequestCallback callback) - { - var args = new OnBeforeResourceLoadEventArgs(browserControl, browser, frame, request, callback); + //CefReturnValue IRequestHandler.OnBeforeResourceLoad(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IRequestCallback callback) + //{ + // var args = new OnBeforeResourceLoadEventArgs(browserControl, browser, frame, request, callback); - OnBeforeResourceLoadEvent?.Invoke(this, args); + // OnBeforeResourceLoadEvent?.Invoke(this, args); - EnsureCallbackDisposal(callback); - return args.ContinuationHandling; - } + // EnsureCallbackDisposal(callback); + // return args.ContinuationHandling; + //} bool IRequestHandler.GetAuthCredentials(IWebBrowser browserControl, IBrowser browser, IFrame frame, bool isProxy, string host, int port, string realm, string scheme, IAuthCallback callback) { @@ -102,23 +102,23 @@ void IRequestHandler.OnRenderProcessTerminated(IWebBrowser browserControl, IBrow OnRenderProcessTerminatedEvent?.Invoke(this, args); } - bool IRequestHandler.CanGetCookies(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request) - { - var args = new CanGetCookiesEventArg(browserControl, browser, frame, request); + //bool IRequestHandler.CanGetCookies(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request) + //{ + // var args = new CanGetCookiesEventArg(browserControl, browser, frame, request); - CanGetCookiesEvent?.Invoke(this, args); + // CanGetCookiesEvent?.Invoke(this, args); - return args.GetCookies; - } + // return args.GetCookies; + //} - bool IRequestHandler.CanSetCookie(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, Cookie cookie) - { - var args = new CanSetCookieEventArg(browserControl, browser, frame, request, cookie); + //bool IRequestHandler.CanSetCookie(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, Cookie cookie) + //{ + // var args = new CanSetCookieEventArg(browserControl, browser, frame, request, cookie); - CanSetCookieEvent?.Invoke(this, args); + // CanSetCookieEvent?.Invoke(this, args); - return args.SetCookie; - } + // return args.SetCookie; + //} bool IRequestHandler.OnQuotaRequest(IWebBrowser browserControl, IBrowser browser, string originUrl, long newSize, IRequestCallback callback) { @@ -129,22 +129,22 @@ bool IRequestHandler.OnQuotaRequest(IWebBrowser browserControl, IBrowser browser return args.ContinueAsync; } - void IRequestHandler.OnResourceRedirect(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response, ref string newUrl) - { - var args = new OnResourceRedirectEventArgs(browserControl, browser, frame, request, response, newUrl); - OnResourceRedirectEvent?.Invoke(this, args); - if (!Equals(newUrl, args.NewUrl)) - { - newUrl = args.NewUrl; - } - } + //void IRequestHandler.OnResourceRedirect(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response, ref string newUrl) + //{ + // var args = new OnResourceRedirectEventArgs(browserControl, browser, frame, request, response, newUrl); + // OnResourceRedirectEvent?.Invoke(this, args); + // if (!Equals(newUrl, args.NewUrl)) + // { + // newUrl = args.NewUrl; + // } + //} - bool IRequestHandler.OnProtocolExecution(IWebBrowser browserControl, IBrowser browser, string url) - { - var args = new OnProtocolExecutionEventArgs(browserControl, browser, url); - OnProtocolExecutionEvent?.Invoke(this, args); - return args.AttemptExecution; - } + //bool IRequestHandler.OnProtocolExecution(IWebBrowser browserControl, IBrowser browser, string url) + //{ + // var args = new OnProtocolExecutionEventArgs(browserControl, browser, url); + // OnProtocolExecutionEvent?.Invoke(this, args); + // return args.AttemptExecution; + //} void IRequestHandler.OnRenderViewReady(IWebBrowser browserControl, IBrowser browser) { @@ -152,26 +152,26 @@ void IRequestHandler.OnRenderViewReady(IWebBrowser browserControl, IBrowser brow OnRenderViewReadyEvent?.Invoke(this, args); } - bool IRequestHandler.OnResourceResponse(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response) - { - var args = new OnResourceResponseEventArgs(browserControl, browser, frame, request, response); - OnResourceResponseEvent?.Invoke(this, args); - return args.RedirectOrRetry; - } + //bool IRequestHandler.OnResourceResponse(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response) + //{ + // var args = new OnResourceResponseEventArgs(browserControl, browser, frame, request, response); + // OnResourceResponseEvent?.Invoke(this, args); + // return args.RedirectOrRetry; + //} - IResponseFilter IRequestHandler.GetResourceResponseFilter(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response) - { - var args = new GetResourceResponseFilterEventArgs(browserControl, browser, frame, request, response); - GetResourceResponseFilterEvent?.Invoke(this, args); - return args.ResponseFilter; - } + //IResponseFilter IRequestHandler.GetResourceResponseFilter(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response) + //{ + // var args = new GetResourceResponseFilterEventArgs(browserControl, browser, frame, request, response); + // GetResourceResponseFilterEvent?.Invoke(this, args); + // return args.ResponseFilter; + //} - void IRequestHandler.OnResourceLoadComplete(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response, UrlRequestStatus status, long receivedContentLength) - { - var args = new OnResourceLoadCompleteEventArgs(browserControl, browser, frame, request, response, status, receivedContentLength); + //void IRequestHandler.OnResourceLoadComplete(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response, UrlRequestStatus status, long receivedContentLength) + //{ + // var args = new OnResourceLoadCompleteEventArgs(browserControl, browser, frame, request, response, status, receivedContentLength); - OnResourceLoadCompleteEvent?.Invoke(this, args); - } + // OnResourceLoadCompleteEvent?.Invoke(this, args); + //} bool IRequestHandler.OnSelectClientCertificate(IWebBrowser browserControl, IBrowser browser, bool isProxy, string host, int port, X509Certificate2Collection certificates, ISelectClientCertificateCallback callback) { @@ -194,5 +194,10 @@ private static void EnsureCallbackDisposal(IAuthCallback callbackToDispose) callbackToDispose.Dispose(); } } + + IResourceRequestHandler IRequestHandler.GetResourceRequestHandler(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, bool iNavigation, bool isDownload, string requestInitiator, ref bool disableDefaultHandling) + { + return null; + } } } diff --git a/CefSharp.OffScreen.Example/CefSharp.OffScreen.Example.csproj b/CefSharp.OffScreen.Example/CefSharp.OffScreen.Example.csproj index e765bcc086..3ecb45d74d 100644 --- a/CefSharp.OffScreen.Example/CefSharp.OffScreen.Example.csproj +++ b/CefSharp.OffScreen.Example/CefSharp.OffScreen.Example.csproj @@ -1,7 +1,7 @@  - - + + diff --git a/CefSharp.OffScreen.Example/packages.config b/CefSharp.OffScreen.Example/packages.config index 75bf7d42e6..9a753fcc20 100644 --- a/CefSharp.OffScreen.Example/packages.config +++ b/CefSharp.OffScreen.Example/packages.config @@ -1,6 +1,6 @@  - - + + \ No newline at end of file diff --git a/CefSharp.OffScreen/ChromiumWebBrowser.cs b/CefSharp.OffScreen/ChromiumWebBrowser.cs index 0eeb3fd69a..99bf6bc005 100644 --- a/CefSharp.OffScreen/ChromiumWebBrowser.cs +++ b/CefSharp.OffScreen/ChromiumWebBrowser.cs @@ -169,10 +169,10 @@ public bool IsDisposed /// The drag handler. public IDragHandler DragHandler { get; set; } /// - /// Implement and control the loading of resources + /// Implement and control the loading of resources /// /// The resource handler factory. - public IResourceHandlerFactory ResourceHandlerFactory { get; set; } + public IResourceRequestHandlerFactory ResourceRequestHandlerFactory { get; set; } /// /// Implement and assign to handle messages from the render process. /// @@ -312,7 +312,6 @@ public ChromiumWebBrowser(string address = "", BrowserSettings browserSettings = } } - ResourceHandlerFactory = new DefaultResourceHandlerFactory(); RequestContext = requestContext; Cef.AddDisposable(this); diff --git a/CefSharp.Test/CefSharp.Test.csproj b/CefSharp.Test/CefSharp.Test.csproj index 826f7df851..2ff529312b 100644 --- a/CefSharp.Test/CefSharp.Test.csproj +++ b/CefSharp.Test/CefSharp.Test.csproj @@ -1,7 +1,7 @@  - - + + Debug diff --git a/CefSharp.Test/packages.config b/CefSharp.Test/packages.config index d65b9cc089..0f6fd7107b 100644 --- a/CefSharp.Test/packages.config +++ b/CefSharp.Test/packages.config @@ -1,8 +1,8 @@  - - + + diff --git a/CefSharp.WinForms.Example/CefSharp.WinForms.Example.csproj b/CefSharp.WinForms.Example/CefSharp.WinForms.Example.csproj index b2380319de..18b03c970f 100644 --- a/CefSharp.WinForms.Example/CefSharp.WinForms.Example.csproj +++ b/CefSharp.WinForms.Example/CefSharp.WinForms.Example.csproj @@ -1,7 +1,7 @@  - - + + Debug diff --git a/CefSharp.WinForms.Example/packages.config b/CefSharp.WinForms.Example/packages.config index 75bf7d42e6..9a753fcc20 100644 --- a/CefSharp.WinForms.Example/packages.config +++ b/CefSharp.WinForms.Example/packages.config @@ -1,6 +1,6 @@  - - + + \ No newline at end of file diff --git a/CefSharp.WinForms/ChromiumWebBrowser.cs b/CefSharp.WinForms/ChromiumWebBrowser.cs index 33fdcb021c..ebe2cb6966 100644 --- a/CefSharp.WinForms/ChromiumWebBrowser.cs +++ b/CefSharp.WinForms/ChromiumWebBrowser.cs @@ -251,11 +251,11 @@ public IRequestContext RequestContext [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), DefaultValue(null)] public IDragHandler DragHandler { get; set; } /// - /// Implement and control the loading of resources + /// Implement and control the loading of resources /// /// The resource handler factory. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), DefaultValue(null)] - public IResourceHandlerFactory ResourceHandlerFactory { get; set; } + public IResourceRequestHandlerFactory ResourceRequestHandlerFactory { get; set; } /// /// Event handler that will get called when the resource load for a navigation fails or is canceled. @@ -450,11 +450,6 @@ private void InitializeFieldsAndCefIfRequired() FocusHandler = new DefaultFocusHandler(); } - if (ResourceHandlerFactory == null) - { - ResourceHandlerFactory = new DefaultResourceHandlerFactory(); - } - if (browserSettings == null) { browserSettings = new BrowserSettings(frameworkCreated: true); diff --git a/CefSharp.Wpf.Example/CefSharp.Wpf.Example.csproj b/CefSharp.Wpf.Example/CefSharp.Wpf.Example.csproj index b9c68d0d0d..15be98b457 100644 --- a/CefSharp.Wpf.Example/CefSharp.Wpf.Example.csproj +++ b/CefSharp.Wpf.Example/CefSharp.Wpf.Example.csproj @@ -1,7 +1,7 @@  - - + + Debug diff --git a/CefSharp.Wpf.Example/Handlers/DragHandler.cs b/CefSharp.Wpf.Example/Handlers/DragHandler.cs index ffcb5d6500..6d143acf17 100644 --- a/CefSharp.Wpf.Example/Handlers/DragHandler.cs +++ b/CefSharp.Wpf.Example/Handlers/DragHandler.cs @@ -18,7 +18,7 @@ bool IDragHandler.OnDragEnter(IWebBrowser browserControl, IBrowser browser, IDra return false; } - void IDragHandler.OnDraggableRegionsChanged(IWebBrowser browserControl, IBrowser browser, IList regions) + void IDragHandler.OnDraggableRegionsChanged(IWebBrowser browserControl, IBrowser browser, IFrame frame, IList regions) { //By default popup browers are native windows in WPF so we cannot handle their drag using this method if (browser.IsPopup == false) diff --git a/CefSharp.Wpf.Example/Handlers/RequestContextHandler.cs b/CefSharp.Wpf.Example/Handlers/RequestContextHandler.cs index 358552b0fc..d268ad377a 100644 --- a/CefSharp.Wpf.Example/Handlers/RequestContextHandler.cs +++ b/CefSharp.Wpf.Example/Handlers/RequestContextHandler.cs @@ -6,7 +6,12 @@ namespace CefSharp.Wpf.Example.Handlers { public class RequestContextHandler : IRequestContextHandler { - private ICookieManager customCookieManager; + private readonly ICookieManager customCookieManager; + + IResourceRequestHandler IRequestContextHandler.GetResourceRequestHandler(IBrowser browser, IFrame frame, IRequest request, bool iNavigation, bool isDownload, string requestInitiator, ref bool disableDefaultHandling) + { + return null; + } bool IRequestContextHandler.OnBeforePluginLoad(string mimeType, string url, bool isMainFrame, string topOriginUrl, WebPluginInfo pluginInfo, ref PluginPolicy pluginPolicy) { @@ -16,28 +21,6 @@ bool IRequestContextHandler.OnBeforePluginLoad(string mimeType, string url, bool return false; } - ICookieManager IRequestContextHandler.GetCookieManager() - { - if (customCookieManager == null) - { - //In memory cookie manager - //customCookieManager = new CookieManager(null, persistSessionCookies: false, callback: null); - - //Store cookies in cookies directory (user must have write permission to this folder) - customCookieManager = new CookieManager("cookies", persistSessionCookies: false, callback: null); - } - - return customCookieManager; - - //NOTE: DO NOT RETURN A NEW COOKIE MANAGER EVERY TIME - //This method will be called many times, you should return the same cookie manager within the scope - //of the RequestContext (unless you REALLY know what your doing) - //return new CookieManager("cookies", persistSessionCookies: false, callback: null); - - //Default to using the Global cookieManager (default) - //return null; - } - void IRequestContextHandler.OnRequestContextInitialized(IRequestContext requestContext) { //You can set preferences here on your newly initialized request context. diff --git a/CefSharp.Wpf.Example/packages.config b/CefSharp.Wpf.Example/packages.config index aa9488d1a2..1ae9d0f30c 100644 --- a/CefSharp.Wpf.Example/packages.config +++ b/CefSharp.Wpf.Example/packages.config @@ -1,7 +1,7 @@  - - + + diff --git a/CefSharp.Wpf/ChromiumWebBrowser.cs b/CefSharp.Wpf/ChromiumWebBrowser.cs index b90896c868..b4c2f8d8b9 100644 --- a/CefSharp.Wpf/ChromiumWebBrowser.cs +++ b/CefSharp.Wpf/ChromiumWebBrowser.cs @@ -250,10 +250,10 @@ public IRequestContext RequestContext /// The drag handler. public IDragHandler DragHandler { get; set; } /// - /// Implement and control the loading of resources + /// Implement and control the loading of resources /// /// The resource handler factory. - public IResourceHandlerFactory ResourceHandlerFactory { get; set; } + public IResourceRequestHandlerFactory ResourceRequestHandlerFactory { get; set; } /// /// Implement and control how the control is rendered /// @@ -564,7 +564,6 @@ private void NoInliningConstructor() managedCefBrowserAdapter = new ManagedCefBrowserAdapter(this, true); - ResourceHandlerFactory = new DefaultResourceHandlerFactory(); browserSettings = new BrowserSettings(frameworkCreated: true); RenderHandler = new InteropBitmapRenderHandler(); diff --git a/CefSharp/CefSharp.csproj b/CefSharp/CefSharp.csproj index e244b3f8ac..45ce8fe208 100644 --- a/CefSharp/CefSharp.csproj +++ b/CefSharp/CefSharp.csproj @@ -98,6 +98,8 @@ + + @@ -114,11 +116,15 @@ + + + + @@ -126,8 +132,6 @@ - - @@ -235,7 +239,6 @@ - @@ -248,7 +251,6 @@ - @@ -264,7 +266,6 @@ - @@ -311,7 +312,9 @@ - + + +