Skip to content

Commit

Permalink
Initial version 75 upgrade and NetworkService changes
Browse files Browse the repository at this point in the history
Compiles, that's about it at this point, there are major CEF breaking changes, and lots to be addressed.

Browser Process (main process)
- Removed IResourceHandlerFactory as it no longer fits with the structure that CEF provides
- New IResourceRequestHandler interface added, not plumbed in yet
- CefSettings - Add RootCachePath and ApplicationClientIdForFileScanning

BrowserSubprocess (render process)
- SendProcessMessage was moved from CefBrowser to CefFrame
- OnBrowserCreated added extraInfo param

The BrowserSubprocess changes for this upgrade should be complete
  • Loading branch information
amaitland committed Jun 12, 2019
1 parent 75efba1 commit a83932c
Show file tree
Hide file tree
Showing 59 changed files with 1,035 additions and 1,275 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace CefSharp
bool JavascriptAsyncMethodHandler::Execute(const CefString& name, CefRefPtr<CefV8Value> object, const CefV8ValueList& arguments, CefRefPtr<CefV8Value>& retval, CefString& exception)
{
auto context = CefV8Context::GetCurrentContext();
auto browser = context->GetBrowser();
auto frame = context->GetFrame();

CefRefPtr<CefV8Value> promiseData;
CefRefPtr<CefV8Exception> promiseException;
Expand Down Expand Up @@ -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;
}
Expand Down
18 changes: 9 additions & 9 deletions CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace CefSharp
};

// CefRenderProcessHandler
void CefAppUnmanagedWrapper::OnBrowserCreated(CefRefPtr<CefBrowser> browser)
void CefAppUnmanagedWrapper::OnBrowserCreated(CefRefPtr<CefBrowser> browser, CefRefPtr<CefDictionaryValue> extraInfo)
{
auto wrapper = gcnew CefBrowserWrapper(browser);
_onBrowserCreated->Invoke(wrapper);
Expand Down Expand Up @@ -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<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context)
Expand All @@ -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());

Expand Down Expand Up @@ -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<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context, CefRefPtr<CefV8Exception> exception, CefRefPtr<CefV8StackTrace> stackTrace)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -269,7 +269,7 @@ namespace CefSharp
return wrapper;
}

bool CefAppUnmanagedWrapper::OnProcessMessageReceived(CefRefPtr<CefBrowser> browser, CefProcessId sourceProcessId, CefRefPtr<CefProcessMessage> message)
bool CefAppUnmanagedWrapper::OnProcessMessageReceived(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefProcessId sourceProcessId, CefRefPtr<CefProcessMessage> message)
{
auto handled = false;
auto name = message->GetName();
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -471,7 +471,7 @@ namespace CefSharp
{
responseArgList->SetString(2, errorMessage);
}
browser->SendProcessMessage(sourceProcessId, response);
frame->SendProcessMessage(sourceProcessId, response);

handled = true;
}
Expand Down Expand Up @@ -594,7 +594,7 @@ namespace CefSharp

args->SetList(0, boundObjects);

browser->SendProcessMessage(CefProcessId::PID_BROWSER, msg);
frame->SendProcessMessage(CefProcessId::PID_BROWSER, msg);
}
}
finally
Expand Down
4 changes: 2 additions & 2 deletions CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ namespace CefSharp
JavascriptRootObjectWrapper^ GetJsRootObjectWrapper(int browserId, int64 frameId);

virtual DECL CefRefPtr<CefRenderProcessHandler> GetRenderProcessHandler() OVERRIDE;
virtual DECL void OnBrowserCreated(CefRefPtr<CefBrowser> browser) OVERRIDE;
virtual DECL void OnBrowserCreated(CefRefPtr<CefBrowser> browser, CefRefPtr<CefDictionaryValue> extraInfo) OVERRIDE;
virtual DECL void OnBrowserDestroyed(CefRefPtr<CefBrowser> browser) OVERRIDE;
virtual DECL void OnContextCreated(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context) OVERRIDE;
virtual DECL void OnContextReleased(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context) OVERRIDE;
virtual DECL bool OnProcessMessageReceived(CefRefPtr<CefBrowser> browser, CefProcessId sourceProcessId, CefRefPtr<CefProcessMessage> message) OVERRIDE;
virtual DECL bool OnProcessMessageReceived(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefProcessId sourceProcessId, CefRefPtr<CefProcessMessage> message) OVERRIDE;
virtual DECL void OnRenderThreadCreated(CefRefPtr<CefListValue> extraInfo) OVERRIDE;
virtual DECL void OnWebKitInitialized() OVERRIDE;
virtual DECL void OnRegisterCustomSchemes(CefRawPtr<CefSchemeRegistrar> registrar) OVERRIDE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand All @@ -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);
Expand All @@ -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();
}
Expand Down
60 changes: 35 additions & 25 deletions CefSharp.BrowserSubprocess.Core/RegisterBoundObjectHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ namespace CefSharp
if (cachedObjects->Count == objectCount && ignoreCache == false)
{
auto frame = context->GetFrame();

if (frame.get())
{
if (Object::ReferenceEquals(_browserWrapper, nullptr))
Expand Down Expand Up @@ -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);
}
}
}
}
Expand All @@ -331,7 +341,7 @@ namespace CefSharp
}

