mirror of
https://github.com/cefsharp/CefSharp.git
synced 2026-12-05 11:42:36 +00:00
00d57a555c
* Javascript Binding - Add Ability to limit origins * Move JS binding settings to CefBrowserWrapper and optimize origin validation * Initialize origins to null * Normalize allowed origins * Optimize origin validation * Add null check for origin compare * Fix JavaScript Binding API settings for popups Move the JS binding API configuration block out of the !browser->IsPopup() scope in OnBrowserCreated. This ensures that IsJavascriptBindingApiAllowed() enforces configured restrictions for popups as well. * Fix possible null deref for JavascriptBindingApiAllowOrigins In IsJavascriptBindingApiAllowed, added a null check for JavascriptBindingApiAllowOrigins to prevent a potential null dereference if JavascriptBindingApiHasAllowOrigins is true but the allowOrigins list itself was null. * Simplify origin normalization and add null check * Add more test cases * Refactor IsJavascriptBindingApiAllowed signature Refactored IsJavascriptBindingApiAllowed to accept a CefBrowserWrapper^ parameter directly, eliminating redundant lookups and improving clarity. Updated all call sites to pass the browser wrapper explicitly. * Clarify summary for HasJavascriptBindingApiAllowOrigins Clarify documentation for HasJavascriptBindingApiAllowOrigins method to specify zero or more origins * Simplify origin comparison logic in CefAppUnmanagedWrapper Refactored code to directly compare wide string origins using _wcsicmp, removing unnecessary pointer casts and null checks. This streamlines the logic and improves readability. * Add tests for JavaScript binding API behavior across cross-origin navigation --------- Co-authored-by: amaitland <307872+amaitland@users.noreply.github.com> Co-authored-by: Luca Sonntag <luca.sonntag@cgm.com>
76 lines
2.4 KiB
C++
76 lines
2.4 KiB
C++
// Copyright © 2013 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 "include/cef_browser.h"
|
|
#include "include/cef_v8.h"
|
|
|
|
#include "TypeUtils.h"
|
|
#include "Stdafx.h"
|
|
#include "JavascriptRootObjectWrapper.h"
|
|
|
|
using namespace CefSharp::BrowserSubprocess::Async;
|
|
#ifndef NETCOREAPP
|
|
using namespace System::ServiceModel;
|
|
#endif
|
|
using namespace System::Threading;
|
|
using namespace System::Threading::Tasks;
|
|
|
|
namespace CefSharp
|
|
{
|
|
namespace BrowserSubprocess
|
|
{
|
|
// "Master class" for wrapping everything that the Cef Subprocess needs
|
|
// for ONE CefBrowser.
|
|
public ref class CefBrowserWrapper
|
|
{
|
|
private:
|
|
MCefRefPtr<CefBrowser> _cefBrowser;
|
|
MCefRefPtr<CefListValue> _javascriptBindingApiAllowOrigins;
|
|
|
|
public:
|
|
CefBrowserWrapper(const CefRefPtr<CefBrowser> &cefBrowser)
|
|
{
|
|
_cefBrowser = cefBrowser.get();
|
|
BrowserId = cefBrowser->GetIdentifier();
|
|
IsPopup = cefBrowser->IsPopup();
|
|
|
|
JavascriptBindingApiEnabled = true;
|
|
JavascriptBindingApiHasAllowOrigins = false;
|
|
JavascriptBindingApiAllowOrigins = nullptr;
|
|
}
|
|
|
|
!CefBrowserWrapper()
|
|
{
|
|
_cefBrowser = nullptr;
|
|
|
|
_javascriptBindingApiAllowOrigins = nullptr;
|
|
}
|
|
|
|
~CefBrowserWrapper()
|
|
{
|
|
this->!CefBrowserWrapper();
|
|
}
|
|
|
|
property int BrowserId;
|
|
property bool IsPopup;
|
|
property bool JavascriptBindingApiEnabled;
|
|
property bool JavascriptBindingApiHasAllowOrigins;
|
|
property CefRefPtr<CefListValue> JavascriptBindingApiAllowOrigins
|
|
{
|
|
CefRefPtr<CefListValue> get() { return _javascriptBindingApiAllowOrigins.get(); }
|
|
void set(CefRefPtr<CefListValue> value) { _javascriptBindingApiAllowOrigins = value.get(); }
|
|
}
|
|
|
|
#ifndef NETCOREAPP
|
|
// This allows us to create the WCF proxies back to our parent process.
|
|
property ChannelFactory<IBrowserProcess^>^ ChannelFactory;
|
|
// The WCF proxy to the parent process.
|
|
property IBrowserProcess^ BrowserProcess;
|
|
#endif
|
|
};
|
|
}
|
|
}
|