mirror of
https://github.com/cefsharp/CefSharp.git
synced 2026-12-06 04:00:07 +00:00
Merge remote-tracking branch 'remotes/upstream/master' into cef/2272
This commit is contained in:
+12
-6
@@ -63,6 +63,11 @@ namespace CefSharp
|
||||
}
|
||||
|
||||
public:
|
||||
/// <summary>
|
||||
/// Called on the browser process UI thread immediately after the CEF context has been initialized.
|
||||
/// </summary>
|
||||
static property Action^ OnContextInitialized;
|
||||
|
||||
static void AddDisposable(IDisposable^ item)
|
||||
{
|
||||
msclr::lock l(_sync);
|
||||
@@ -162,7 +167,7 @@ namespace CefSharp
|
||||
}
|
||||
|
||||
CefMainArgs main_args;
|
||||
CefRefPtr<CefSharpApp> app(new CefSharpApp(cefSettings));
|
||||
CefRefPtr<CefSharpApp> app(new CefSharpApp(cefSettings, OnContextInitialized));
|
||||
|
||||
success = CefInitialize(main_args, *(cefSettings->_cefSettings), app.get(), NULL);
|
||||
app->CompleteSchemeRegistrations();
|
||||
@@ -431,13 +436,14 @@ namespace CefSharp
|
||||
{
|
||||
if (IsInitialized)
|
||||
{
|
||||
OnContextInitialized = nullptr;
|
||||
|
||||
msclr::lock l(_sync);
|
||||
for each(IDisposable^ diposable in Enumerable::ToList(_disposables))
|
||||
{
|
||||
msclr::lock l(_sync);
|
||||
for each(IDisposable^ diposable in Enumerable::ToList(_disposables))
|
||||
{
|
||||
delete diposable;
|
||||
}
|
||||
delete diposable;
|
||||
}
|
||||
|
||||
GC::Collect();
|
||||
GC::WaitForPendingFinalizers();
|
||||
|
||||
|
||||
@@ -11,19 +11,36 @@
|
||||
|
||||
namespace CefSharp
|
||||
{
|
||||
class CefSharpApp : public CefApp
|
||||
private class CefSharpApp : public CefApp,
|
||||
public CefBrowserProcessHandler
|
||||
{
|
||||
gcroot<CefSettings^> _cefSettings;
|
||||
gcroot<Action^> _onContextInitialized;
|
||||
|
||||
public:
|
||||
CefSharpApp(CefSettings^ cefSettings) :
|
||||
_cefSettings(cefSettings)
|
||||
CefSharpApp(CefSettings^ cefSettings, Action^ onContextInitialized) :
|
||||
_cefSettings(cefSettings),
|
||||
_onContextInitialized(onContextInitialized)
|
||||
{
|
||||
}
|
||||
|
||||
~CefSharpApp()
|
||||
{
|
||||
_cefSettings = nullptr;
|
||||
_onContextInitialized = nullptr;
|
||||
}
|
||||
|
||||
virtual CefRefPtr<CefBrowserProcessHandler> GetBrowserProcessHandler() OVERRIDE
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
virtual void OnContextInitialized() OVERRIDE
|
||||
{
|
||||
if (static_cast<Action^>(_onContextInitialized) != nullptr)
|
||||
{
|
||||
_onContextInitialized->Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
virtual void OnBeforeCommandLineProcessing(const CefString& process_type, CefRefPtr<CefCommandLine> command_line) OVERRIDE
|
||||
|
||||
@@ -183,7 +183,7 @@ namespace CefSharp
|
||||
}
|
||||
}
|
||||
|
||||
bool SendKeyEvent(int message, int wParam, IntPtr lParamIntPtr)
|
||||
bool SendKeyEvent(int message, int wParam, int lParam)
|
||||
{
|
||||
auto browser = _clientAdapter->GetCefBrowser();
|
||||
|
||||
@@ -192,8 +192,6 @@ namespace CefSharp
|
||||
return false;
|
||||
}
|
||||
|
||||
LPARAM lParam = IntPtr::Size == 8 ? lParamIntPtr.ToInt64() : lParamIntPtr.ToInt32();
|
||||
|
||||
CefKeyEvent keyEvent;
|
||||
keyEvent.windows_key_code = wParam;
|
||||
keyEvent.native_key_code = lParam;
|
||||
@@ -661,9 +659,9 @@ namespace CefSharp
|
||||
}
|
||||
}
|
||||
|
||||
void RegisterJsObject(String^ name, Object^ object)
|
||||
void RegisterJsObject(String^ name, Object^ object, bool lowerCaseJavascriptNames)
|
||||
{
|
||||
_javaScriptObjectRepository->Register(name, object);
|
||||
_javaScriptObjectRepository->Register(name, object, lowerCaseJavascriptNames);
|
||||
}
|
||||
|
||||
void ReplaceMisspelling(String^ word)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
namespace CefSharp.Example
|
||||
@@ -52,6 +53,11 @@ namespace CefSharp.Example
|
||||
SchemeHandlerFactory = new CefSharpSchemeHandlerFactory()
|
||||
});
|
||||
|
||||
Cef.OnContextInitialized = delegate
|
||||
{
|
||||
Cef.SetCookiePath("cookies", true);
|
||||
};
|
||||
|
||||
//Cef will check if all dependencies are present
|
||||
//For special case when Checking Windows Xp Dependencies
|
||||
//DependencyChecker.IsWindowsXp = true;
|
||||
|
||||
@@ -302,9 +302,9 @@ namespace CefSharp.OffScreen
|
||||
Load(url);
|
||||
}
|
||||
|
||||
public void RegisterJsObject(string name, object objectToBind)
|
||||
public void RegisterJsObject(string name, object objectToBind, bool lowerCaseJavascriptNames = true)
|
||||
{
|
||||
managedCefBrowserAdapter.RegisterJsObject(name, objectToBind);
|
||||
managedCefBrowserAdapter.RegisterJsObject(name, objectToBind, lowerCaseJavascriptNames);
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
|
||||
@@ -197,9 +197,9 @@ namespace CefSharp.WinForms
|
||||
Load(url);
|
||||
}
|
||||
|
||||
public void RegisterJsObject(string name, object objectToBind)
|
||||
public void RegisterJsObject(string name, object objectToBind, bool lowerCaseJavascriptNames = true)
|
||||
{
|
||||
managedCefBrowserAdapter.RegisterJsObject(name, objectToBind);
|
||||
managedCefBrowserAdapter.RegisterJsObject(name, objectToBind, lowerCaseJavascriptNames);
|
||||
}
|
||||
|
||||
public void ExecuteScriptAsync(string script)
|
||||
|
||||
@@ -20,6 +20,15 @@ namespace CefSharp.Wpf.Example.Views
|
||||
browser.MenuHandler = new Handlers.MenuHandler();
|
||||
browser.GeolocationHandler = new Handlers.GeolocationHandler();
|
||||
browser.DownloadHandler = new DownloadHandler();
|
||||
browser.PreviewTextInput += (o, e) =>
|
||||
{
|
||||
foreach (var character in e.Text)
|
||||
{
|
||||
browser.SendKeyEvent((int)WM.CHAR, character, 0);
|
||||
}
|
||||
|
||||
e.Handled = true;
|
||||
};
|
||||
|
||||
CefExample.RegisterTestResources(browser);
|
||||
}
|
||||
|
||||
@@ -925,7 +925,7 @@ namespace CefSharp.Wpf
|
||||
{
|
||||
Child = popupImage = CreateImage(),
|
||||
PlacementTarget = this,
|
||||
Placement = PlacementMode.Relative,
|
||||
Placement = PlacementMode.Absolute,
|
||||
};
|
||||
|
||||
newPopup.MouseEnter += PopupMouseEnter;
|
||||
@@ -963,7 +963,7 @@ namespace CefSharp.Wpf
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
|
||||
handled = managedCefBrowserAdapter.SendKeyEvent(message, wParam.ToInt32(), lParam);
|
||||
handled = managedCefBrowserAdapter.SendKeyEvent(message, wParam.CastToInt32(), lParam.CastToInt32());
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -1060,12 +1060,13 @@ namespace CefSharp.Wpf
|
||||
|
||||
private void SetPopupSizeAndPositionImpl(int width, int height, int x, int y)
|
||||
{
|
||||
popup.Width = width;
|
||||
popup.Height = height;
|
||||
popup.Width = width / matrix.M11;
|
||||
popup.Height = height / matrix.M22;
|
||||
|
||||
var popupOffset = new Point(x, y);
|
||||
popup.HorizontalOffset = popupOffset.X / matrix.M11;
|
||||
popup.VerticalOffset = popupOffset.Y / matrix.M22;
|
||||
var popupOffset = new Point(x / matrix.M11, y / matrix.M22);
|
||||
var locationFromScreen = PointToScreen(popupOffset);
|
||||
popup.HorizontalOffset = locationFromScreen.X / matrix.M11;
|
||||
popup.VerticalOffset = locationFromScreen.Y / matrix.M22;
|
||||
}
|
||||
|
||||
private void OnTooltipTimerTick(object sender, EventArgs e)
|
||||
@@ -1150,7 +1151,7 @@ namespace CefSharp.Wpf
|
||||
var message = (int)(e.IsDown ? WM.KEYDOWN : WM.KEYUP);
|
||||
var virtualKey = KeyInterop.VirtualKeyFromKey(e.Key);
|
||||
|
||||
e.Handled = managedCefBrowserAdapter.SendKeyEvent(message, virtualKey, new IntPtr((int)modifiers));
|
||||
e.Handled = managedCefBrowserAdapter.SendKeyEvent(message, virtualKey, (int)modifiers);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1386,9 +1387,9 @@ namespace CefSharp.Wpf
|
||||
managedCefBrowserAdapter.CloseDevTools();
|
||||
}
|
||||
|
||||
public void RegisterJsObject(string name, object objectToBind)
|
||||
public void RegisterJsObject(string name, object objectToBind, bool lowerCaseJavascriptNames = true)
|
||||
{
|
||||
managedCefBrowserAdapter.RegisterJsObject(name, objectToBind);
|
||||
managedCefBrowserAdapter.RegisterJsObject(name, objectToBind, lowerCaseJavascriptNames);
|
||||
}
|
||||
|
||||
public void ExecuteScriptAsync(string script)
|
||||
@@ -1472,5 +1473,17 @@ namespace CefSharp.Wpf
|
||||
{
|
||||
managedCefBrowserAdapter.SetZoomLevel(zoomLevel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends a Key Event directly to the underlying Browser (CEF).
|
||||
/// </summary>
|
||||
/// <param name="message">The message</param>
|
||||
/// <param name="wParam">The wParam</param>
|
||||
/// <param name="lParam">The lParam</param>
|
||||
/// <returns>bool</returns>
|
||||
public bool SendKeyEvent(int message, int wParam, int lParam)
|
||||
{
|
||||
return managedCefBrowserAdapter.SendKeyEvent(message, wParam, lParam);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,7 +86,8 @@ namespace CefSharp
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the object. (e.g. "foo", if you want the object to be accessible as window.foo).</param>
|
||||
/// <param name="objectToBind">The object to be made accessible to Javascript.</param>
|
||||
void RegisterJsObject(string name, object objectToBind);
|
||||
/// <param name="lowerCaseJavascriptNames">lower-case the names of properties/methods, defaults to true</param>
|
||||
void RegisterJsObject(string name, object objectToBind, bool lowerCaseJavascriptNames = true);
|
||||
|
||||
/// <summary>
|
||||
/// Execute some Javascript code in the context of this WebBrowser. As the method name implies, the script will be
|
||||
|
||||
@@ -35,14 +35,14 @@ namespace CefSharp.Internals
|
||||
return result;
|
||||
}
|
||||
|
||||
public void Register(string name, object value)
|
||||
public void Register(string name, object value, bool lowerCaseJavascriptNames)
|
||||
{
|
||||
var jsObject = CreateJavascriptObject();
|
||||
jsObject.Value = value;
|
||||
jsObject.Name = name;
|
||||
jsObject.JavascriptName = name;
|
||||
|
||||
AnalyseObjectForBinding(jsObject, analyseMethods: true, readPropertyValue: false);
|
||||
AnalyseObjectForBinding(jsObject, analyseMethods: true, readPropertyValue: false, lowerCaseJavascriptNames: lowerCaseJavascriptNames);
|
||||
|
||||
RootObject.MemberObjects.Add(jsObject);
|
||||
}
|
||||
@@ -88,7 +88,7 @@ namespace CefSharp.Internals
|
||||
jsObject.Name = "FunctionResult(" + name + ")";
|
||||
jsObject.JavascriptName = jsObject.Name;
|
||||
|
||||
AnalyseObjectForBinding(jsObject, analyseMethods: false, readPropertyValue: true);
|
||||
AnalyseObjectForBinding(jsObject, analyseMethods: false, readPropertyValue: true, lowerCaseJavascriptNames:true);
|
||||
|
||||
result = jsObject;
|
||||
}
|
||||
@@ -169,7 +169,8 @@ namespace CefSharp.Internals
|
||||
/// <param name="obj">Javascript object</param>
|
||||
/// <param name="analyseMethods">Analyse methods for inclusion in metadata model</param>
|
||||
/// <param name="readPropertyValue">When analysis is done on a property, if true then get it's value for transmission over WCF</param>
|
||||
private void AnalyseObjectForBinding(JavascriptObject obj, bool analyseMethods, bool readPropertyValue)
|
||||
/// <param name="lowerCaseJavascriptNames">decide wether your JS mathods and properties are automatically lowercased or not</param>
|
||||
private void AnalyseObjectForBinding(JavascriptObject obj, bool analyseMethods, bool readPropertyValue, bool lowerCaseJavascriptNames)
|
||||
{
|
||||
if (obj.Value == null)
|
||||
{
|
||||
@@ -192,7 +193,7 @@ namespace CefSharp.Internals
|
||||
continue;
|
||||
}
|
||||
|
||||
var jsMethod = CreateJavaScriptMethod(methodInfo);
|
||||
var jsMethod = CreateJavaScriptMethod(methodInfo, lowerCaseJavascriptNames);
|
||||
obj.Methods.Add(jsMethod);
|
||||
}
|
||||
}
|
||||
@@ -204,16 +205,16 @@ namespace CefSharp.Internals
|
||||
continue;
|
||||
}
|
||||
|
||||
var jsProperty = CreateJavaScriptProperty(propertyInfo);
|
||||
var jsProperty = CreateJavaScriptProperty(propertyInfo, lowerCaseJavascriptNames);
|
||||
if (jsProperty.IsComplexType)
|
||||
{
|
||||
var jsObject = CreateJavascriptObject();
|
||||
jsObject.Name = propertyInfo.Name;
|
||||
jsObject.JavascriptName = LowercaseFirst(propertyInfo.Name);
|
||||
jsObject.JavascriptName = GetJavascriptName(propertyInfo.Name, lowerCaseJavascriptNames);
|
||||
jsObject.Value = jsProperty.GetValue(obj.Value);
|
||||
jsProperty.JsObject = jsObject;
|
||||
|
||||
AnalyseObjectForBinding(jsProperty.JsObject, analyseMethods, readPropertyValue);
|
||||
AnalyseObjectForBinding(jsProperty.JsObject, analyseMethods, readPropertyValue, lowerCaseJavascriptNames);
|
||||
}
|
||||
else if (readPropertyValue)
|
||||
{
|
||||
@@ -223,24 +224,24 @@ namespace CefSharp.Internals
|
||||
}
|
||||
}
|
||||
|
||||
private static JavascriptMethod CreateJavaScriptMethod(MethodInfo methodInfo)
|
||||
private static JavascriptMethod CreateJavaScriptMethod(MethodInfo methodInfo, bool lowerCaseJavascriptNames)
|
||||
{
|
||||
var jsMethod = new JavascriptMethod();
|
||||
|
||||
jsMethod.ManagedName = methodInfo.Name;
|
||||
jsMethod.JavascriptName = LowercaseFirst(methodInfo.Name);
|
||||
jsMethod.JavascriptName = GetJavascriptName(methodInfo.Name, lowerCaseJavascriptNames);
|
||||
jsMethod.Function = methodInfo.Invoke;
|
||||
jsMethod.ParameterCount = methodInfo.GetParameters().Length;
|
||||
|
||||
return jsMethod;
|
||||
}
|
||||
|
||||
private static JavascriptProperty CreateJavaScriptProperty(PropertyInfo propertyInfo)
|
||||
private static JavascriptProperty CreateJavaScriptProperty(PropertyInfo propertyInfo, bool lowerCaseJavascriptNames)
|
||||
{
|
||||
var jsProperty = new JavascriptProperty();
|
||||
|
||||
jsProperty.ManagedName = propertyInfo.Name;
|
||||
jsProperty.JavascriptName = LowercaseFirst(propertyInfo.Name);
|
||||
jsProperty.JavascriptName = GetJavascriptName(propertyInfo.Name, lowerCaseJavascriptNames);
|
||||
jsProperty.SetValue = (o, v) => propertyInfo.SetValue(o, v, null);
|
||||
jsProperty.GetValue = (o) => propertyInfo.GetValue(o, null);
|
||||
|
||||
@@ -274,8 +275,13 @@ namespace CefSharp.Internals
|
||||
return !baseType.IsPrimitive && baseType != typeof(string);
|
||||
}
|
||||
|
||||
private static string LowercaseFirst(string str)
|
||||
private static string GetJavascriptName(string str, bool lowerCaseJavascriptNames)
|
||||
{
|
||||
if (!lowerCaseJavascriptNames)
|
||||
{
|
||||
return str;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(str))
|
||||
{
|
||||
return string.Empty;
|
||||
|
||||
Reference in New Issue
Block a user