From a10789749dcb3bc06be3fbc5ffb003e025aa2771 Mon Sep 17 00:00:00 2001 From: Per Lundberg Date: Mon, 13 May 2013 22:16:40 +0300 Subject: [PATCH] Whitespace fixes. (My bad; C++ settings for VS2012 was incorrectly set to use tabs instead of spaces, leading to some noise in the diff.) --- CefSharp.Wpf.Example/MainWindow.xaml.cs | 56 +-- CefSharp.Wpf/WebView.h | 420 +++++++++--------- CefSharp/BindingHandler.cpp | 546 ++++++++++++------------ CefSharp/BindingHandler.h | 46 +- CefSharp/PropertyAccessor.h | 168 ++++---- CefSharp/TypeUtil.cpp | 392 ++++++++--------- 6 files changed, 814 insertions(+), 814 deletions(-) diff --git a/CefSharp.Wpf.Example/MainWindow.xaml.cs b/CefSharp.Wpf.Example/MainWindow.xaml.cs index 3b8b6308d..139cd16dc 100644 --- a/CefSharp.Wpf.Example/MainWindow.xaml.cs +++ b/CefSharp.Wpf.Example/MainWindow.xaml.cs @@ -49,37 +49,37 @@ namespace CefSharp.Wpf.Example invoke => Dispatcher.BeginInvoke(invoke)); handlers = new Dictionary - { - // file - { showDevToolsMenuItem, ShowDevToolsActivated}, - { closeDevToolsMenuItem, CloseDevToolsActivated}, - { exitMenuItem, ExitActivated }, + { + // file + { showDevToolsMenuItem, ShowDevToolsActivated}, + { closeDevToolsMenuItem, CloseDevToolsActivated}, + { exitMenuItem, ExitActivated }, - // edit - { undoMenuItem, UndoActivated }, - { redoMenuItem, RedoActivated }, - { cutMenuItem, CutActivated }, - { copyMenuItem, CopyActivated }, - { pasteMenuItem, PasteActivated }, - { deleteMenuItem, DeleteActivated }, - { selectAllMenuItem, SelectAllActivated }, + // edit + { undoMenuItem, UndoActivated }, + { redoMenuItem, RedoActivated }, + { cutMenuItem, CutActivated }, + { copyMenuItem, CopyActivated }, + { pasteMenuItem, PasteActivated }, + { deleteMenuItem, DeleteActivated }, + { selectAllMenuItem, SelectAllActivated }, - // test - { testResourceLoadMenuItem, TestResourceLoadActivated }, - { testSchemeLoadMenuItem, TestSchemeLoadActivated }, - { testExecuteScriptMenuItem, TestExecuteScriptActivated }, - { testEvaluateScriptMenuItem, TestEvaluateScriptActivated }, - { testBindMenuItem, TestBindActivated }, - { testConsoleMessageMenuItem, TestConsoleMessageActivated }, - { testTooltipMenuItem, TestTooltipActivated }, - { testPopupMenuItem, TestPopupActivated }, - { testLoadStringMenuItem, TestLoadStringActivated }, - { testCookieVisitorMenuItem, TestCookieVisitorActivated }, + // test + { testResourceLoadMenuItem, TestResourceLoadActivated }, + { testSchemeLoadMenuItem, TestSchemeLoadActivated }, + { testExecuteScriptMenuItem, TestExecuteScriptActivated }, + { testEvaluateScriptMenuItem, TestEvaluateScriptActivated }, + { testBindMenuItem, TestBindActivated }, + { testConsoleMessageMenuItem, TestConsoleMessageActivated }, + { testTooltipMenuItem, TestTooltipActivated }, + { testPopupMenuItem, TestPopupActivated }, + { testLoadStringMenuItem, TestLoadStringActivated }, + { testCookieVisitorMenuItem, TestCookieVisitorActivated }, - // navigation - { backButton, BackActivated }, - { forwardButton, ForwardActivated }, - }; + // navigation + { backButton, BackActivated }, + { forwardButton, ForwardActivated }, + }; } public void SetTitle(string title) diff --git a/CefSharp.Wpf/WebView.h b/CefSharp.Wpf/WebView.h index ed78a3eff..3beea01ad 100644 --- a/CefSharp.Wpf/WebView.h +++ b/CefSharp.Wpf/WebView.h @@ -19,259 +19,259 @@ using namespace System::Windows::Threading; namespace CefSharp { - namespace Wpf - { - public ref class WebView sealed : public ContentControl, IRenderWebBrowser - { - private: - delegate void ActionHandler(); - delegate bool MoveFocusHandler(TraversalRequest^ request); + namespace Wpf + { + public ref class WebView sealed : public ContentControl, IRenderWebBrowser + { + private: + delegate void ActionHandler(); + delegate bool MoveFocusHandler(TraversalRequest^ request); - BrowserSettings^ _settings; + BrowserSettings^ _settings; - MCefRefPtr _clientAdapter; - BrowserCore^ _browserCore; - MCefRefPtr _scriptCore; + MCefRefPtr _clientAdapter; + BrowserCore^ _browserCore; + MCefRefPtr _scriptCore; - Object^ _sync; - HwndSource^ _source; - Matrix^ _matrix; - HwndSourceHook^ _hook; - ::ToolTip^ _toolTip; - Popup^ _popup; - DispatcherTimer^ _timer; + Object^ _sync; + HwndSource^ _source; + Matrix^ _matrix; + HwndSourceHook^ _hook; + ::ToolTip^ _toolTip; + Popup^ _popup; + DispatcherTimer^ _timer; - Image^ _image; - int _width, _height; - InteropBitmap^ _ibitmap; - HANDLE _fileMappingHandle, _backBufferHandle; - ActionHandler^ _paintDelegate; + Image^ _image; + int _width, _height; + InteropBitmap^ _ibitmap; + HANDLE _fileMappingHandle, _backBufferHandle; + ActionHandler^ _paintDelegate; - Image^ _popupImage; - int _popupWidth, _popupHeight, _popupX, _popupY; - int _popupImageWidth, _popupImageHeight; - InteropBitmap^ _popupIbitmap; - HANDLE _popupFileMappingHandle, _popupBackBufferHandle; - ActionHandler^ _paintPopupDelegate; - ActionHandler^ _resizePopupDelegate; + Image^ _popupImage; + int _popupWidth, _popupHeight, _popupX, _popupY; + int _popupImageWidth, _popupImageHeight; + InteropBitmap^ _popupIbitmap; + HANDLE _popupFileMappingHandle, _popupBackBufferHandle; + ActionHandler^ _paintPopupDelegate; + ActionHandler^ _resizePopupDelegate; - void Initialize(String^ address, BrowserSettings^ settings); - bool TryGetCefBrowser(CefRefPtr& browser); - void BrowserCore_PropertyChanged(Object^ sender, PropertyChangedEventArgs^ e); - void Timer_Tick(Object^ sender, EventArgs^ e); - void ToolTip_Closed(Object^ sender, RoutedEventArgs^ e); - void SetCursor(SafeFileHandle^ handle); - void SetTooltipText(String^ text); - IntPtr SourceHook(IntPtr hWnd, int message, IntPtr wParam, IntPtr lParam, bool% handled); - void SetBitmap(); + void Initialize(String^ address, BrowserSettings^ settings); + bool TryGetCefBrowser(CefRefPtr& browser); + void BrowserCore_PropertyChanged(Object^ sender, PropertyChangedEventArgs^ e); + void Timer_Tick(Object^ sender, EventArgs^ e); + void ToolTip_Closed(Object^ sender, RoutedEventArgs^ e); + void SetCursor(SafeFileHandle^ handle); + void SetTooltipText(String^ text); + IntPtr SourceHook(IntPtr hWnd, int message, IntPtr wParam, IntPtr lParam, bool% handled); + void SetBitmap(); - void SetBuffer(int& currentWidth, int& currentHeight, int width, int height, - HANDLE& fileMappingHandle, HANDLE& backBufferHandle, - InteropBitmap^& ibitmap, ActionHandler^ paintDelegate, - const void* buffer); + void SetBuffer(int& currentWidth, int& currentHeight, int width, int height, + HANDLE& fileMappingHandle, HANDLE& backBufferHandle, + InteropBitmap^& ibitmap, ActionHandler^ paintDelegate, + const void* buffer); - void SetPopupBitmap(); - void OnPreviewKey(KeyEventArgs^ e); - void OnMouseButton(MouseButtonEventArgs^ e); + void SetPopupBitmap(); + void OnPreviewKey(KeyEventArgs^ e); + void OnMouseButton(MouseButtonEventArgs^ e); - void ShowHidePopup(bool isOpened); - void SetPopupSizeAndPositionImpl(); + void ShowHidePopup(bool isOpened); + void SetPopupSizeAndPositionImpl(); - void OnLoaded(Object^ sender, RoutedEventArgs^ e); - void OnUnloaded(Object^ sender, RoutedEventArgs^ e); - void OnPopupMouseMove(Object^ sender, MouseEventArgs^ e); - void OnPopupMouseWheel(Object^ sender,MouseWheelEventArgs^ e); - void OnPopupMouseDown(Object^ sender,MouseButtonEventArgs^ e); - void OnPopupMouseUp(Object^ sender, MouseButtonEventArgs^ e); - void OnPopupMouseLeave(Object^ sender, MouseEventArgs^ e); - void OnHidePopup(Object^ sender, EventArgs^ e); + void OnLoaded(Object^ sender, RoutedEventArgs^ e); + void OnUnloaded(Object^ sender, RoutedEventArgs^ e); + void OnPopupMouseMove(Object^ sender, MouseEventArgs^ e); + void OnPopupMouseWheel(Object^ sender,MouseWheelEventArgs^ e); + void OnPopupMouseDown(Object^ sender,MouseButtonEventArgs^ e); + void OnPopupMouseUp(Object^ sender, MouseButtonEventArgs^ e); + void OnPopupMouseLeave(Object^ sender, MouseEventArgs^ e); + void OnHidePopup(Object^ sender, EventArgs^ e); - void HidePopup(); - void AddSourceHook(); + void HidePopup(); + void AddSourceHook(); - public protected: // a.k.a protected internal - virtual void OnVisualParentChanged(DependencyObject^ oldParent) override; + public protected: // a.k.a protected internal + virtual void OnVisualParentChanged(DependencyObject^ oldParent) override; - protected: - virtual Size ArrangeOverride(Size size) override; - virtual void OnGotFocus(RoutedEventArgs^ e) override; - virtual void OnLostFocus(RoutedEventArgs^ e) override; - virtual void OnPreviewKeyDown(KeyEventArgs^ e) override; - virtual void OnPreviewKeyUp(KeyEventArgs^ e) override; + protected: + virtual Size ArrangeOverride(Size size) override; + virtual void OnGotFocus(RoutedEventArgs^ e) override; + virtual void OnLostFocus(RoutedEventArgs^ e) override; + virtual void OnPreviewKeyDown(KeyEventArgs^ e) override; + virtual void OnPreviewKeyUp(KeyEventArgs^ e) override; - virtual void OnMouseMove(MouseEventArgs^ e) override; - virtual void OnMouseWheel(MouseWheelEventArgs^ e) override; - virtual void OnMouseDown(MouseButtonEventArgs^ e) override; - virtual void OnMouseUp(MouseButtonEventArgs^ e) override; - virtual void OnMouseLeave(MouseEventArgs^ e) override; + virtual void OnMouseMove(MouseEventArgs^ e) override; + virtual void OnMouseWheel(MouseWheelEventArgs^ e) override; + virtual void OnMouseDown(MouseButtonEventArgs^ e) override; + virtual void OnMouseUp(MouseButtonEventArgs^ e) override; + virtual void OnMouseLeave(MouseEventArgs^ e) override; - public: - virtual event PropertyChangedEventHandler^ PropertyChanged - { - void add(PropertyChangedEventHandler^ handler) - { - _browserCore->PropertyChanged += handler; - } + public: + virtual event PropertyChangedEventHandler^ PropertyChanged + { + void add(PropertyChangedEventHandler^ handler) + { + _browserCore->PropertyChanged += handler; + } - void remove(PropertyChangedEventHandler^ handler) - { - _browserCore->PropertyChanged -= handler; - } - } + void remove(PropertyChangedEventHandler^ handler) + { + _browserCore->PropertyChanged -= handler; + } + } - virtual event ConsoleMessageEventHandler^ ConsoleMessage; - virtual event KeyEventHandler^ BrowserKey; - virtual event LoadCompletedEventHandler^ LoadCompleted; + virtual event ConsoleMessageEventHandler^ ConsoleMessage; + virtual event KeyEventHandler^ BrowserKey; + virtual event LoadCompletedEventHandler^ LoadCompleted; - WebView() - { - Initialize(String::Empty, gcnew BrowserSettings); - } + WebView() + { + Initialize(String::Empty, gcnew BrowserSettings); + } - WebView(String^ address, BrowserSettings^ settings) - { - Initialize(address, settings); - } + WebView(String^ address, BrowserSettings^ settings) + { + Initialize(address, settings); + } - ~WebView() - { - if (_source && _hook) - { - _source->RemoveHook(_hook); - } + ~WebView() + { + if (_source && _hook) + { + _source->RemoveHook(_hook); + } - CefRefPtr browser; - if (TryGetCefBrowser(browser)) - { - browser->CloseBrowser(); - } - } + CefRefPtr browser; + if (TryGetCefBrowser(browser)) + { + browser->CloseBrowser(); + } + } - virtual property bool IsBrowserInitialized - { - bool get() { return _browserCore->IsBrowserInitialized; } - } + virtual property bool IsBrowserInitialized + { + bool get() { return _browserCore->IsBrowserInitialized; } + } - virtual property bool IsLoading - { - bool get() { return _browserCore->IsLoading; } - } + virtual property bool IsLoading + { + bool get() { return _browserCore->IsLoading; } + } - virtual property bool CanGoBack - { - bool get() { return _browserCore->CanGoBack; } - } + virtual property bool CanGoBack + { + bool get() { return _browserCore->CanGoBack; } + } - virtual property bool CanGoForward - { - bool get() { return _browserCore->CanGoForward; } - } + virtual property bool CanGoForward + { + bool get() { return _browserCore->CanGoForward; } + } - virtual property int ContentsWidth - { - int get() { return _browserCore->ContentsWidth; } - void set(int contentsWidth) { _browserCore->ContentsWidth = contentsWidth; } - } + virtual property int ContentsWidth + { + int get() { return _browserCore->ContentsWidth; } + void set(int contentsWidth) { _browserCore->ContentsWidth = contentsWidth; } + } - virtual property int ContentsHeight - { - int get() { return _browserCore->ContentsHeight; } - void set(int contentsHeight) { _browserCore->ContentsHeight = contentsHeight; } - } + virtual property int ContentsHeight + { + int get() { return _browserCore->ContentsHeight; } + void set(int contentsHeight) { _browserCore->ContentsHeight = contentsHeight; } + } - virtual property String^ Address - { - String^ get() { return _browserCore->Address; } - void set(String^ address) { _browserCore->Address = address; } - } + virtual property String^ Address + { + String^ get() { return _browserCore->Address; } + void set(String^ address) { _browserCore->Address = address; } + } - virtual property String^ Title - { - String^ get() { return _browserCore->Title; } - void set(String^ title) { _browserCore->Title = title; } - } + virtual property String^ Title + { + String^ get() { return _browserCore->Title; } + void set(String^ title) { _browserCore->Title = title; } + } - virtual property String^ TooltipText - { - String^ get() { return _browserCore->TooltipText; } - void set(String^ text) { _browserCore->TooltipText = text; } - } + virtual property String^ TooltipText + { + String^ get() { return _browserCore->TooltipText; } + void set(String^ text) { _browserCore->TooltipText = text; } + } - virtual property ILifeSpanHandler^ LifeSpanHandler - { - ILifeSpanHandler^ get() { return _browserCore->LifeSpanHandler; } - void set(ILifeSpanHandler^ handler) { _browserCore->LifeSpanHandler = handler; } - } + virtual property ILifeSpanHandler^ LifeSpanHandler + { + ILifeSpanHandler^ get() { return _browserCore->LifeSpanHandler; } + void set(ILifeSpanHandler^ handler) { _browserCore->LifeSpanHandler = handler; } + } - virtual property ILoadHandler^ LoadHandler - { - ILoadHandler^ get() { return _browserCore->LoadHandler; } - void set(ILoadHandler^ handler) { _browserCore->LoadHandler = handler; } - } + virtual property ILoadHandler^ LoadHandler + { + ILoadHandler^ get() { return _browserCore->LoadHandler; } + void set(ILoadHandler^ handler) { _browserCore->LoadHandler = handler; } + } - virtual property IRequestHandler^ RequestHandler - { - IRequestHandler^ get() { return _browserCore->RequestHandler; } - void set(IRequestHandler^ handler) { _browserCore->RequestHandler = handler; } - } + virtual property IRequestHandler^ RequestHandler + { + IRequestHandler^ get() { return _browserCore->RequestHandler; } + void set(IRequestHandler^ handler) { _browserCore->RequestHandler = handler; } + } - virtual property IMenuHandler^ MenuHandler - { - IMenuHandler^ get() { return _browserCore->MenuHandler; } - void set(IMenuHandler^ handler) { _browserCore->MenuHandler = handler; } - } + virtual property IMenuHandler^ MenuHandler + { + IMenuHandler^ get() { return _browserCore->MenuHandler; } + void set(IMenuHandler^ handler) { _browserCore->MenuHandler = handler; } + } - virtual property IKeyboardHandler^ KeyboardHandler - { - IKeyboardHandler^ get() { return _browserCore->KeyboardHandler; } - void set(IKeyboardHandler^ handler) { _browserCore->KeyboardHandler = handler; } - } + virtual property IKeyboardHandler^ KeyboardHandler + { + IKeyboardHandler^ get() { return _browserCore->KeyboardHandler; } + void set(IKeyboardHandler^ handler) { _browserCore->KeyboardHandler = handler; } + } - virtual void OnInitialized(); + virtual void OnInitialized(); - virtual void Load(String^ url); - virtual void LoadHtml(String^ html); - virtual void LoadHtml(String^ html, String^ url); - virtual void Stop(); - virtual void Back(); - virtual void Forward(); - virtual void Reload(); - virtual void Reload(bool ignoreCache); - virtual void ClearHistory(); - virtual void ShowDevTools(); - virtual void CloseDevTools(); + virtual void Load(String^ url); + virtual void LoadHtml(String^ html); + virtual void LoadHtml(String^ html, String^ url); + virtual void Stop(); + virtual void Back(); + virtual void Forward(); + virtual void Reload(); + virtual void Reload(bool ignoreCache); + virtual void ClearHistory(); + virtual void ShowDevTools(); + virtual void CloseDevTools(); - virtual void Undo(); - virtual void Redo(); - virtual void Cut(); - virtual void Copy(); - virtual void Paste(); - virtual void Delete(); - virtual void SelectAll(); - virtual void Print(); + virtual void Undo(); + virtual void Redo(); + virtual void Cut(); + virtual void Copy(); + virtual void Paste(); + virtual void Delete(); + virtual void SelectAll(); + virtual void Print(); - void ExecuteScript(String^ script); - Object^ EvaluateScript(String^ script); - Object^ EvaluateScript(String^ script, TimeSpan timeout); + void ExecuteScript(String^ script); + Object^ EvaluateScript(String^ script); + Object^ EvaluateScript(String^ script, TimeSpan timeout); - virtual void SetNavState(bool isLoading, bool canGoBack, bool canGoForward); + virtual void SetNavState(bool isLoading, bool canGoBack, bool canGoForward); - virtual void OnFrameLoadStart(String^ url); - virtual void OnFrameLoadEnd(String^ url); - virtual void OnTakeFocus(bool next); - virtual void OnConsoleMessage(String^ message, String^ source, int line); + virtual void OnFrameLoadStart(String^ url); + virtual void OnFrameLoadEnd(String^ url); + virtual void OnTakeFocus(bool next); + virtual void OnConsoleMessage(String^ message, String^ source, int line); - virtual void RegisterJsObject(String^ name, Object^ objectToBind); - virtual IDictionary^ GetBoundObjects(); + virtual void RegisterJsObject(String^ name, Object^ objectToBind); + virtual IDictionary^ GetBoundObjects(); - virtual void OnApplyTemplate() override; - virtual void SetCursor(IntPtr cursor); - virtual void SetBuffer(int width, int height, const void* buffer); - virtual void SetPopupBuffer(int width, int height, const void* buffer); + virtual void OnApplyTemplate() override; + virtual void SetCursor(IntPtr cursor); + virtual void SetBuffer(int width, int height, const void* buffer); + virtual void SetPopupBuffer(int width, int height, const void* buffer); - virtual void SetPopupIsOpen(bool isOpen); - virtual void SetPopupSizeAndPosition(const void* rect); + virtual void SetPopupIsOpen(bool isOpen); + virtual void SetPopupSizeAndPosition(const void* rect); - }; - } + }; + } } \ No newline at end of file diff --git a/CefSharp/BindingHandler.cpp b/CefSharp/BindingHandler.cpp index 18fa8f8b1..b5f3b263a 100644 --- a/CefSharp/BindingHandler.cpp +++ b/CefSharp/BindingHandler.cpp @@ -7,324 +7,324 @@ using namespace System::Reflection; namespace CefSharp { - namespace Internals - { - namespace JavascriptBinding - { - bool BindingHandler::IsNullableType(Type^ type) - { - // This is check traditionaly perform by this C# code: - // return (type.IsGenericType && type.GetGenericTypeDefinition().Equals(typeof(Nullable<>))); - // But we have some problems with Nullable<>::typeid. - return Nullable::GetUnderlyingType(type) != nullptr; - } + namespace Internals + { + namespace JavascriptBinding + { + bool BindingHandler::IsNullableType(Type^ type) + { + // This is check traditionaly perform by this C# code: + // return (type.IsGenericType && type.GetGenericTypeDefinition().Equals(typeof(Nullable<>))); + // But we have some problems with Nullable<>::typeid. + return Nullable::GetUnderlyingType(type) != nullptr; + } - /// - /// Returns conversion cost, or -1 if no conversion available. - int BindingHandler::GetChangeTypeCost(Object^ value, Type^ conversionType) - { - // TODO: temporary Int64 support fully disabled - if (conversionType == Int64::typeid - || conversionType == Nullable::typeid - || conversionType == UInt64::typeid - || conversionType == Nullable::typeid - ) - return -1; + /// + /// Returns conversion cost, or -1 if no conversion available. + int BindingHandler::GetChangeTypeCost(Object^ value, Type^ conversionType) + { + // TODO: temporary Int64 support fully disabled + if (conversionType == Int64::typeid + || conversionType == Nullable::typeid + || conversionType == UInt64::typeid + || conversionType == Nullable::typeid + ) + return -1; - // Null conversion - if (value == nullptr) - { - // TODO: This is check for reference type, may be not accuracy. - if (conversionType->IsValueType == false) return 0; + // Null conversion + if (value == nullptr) + { + // TODO: This is check for reference type, may be not accuracy. + if (conversionType->IsValueType == false) return 0; - // Nullable types also can be converted to null without penalty. - if (IsNullableType(conversionType)) return 0; + // Nullable types also can be converted to null without penalty. + if (IsNullableType(conversionType)) return 0; - // Non-reference and non-nullable types can not be converted from null. - return -1; - } + // Non-reference and non-nullable types can not be converted from null. + return -1; + } - // value is not null + // value is not null - // value have same type - no conversion required - Type^ valueType = value->GetType(); - if (valueType == conversionType) return 0; + // value have same type - no conversion required + Type^ valueType = value->GetType(); + if (valueType == conversionType) return 0; - int baseCost = 0; + int baseCost = 0; - // but conversionType can be Nullable - Type^ targetType = Nullable::GetUnderlyingType(conversionType); - if (targetType != nullptr) - { - // this is a nullable type, and it cost + 1 - conversionType = targetType; - baseCost++; - } - if (valueType == conversionType) return baseCost + 0; + // but conversionType can be Nullable + Type^ targetType = Nullable::GetUnderlyingType(conversionType); + if (targetType != nullptr) + { + // this is a nullable type, and it cost + 1 + conversionType = targetType; + baseCost++; + } + if (valueType == conversionType) return baseCost + 0; - if (valueType == Boolean::typeid) - { - // Boolean can be converted only to Boolean - if(conversionType == Boolean::typeid) return baseCost + 0; - return -1; - } - else if (valueType == Int32::typeid) - { - int int32Val = safe_cast(value); + if (valueType == Boolean::typeid) + { + // Boolean can be converted only to Boolean + if(conversionType == Boolean::typeid) return baseCost + 0; + return -1; + } + else if (valueType == Int32::typeid) + { + int int32Val = safe_cast(value); - if (conversionType == Int32::typeid) return baseCost + 0; - else if (conversionType == UInt32::typeid && (int32Val >= 0)) return baseCost + 1; - else if (conversionType == Int16::typeid && (int32Val >= Int16::MinValue && int32Val <= Int16::MaxValue)) return baseCost + 2; - else if (conversionType == UInt16::typeid && (int32Val >= UInt16::MinValue && int32Val <= UInt16::MaxValue)) return baseCost + 3; - else if (conversionType == Char::typeid && (int32Val >= Char::MinValue && int32Val <= Char::MaxValue)) return baseCost + 4; - else if (conversionType == SByte::typeid && (int32Val >= SByte::MinValue && int32Val <= SByte::MaxValue)) return baseCost + 5; - else if (conversionType == Byte::typeid && (int32Val >= Byte::MinValue && int32Val <= Byte::MaxValue)) return baseCost + 6; - else if (conversionType == Double::typeid) return baseCost + 9; - else if (conversionType == Single::typeid) return baseCost + 10; - else if (conversionType == Decimal::typeid) return baseCost + 11; - else if (conversionType == Int64::typeid) return -1; - else if (conversionType == UInt64::typeid) return -1; - return -1; - } - else if(valueType == Double::typeid) - { - double doubleVal = safe_cast(value); + if (conversionType == Int32::typeid) return baseCost + 0; + else if (conversionType == UInt32::typeid && (int32Val >= 0)) return baseCost + 1; + else if (conversionType == Int16::typeid && (int32Val >= Int16::MinValue && int32Val <= Int16::MaxValue)) return baseCost + 2; + else if (conversionType == UInt16::typeid && (int32Val >= UInt16::MinValue && int32Val <= UInt16::MaxValue)) return baseCost + 3; + else if (conversionType == Char::typeid && (int32Val >= Char::MinValue && int32Val <= Char::MaxValue)) return baseCost + 4; + else if (conversionType == SByte::typeid && (int32Val >= SByte::MinValue && int32Val <= SByte::MaxValue)) return baseCost + 5; + else if (conversionType == Byte::typeid && (int32Val >= Byte::MinValue && int32Val <= Byte::MaxValue)) return baseCost + 6; + else if (conversionType == Double::typeid) return baseCost + 9; + else if (conversionType == Single::typeid) return baseCost + 10; + else if (conversionType == Decimal::typeid) return baseCost + 11; + else if (conversionType == Int64::typeid) return -1; + else if (conversionType == UInt64::typeid) return -1; + return -1; + } + else if(valueType == Double::typeid) + { + double doubleVal = safe_cast(value); - if (conversionType == Double::typeid) return baseCost + 0; - else if (conversionType == Single::typeid && (doubleVal >= Single::MinValue && doubleVal <= Single::MaxValue)) return baseCost + 1; - else if (conversionType == Decimal::typeid /* && (doubleVal >= Decimal::MinValue && doubleVal <= Decimal::MaxValue) */) return baseCost + 2; - else if (conversionType == Int32::typeid && (doubleVal >= Int32::MinValue && doubleVal <= Int32::MaxValue)) return baseCost + 3; - else if (conversionType == UInt32::typeid && (doubleVal >= UInt32::MinValue && doubleVal <= UInt32::MaxValue)) return baseCost + 4; - else if (conversionType == Int16::typeid && (doubleVal >= Int16::MinValue && doubleVal <= Int16::MaxValue)) return baseCost + 5; - else if (conversionType == UInt16::typeid && (doubleVal >= UInt16::MinValue && doubleVal <= UInt16::MaxValue)) return baseCost + 6; - else if (conversionType == Char::typeid && (doubleVal >= Char::MinValue && doubleVal <= Char::MaxValue)) return baseCost + 6; - else if (conversionType == SByte::typeid && (doubleVal >= SByte::MinValue && doubleVal <= SByte::MaxValue)) return baseCost + 8; - else if (conversionType == Byte::typeid && (doubleVal >= Byte::MinValue && doubleVal <= Byte::MaxValue)) return baseCost + 9; - else if (conversionType == Int64::typeid) return -1; - else if (conversionType == UInt64::typeid) return -1; - return -1; - } - else if(valueType == String::typeid) - { - // String can be converted only to String - if(conversionType == String::typeid) return baseCost + 0; - return -1; - } - else - { - // No conversion available - return -1; - } - } + if (conversionType == Double::typeid) return baseCost + 0; + else if (conversionType == Single::typeid && (doubleVal >= Single::MinValue && doubleVal <= Single::MaxValue)) return baseCost + 1; + else if (conversionType == Decimal::typeid /* && (doubleVal >= Decimal::MinValue && doubleVal <= Decimal::MaxValue) */) return baseCost + 2; + else if (conversionType == Int32::typeid && (doubleVal >= Int32::MinValue && doubleVal <= Int32::MaxValue)) return baseCost + 3; + else if (conversionType == UInt32::typeid && (doubleVal >= UInt32::MinValue && doubleVal <= UInt32::MaxValue)) return baseCost + 4; + else if (conversionType == Int16::typeid && (doubleVal >= Int16::MinValue && doubleVal <= Int16::MaxValue)) return baseCost + 5; + else if (conversionType == UInt16::typeid && (doubleVal >= UInt16::MinValue && doubleVal <= UInt16::MaxValue)) return baseCost + 6; + else if (conversionType == Char::typeid && (doubleVal >= Char::MinValue && doubleVal <= Char::MaxValue)) return baseCost + 6; + else if (conversionType == SByte::typeid && (doubleVal >= SByte::MinValue && doubleVal <= SByte::MaxValue)) return baseCost + 8; + else if (conversionType == Byte::typeid && (doubleVal >= Byte::MinValue && doubleVal <= Byte::MaxValue)) return baseCost + 9; + else if (conversionType == Int64::typeid) return -1; + else if (conversionType == UInt64::typeid) return -1; + return -1; + } + else if(valueType == String::typeid) + { + // String can be converted only to String + if(conversionType == String::typeid) return baseCost + 0; + return -1; + } + else + { + // No conversion available + return -1; + } + } - Object^ BindingHandler::ChangeType(Object^ value, Type^ conversionType) - { - if (GetChangeTypeCost(value, conversionType) < 0) - { - throw gcnew Exception("No conversion available."); - } + Object^ BindingHandler::ChangeType(Object^ value, Type^ conversionType) + { + if (GetChangeTypeCost(value, conversionType) < 0) + { + throw gcnew Exception("No conversion available."); + } - if (value == nullptr) return nullptr; + if (value == nullptr) return nullptr; - Type^ targetType = Nullable::GetUnderlyingType(conversionType); - if (targetType != nullptr) conversionType = targetType; + Type^ targetType = Nullable::GetUnderlyingType(conversionType); + if (targetType != nullptr) conversionType = targetType; - return Convert::ChangeType(value, conversionType); - } + return Convert::ChangeType(value, conversionType); + } - bool BindingHandler::Execute(const CefString& name, CefRefPtr object, const CefV8ValueList& arguments, CefRefPtr& retval, CefString& exception) - { - auto unmanagedWrapper = static_cast(object->GetUserData().get()); - Object^ self = unmanagedWrapper->Get(); - if(self == nullptr) - { - exception = "Binding's CLR object is null."; - return true; - } + bool BindingHandler::Execute(const CefString& name, CefRefPtr object, const CefV8ValueList& arguments, CefRefPtr& retval, CefString& exception) + { + auto unmanagedWrapper = static_cast(object->GetUserData().get()); + Object^ self = unmanagedWrapper->Get(); + if(self == nullptr) + { + exception = "Binding's CLR object is null."; + return true; + } - String^ methodName = toClr(name); - Type^ type = self->GetType(); - auto methods = type->GetMember(methodName, MemberTypes::Method, BindingFlags::Instance | BindingFlags::Public); + String^ methodName = toClr(name); + Type^ type = self->GetType(); + auto methods = type->GetMember(methodName, MemberTypes::Method, BindingFlags::Instance | BindingFlags::Public); - if(methods->Length == 0) - { - exception = toNative("No method named " + methodName + "."); - return true; - } + if(methods->Length == 0) + { + exception = toNative("No method named " + methodName + "."); + return true; + } - //TODO: cache for type info here + //TODO: cache for type info here - auto suppliedArguments = gcnew array(arguments.size()); - try - { - for(int i = 0; i < suppliedArguments->Length; i++) - { - suppliedArguments[i] = convertFromCef(arguments[i]); - } - } - catch(System::Exception^ err) - { - exception = toNative(err->Message); - return true; - } + auto suppliedArguments = gcnew array(arguments.size()); + try + { + for(int i = 0; i < suppliedArguments->Length; i++) + { + suppliedArguments[i] = convertFromCef(arguments[i]); + } + } + catch(System::Exception^ err) + { + exception = toNative(err->Message); + return true; + } - // choose best method - MethodInfo^ bestMethod; - array^ bestMethodArguments; + // choose best method + MethodInfo^ bestMethod; + array^ bestMethodArguments; - FindBestMethod(methods, suppliedArguments, bestMethod, bestMethodArguments); + FindBestMethod(methods, suppliedArguments, bestMethod, bestMethodArguments); - if (bestMethod != nullptr) - { - try - { - Object^ result = bestMethod->Invoke(self, bestMethodArguments); - retval = convertToCef(result, bestMethod->ReturnType); - return true; - } - catch(System::Reflection::TargetInvocationException^ err) - { - exception = toNative(err->InnerException->Message); - } - catch(System::Exception^ err) - { - exception = toNative(err->Message); - } - } - else - { - exception = toNative("Argument mismatch for method \"" + methodName + "\"."); - } - return true; - } + if (bestMethod != nullptr) + { + try + { + Object^ result = bestMethod->Invoke(self, bestMethodArguments); + retval = convertToCef(result, bestMethod->ReturnType); + return true; + } + catch(System::Reflection::TargetInvocationException^ err) + { + exception = toNative(err->InnerException->Message); + } + catch(System::Exception^ err) + { + exception = toNative(err->Message); + } + } + else + { + exception = toNative("Argument mismatch for method \"" + methodName + "\"."); + } + return true; + } - void BindingHandler::FindBestMethod(array^ methods, array^ suppliedArguments, MethodInfo^% bestMethod, array^% bestMethodArguments) - { - auto bestMethodCost = -1; + void BindingHandler::FindBestMethod(array^ methods, array^ suppliedArguments, MethodInfo^% bestMethod, array^% bestMethodArguments) + { + auto bestMethodCost = -1; - for (int i = 0; i < methods->Length; i++) - { - auto method = (MethodInfo^) methods[i]; - auto parametersInfo = method->GetParameters(); + for (int i = 0; i < methods->Length; i++) + { + auto method = (MethodInfo^) methods[i]; + auto parametersInfo = method->GetParameters(); - if (suppliedArguments->Length == parametersInfo->Length) - { - int failed = 0; - int cost = 0; - auto arguments = gcnew array(suppliedArguments->Length); + if (suppliedArguments->Length == parametersInfo->Length) + { + int failed = 0; + int cost = 0; + auto arguments = gcnew array(suppliedArguments->Length); - try - { - for (int p = 0; p < suppliedArguments->Length; p++) - { - Type^ paramType = parametersInfo[p]->ParameterType; + try + { + for (int p = 0; p < suppliedArguments->Length; p++) + { + Type^ paramType = parametersInfo[p]->ParameterType; - int paramCost = GetChangeTypeCost(suppliedArguments[p], paramType); - if (paramCost < 0 ) - { - failed++; - break; - } - else - { - arguments[p] = ChangeType(suppliedArguments[p], paramType); - cost += paramCost; - } - } - } - catch(Exception^) - { - failed++; - } + int paramCost = GetChangeTypeCost(suppliedArguments[p], paramType); + if (paramCost < 0 ) + { + failed++; + break; + } + else + { + arguments[p] = ChangeType(suppliedArguments[p], paramType); + cost += paramCost; + } + } + } + catch(Exception^) + { + failed++; + } - if (failed > 0) - { - continue; - } + if (failed > 0) + { + continue; + } - if (cost < bestMethodCost || bestMethodCost < 0) - { - bestMethod = method; - bestMethodArguments = arguments; - bestMethodCost = cost; - } + if (cost < bestMethodCost || bestMethodCost < 0) + { + bestMethod = method; + bestMethodArguments = arguments; + bestMethodCost = cost; + } - // this is best as possible cost - if (cost == 0) - break; - } - } - } + // this is best as possible cost + if (cost == 0) + break; + } + } + } - void BindingHandler::Bind(String^ name, Object^ obj, CefRefPtr window) - { - auto unmanagedWrapper = new UnmanagedWrapper(obj); + void BindingHandler::Bind(String^ name, Object^ obj, CefRefPtr window) + { + auto unmanagedWrapper = new UnmanagedWrapper(obj); - // Create the Javascript/V8 object and associate it with the wrapped object. - auto propertyAccessor = new PropertyAccessor(); - auto wrappedObject = window->CreateObject(static_cast>(propertyAccessor)); - wrappedObject->SetUserData(static_cast>(unmanagedWrapper)); + // Create the Javascript/V8 object and associate it with the wrapped object. + auto propertyAccessor = new PropertyAccessor(); + auto wrappedObject = window->CreateObject(static_cast>(propertyAccessor)); + wrappedObject->SetUserData(static_cast>(unmanagedWrapper)); - auto handler = static_cast(new BindingHandler()); + auto handler = static_cast(new BindingHandler()); - // Build a list of methods on the bound object - auto methods = obj->GetType()->GetMethods(BindingFlags::Instance | BindingFlags::Public); - auto methodNames = gcnew Dictionary(); + // Build a list of methods on the bound object + auto methods = obj->GetType()->GetMethods(BindingFlags::Instance | BindingFlags::Public); + auto methodNames = gcnew Dictionary(); - for each(auto method in methods) - { - // "Special name"-methods are things like property getters and setters, which we don't want to include in the list. - if (method->IsSpecialName) continue; - methodNames->Add(method->Name, nullptr); - } + for each(auto method in methods) + { + // "Special name"-methods are things like property getters and setters, which we don't want to include in the list. + if (method->IsSpecialName) continue; + methodNames->Add(method->Name, nullptr); + } - CreateJavascriptMethods(handler, wrappedObject, methodNames->Keys); + CreateJavascriptMethods(handler, wrappedObject, methodNames->Keys); - unmanagedWrapper->Properties = GetProperties(obj->GetType()); - CreateJavascriptProperties(handler, wrappedObject, unmanagedWrapper->Properties); + unmanagedWrapper->Properties = GetProperties(obj->GetType()); + CreateJavascriptProperties(handler, wrappedObject, unmanagedWrapper->Properties); - window->SetValue(toNative(name), wrappedObject, V8_PROPERTY_ATTRIBUTE_NONE); - } + window->SetValue(toNative(name), wrappedObject, V8_PROPERTY_ATTRIBUTE_NONE); + } - Dictionary^ BindingHandler::GetProperties(Type^ type) - { - auto properties = type->GetProperties(BindingFlags::Instance | BindingFlags::Public); - auto result = gcnew Dictionary(); + Dictionary^ BindingHandler::GetProperties(Type^ type) + { + auto properties = type->GetProperties(BindingFlags::Instance | BindingFlags::Public); + auto result = gcnew Dictionary(); - for each(auto property in properties) - { - result[property->Name] = property; - } + for each(auto property in properties) + { + result[property->Name] = property; + } - return result; - } + return result; + } - void BindingHandler::CreateJavascriptMethods(CefV8Handler* handler, CefRefPtr javascriptObject, IEnumerable^ methodNames) - { - for each(String^ methodName in methodNames) - { - auto nameStr = toNative(methodName); - javascriptObject->SetValue(nameStr, CefV8Value::CreateFunction(nameStr, handler), V8_PROPERTY_ATTRIBUTE_NONE); - } - } + void BindingHandler::CreateJavascriptMethods(CefV8Handler* handler, CefRefPtr javascriptObject, IEnumerable^ methodNames) + { + for each(String^ methodName in methodNames) + { + auto nameStr = toNative(methodName); + javascriptObject->SetValue(nameStr, CefV8Value::CreateFunction(nameStr, handler), V8_PROPERTY_ATTRIBUTE_NONE); + } + } - void BindingHandler::CreateJavascriptProperties(CefV8Handler* handler, CefRefPtr javascriptObject, Dictionary^ properties) - { - for each(String^ propertyName in properties->Keys) - { - // TODO: Handle read-only properties correctly here. - auto nameStr = toNative(propertyName); + void BindingHandler::CreateJavascriptProperties(CefV8Handler* handler, CefRefPtr javascriptObject, Dictionary^ properties) + { + for each(String^ propertyName in properties->Keys) + { + // TODO: Handle read-only properties correctly here. + auto nameStr = toNative(propertyName); - cef_v8_propertyattribute_t propertyAttribute = V8_PROPERTY_ATTRIBUTE_NONE; + cef_v8_propertyattribute_t propertyAttribute = V8_PROPERTY_ATTRIBUTE_NONE; - if (properties[propertyName]->GetSetMethod() == nullptr) - { - propertyAttribute = V8_PROPERTY_ATTRIBUTE_READONLY; - } + if (properties[propertyName]->GetSetMethod() == nullptr) + { + propertyAttribute = V8_PROPERTY_ATTRIBUTE_READONLY; + } - javascriptObject->SetValue(nameStr, V8_ACCESS_CONTROL_DEFAULT, propertyAttribute); - } - } - } - } + javascriptObject->SetValue(nameStr, V8_ACCESS_CONTROL_DEFAULT, propertyAttribute); + } + } + } + } } \ No newline at end of file diff --git a/CefSharp/BindingHandler.h b/CefSharp/BindingHandler.h index 1ae761f79..26a5af9ce 100644 --- a/CefSharp/BindingHandler.h +++ b/CefSharp/BindingHandler.h @@ -6,31 +6,31 @@ using namespace System::Reflection; namespace CefSharp { - namespace Internals - { - namespace JavascriptBinding - { - private class BindingHandler : public CefV8Handler - { - // Type Converter - static bool IsNullableType(Type^ type); - static int GetChangeTypeCost(Object^ value, Type^ conversionType); - static Object^ ChangeType(Object^ value, Type^ conversionType); + namespace Internals + { + namespace JavascriptBinding + { + private class BindingHandler : public CefV8Handler + { + // Type Converter + static bool IsNullableType(Type^ type); + static int GetChangeTypeCost(Object^ value, Type^ conversionType); + static Object^ ChangeType(Object^ value, Type^ conversionType); - static void CreateJavascriptMethods(CefV8Handler* handler, CefRefPtr javascriptObject, IEnumerable^ methodNames); - static void CreateJavascriptProperties(CefV8Handler* handler, CefRefPtr javascriptObject, Dictionary^ properties); - static Dictionary^ GetProperties(Type^ type); - static void BindingHandler::FindBestMethod(array^ methods, array^ suppliedArguments, MethodInfo^% bestMethod, array^% bestMethodArguments); + static void CreateJavascriptMethods(CefV8Handler* handler, CefRefPtr javascriptObject, IEnumerable^ methodNames); + static void CreateJavascriptProperties(CefV8Handler* handler, CefRefPtr javascriptObject, Dictionary^ properties); + static Dictionary^ GetProperties(Type^ type); + static void BindingHandler::FindBestMethod(array^ methods, array^ suppliedArguments, MethodInfo^% bestMethod, array^% bestMethodArguments); - CefRefPtr ConvertToCef(Object^ obj, Type^ type); - Object^ ConvertFromCef(CefRefPtr obj); - virtual bool Execute(const CefString& name, CefRefPtr object, const CefV8ValueList& arguments, CefRefPtr& retval, CefString& exception); + CefRefPtr ConvertToCef(Object^ obj, Type^ type); + Object^ ConvertFromCef(CefRefPtr obj); + virtual bool Execute(const CefString& name, CefRefPtr object, const CefV8ValueList& arguments, CefRefPtr& retval, CefString& exception); - public: - static void Bind(String^ name, Object^ obj, CefRefPtr window); + public: + static void Bind(String^ name, Object^ obj, CefRefPtr window); - IMPLEMENT_REFCOUNTING(BindingHandler); - }; - } - } + IMPLEMENT_REFCOUNTING(BindingHandler); + }; + } + } } \ No newline at end of file diff --git a/CefSharp/PropertyAccessor.h b/CefSharp/PropertyAccessor.h index 7c20ef96d..bcd8383b9 100644 --- a/CefSharp/PropertyAccessor.h +++ b/CefSharp/PropertyAccessor.h @@ -3,98 +3,98 @@ namespace CefSharp { - namespace Internals - { - namespace JavascriptBinding - { - private class PropertyAccessor : CefV8Accessor - { - /// - // Handle retrieval the accessor value identified by |name|. |object| is the - // receiver ('this' object) of the accessor. If retrieval succeeds set - // |retval| to the return value. If retrieval fails set |exception| to the - // exception that will be thrown. Return true if accessor retrieval was - // handled. - /// - /*--cef()--*/ - virtual bool Get(const CefString& name, const CefRefPtr object, CefRefPtr& retval, - CefString& exception) override - { - auto unmanagedWrapper = static_cast(object->GetUserData().get()); - auto clrName = toClr(name); - PropertyInfo^ property; + namespace Internals + { + namespace JavascriptBinding + { + private class PropertyAccessor : CefV8Accessor + { + /// + // Handle retrieval the accessor value identified by |name|. |object| is the + // receiver ('this' object) of the accessor. If retrieval succeeds set + // |retval| to the return value. If retrieval fails set |exception| to the + // exception that will be thrown. Return true if accessor retrieval was + // handled. + /// + /*--cef()--*/ + virtual bool Get(const CefString& name, const CefRefPtr object, CefRefPtr& retval, + CefString& exception) override + { + auto unmanagedWrapper = static_cast(object->GetUserData().get()); + auto clrName = toClr(name); + PropertyInfo^ property; - if (unmanagedWrapper->Properties->TryGetValue(clrName, property)) - { - auto wrappedObject = unmanagedWrapper->Get(); + if (unmanagedWrapper->Properties->TryGetValue(clrName, property)) + { + auto wrappedObject = unmanagedWrapper->Get(); - if (wrappedObject == nullptr) - { - exception = "Binding's CLR object is null."; - return true; - } + if (wrappedObject == nullptr) + { + exception = "Binding's CLR object is null."; + return true; + } - try - { - auto clrValue = property->GetValue(wrappedObject, nullptr); + try + { + auto clrValue = property->GetValue(wrappedObject, nullptr); - retval = convertToCef(clrValue, nullptr); - return true; - } - catch (Exception^ e) - { - exception = toNative(e->Message); - return true; - } - } - else - { - // Will probably never get here in reality, since V8 knows the name of the properties that exist on this - // object and will only call us for existant properties. - return false; - } - } + retval = convertToCef(clrValue, nullptr); + return true; + } + catch (Exception^ e) + { + exception = toNative(e->Message); + return true; + } + } + else + { + // Will probably never get here in reality, since V8 knows the name of the properties that exist on this + // object and will only call us for existant properties. + return false; + } + } - /// - // Handle assignment of the accessor value identified by |name|. |object| is - // the receiver ('this' object) of the accessor. |value| is the new value - // being assigned to the accessor. If assignment fails set |exception| to the - // exception that will be thrown. Return true if accessor assignment was - // handled. - /// - /*--cef()--*/ - virtual bool Set(const CefString& name, const CefRefPtr object, const CefRefPtr value, - CefString& exception) override - { - auto unmanagedWrapper = static_cast(object->GetUserData().get()); - auto clrName = toClr(name); - PropertyInfo^ property; + /// + // Handle assignment of the accessor value identified by |name|. |object| is + // the receiver ('this' object) of the accessor. |value| is the new value + // being assigned to the accessor. If assignment fails set |exception| to the + // exception that will be thrown. Return true if accessor assignment was + // handled. + /// + /*--cef()--*/ + virtual bool Set(const CefString& name, const CefRefPtr object, const CefRefPtr value, + CefString& exception) override + { + auto unmanagedWrapper = static_cast(object->GetUserData().get()); + auto clrName = toClr(name); + PropertyInfo^ property; - if (unmanagedWrapper->Properties->TryGetValue(clrName, property)) - { - auto wrappedObject = unmanagedWrapper->Get(); + if (unmanagedWrapper->Properties->TryGetValue(clrName, property)) + { + auto wrappedObject = unmanagedWrapper->Get(); - if (wrappedObject == nullptr) - { - exception = "Binding's CLR object is null."; - return true; - } + if (wrappedObject == nullptr) + { + exception = "Binding's CLR object is null."; + return true; + } - auto clrValue = convertFromCef(value); - property->SetValue(wrappedObject, clrValue, nullptr); + auto clrValue = convertFromCef(value); + property->SetValue(wrappedObject, clrValue, nullptr); - return true; - } - else - { - // Will probably never get here in reality, since V8 knows the name of the properties that exist on this - // object and will only call us for existant properties. - return false; - } - } + return true; + } + else + { + // Will probably never get here in reality, since V8 knows the name of the properties that exist on this + // object and will only call us for existant properties. + return false; + } + } - IMPLEMENT_REFCOUNTING(PropertyAccessor) - }; - } - } + IMPLEMENT_REFCOUNTING(PropertyAccessor) + }; + } + } } \ No newline at end of file diff --git a/CefSharp/TypeUtil.cpp b/CefSharp/TypeUtil.cpp index af2ff87d1..a03868472 100644 --- a/CefSharp/TypeUtil.cpp +++ b/CefSharp/TypeUtil.cpp @@ -4,233 +4,233 @@ using namespace System::Collections::Generic; namespace CefSharp { - CefRefPtr convertToCef(Object^ obj, Type^ type) - { - if (type == Void::typeid) - { - return CefV8Value::CreateUndefined(); - } - if (obj == nullptr) - { - return CefV8Value::CreateNull(); - } + CefRefPtr convertToCef(Object^ obj, Type^ type) + { + if (type == Void::typeid) + { + return CefV8Value::CreateUndefined(); + } + if (obj == nullptr) + { + return CefV8Value::CreateNull(); + } - if (type == nullptr) - { - type = obj->GetType(); - } + if (type == nullptr) + { + type = obj->GetType(); + } - Type^ underlyingType = Nullable::GetUnderlyingType(type); - if(underlyingType != nullptr) type = underlyingType; + Type^ underlyingType = Nullable::GetUnderlyingType(type); + if(underlyingType != nullptr) type = underlyingType; - if (type == Boolean::typeid) - { - return CefV8Value::CreateBool(safe_cast(obj)); - } - if (type == Int32::typeid) - { - return CefV8Value::CreateInt(safe_cast(obj)); - } - if (type == String::typeid) - { - CefString str = toNative(safe_cast(obj)); - return CefV8Value::CreateString(str); - } - if (type == Double::typeid) - { - return CefV8Value::CreateDouble(safe_cast(obj)); - } - if (type == Decimal::typeid) - { - return CefV8Value::CreateDouble(Convert::ToDouble(obj)); - } - if (type == SByte::typeid) - { - return CefV8Value::CreateInt(Convert::ToInt32(obj)); - } - if (type == Int16::typeid) - { - return CefV8Value::CreateInt(Convert::ToInt32(obj)); - } - if (type == Int64::typeid) - { - return CefV8Value::CreateDouble(Convert::ToDouble(obj)); - } - if (type == Byte::typeid) - { - return CefV8Value::CreateInt(Convert::ToInt32(obj)); - } - if (type == UInt16::typeid) - { - return CefV8Value::CreateInt(Convert::ToInt32(obj)); - } - if (type == UInt32::typeid) - { - return CefV8Value::CreateDouble(Convert::ToDouble(obj)); - } - if (type == UInt64::typeid) - { - return CefV8Value::CreateDouble(Convert::ToDouble(obj)); - } - if (type == Single::typeid) - { - return CefV8Value::CreateDouble(Convert::ToDouble(obj)); - } - if (type == Char::typeid) - { - return CefV8Value::CreateInt(Convert::ToInt32(obj)); - } - if (type->IsArray) - { - Array^ managedArray = (Array^)obj; - CefRefPtr cefArray = CefV8Value::CreateArray(managedArray->Length); + if (type == Boolean::typeid) + { + return CefV8Value::CreateBool(safe_cast(obj)); + } + if (type == Int32::typeid) + { + return CefV8Value::CreateInt(safe_cast(obj)); + } + if (type == String::typeid) + { + CefString str = toNative(safe_cast(obj)); + return CefV8Value::CreateString(str); + } + if (type == Double::typeid) + { + return CefV8Value::CreateDouble(safe_cast(obj)); + } + if (type == Decimal::typeid) + { + return CefV8Value::CreateDouble(Convert::ToDouble(obj)); + } + if (type == SByte::typeid) + { + return CefV8Value::CreateInt(Convert::ToInt32(obj)); + } + if (type == Int16::typeid) + { + return CefV8Value::CreateInt(Convert::ToInt32(obj)); + } + if (type == Int64::typeid) + { + return CefV8Value::CreateDouble(Convert::ToDouble(obj)); + } + if (type == Byte::typeid) + { + return CefV8Value::CreateInt(Convert::ToInt32(obj)); + } + if (type == UInt16::typeid) + { + return CefV8Value::CreateInt(Convert::ToInt32(obj)); + } + if (type == UInt32::typeid) + { + return CefV8Value::CreateDouble(Convert::ToDouble(obj)); + } + if (type == UInt64::typeid) + { + return CefV8Value::CreateDouble(Convert::ToDouble(obj)); + } + if (type == Single::typeid) + { + return CefV8Value::CreateDouble(Convert::ToDouble(obj)); + } + if (type == Char::typeid) + { + return CefV8Value::CreateInt(Convert::ToInt32(obj)); + } + if (type->IsArray) + { + Array^ managedArray = (Array^)obj; + CefRefPtr cefArray = CefV8Value::CreateArray(managedArray->Length); - for (int i = 0; i < managedArray->Length; i++) - { - Object^ arrObj; + for (int i = 0; i < managedArray->Length; i++) + { + Object^ arrObj; - arrObj = managedArray->GetValue(i); + arrObj = managedArray->GetValue(i); - if (arrObj != nullptr) - { - CefRefPtr cefObj = convertToCef(arrObj, arrObj->GetType()); + if (arrObj != nullptr) + { + CefRefPtr cefObj = convertToCef(arrObj, arrObj->GetType()); - cefArray->SetValue(i, cefObj); - } - else - { - cefArray->SetValue(i, CefV8Value::CreateNull()); - } - } + cefArray->SetValue(i, cefObj); + } + else + { + cefArray->SetValue(i, CefV8Value::CreateNull()); + } + } - return cefArray; - } - if (type->IsValueType && !type->IsPrimitive && !type->IsEnum) - { - cli::array^ fields = type->GetFields(); - CefRefPtr cefArray = CefV8Value::CreateArray(fields->Length); + return cefArray; + } + if (type->IsValueType && !type->IsPrimitive && !type->IsEnum) + { + cli::array^ fields = type->GetFields(); + CefRefPtr cefArray = CefV8Value::CreateArray(fields->Length); - for (int i = 0; i < fields->Length; i++) - { - String^ fieldName = fields[i]->Name; + for (int i = 0; i < fields->Length; i++) + { + String^ fieldName = fields[i]->Name; - CefString strFieldName = toNative(safe_cast(fieldName)); + CefString strFieldName = toNative(safe_cast(fieldName)); - Object^ fieldVal = fields[i]->GetValue(obj); + Object^ fieldVal = fields[i]->GetValue(obj); - if (fieldVal != nullptr) - { - CefRefPtr cefVal = convertToCef(fieldVal, fieldVal->GetType()); + if (fieldVal != nullptr) + { + CefRefPtr cefVal = convertToCef(fieldVal, fieldVal->GetType()); - cefArray->SetValue(strFieldName, cefVal, V8_PROPERTY_ATTRIBUTE_NONE); - } - else - { - cefArray->SetValue(strFieldName, CefV8Value::CreateNull(), V8_PROPERTY_ATTRIBUTE_NONE); - } - } + cefArray->SetValue(strFieldName, cefVal, V8_PROPERTY_ATTRIBUTE_NONE); + } + else + { + cefArray->SetValue(strFieldName, CefV8Value::CreateNull(), V8_PROPERTY_ATTRIBUTE_NONE); + } + } - return cefArray; - } - //TODO: What exception type? - throw gcnew Exception(String::Format("Cannot convert '{0}' object from CLR to CEF.", type->FullName)); - } + return cefArray; + } + //TODO: What exception type? + throw gcnew Exception(String::Format("Cannot convert '{0}' object from CLR to CEF.", type->FullName)); + } - System::String^ stdToString(const std::string& s) - { - return gcnew System::String(s.c_str()); - } + System::String^ stdToString(const std::string& s) + { + return gcnew System::String(s.c_str()); + } - Object^ convertFromCef(CefRefPtr obj) - { - if (obj->IsNull() || obj->IsUndefined()) - { - return nullptr; - } + Object^ convertFromCef(CefRefPtr obj) + { + if (obj->IsNull() || obj->IsUndefined()) + { + return nullptr; + } - if (obj->IsBool()) - return gcnew System::Boolean(obj->GetBoolValue()); - if (obj->IsInt()) - return gcnew System::Int32(obj->GetIntValue()); - if (obj->IsDouble()) - return gcnew System::Double(obj->GetDoubleValue()); - if (obj->IsString()) - return toClr(obj->GetStringValue()); + if (obj->IsBool()) + return gcnew System::Boolean(obj->GetBoolValue()); + if (obj->IsInt()) + return gcnew System::Int32(obj->GetIntValue()); + if (obj->IsDouble()) + return gcnew System::Double(obj->GetDoubleValue()); + if (obj->IsString()) + return toClr(obj->GetStringValue()); - if (obj->IsArray()) - { - int arrLength = obj->GetArrayLength(); + if (obj->IsArray()) + { + int arrLength = obj->GetArrayLength(); - if (arrLength > 0) - { - std::vector keys; - if (obj->GetKeys(keys)) - { - Dictionary^ result = gcnew Dictionary(); + if (arrLength > 0) + { + std::vector keys; + if (obj->GetKeys(keys)) + { + Dictionary^ result = gcnew Dictionary(); - for (int i = 0; i < arrLength; i++) - { - std::string p_key = keys[i].ToString(); - String^ p_keyStr = stdToString(p_key); + for (int i = 0; i < arrLength; i++) + { + std::string p_key = keys[i].ToString(); + String^ p_keyStr = stdToString(p_key); - if ((obj->HasValue(keys[i])) && (!p_keyStr->StartsWith("__"))) - { - CefRefPtr data; + if ((obj->HasValue(keys[i])) && (!p_keyStr->StartsWith("__"))) + { + CefRefPtr data; - data = obj->GetValue(keys[i]); - if (data != nullptr) - { - Object^ p_data = convertFromCef(data); + data = obj->GetValue(keys[i]); + if (data != nullptr) + { + Object^ p_data = convertFromCef(data); - result->Add(p_keyStr, p_data); - } - } - } + result->Add(p_keyStr, p_data); + } + } + } - return result; - } - } + return result; + } + } - return nullptr; - } + return nullptr; + } - if (obj->IsObject()) - { - std::vector keys; - if (obj->GetKeys(keys)) - { - int objLength = keys.size(); - if (objLength > 0) - { - Dictionary^ result = gcnew Dictionary(); + if (obj->IsObject()) + { + std::vector keys; + if (obj->GetKeys(keys)) + { + int objLength = keys.size(); + if (objLength > 0) + { + Dictionary^ result = gcnew Dictionary(); - for (int i = 0; i < objLength; i++) - { - std::string p_key = keys[i].ToString(); - String^ p_keyStr = stdToString(p_key); + for (int i = 0; i < objLength; i++) + { + std::string p_key = keys[i].ToString(); + String^ p_keyStr = stdToString(p_key); - if ((obj->HasValue(keys[i])) && (!p_keyStr->StartsWith("__"))) - { - CefRefPtr data; + if ((obj->HasValue(keys[i])) && (!p_keyStr->StartsWith("__"))) + { + CefRefPtr data; - data = obj->GetValue(keys[i]); - if (data != nullptr) - { - Object^ p_data = convertFromCef(data); + data = obj->GetValue(keys[i]); + if (data != nullptr) + { + Object^ p_data = convertFromCef(data); - result->Add(p_keyStr, p_data); - } - } - } + result->Add(p_keyStr, p_data); + } + } + } - return result; - } - } + return result; + } + } - return nullptr; - } + return nullptr; + } - //TODO: What exception type? - throw gcnew Exception("Cannot convert object from Cef to CLR."); - } + //TODO: What exception type? + throw gcnew Exception("Cannot convert object from Cef to CLR."); + } } \ No newline at end of file