private:
void NotifyObjectBound(const CefRefPtr<CefBrowser> browser, List<Tuple<String^, bool, bool>^>^ objectNamesWithBoundStatus)
void NotifyObjectBound(const CefRefPtr<CefFrame> frame, List<Tuple<String^, bool, bool>^>^ 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
Expand All @@ -358,7 +368,7 @@ namespace CefSharp

args->SetList(0, boundObjects);

browser->SendProcessMessage(CefProcessId::PID_BROWSER, msg);
frame->SendProcessMessage(CefProcessId::PID_BROWSER, msg);
}


Expand Down
26 changes: 26 additions & 0 deletions CefSharp.Core/AbstractCefSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,20 @@ namespace CefSharp
void set(String^ value) { StringUtils::AssignNativeFromClr(_cefSettings->cache_path, value); }
}

/// <summary>
/// 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.
/// </summary>
property String^ RootCachePath
{
String^ get() { return StringUtils::ToClr(_cefSettings->root_cache_path); }
void set(String^ value) { StringUtils::AssignNativeFromClr(_cefSettings->root_cache_path, value); }
}

/// <summary>
/// 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
Expand Down Expand Up @@ -384,6 +398,18 @@ namespace CefSharp
void set(uint32 value) { _cefSettings->background_color = value; }
}

/// <summary>
/// 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.
/// </summary>
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); }
}

/// <summary>
/// Registers a custom scheme using the provided settings.
/// </summary>
Expand Down
22 changes: 1 addition & 21 deletions CefSharp.Core/Cef.h
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ namespace CefSharp

/// <summary>
/// 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.
/// </summary>
Expand All @@ -383,26 +383,6 @@ namespace CefSharp
return nullptr;
}

/// <summary>
/// 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.
/// </summary>
/// <returns>A blocking cookie manager</returns>
static ICookieManager^ GetBlockingCookieManager()
{
auto cookieManager = CefCookieManager::GetBlockingManager();
if (cookieManager.get())
{
return gcnew CookieManager(cookieManager);
}

return nullptr;
}

/// <summary>
/// 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).
Expand Down
1 change: 1 addition & 0 deletions CefSharp.Core/CefSharp.Core.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@
<ClInclude Include="Internals\CefExtensionHandlerAdapter.h" />
<ClInclude Include="Internals\CefExtensionWrapper.h" />
<ClInclude Include="Internals\CefGetExtensionResourceCallbackWrapper.h" />
<ClInclude Include="Internals\CefResourceRequestHandlerAdapter.h" />
<ClInclude Include="Internals\CefRunFileDialogCallbackAdapter.h" />
<ClInclude Include="Internals\CefSchemeRegistrarWrapper.h" />
<ClInclude Include="Internals\CefValueWrapper.h" />
Expand Down
3 changes: 3 additions & 0 deletions CefSharp.Core/CefSharp.Core.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,9 @@
<ClInclude Include="Internals\CefSchemeRegistrarWrapper.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Internals\CefResourceRequestHandlerAdapter.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Internals\CefSharpBrowserWrapper.h">
Expand Down
13 changes: 2 additions & 11 deletions CefSharp.Core/CookieManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<String^>^ schemes, bool includeDefaults, ICompletionCallback^ callback)
{
ThrowIfDisposed();

CefRefPtr<CefCompletionCallback> wrapper = callback == nullptr ? NULL : new CefCompletionCallbackAdapter(callback);

return _cookieManager->SetStoragePath(StringUtils::ToNative(path), persistSessionCookies, wrapper);
}

void CookieManager::SetSupportedSchemes(cli::array<String^>^ schemes, ICompletionCallback^ callback)
{
ThrowIfDisposed();

CefRefPtr<CefCompletionCallback> 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)
Expand Down
Loading

0 comments on commit a83932c

Please sign in to comment.