From 3407a91d1dd917a558b1f5e0fdc6e425f75e2219 Mon Sep 17 00:00:00 2001 From: Bodekaer Date: Wed, 7 Jan 2015 16:10:56 +0100 Subject: [PATCH 01/73] Added drag-drop support, to allow dragging files, text and links into the browser (WPF-only currently) --- CefSharp.Core/Internals/CefDragDataWrapper.h | 18 ++ CefSharp.Core/ManagedCefBrowserAdapter.h | 56 ++++++ .../Views/BrowserTabView.xaml | 1 + CefSharp.Wpf/ChromiumWebBrowser.cs | 187 ++++++++++++++++++ CefSharp/CefDragOperationsMask.cs | 24 +++ CefSharp/CefSharp.csproj | 3 + CefSharp/IMouseEvent.cs | 16 ++ CefSharp/MouseEvent.cs | 17 ++ 8 files changed, 322 insertions(+) create mode 100644 CefSharp/CefDragOperationsMask.cs create mode 100644 CefSharp/IMouseEvent.cs create mode 100644 CefSharp/MouseEvent.cs diff --git a/CefSharp.Core/Internals/CefDragDataWrapper.h b/CefSharp.Core/Internals/CefDragDataWrapper.h index 4a4f6d402..0b0ff8b68 100644 --- a/CefSharp.Core/Internals/CefDragDataWrapper.h +++ b/CefSharp.Core/Internals/CefDragDataWrapper.h @@ -41,6 +41,24 @@ namespace CefSharp virtual property bool IsFragment; virtual property bool IsLink; + /// + // Create a new CefDragData object. + /// + /*--cef()--*/ + static CefDragDataWrapper^ Create(){ + CefRefPtr cefDragData = CefDragData::Create(); + return gcnew CefDragDataWrapper(cefDragData); + } + + + virtual property CefRefPtr* _internalDragData + { + CefRefPtr* get() + { + return new CefRefPtr(_wrappedDragData.get()); + } + } + //TODO: Vector is a pointer, so can potentially be updated (items may be possibly removed) virtual property IList^ FileNames { diff --git a/CefSharp.Core/ManagedCefBrowserAdapter.h b/CefSharp.Core/ManagedCefBrowserAdapter.h index d56fcef42..51051f351 100644 --- a/CefSharp.Core/ManagedCefBrowserAdapter.h +++ b/CefSharp.Core/ManagedCefBrowserAdapter.h @@ -9,6 +9,7 @@ #include "MouseButtonType.h" #include "PaintElementType.h" #include "Internals/ClientAdapter.h" +#include "Internals/CefDragDataWrapper.h" #include "Internals/RenderClientAdapter.h" #include "Internals/MCefRefPtr.h" #include "Internals/StringVisitor.h" @@ -667,5 +668,60 @@ namespace CefSharp browser->GetHost()->AddWordToDictionary(wordNative); } } + + CefMouseEvent GetCefMouseEvent(IMouseEvent^ mouseEvent){ + CefMouseEvent cefMouseEvent; + cefMouseEvent.x = mouseEvent->X; + cefMouseEvent.y = mouseEvent->Y; + cefMouseEvent.modifiers = (uint32)mouseEvent->Modifiers; + return cefMouseEvent; + } + + void OnDragTargetDragEnter(CefDragDataWrapper^ dragData, IMouseEvent^ mouseEvent, CefDragOperationsMask allowedOperations) + { + auto browser = _clientAdapter->GetCefBrowser(); + + if (browser != nullptr) + { + dragData->ResetFileContents(); // Recommended by documentation to reset before calling DragEnter + browser->GetHost()->DragTargetDragEnter(*dragData->_internalDragData, GetCefMouseEvent(mouseEvent), (CefBrowserHost::DragOperationsMask) allowedOperations); + } + } + + + + + void OnDragTargetDragOver(IMouseEvent^ mouseEvent, CefDragOperationsMask allowedOperations) + { + auto browser = _clientAdapter->GetCefBrowser(); + + if (browser != nullptr) + { + browser->GetHost()->DragTargetDragOver(GetCefMouseEvent(mouseEvent), (CefBrowserHost::DragOperationsMask) allowedOperations); + } + } + + + void OnDragTargetDragLeave() + { + auto browser = _clientAdapter->GetCefBrowser(); + + if (browser != nullptr) + { + browser->GetHost()->DragTargetDragLeave(); + } + } + + + void OnDragTargetDragDrop(IMouseEvent^ mouseEvent) + { + auto browser = _clientAdapter->GetCefBrowser(); + + if (browser != nullptr) + { + browser->GetHost()->DragTargetDrop(GetCefMouseEvent(mouseEvent)); + } + } + }; } diff --git a/CefSharp.Wpf.Example/Views/BrowserTabView.xaml b/CefSharp.Wpf.Example/Views/BrowserTabView.xaml index 3f985a571..383daf0ea 100644 --- a/CefSharp.Wpf.Example/Views/BrowserTabView.xaml +++ b/CefSharp.Wpf.Example/Views/BrowserTabView.xaml @@ -172,6 +172,7 @@ Opacity="{Binding ElementName=opacitySlider, Path=Value}" Address="{Binding Address, Mode=TwoWay}" Title="{Binding Title, Mode=OneWayToSource}" + AllowDrop="True" WebBrowser="{Binding WebBrowser, Mode=OneWayToSource}"> diff --git a/CefSharp.Wpf/ChromiumWebBrowser.cs b/CefSharp.Wpf/ChromiumWebBrowser.cs index 69fbcf81b..b2f3bd821 100644 --- a/CefSharp.Wpf/ChromiumWebBrowser.cs +++ b/CefSharp.Wpf/ChromiumWebBrowser.cs @@ -7,7 +7,9 @@ using CefSharp.Internals; using Microsoft.Win32.SafeHandles; using System; using System.Collections.Generic; +using System.IO; using System.Threading.Tasks; +using System.Linq; using System.Windows; using System.Windows.Controls; using System.Windows.Controls.Primitives; @@ -422,6 +424,12 @@ namespace CefSharp.Wpf GotKeyboardFocus += OnGotKeyboardFocus; LostKeyboardFocus += OnLostKeyboardFocus; + // Drag Drop events + DragEnter += OnDragEnter; + DragOver += OnDragOver; + DragLeave += OnDragLeave; + Drop += OnDrop; + IsVisibleChanged += OnIsVisibleChanged; ToolTip = toolTip = new ToolTip(); @@ -459,6 +467,151 @@ namespace CefSharp.Wpf PresentationSource.AddSourceChangedHandler(this, PresentationSourceChangedHandler); } + void OnDrop(object sender, DragEventArgs e) + { + managedCefBrowserAdapter.OnDragTargetDragDrop(GetMouseEvent(e)); + } + + void OnDragLeave(object sender, DragEventArgs e) + { + managedCefBrowserAdapter.OnDragTargetDragLeave(); + } + + void OnDragOver(object sender, DragEventArgs e) + { + managedCefBrowserAdapter.OnDragTargetDragOver(GetMouseEvent(e), GetDragOperationsMask(e.AllowedEffects)); + } + + + + void OnDragEnter(object sender, DragEventArgs e) + { + managedCefBrowserAdapter.OnDragTargetDragEnter(GetDragDataWrapper(e), GetMouseEvent(e), GetDragOperationsMask(e.AllowedEffects)); + } + + /// + /// Converts .NET drag drop effects to CEF Drag Operations + /// s + private CefDragOperationsMask GetDragOperationsMask(DragDropEffects dragDropEffects) + { + var operations = CefDragOperationsMask.None; + + if (dragDropEffects.HasFlag(DragDropEffects.All)) + { + operations |= CefDragOperationsMask.Every; + } + if (dragDropEffects.HasFlag(DragDropEffects.Copy)) + { + operations |= CefDragOperationsMask.Copy; + } + if (dragDropEffects.HasFlag(DragDropEffects.Move)) + { + operations |= CefDragOperationsMask.Move; + } + if (dragDropEffects.HasFlag(DragDropEffects.Link)) + { + operations |= CefDragOperationsMask.Link; + } + + return operations; + + } + + private CefDragDataWrapper GetDragDataWrapper(DragEventArgs e) + { + // Convert Drag Data + var dragData = CefDragDataWrapper.Create(); + + // Files + dragData.IsFile = e.Data.GetDataPresent(DataFormats.FileDrop); + if (dragData.IsFile) + { + // As per documentation, we only need to specify FileNames, not FileName, when dragging into the browser (http://magpcss.org/ceforum/apidocs3/projects/(default)/CefDragData.html) + foreach (var filePath in (string[])e.Data.GetData(DataFormats.FileDrop)) + { + var displayName = System.IO.Path.GetFileName(filePath); + + dragData.AddFile(filePath.Replace("\\", "/"), displayName); + } + } + + // Link/Url + var link = GetLink(e.Data); + dragData.IsLink = !string.IsNullOrEmpty(link); + if (dragData.IsLink) + { + dragData.LinkUrl = link; + } + + // Text/HTML + dragData.IsFragment = e.Data.GetDataPresent(DataFormats.Text); + if (dragData.IsFragment) + { + dragData.FragmentText = (string)e.Data.GetData(DataFormats.Text); + dragData.FragmentHtml = (string)e.Data.GetData(DataFormats.Html); + } + + + + + + + return dragData; + } + + private string GetLink(IDataObject data) + { + const string asciiUrlDataFormatName = "UniformResourceLocator"; + const string unicodeUrlDataFormatName = "UniformResourceLocatorW"; + + // Try Unicode + if (data.GetDataPresent(unicodeUrlDataFormatName)) + { + // Try to read a Unicode URL from the data + var unicodeUrl = ReadUrlFromDragDropData(data, unicodeUrlDataFormatName, Encoding.Unicode); + if (unicodeUrl != null) + { + return unicodeUrl; + } + } + + // Try ASCII + if (data.GetDataPresent(asciiUrlDataFormatName)){ + // Try to read an ASCII URL from the data + return ReadUrlFromDragDropData(data, asciiUrlDataFormatName, Encoding.ASCII); + } + + // Not a valid link + return null; + + } + + + /// Reads a URL using a particular text encoding from drag-and-drop data. + /// The drag-and-drop data. + /// The data format name of the URL type. + /// The text encoding of the URL type. + /// A URL, or if does not contain a URL + /// of the correct type. + private string ReadUrlFromDragDropData(IDataObject data, string urlDataFormatName, Encoding urlEncoding) + { + // Read the URL from the data + string url; + using (Stream urlStream = (Stream)data.GetData(urlDataFormatName)) + { + using (TextReader reader = new StreamReader(urlStream, urlEncoding)) + { + url = reader.ReadToEnd(); + } + } + + // URLs in drag/drop data are often padded with null characters so remove these + return url.TrimEnd('\0'); + } + + + + ~ChromiumWebBrowser() { Dispose(false); @@ -736,6 +889,37 @@ namespace CefSharp.Wpf UiThreadRunAsync(() => { popup.IsOpen = isOpen; }); } + /// + /// Converts a .NET Mouse event to a CefSharp MouseEvent + /// + private MouseEvent GetMouseEvent(MouseEventArgs e) + { + var point = GetPixelPosition(e); + var modifiers = GetModifiers(e); + + return new MouseEvent + { + X = (int)point.X, + Y = (int)point.Y, + Modifiers = modifiers + }; + } + + /// + /// Converts a .NET Drag event to a CefSharp MouseEvent + /// + private MouseEvent GetMouseEvent(DragEventArgs e) + { + var point = e.GetPosition(this); + + return new MouseEvent + { + X = (int)point.X, + Y = (int)point.Y, + //Modifiers = modifiers // TODO: Add support for modifiers in drag events (might not be need as it can be accessed via the mouse events) + }; + } + private static CefEventFlags GetModifiers(MouseEventArgs e) { CefEventFlags modifiers = 0; @@ -753,6 +937,7 @@ namespace CefSharp.Wpf modifiers |= CefEventFlags.RightMouseButton; } + if (Keyboard.IsKeyDown(Key.LeftCtrl)) { modifiers |= CefEventFlags.ControlDown | CefEventFlags.IsLeft; @@ -1284,5 +1469,7 @@ namespace CefSharp.Wpf { managedCefBrowserAdapter.Invalidate(type); } + + } } diff --git a/CefSharp/CefDragOperationsMask.cs b/CefSharp/CefDragOperationsMask.cs new file mode 100644 index 000000000..9667159e6 --- /dev/null +++ b/CefSharp/CefDragOperationsMask.cs @@ -0,0 +1,24 @@ +// Copyright © 2010-2014 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. + +using System; + +namespace CefSharp +{ + /// + /// Drag operation mask types + /// + [Flags] + public enum CefDragOperationsMask + { + None = 0, + Copy = 1, + Link = 2, + Generic = 4, + Private = 8, + Move = 16, + Delete = 32, + Every = int.MaxValue, + } +} diff --git a/CefSharp/CefSharp.csproj b/CefSharp/CefSharp.csproj index 054fca807..e016bdf63 100644 --- a/CefSharp/CefSharp.csproj +++ b/CefSharp/CefSharp.csproj @@ -89,7 +89,10 @@ + + + diff --git a/CefSharp/IMouseEvent.cs b/CefSharp/IMouseEvent.cs new file mode 100644 index 000000000..6c26fddc0 --- /dev/null +++ b/CefSharp/IMouseEvent.cs @@ -0,0 +1,16 @@ +// Copyright © 2010-2014 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. + +using System.Collections.Generic; +using System.IO; + +namespace CefSharp +{ + public interface IMouseEvent + { + int X { get; set; } + int Y { get; set; } + CefEventFlags Modifiers { get; set; } + } +} \ No newline at end of file diff --git a/CefSharp/MouseEvent.cs b/CefSharp/MouseEvent.cs new file mode 100644 index 000000000..8a4d5f72a --- /dev/null +++ b/CefSharp/MouseEvent.cs @@ -0,0 +1,17 @@ +// Copyright © 2010-2014 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. + +using System; +using System.Collections.Generic; +using System.IO; + +namespace CefSharp +{ + public class MouseEvent : IMouseEvent + { + public int X { get; set; } + public int Y { get; set; } + public CefEventFlags Modifiers { get; set; } + } +} From 03ed74c02156e43da8af66d7d4707fd62286ba21 Mon Sep 17 00:00:00 2001 From: Bodekaer Date: Wed, 7 Jan 2015 16:13:49 +0100 Subject: [PATCH 02/73] Added build.bat script for slightly more convenient NuGet compiling --- Build.bat | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 Build.bat diff --git a/Build.bat b/Build.bat new file mode 100644 index 000000000..b1edbcf23 --- /dev/null +++ b/Build.bat @@ -0,0 +1,3 @@ +SET ThisScriptsDirectory=%~dp0 +SET PowerShellScriptPath=%ThisScriptsDirectory%Build.ps1 +PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& {Start-Process PowerShell -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File ""%PowerShellScriptPath%""' -Verb RunAs}"; \ No newline at end of file From c2242e51580ccff5d8ff3165f1fece2d6e6dc2bf Mon Sep 17 00:00:00 2001 From: amaitland Date: Fri, 16 Jan 2015 12:22:40 +1000 Subject: [PATCH 03/73] Create another layer of abstraction around BitmapInfo - Allow for future possibility of implementing WritableBitmap in WPF --- CefSharp.OffScreen/ChromiumWebBrowser.cs | 2 +- CefSharp.OffScreen/GdiBitmapInfo.cs | 12 +++++++- CefSharp.Wpf/CefSharp.Wpf.csproj | 1 + CefSharp.Wpf/ChromiumWebBrowser.cs | 23 +++++---------- CefSharp.Wpf/InteropBitmapInfo.cs | 36 ++++++++++++++++++++---- CefSharp.Wpf/RenderingEventArgs.cs | 4 +-- CefSharp.Wpf/WpfBitmapInfo.cs | 11 ++++++++ CefSharp/Internals/BitmapInfo.cs | 3 +- 8 files changed, 66 insertions(+), 26 deletions(-) create mode 100644 CefSharp.Wpf/WpfBitmapInfo.cs diff --git a/CefSharp.OffScreen/ChromiumWebBrowser.cs b/CefSharp.OffScreen/ChromiumWebBrowser.cs index b047d4125..a71d46833 100644 --- a/CefSharp.OffScreen/ChromiumWebBrowser.cs +++ b/CefSharp.OffScreen/ChromiumWebBrowser.cs @@ -343,7 +343,7 @@ namespace CefSharp.OffScreen public BitmapInfo CreateBitmapInfo(bool isPopup) { //The bitmap buffer is 32 BPP - return new GdiBitmapInfo { IsPopup = isPopup, BytesPerPixel = 4, BitmapLock = bitmapLock }; + return new GdiBitmapInfo { IsPopup = isPopup, BitmapLock = bitmapLock }; } void IRenderWebBrowser.InvokeRenderAsync(BitmapInfo bitmapInfo) diff --git a/CefSharp.OffScreen/GdiBitmapInfo.cs b/CefSharp.OffScreen/GdiBitmapInfo.cs index a6d49e7f7..dadb1b73a 100644 --- a/CefSharp.OffScreen/GdiBitmapInfo.cs +++ b/CefSharp.OffScreen/GdiBitmapInfo.cs @@ -8,7 +8,17 @@ namespace CefSharp.OffScreen { public class GdiBitmapInfo : BitmapInfo { - public bool IsCleared { get; set; } + public bool IsCleared { get; private set; } + + public GdiBitmapInfo() + { + BytesPerPixel = 4; + } + + public override bool CreateNewBitmap + { + get { return IsCleared; } + } public override void ClearBitmap() { diff --git a/CefSharp.Wpf/CefSharp.Wpf.csproj b/CefSharp.Wpf/CefSharp.Wpf.csproj index 0c7fa1711..6dbf069e4 100644 --- a/CefSharp.Wpf/CefSharp.Wpf.csproj +++ b/CefSharp.Wpf/CefSharp.Wpf.csproj @@ -102,6 +102,7 @@ + diff --git a/CefSharp.Wpf/ChromiumWebBrowser.cs b/CefSharp.Wpf/ChromiumWebBrowser.cs index 69fbcf81b..6b322ed39 100644 --- a/CefSharp.Wpf/ChromiumWebBrowser.cs +++ b/CefSharp.Wpf/ChromiumWebBrowser.cs @@ -20,8 +20,6 @@ namespace CefSharp.Wpf { public class ChromiumWebBrowser : ContentControl, IRenderWebBrowser, IWpfWebBrowser { - private static readonly PixelFormat PixelFormat = PixelFormats.Bgra32; - private static readonly int BytesPerPixel = PixelFormat.BitsPerPixel / 8; private HwndSource source; private HwndSourceHook sourceHook; private DispatcherTimer tooltipTimer; @@ -636,7 +634,7 @@ namespace CefSharp.Wpf public BitmapInfo CreateBitmapInfo(bool isPopup) { - return new InteropBitmapInfo { IsPopup = isPopup, BytesPerPixel = BytesPerPixel }; + return new InteropBitmapInfo { IsPopup = isPopup }; } void IRenderWebBrowser.InvokeRenderAsync(BitmapInfo bitmapInfo) @@ -645,29 +643,22 @@ namespace CefSharp.Wpf { lock (bitmapInfo.BitmapLock) { - var interopBitmapInfo = (InteropBitmapInfo)bitmapInfo; + var wpfBitmapInfo = (WpfBitmapInfo)bitmapInfo; // Inform parents that the browser rendering is updating - OnRendering(this, interopBitmapInfo); + OnRendering(this, wpfBitmapInfo); // Now update the WPF image - var bitmap = interopBitmapInfo.InteropBitmap; - if (bitmap == null) + if (wpfBitmapInfo.CreateNewBitmap) { var img = bitmapInfo.IsPopup ? popupImage : image; img.Source = null; GC.Collect(1); - var stride = bitmapInfo.Width * bitmapInfo.BytesPerPixel; - - bitmap = (InteropBitmap)Imaging.CreateBitmapSourceFromMemorySection(bitmapInfo.FileMappingHandle, - bitmapInfo.Width, bitmapInfo.Height, PixelFormat, stride, 0); - img.Source = bitmap; - - interopBitmapInfo.InteropBitmap = bitmap; + img.Source = wpfBitmapInfo.CreateBitmap(); } - bitmap.Invalidate(); + wpfBitmapInfo.Invalidate(); } }, DispatcherPriority.Render); @@ -1230,7 +1221,7 @@ namespace CefSharp.Wpf /// /// Raises Rendering event /// - protected virtual void OnRendering(object sender, InteropBitmapInfo bitmapInfo) + protected virtual void OnRendering(object sender, WpfBitmapInfo bitmapInfo) { var rendering = Rendering; if (rendering != null) diff --git a/CefSharp.Wpf/InteropBitmapInfo.cs b/CefSharp.Wpf/InteropBitmapInfo.cs index 20d0f7cab..a92b09cf9 100644 --- a/CefSharp.Wpf/InteropBitmapInfo.cs +++ b/CefSharp.Wpf/InteropBitmapInfo.cs @@ -1,16 +1,42 @@ using System.Windows.Interop; -using CefSharp.Internals; +using System.Windows.Media; +using System.Windows.Media.Imaging; namespace CefSharp.Wpf { - public class InteropBitmapInfo : BitmapInfo + public class InteropBitmapInfo : WpfBitmapInfo { - // Cannot be InteropBitmap since we really don't want CefSharp to be dependent on WPF libraries. - public InteropBitmap InteropBitmap { get; set; } + private static readonly PixelFormat PixelFormat = PixelFormats.Bgra32; + + public InteropBitmap Bitmap { get; private set; } + + public InteropBitmapInfo() + { + BytesPerPixel = PixelFormat.BitsPerPixel / 8; + } + + public override bool CreateNewBitmap + { + get { return Bitmap == null; } + } public override void ClearBitmap() { - InteropBitmap = null; + Bitmap = null; + } + + public override void Invalidate() + { + Bitmap.Invalidate(); + } + + public override BitmapSource CreateBitmap() + { + var stride = Width * BytesPerPixel; + + Bitmap = (InteropBitmap)Imaging.CreateBitmapSourceFromMemorySection(FileMappingHandle, Width, Height, PixelFormat, stride, 0); + + return Bitmap; } } } diff --git a/CefSharp.Wpf/RenderingEventArgs.cs b/CefSharp.Wpf/RenderingEventArgs.cs index d8d4e7ef3..f58cd2624 100644 --- a/CefSharp.Wpf/RenderingEventArgs.cs +++ b/CefSharp.Wpf/RenderingEventArgs.cs @@ -11,7 +11,7 @@ namespace CefSharp.Wpf /// public class RenderingEventArgs : EventArgs { - public RenderingEventArgs(InteropBitmapInfo bitmapInfo) + public RenderingEventArgs(WpfBitmapInfo bitmapInfo) { BitmapInfo = bitmapInfo; } @@ -19,7 +19,7 @@ namespace CefSharp.Wpf /// /// The bitmap info being rendered. /// - public InteropBitmapInfo BitmapInfo { get; private set; } + public WpfBitmapInfo BitmapInfo { get; private set; } } } diff --git a/CefSharp.Wpf/WpfBitmapInfo.cs b/CefSharp.Wpf/WpfBitmapInfo.cs new file mode 100644 index 000000000..12055c59e --- /dev/null +++ b/CefSharp.Wpf/WpfBitmapInfo.cs @@ -0,0 +1,11 @@ +using System.Windows.Media.Imaging; +using CefSharp.Internals; + +namespace CefSharp.Wpf +{ + public abstract class WpfBitmapInfo : BitmapInfo + { + public abstract void Invalidate(); + public abstract BitmapSource CreateBitmap(); + } +} diff --git a/CefSharp/Internals/BitmapInfo.cs b/CefSharp/Internals/BitmapInfo.cs index 7cb019466..1cc0d2dd7 100644 --- a/CefSharp/Internals/BitmapInfo.cs +++ b/CefSharp/Internals/BitmapInfo.cs @@ -17,8 +17,9 @@ namespace CefSharp.Internals public IntPtr FileMappingHandle { get; set; } - public int BytesPerPixel { get; set; } + public int BytesPerPixel { get; protected set; } + public abstract bool CreateNewBitmap { get; } public abstract void ClearBitmap(); protected BitmapInfo() From 899e991a0a31be1cec78cabbf5f72e1a4b0d1575 Mon Sep 17 00:00:00 2001 From: amaitland Date: Fri, 16 Jan 2015 13:40:49 +1000 Subject: [PATCH 04/73] First attempt at WritableBitmapInfo implementation - uses dirty rects to determine which part of the screen to update --- CefSharp.Core/Internals/RenderClientAdapter.h | 12 ++++ CefSharp.Wpf/CefSharp.Wpf.csproj | 1 + CefSharp.Wpf/ChromiumWebBrowser.cs | 1 + CefSharp.Wpf/WpfBitmapInfo.cs | 6 +- CefSharp.Wpf/WritableBitmapInfo.cs | 64 +++++++++++++++++++ CefSharp/CefDirtyRect.cs | 27 ++++++++ CefSharp/CefSharp.csproj | 1 + CefSharp/Internals/BitmapInfo.cs | 4 ++ 8 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 CefSharp.Wpf/WritableBitmapInfo.cs create mode 100644 CefSharp/CefDirtyRect.cs diff --git a/CefSharp.Core/Internals/RenderClientAdapter.h b/CefSharp.Core/Internals/RenderClientAdapter.h index 79ed98c4e..0b864f222 100644 --- a/CefSharp.Core/Internals/RenderClientAdapter.h +++ b/CefSharp.Core/Internals/RenderClientAdapter.h @@ -92,6 +92,18 @@ namespace CefSharp lock l(bitmapInfo->BitmapLock); + if(bitmapInfo->DirtyRectSupport) + { + auto rects = gcnew List(dirtyRects.size()); + + for each(CefRect r in dirtyRects) + { + rects->Add(CefDirtyRect(r.x, r.y, r.width, r.height)); + } + + bitmapInfo->DirtyRects = rects; + } + auto fileMappingHandle = (HANDLE)bitmapInfo->FileMappingHandle; auto backBufferHandle = (HANDLE)bitmapInfo->BackBufferHandle; diff --git a/CefSharp.Wpf/CefSharp.Wpf.csproj b/CefSharp.Wpf/CefSharp.Wpf.csproj index 6dbf069e4..79cab498c 100644 --- a/CefSharp.Wpf/CefSharp.Wpf.csproj +++ b/CefSharp.Wpf/CefSharp.Wpf.csproj @@ -103,6 +103,7 @@ + diff --git a/CefSharp.Wpf/ChromiumWebBrowser.cs b/CefSharp.Wpf/ChromiumWebBrowser.cs index 6b322ed39..e6f41bd19 100644 --- a/CefSharp.Wpf/ChromiumWebBrowser.cs +++ b/CefSharp.Wpf/ChromiumWebBrowser.cs @@ -635,6 +635,7 @@ namespace CefSharp.Wpf public BitmapInfo CreateBitmapInfo(bool isPopup) { return new InteropBitmapInfo { IsPopup = isPopup }; + //return new WritableBitmapInfo { IsPopup = isPopup }; } void IRenderWebBrowser.InvokeRenderAsync(BitmapInfo bitmapInfo) diff --git a/CefSharp.Wpf/WpfBitmapInfo.cs b/CefSharp.Wpf/WpfBitmapInfo.cs index 12055c59e..5da657074 100644 --- a/CefSharp.Wpf/WpfBitmapInfo.cs +++ b/CefSharp.Wpf/WpfBitmapInfo.cs @@ -1,4 +1,8 @@ -using System.Windows.Media.Imaging; +// Copyright © 2010-2014 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. + +using System.Windows.Media.Imaging; using CefSharp.Internals; namespace CefSharp.Wpf diff --git a/CefSharp.Wpf/WritableBitmapInfo.cs b/CefSharp.Wpf/WritableBitmapInfo.cs new file mode 100644 index 000000000..29643357f --- /dev/null +++ b/CefSharp.Wpf/WritableBitmapInfo.cs @@ -0,0 +1,64 @@ +// Copyright © 2010-2014 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. + +using System.Windows; +using System.Windows.Media; +using System.Windows.Media.Imaging; + +namespace CefSharp.Wpf +{ + public class WritableBitmapInfo : WpfBitmapInfo + { + private static readonly PixelFormat PixelFormat = PixelFormats.Bgra32; + + public WriteableBitmap Bitmap { get; private set; } + + public WritableBitmapInfo() + { + BytesPerPixel = PixelFormat.BitsPerPixel / 8; + DirtyRectSupport = true; + } + + public override bool CreateNewBitmap + { + get { return Bitmap == null; } + } + + public override void ClearBitmap() + { + Bitmap = null; + } + + public override void Invalidate() + { + //int stride = browserWidth * 4; + var stride = Width * BytesPerPixel; + var sourceBufferSize = stride * Height; + + if (Width == 0 || Height == 0) + { + return; + } + + foreach (var dirtyRect in DirtyRects) + { + if (dirtyRect.Width == 0 || dirtyRect.Height == 0) + { + continue; + } + + // Update the dirty region + var sourceRect = new Int32Rect(dirtyRect.X, dirtyRect.Y, dirtyRect.Width, dirtyRect.Height); + Bitmap.WritePixels(sourceRect, BackBufferHandle, sourceBufferSize, stride, dirtyRect.X, dirtyRect.Y); + } + } + + public override BitmapSource CreateBitmap() + { + Bitmap = new WriteableBitmap(Width, Height, 96, 96, PixelFormat, null); + + return Bitmap; + } + } +} diff --git a/CefSharp/CefDirtyRect.cs b/CefSharp/CefDirtyRect.cs new file mode 100644 index 000000000..1d97fde2f --- /dev/null +++ b/CefSharp/CefDirtyRect.cs @@ -0,0 +1,27 @@ +// Copyright © 2010-2014 The CefSharp Authors. All rights reserved. +// +// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. + +namespace CefSharp +{ + public struct CefDirtyRect + { + private readonly int x; + private readonly int y; + private readonly int width; + private readonly int height; + + public CefDirtyRect(int x, int y, int width, int height) + { + this.x = x; + this.y = y; + this.width = width; + this.height = height; + } + + public int X { get { return x; } } + public int Y { get { return y; } } + public int Width { get { return width; } } + public int Height { get { return height; } } + } +} diff --git a/CefSharp/CefSharp.csproj b/CefSharp/CefSharp.csproj index 4ec0ff42a..f924f4ca2 100644 --- a/CefSharp/CefSharp.csproj +++ b/CefSharp/CefSharp.csproj @@ -88,6 +88,7 @@ + diff --git a/CefSharp/Internals/BitmapInfo.cs b/CefSharp/Internals/BitmapInfo.cs index 1cc0d2dd7..8353aa12d 100644 --- a/CefSharp/Internals/BitmapInfo.cs +++ b/CefSharp/Internals/BitmapInfo.cs @@ -3,6 +3,7 @@ // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. using System; +using System.Collections.Generic; namespace CefSharp.Internals { @@ -18,10 +19,13 @@ namespace CefSharp.Internals public IntPtr FileMappingHandle { get; set; } public int BytesPerPixel { get; protected set; } + public bool DirtyRectSupport { get; protected set; } public abstract bool CreateNewBitmap { get; } public abstract void ClearBitmap(); + public IList DirtyRects { get; set; } + protected BitmapInfo() { BitmapLock = new object(); From 2defbb59e2991b78dcb8df669e8dfa07926bcd18 Mon Sep 17 00:00:00 2001 From: amaitland Date: Fri, 16 Jan 2015 14:05:54 +1000 Subject: [PATCH 05/73] Untabify --- CefSharp/CefDirtyRect.cs | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/CefSharp/CefDirtyRect.cs b/CefSharp/CefDirtyRect.cs index 1d97fde2f..6f3376c0a 100644 --- a/CefSharp/CefDirtyRect.cs +++ b/CefSharp/CefDirtyRect.cs @@ -4,24 +4,24 @@ namespace CefSharp { - public struct CefDirtyRect - { - private readonly int x; - private readonly int y; - private readonly int width; - private readonly int height; + public struct CefDirtyRect + { + private readonly int x; + private readonly int y; + private readonly int width; + private readonly int height; - public CefDirtyRect(int x, int y, int width, int height) - { - this.x = x; - this.y = y; - this.width = width; - this.height = height; - } + public CefDirtyRect(int x, int y, int width, int height) + { + this.x = x; + this.y = y; + this.width = width; + this.height = height; + } - public int X { get { return x; } } - public int Y { get { return y; } } - public int Width { get { return width; } } - public int Height { get { return height; } } - } + public int X { get { return x; } } + public int Y { get { return y; } } + public int Width { get { return width; } } + public int Height { get { return height; } } + } } From 9d2d8f7a406d9fccf05b11b6c7b9bed88d0e0159 Mon Sep 17 00:00:00 2001 From: jankurianski Date: Thu, 22 Jan 2015 11:45:30 +1100 Subject: [PATCH 06/73] Fix OffScreen's Address field This fix ensures the Address field returns the correct value after construction (instead of null). The Address field setter is now private as callers should use Load() to change url. --- CefSharp.OffScreen/ChromiumWebBrowser.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CefSharp.OffScreen/ChromiumWebBrowser.cs b/CefSharp.OffScreen/ChromiumWebBrowser.cs index b047d4125..0bcace357 100644 --- a/CefSharp.OffScreen/ChromiumWebBrowser.cs +++ b/CefSharp.OffScreen/ChromiumWebBrowser.cs @@ -47,6 +47,7 @@ namespace CefSharp.OffScreen ResourceHandler = new DefaultResourceHandler(); Cef.AddDisposable(this); + Address = address; managedCefBrowserAdapter = new ManagedCefBrowserAdapter(this, true); managedCefBrowserAdapter.CreateOffscreenBrowser(IntPtr.Zero, browserSettings ?? new BrowserSettings(), address); @@ -197,7 +198,7 @@ namespace CefSharp.OffScreen managedCefBrowserAdapter.AddWordToDictionary(word); } - public string Address { get; set; } + public string Address { get; private set; } public bool CanGoBack { get; private set; } From aba800a9c3c3ca03043605f6d962ec23caab62d6 Mon Sep 17 00:00:00 2001 From: pushplay Date: Mon, 26 Jan 2015 14:16:46 -0800 Subject: [PATCH 07/73] Implement CefGeolocationHandler::OnRequestGeolocationPermission delegating the request to a CefSharp.IGeolocationHandler implementation. This allows CefSharp to permit geolocation requests. --- CefSharp.Core/Internals/ClientAdapter.cpp | 26 +++++++++++++++++++ CefSharp.Core/Internals/ClientAdapter.h | 9 ++++++- CefSharp.OffScreen/ChromiumWebBrowser.cs | 1 + .../BrowserTabUserControl.cs | 1 + .../CefSharp.WinForms.Example.csproj | 1 + .../GeolocationHandler.cs | 22 ++++++++++++++++ CefSharp.WinForms/ChromiumWebBrowser.cs | 1 + .../CefSharp.Wpf.Example.csproj | 1 + .../Handlers/GeolocationHandler.cs | 22 ++++++++++++++++ .../Views/BrowserTabView.xaml.cs | 1 + CefSharp.Wpf/ChromiumWebBrowser.cs | 1 + CefSharp/CefSharp.csproj | 1 + CefSharp/IGeolocationHandler.cs | 26 +++++++++++++++++++ CefSharp/IWebBrowser.cs | 5 ++++ 14 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 CefSharp.WinForms.Example/GeolocationHandler.cs create mode 100644 CefSharp.Wpf.Example/Handlers/GeolocationHandler.cs create mode 100644 CefSharp/IGeolocationHandler.cs diff --git a/CefSharp.Core/Internals/ClientAdapter.cpp b/CefSharp.Core/Internals/ClientAdapter.cpp index 860ca3683..dcfc8ba37 100644 --- a/CefSharp.Core/Internals/ClientAdapter.cpp +++ b/CefSharp.Core/Internals/ClientAdapter.cpp @@ -569,5 +569,31 @@ namespace CefSharp return handler->OnDragEnter(_browserControl, dragDataWrapper, (CefSharp::DragOperationsMask)mask); } + + bool ClientAdapter::OnRequestGeolocationPermission(CefRefPtr browser, const CefString& requesting_url, int request_id, CefRefPtr callback) + { + IGeolocationHandler^ handler = _browserControl->GeolocationHandler; + if (handler == nullptr) + { + // Default deny, as CEF does. + return false; + } + + if (handler->OnRequestGeolocationPermission(_browserControl, StringUtils::ToClr(requesting_url), request_id)) { + callback->Continue(true); + return true; + } + + return false; + } + + void ClientAdapter::OnCancelGeolocationPermission(CefRefPtr browser, const CefString& requesting_url, int request_id) + { + IGeolocationHandler^ handler = _browserControl->GeolocationHandler; + if (handler != nullptr) + { + handler->OnCancelGeolocationPermission(_browserControl, StringUtils::ToClr(requesting_url), request_id); + } + } } } diff --git a/CefSharp.Core/Internals/ClientAdapter.h b/CefSharp.Core/Internals/ClientAdapter.h index d4356a238..abcebd05e 100644 --- a/CefSharp.Core/Internals/ClientAdapter.h +++ b/CefSharp.Core/Internals/ClientAdapter.h @@ -29,7 +29,8 @@ namespace CefSharp public CefKeyboardHandler, public CefJSDialogHandler, public CefDialogHandler, - public CefDragHandler + public CefDragHandler, + public CefGeolocationHandler { private: CriticalSection _syncRoot; @@ -75,6 +76,7 @@ namespace CefSharp virtual CefRefPtr GetJSDialogHandler() OVERRIDE{ return this; } virtual CefRefPtr GetDialogHandler() OVERRIDE{ return this; } virtual CefRefPtr GetDragHandler() OVERRIDE{ return this; } + virtual CefRefPtr GetGeolocationHandler() OVERRIDE{ return this; } // CefLifeSpanHandler virtual DECL bool OnBeforePopup(CefRefPtr browser, CefRefPtr frame, @@ -136,6 +138,11 @@ namespace CefSharp //CefDragHandler virtual DECL bool OnDragEnter(CefRefPtr browser, CefRefPtr dragData, DragOperationsMask mask) OVERRIDE; + //CefGeolocationHandler + virtual DECL bool OnRequestGeolocationPermission(CefRefPtr browser, const CefString& requesting_url, int request_id, + CefRefPtr callback) OVERRIDE; + virtual DECL void OnCancelGeolocationPermission(CefRefPtr browser, const CefString& requesting_url, int request_id) OVERRIDE; + IMPLEMENT_REFCOUNTING(ClientAdapter); }; } diff --git a/CefSharp.OffScreen/ChromiumWebBrowser.cs b/CefSharp.OffScreen/ChromiumWebBrowser.cs index 0bcace357..5fa4660b0 100644 --- a/CefSharp.OffScreen/ChromiumWebBrowser.cs +++ b/CefSharp.OffScreen/ChromiumWebBrowser.cs @@ -169,6 +169,7 @@ namespace CefSharp.OffScreen public IRequestHandler RequestHandler { get; set; } public IDragHandler DragHandler { get; set; } public IResourceHandler ResourceHandler { get; set; } + public IGeolocationHandler GeolocationHandler { get; set; } public event EventHandler LoadError; public event EventHandler FrameLoadStart; diff --git a/CefSharp.WinForms.Example/BrowserTabUserControl.cs b/CefSharp.WinForms.Example/BrowserTabUserControl.cs index 88e8638aa..72f841cb6 100644 --- a/CefSharp.WinForms.Example/BrowserTabUserControl.cs +++ b/CefSharp.WinForms.Example/BrowserTabUserControl.cs @@ -26,6 +26,7 @@ namespace CefSharp.WinForms.Example browser.MenuHandler = new MenuHandler(); browser.RequestHandler = new RequestHandler(); browser.JsDialogHandler = new JsDialogHandler(); + browser.GeolocationHandler = new GeolocationHandler(); //browser.FocusHandler = new FocusHandler(browser, urlTextBox); browser.NavStateChanged += OnBrowserNavStateChanged; browser.ConsoleMessage += OnBrowserConsoleMessage; diff --git a/CefSharp.WinForms.Example/CefSharp.WinForms.Example.csproj b/CefSharp.WinForms.Example/CefSharp.WinForms.Example.csproj index 25d83d5a3..9a3d8c6f6 100644 --- a/CefSharp.WinForms.Example/CefSharp.WinForms.Example.csproj +++ b/CefSharp.WinForms.Example/CefSharp.WinForms.Example.csproj @@ -78,6 +78,7 @@ BrowserTabUserControl.cs + Form diff --git a/CefSharp.WinForms.Example/GeolocationHandler.cs b/CefSharp.WinForms.Example/GeolocationHandler.cs new file mode 100644 index 000000000..63ddc1d3f --- /dev/null +++ b/CefSharp.WinForms.Example/GeolocationHandler.cs @@ -0,0 +1,22 @@ +// Copyright © 2010-2014 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. + +using System; +using System.Windows.Forms; + +namespace CefSharp.WinForms.Example +{ + internal class GeolocationHandler : IGeolocationHandler + { + public bool OnRequestGeolocationPermission(IWebBrowser browser, string requestingUrl, int requestId) + { + var result = MessageBox.Show(String.Format("{0} wants to use your computer's location. Allow?", requestingUrl), "Geolocation", MessageBoxButtons.YesNo); + return result == DialogResult.Yes; + } + + public void OnCancelGeolocationPermission(IWebBrowser browser, string requestingUrl, int requestId) + { + } + } +} diff --git a/CefSharp.WinForms/ChromiumWebBrowser.cs b/CefSharp.WinForms/ChromiumWebBrowser.cs index ea2fdc618..9b0d007e8 100644 --- a/CefSharp.WinForms/ChromiumWebBrowser.cs +++ b/CefSharp.WinForms/ChromiumWebBrowser.cs @@ -31,6 +31,7 @@ namespace CefSharp.WinForms public IFocusHandler FocusHandler { get; set; } public IDragHandler DragHandler { get; set; } public IResourceHandler ResourceHandler { get; set; } + public IGeolocationHandler GeolocationHandler { get; set; } public bool CanGoForward { get; private set; } public bool CanGoBack { get; private set; } diff --git a/CefSharp.Wpf.Example/CefSharp.Wpf.Example.csproj b/CefSharp.Wpf.Example/CefSharp.Wpf.Example.csproj index 342c3db2e..8bb040fd3 100644 --- a/CefSharp.Wpf.Example/CefSharp.Wpf.Example.csproj +++ b/CefSharp.Wpf.Example/CefSharp.Wpf.Example.csproj @@ -105,6 +105,7 @@ Designer + diff --git a/CefSharp.Wpf.Example/Handlers/GeolocationHandler.cs b/CefSharp.Wpf.Example/Handlers/GeolocationHandler.cs new file mode 100644 index 000000000..5c184a01b --- /dev/null +++ b/CefSharp.Wpf.Example/Handlers/GeolocationHandler.cs @@ -0,0 +1,22 @@ +// Copyright © 2010-2014 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. + +using System; +using System.Windows; + +namespace CefSharp.Wpf.Example.Handlers +{ + internal class GeolocationHandler : IGeolocationHandler + { + public bool OnRequestGeolocationPermission(IWebBrowser browser, string requestingUrl, int requestId) + { + var result = MessageBox.Show(String.Format("{0} wants to use your computer's location. Allow?", requestingUrl), "Geolocation", MessageBoxButton.YesNo); + return result == MessageBoxResult.Yes; + } + + public void OnCancelGeolocationPermission(IWebBrowser browser, string requestingUrl, int requestId) + { + } + } +} diff --git a/CefSharp.Wpf.Example/Views/BrowserTabView.xaml.cs b/CefSharp.Wpf.Example/Views/BrowserTabView.xaml.cs index 5d13a1d09..1c5acc88a 100644 --- a/CefSharp.Wpf.Example/Views/BrowserTabView.xaml.cs +++ b/CefSharp.Wpf.Example/Views/BrowserTabView.xaml.cs @@ -19,6 +19,7 @@ namespace CefSharp.Wpf.Example.Views browser.RegisterJsObject("bound", new BoundObject()); browser.MenuHandler = new Handlers.MenuHandler(); + browser.GeolocationHandler = new Handlers.GeolocationHandler(); CefExample.RegisterTestResources(browser); } diff --git a/CefSharp.Wpf/ChromiumWebBrowser.cs b/CefSharp.Wpf/ChromiumWebBrowser.cs index 05d8577df..43342ce2e 100644 --- a/CefSharp.Wpf/ChromiumWebBrowser.cs +++ b/CefSharp.Wpf/ChromiumWebBrowser.cs @@ -48,6 +48,7 @@ namespace CefSharp.Wpf public IFocusHandler FocusHandler { get; set; } public IDragHandler DragHandler { get; set; } public IResourceHandler ResourceHandler { get; set; } + public IGeolocationHandler GeolocationHandler { get; set; } public event EventHandler ConsoleMessage; public event EventHandler StatusMessage; diff --git a/CefSharp/CefSharp.csproj b/CefSharp/CefSharp.csproj index 4ec0ff42a..4f7b3c842 100644 --- a/CefSharp/CefSharp.csproj +++ b/CefSharp/CefSharp.csproj @@ -94,6 +94,7 @@ + diff --git a/CefSharp/IGeolocationHandler.cs b/CefSharp/IGeolocationHandler.cs new file mode 100644 index 000000000..04cb02f8d --- /dev/null +++ b/CefSharp/IGeolocationHandler.cs @@ -0,0 +1,26 @@ +// Copyright © 2010-2014 The CefSharp Authors. All rights reserved. +// +// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. + +namespace CefSharp +{ + public interface IGeolocationHandler + { + /// + /// Called when a page requests permission to access geolocation information. + /// + /// the browser object + /// the URL requesting permission + /// the unique ID for the permission request + /// true to allow the request and false to deny + bool OnRequestGeolocationPermission(IWebBrowser browser, string requestingUrl, int requestId); + + /// + /// Called when a geolocation access request is canceled. + /// + /// the browser object + /// the URL that originally requested permission + /// the unique ID for the permission request, as seen in + void OnCancelGeolocationPermission(IWebBrowser browser, string requestingUrl, int requestId); + } +} diff --git a/CefSharp/IWebBrowser.cs b/CefSharp/IWebBrowser.cs index 52ad78b16..f9d833d92 100644 --- a/CefSharp/IWebBrowser.cs +++ b/CefSharp/IWebBrowser.cs @@ -154,6 +154,11 @@ namespace CefSharp /// IResourceHandler ResourceHandler { get; set; } + /// + /// Implement and assign to handle requests for permission to use geolocation. + /// + IGeolocationHandler GeolocationHandler { get; set; } + /// /// A flag that indicates whether the WebBrowser is initialized (true) or not (false). /// From 485e2a97a2c6e737071ec1c77a2d5c87806851bf Mon Sep 17 00:00:00 2001 From: pushplay Date: Mon, 26 Jan 2015 17:30:29 -0800 Subject: [PATCH 08/73] Code clean up: fixing a brace. --- CefSharp.Core/Internals/ClientAdapter.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CefSharp.Core/Internals/ClientAdapter.cpp b/CefSharp.Core/Internals/ClientAdapter.cpp index dcfc8ba37..5c3df65cd 100644 --- a/CefSharp.Core/Internals/ClientAdapter.cpp +++ b/CefSharp.Core/Internals/ClientAdapter.cpp @@ -579,7 +579,8 @@ namespace CefSharp return false; } - if (handler->OnRequestGeolocationPermission(_browserControl, StringUtils::ToClr(requesting_url), request_id)) { + if (handler->OnRequestGeolocationPermission(_browserControl, StringUtils::ToClr(requesting_url), request_id)) + { callback->Continue(true); return true; } From fb3415b5bd29b5198dba8db70d69c11a2fb3b034 Mon Sep 17 00:00:00 2001 From: amaitland Date: Tue, 27 Jan 2015 12:43:47 +1000 Subject: [PATCH 09/73] Add rough outline of Readme.txt to nuget package (Let's see if the readme is opened when using the CI packages) --- CefSharp3.sln | 5 ++--- NuGet/CefSharp.OffScreen.nuspec | 2 ++ NuGet/CefSharp.WinForms.nuspec | 2 ++ NuGet/CefSharp.Wpf.nuspec | 2 ++ NuGet/Readme.txt | 23 +++++++++++++++++++++++ 5 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 NuGet/Readme.txt diff --git a/CefSharp3.sln b/CefSharp3.sln index 444c1b545..b4e61d752 100644 --- a/CefSharp3.sln +++ b/CefSharp3.sln @@ -1,8 +1,6 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.30723.0 -MinimumVisualStudioVersion = 10.0.40219.1 +# Visual Studio 2012 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CefSharp.Test", "CefSharp.Test\CefSharp.Test.csproj", "{7A4D5447-183B-4A11-8E63-9848991B46FF}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CefSharp.Example", "CefSharp.Example\CefSharp.Example.csproj", "{A4394E7B-1155-43A6-989E-8AB72DDDC9E4}" @@ -51,6 +49,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "NuGet", "NuGet", "{A23AA466 NuGet\CefSharp.Wpf.nuspec = NuGet\CefSharp.Wpf.nuspec NuGet\CefSharp.Wpf.props = NuGet\CefSharp.Wpf.props NuGet\pack.bat = NuGet\pack.bat + NuGet\Readme.txt = NuGet\Readme.txt EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CefSharp.Core", "CefSharp.Core\CefSharp.Core.vcxproj", "{7B495581-2271-4F41-9476-ACB86E8C864F}" diff --git a/NuGet/CefSharp.OffScreen.nuspec b/NuGet/CefSharp.OffScreen.nuspec index c695bf578..38442811c 100644 --- a/NuGet/CefSharp.OffScreen.nuspec +++ b/NuGet/CefSharp.OffScreen.nuspec @@ -27,5 +27,7 @@ + + diff --git a/NuGet/CefSharp.WinForms.nuspec b/NuGet/CefSharp.WinForms.nuspec index 10269038f..4441e10a6 100644 --- a/NuGet/CefSharp.WinForms.nuspec +++ b/NuGet/CefSharp.WinForms.nuspec @@ -27,5 +27,7 @@ + + diff --git a/NuGet/CefSharp.Wpf.nuspec b/NuGet/CefSharp.Wpf.nuspec index ec8b16000..4ceacb4f1 100644 --- a/NuGet/CefSharp.Wpf.nuspec +++ b/NuGet/CefSharp.Wpf.nuspec @@ -27,5 +27,7 @@ + + diff --git a/NuGet/Readme.txt b/NuGet/Readme.txt new file mode 100644 index 000000000..90ce4ee03 --- /dev/null +++ b/NuGet/Readme.txt @@ -0,0 +1,23 @@ +CefSharp Nuget Package + +- Make sure you set either `x86` or x64`. (Won't work with `AnyCpu`) +- After installing the `Nuget` package we recommend closing Visual Studio completely and then reopening (This ensures your references show up and you have full intellisense). +- Check your output `\bin` directory to make sure the appropriate references have been copied. + +Basic Troubleshooting +- Info about missing dependencies +- + +For further help please read the following +- Minimal Example Links +- FAQ +- Troubleshooting guide +- Google Groups +- Regular Example Links +- Only when you've exhausted all other options then open an issue on `GitHub` + + +Please consider giving back, it's only with your help will this project to continue. + +Regards, +CefSharp Team \ No newline at end of file From cc17ad1ecc80dcc4099507ac3e261255dda95fb5 Mon Sep 17 00:00:00 2001 From: Alex Maitland Date: Tue, 27 Jan 2015 14:16:30 +1000 Subject: [PATCH 10/73] Update CONTRIBUTING.md Add missing section about using `WinForms`, `WPF` or `OffScreen` --- CONTRIBUTING.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 95dcba95d..0eefda7fa 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -18,7 +18,7 @@ Thanks for your interest in contributing to the project! Please follow these sim `CefSharp` simply takes the building blocks provided by `Cef` and attempts to provide a usable '.Net' implementation. The upstream [`CEF` forum](http://magpcss.org/ceforum/) is a valuable resource, if your issues seems fairly low level, then please conduct some research before posting. -It maybe helpful to run the `cefclient` application and compare output with `CefSharp`. The `WinForms` and `WPF` versions use two different rendering modes, `WPF` uses Offscreen Rendering (`OSR`). +It maybe helpful to run the `cefclient` application and compare output with `CefSharp`. The `WinForms` and `WPF` versions use two different rendering modes, `WPF` uses Offscreen Rendering (`OSR`). `OffScreen` also uses `OSR` mode. - Download **Test App** from http://cefbuilds.com - To compare with WPF run `cefclient --multi-threaded-message-loop --off-screen-rendering-enabled` @@ -44,6 +44,7 @@ Your bug report should **always follow this template**: - **What is the expected output? What do you see instead?** - **What steps will reproduce the problem?** +- **Are you using `WinForms`, `WPF` or `OffScreen`?** - **What version of the product are you using? On what operating system? x86 or x64?** - What version are you using? Nuget? CI Nuget? build from a branch? If so which branch? - Win7, Win 8, etc? @@ -84,4 +85,4 @@ Pull requests are **awesome**. If you're looking to raise a PR for something whi - Max number of columns are 132, please format your code accordingly - Please don't add #Regions to the code - When adding new files, please prepend the standard license disclaimer (just copy and paste from another source file) -- Do your best to follow these guidelines but don't be afraid to make mistakes when trying to apply them. We are all novices in the beginning. \ No newline at end of file +- Do your best to follow these guidelines but don't be afraid to make mistakes when trying to apply them. We are all novices in the beginning. From 43765ad1c331a0e40a687a9ff86040712e29961c Mon Sep 17 00:00:00 2001 From: amaitland Date: Tue, 27 Jan 2015 20:03:25 +1000 Subject: [PATCH 11/73] Upgrade to 3.2171.1979 --- .../CefSharp.BrowserSubprocess.Core.vcxproj | 6 +++--- CefSharp.BrowserSubprocess.Core/packages.config | 2 +- CefSharp.Core/CefSharp.Core.vcxproj | 6 +++--- CefSharp.Core/packages.config | 2 +- .../CefSharp.OffScreen.Example.csproj | 10 +++++----- CefSharp.OffScreen.Example/packages.config | 4 ++-- CefSharp.Test/CefSharp.Test.csproj | 10 +++++----- CefSharp.Test/packages.config | 4 ++-- .../CefSharp.WinForms.Example.csproj | 10 +++++----- CefSharp.WinForms.Example/packages.config | 4 ++-- CefSharp.Wpf.Example/CefSharp.Wpf.Example.csproj | 10 +++++----- CefSharp.Wpf.Example/packages.config | 4 ++-- 12 files changed, 36 insertions(+), 36 deletions(-) diff --git a/CefSharp.BrowserSubprocess.Core/CefSharp.BrowserSubprocess.Core.vcxproj b/CefSharp.BrowserSubprocess.Core/CefSharp.BrowserSubprocess.Core.vcxproj index d8142b3f9..e5c528b23 100644 --- a/CefSharp.BrowserSubprocess.Core/CefSharp.BrowserSubprocess.Core.vcxproj +++ b/CefSharp.BrowserSubprocess.Core/CefSharp.BrowserSubprocess.Core.vcxproj @@ -1,6 +1,6 @@  - + Debug @@ -66,7 +66,7 @@ - 03744085 + 4664bbc5 true @@ -198,6 +198,6 @@ This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - + \ No newline at end of file diff --git a/CefSharp.BrowserSubprocess.Core/packages.config b/CefSharp.BrowserSubprocess.Core/packages.config index faf0feb53..337c7a6c1 100644 --- a/CefSharp.BrowserSubprocess.Core/packages.config +++ b/CefSharp.BrowserSubprocess.Core/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file diff --git a/CefSharp.Core/CefSharp.Core.vcxproj b/CefSharp.Core/CefSharp.Core.vcxproj index eb86525a6..7ce9d5629 100644 --- a/CefSharp.Core/CefSharp.Core.vcxproj +++ b/CefSharp.Core/CefSharp.Core.vcxproj @@ -1,6 +1,6 @@  - + Debug @@ -66,7 +66,7 @@ <_ProjectFileVersion>11.0.51106.1 - 6edfce21 + 84bd8e6a bin\$(Configuration)\ @@ -283,6 +283,6 @@ This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - + \ No newline at end of file diff --git a/CefSharp.Core/packages.config b/CefSharp.Core/packages.config index faf0feb53..337c7a6c1 100644 --- a/CefSharp.Core/packages.config +++ b/CefSharp.Core/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file diff --git a/CefSharp.OffScreen.Example/CefSharp.OffScreen.Example.csproj b/CefSharp.OffScreen.Example/CefSharp.OffScreen.Example.csproj index da7299ff2..17738e3da 100644 --- a/CefSharp.OffScreen.Example/CefSharp.OffScreen.Example.csproj +++ b/CefSharp.OffScreen.Example/CefSharp.OffScreen.Example.csproj @@ -13,7 +13,7 @@ 512 - 320b0b24 + 793b99d4 true @@ -94,9 +94,9 @@ This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - + + - - + + \ No newline at end of file diff --git a/CefSharp.OffScreen.Example/packages.config b/CefSharp.OffScreen.Example/packages.config index 86e5afd80..468defc7a 100644 --- a/CefSharp.OffScreen.Example/packages.config +++ b/CefSharp.OffScreen.Example/packages.config @@ -1,5 +1,5 @@  - - + + \ No newline at end of file diff --git a/CefSharp.Test/CefSharp.Test.csproj b/CefSharp.Test/CefSharp.Test.csproj index deffb5acb..7475b999d 100644 --- a/CefSharp.Test/CefSharp.Test.csproj +++ b/CefSharp.Test/CefSharp.Test.csproj @@ -19,7 +19,7 @@ 3.5 Client - 85aa022d + 578e8d6c true @@ -142,9 +142,9 @@ This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - + + - - + + \ No newline at end of file diff --git a/CefSharp.Test/packages.config b/CefSharp.Test/packages.config index 664576fbb..e4bd01f61 100644 --- a/CefSharp.Test/packages.config +++ b/CefSharp.Test/packages.config @@ -2,8 +2,8 @@ - - + + \ No newline at end of file diff --git a/CefSharp.WinForms.Example/CefSharp.WinForms.Example.csproj b/CefSharp.WinForms.Example/CefSharp.WinForms.Example.csproj index 25d83d5a3..7fced89dd 100644 --- a/CefSharp.WinForms.Example/CefSharp.WinForms.Example.csproj +++ b/CefSharp.WinForms.Example/CefSharp.WinForms.Example.csproj @@ -21,7 +21,7 @@ 3.5 Client - e79ac826 + 386a1560 x64 @@ -159,9 +159,9 @@ This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - + + - - + + \ No newline at end of file diff --git a/CefSharp.WinForms.Example/packages.config b/CefSharp.WinForms.Example/packages.config index 86e5afd80..468defc7a 100644 --- a/CefSharp.WinForms.Example/packages.config +++ b/CefSharp.WinForms.Example/packages.config @@ -1,5 +1,5 @@  - - + + \ No newline at end of file diff --git a/CefSharp.Wpf.Example/CefSharp.Wpf.Example.csproj b/CefSharp.Wpf.Example/CefSharp.Wpf.Example.csproj index 342c3db2e..18fb334db 100644 --- a/CefSharp.Wpf.Example/CefSharp.Wpf.Example.csproj +++ b/CefSharp.Wpf.Example/CefSharp.Wpf.Example.csproj @@ -21,7 +21,7 @@ 3.5 Client - eef213f7 + 1dae910e true @@ -172,9 +172,9 @@ This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - + + - - + + \ No newline at end of file diff --git a/CefSharp.Wpf.Example/packages.config b/CefSharp.Wpf.Example/packages.config index 86e5afd80..468defc7a 100644 --- a/CefSharp.Wpf.Example/packages.config +++ b/CefSharp.Wpf.Example/packages.config @@ -1,5 +1,5 @@  - - + + \ No newline at end of file From ef2463d60893856d7c2409bbb0528e4384378bc9 Mon Sep 17 00:00:00 2001 From: pushplay Date: Wed, 28 Jan 2015 14:38:19 -0800 Subject: [PATCH 12/73] Fixes suggested by @jankurianski --- CefSharp.Example/CefExample.cs | 5 +++++ CefSharp.WinForms.Example/GeolocationHandler.cs | 2 +- CefSharp.Wpf.Example/Handlers/GeolocationHandler.cs | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CefSharp.Example/CefExample.cs b/CefSharp.Example/CefExample.cs index 26dd99280..f8ef96e27 100644 --- a/CefSharp.Example/CefExample.cs +++ b/CefSharp.Example/CefExample.cs @@ -15,6 +15,11 @@ namespace CefSharp.Example public static void Init() { + // Set Google API keys, used for Geolocation requests sans GPS. See http://www.chromium.org/developers/how-tos/api-keys + // Environment.SetEnvironmentVariable("GOOGLE_API_KEY", ""); + // Environment.SetEnvironmentVariable("GOOGLE_DEFAULT_CLIENT_ID", ""); + // Environment.SetEnvironmentVariable("GOOGLE_DEFAULT_CLIENT_SECRET", ""); + var settings = new CefSettings(); settings.RemoteDebuggingPort = 8088; //settings.CefCommandLineArgs.Add("renderer-process-limit", "1"); diff --git a/CefSharp.WinForms.Example/GeolocationHandler.cs b/CefSharp.WinForms.Example/GeolocationHandler.cs index 63ddc1d3f..4fd1382a4 100644 --- a/CefSharp.WinForms.Example/GeolocationHandler.cs +++ b/CefSharp.WinForms.Example/GeolocationHandler.cs @@ -11,7 +11,7 @@ namespace CefSharp.WinForms.Example { public bool OnRequestGeolocationPermission(IWebBrowser browser, string requestingUrl, int requestId) { - var result = MessageBox.Show(String.Format("{0} wants to use your computer's location. Allow?", requestingUrl), "Geolocation", MessageBoxButtons.YesNo); + var result = MessageBox.Show(String.Format("{0} wants to use your computer's location. Allow? ** You must set your Google API key in CefExample.Init() for this to work. **", requestingUrl), "Geolocation", MessageBoxButtons.YesNo); return result == DialogResult.Yes; } diff --git a/CefSharp.Wpf.Example/Handlers/GeolocationHandler.cs b/CefSharp.Wpf.Example/Handlers/GeolocationHandler.cs index 5c184a01b..690f3547f 100644 --- a/CefSharp.Wpf.Example/Handlers/GeolocationHandler.cs +++ b/CefSharp.Wpf.Example/Handlers/GeolocationHandler.cs @@ -11,7 +11,7 @@ namespace CefSharp.Wpf.Example.Handlers { public bool OnRequestGeolocationPermission(IWebBrowser browser, string requestingUrl, int requestId) { - var result = MessageBox.Show(String.Format("{0} wants to use your computer's location. Allow?", requestingUrl), "Geolocation", MessageBoxButton.YesNo); + var result = MessageBox.Show(String.Format("{0} wants to use your computer's location. Allow? ** You must set your Google API key in CefExample.Init() for this to work. **", requestingUrl), "Geolocation", MessageBoxButton.YesNo); return result == MessageBoxResult.Yes; } From b015ed7c2e70ed857eaaf3e8b54c43fa71771fb0 Mon Sep 17 00:00:00 2001 From: amaitland Date: Tue, 27 Jan 2015 15:28:35 +1000 Subject: [PATCH 13/73] Added ClearSchemeHandlerFactories method incase anyone wants to remove their factories --- CefSharp.Core/Cef.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CefSharp.Core/Cef.h b/CefSharp.Core/Cef.h index c8f2c6bda..c57f128ef 100644 --- a/CefSharp.Core/Cef.h +++ b/CefSharp.Core/Cef.h @@ -348,5 +348,14 @@ namespace CefSharp IsInitialized = false; } } + + /// + /// Clear all registered scheme handler factories. + /// + /// Returns false on error. + static bool ClearSchemeHandlerFactories() + { + return CefClearSchemeHandlerFactories(); + } }; } From 823889099d13f01961e718d39a43935701695725 Mon Sep 17 00:00:00 2001 From: amaitland Date: Tue, 27 Jan 2015 15:29:37 +1000 Subject: [PATCH 14/73] Allow setting IsLocal and IsDisplayIsolated for a CustomScheme Added relevant xml comments --- CefSharp.Core/Internals/CefSharpApp.h | 2 +- CefSharp/CefCustomScheme.cs | 58 +++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/CefSharp.Core/Internals/CefSharpApp.h b/CefSharp.Core/Internals/CefSharpApp.h index bd675a223..56ac2385a 100644 --- a/CefSharp.Core/Internals/CefSharpApp.h +++ b/CefSharp.Core/Internals/CefSharpApp.h @@ -56,7 +56,7 @@ namespace CefSharp // when the process is shutting down. // TOOD: Consider adding error handling here. But where do we report any errors that may have occurred? - registrar->AddCustomScheme(StringUtils::ToNative(cefCustomScheme->SchemeName), cefCustomScheme->IsStandard, false, false); + registrar->AddCustomScheme(StringUtils::ToNative(cefCustomScheme->SchemeName), cefCustomScheme->IsStandard, cefCustomScheme->IsLocal, cefCustomScheme->IsDisplayIsolated); } }; diff --git a/CefSharp/CefCustomScheme.cs b/CefSharp/CefCustomScheme.cs index 18c5bf0e9..54034cae5 100644 --- a/CefSharp/CefCustomScheme.cs +++ b/CefSharp/CefCustomScheme.cs @@ -6,14 +6,72 @@ namespace CefSharp { public class CefCustomScheme { + /// + /// Schema Name e.g. custom + /// public string SchemeName { get; set; } + + /// + /// Optional Domain Name. An empty value for a standard scheme + /// will cause the factory to match all domain names. The |domain_name| value + /// will be ignored for non-standard schemes. + /// public string DomainName { get; set; } + + /// + /// If true the scheme will be treated as a standard scheme. + /// Standard schemes are subject to URL canonicalization and parsing rules as + /// defined in the Common Internet Scheme Syntax RFC 1738 Section 3.1 available + /// at http://www.ietf.org/rfc/rfc1738.txt + /// + /// In particular, the syntax for standard scheme URLs must be of the form: + ///
+        ///  [scheme]://[username]:[password]@[host]:[port]/[url-path]
+        /// 
+ /// Standard scheme URLs must have a host component that is a fully qualified + /// domain name as defined in Section 3.5 of RFC 1034 [13] and Section 2.1 of + /// RFC 1123. These URLs will be canonicalized to "scheme://host/path" in the + /// simplest case and "scheme://username:password@host:port/path" in the most + /// explicit case. For example, "scheme:host/path" and "scheme:///host/path" + /// will both be canonicalized to "scheme://host/path". The origin of a + /// standard scheme URL is the combination of scheme, host and port (i.e., + /// "scheme://host:port" in the most explicit case). + /// + /// For non-standard scheme URLs only the "scheme:" component is parsed and + /// canonicalized. The remainder of the URL will be passed to the handler + /// as-is. For example, "scheme:///some%20text" will remain the same. + /// Non-standard scheme URLs cannot be used as a target for form submission. + ///
public bool IsStandard { get; set; } + + /// + /// If true the scheme will be treated as local (i.e. with the + /// same security rules as those applied to "file" URLs). Normal pages cannot + /// link to or access local URLs. Also, by default, local URLs can only perform + /// XMLHttpRequest calls to the same URL (origin + path) that originated the + /// request. To allow XMLHttpRequest calls from a local URL to other URLs with + /// the same origin set the CefSettings.file_access_from_file_urls_allowed + /// value to true. To allow XMLHttpRequest calls from a local URL to all + /// origins set the CefSettings.universal_access_from_file_urls_allowed value + /// to true. + /// + public bool IsLocal { get; set; } + + /// + /// If true the scheme will be treated as display-isolated. + /// This means that pages cannot display these URLs unless they are + /// from the same scheme. For example, pages in another origin cannot create + /// iframes or hyperlinks to URLs with this scheme. + /// + public bool IsDisplayIsolated { get; set; } + public ISchemeHandlerFactory SchemeHandlerFactory { get; set; } public CefCustomScheme() { IsStandard = true; + IsLocal = false; + IsDisplayIsolated = false; } } } From 0c45119f172c5c5d3772986ff8371f5d6b4c98a2 Mon Sep 17 00:00:00 2001 From: amaitland Date: Wed, 28 Jan 2015 17:38:35 +1000 Subject: [PATCH 15/73] Remove SetBufferHelper method and move code inline so some minor tweaks can be performed like only setting variables when required (Small things I know though important in such a performance critical section) --- CefSharp.Core/Internals/RenderClientAdapter.h | 81 +++++++++---------- CefSharp/Internals/BitmapInfo.cs | 1 + 2 files changed, 37 insertions(+), 45 deletions(-) diff --git a/CefSharp.Core/Internals/RenderClientAdapter.h b/CefSharp.Core/Internals/RenderClientAdapter.h index 79ed98c4e..2e6982d9f 100644 --- a/CefSharp.Core/Internals/RenderClientAdapter.h +++ b/CefSharp.Core/Internals/RenderClientAdapter.h @@ -92,14 +92,45 @@ namespace CefSharp lock l(bitmapInfo->BitmapLock); - auto fileMappingHandle = (HANDLE)bitmapInfo->FileMappingHandle; auto backBufferHandle = (HANDLE)bitmapInfo->BackBufferHandle; - SetBufferHelper(bitmapInfo, width, height, &fileMappingHandle, - &backBufferHandle, buffer); + if (backBufferHandle == NULL || bitmapInfo->Width != width || bitmapInfo->Height != height) + { + int pixels = width * height; + int numberOfBytes = pixels * bitmapInfo->BytesPerPixel; + auto fileMappingHandle = (HANDLE)bitmapInfo->FileMappingHandle; - bitmapInfo->FileMappingHandle = (IntPtr)fileMappingHandle; - bitmapInfo->BackBufferHandle = (IntPtr)backBufferHandle; + //Clear the reference to Bitmap so a new one is created by InvokeRenderAsync + bitmapInfo->ClearBitmap(); + + //Release the current handles (if not null) + ReleaseBitmapHandlers(&backBufferHandle, &fileMappingHandle); + + // Create new fileMappingHandle + fileMappingHandle = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, numberOfBytes, NULL); + if (fileMappingHandle == NULL) + { + // TODO: Consider doing something more sensible here, since the browser will be very badly broken if this + // TODO: method call fails. + return; + } + + backBufferHandle = MapViewOfFile(fileMappingHandle, FILE_MAP_ALL_ACCESS, 0, 0, numberOfBytes); + if (backBufferHandle == NULL) + { + // TODO: Consider doing something more sensible here, since the browser will be very badly broken if this + // TODO: method call fails. + return; + } + + bitmapInfo->FileMappingHandle = (IntPtr)fileMappingHandle; + bitmapInfo->BackBufferHandle = (IntPtr)backBufferHandle; + bitmapInfo->Width = width; + bitmapInfo->Height = height; + bitmapInfo->NumberOfBytes = numberOfBytes; + } + + CopyMemory(backBufferHandle, (void*)buffer, bitmapInfo->NumberOfBytes); _renderWebBrowser->InvokeRenderAsync(bitmapInfo); }; @@ -111,46 +142,6 @@ namespace CefSharp }; private: - void SetBufferHelper(BitmapInfo^ bitmapInfo, int newWidth, int newHeight, - HANDLE* fileMappingHandle, HANDLE* backBufferHandle, const void* buffer) - { - int pixels = newWidth * newHeight; - int numberOfBytes = pixels * bitmapInfo->BytesPerPixel; - - if (*backBufferHandle == NULL || - bitmapInfo->Width != newWidth || - bitmapInfo->Height != newHeight) - { - //Clear the reference to Bitmap so a new one is created by InvokeRenderAsync - bitmapInfo->ClearBitmap(); - - //Release the current handles (if not null) - ReleaseBitmapHandlers(backBufferHandle, fileMappingHandle); - - // Create new fileMappingHandle - *fileMappingHandle = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, numberOfBytes, NULL); - if (*fileMappingHandle == NULL) - { - // TODO: Consider doing something more sensible here, since the browser will be very badly broken if this - // TODO: method call fails. - return; - } - - *backBufferHandle = MapViewOfFile(*fileMappingHandle, FILE_MAP_ALL_ACCESS, 0, 0, numberOfBytes); - if (*backBufferHandle == NULL) - { - // TODO: Consider doing something more sensible here, since the browser will be very badly broken if this - // TODO: method call fails. - return; - } - } - - bitmapInfo->Width = newWidth; - bitmapInfo->Height = newHeight; - - CopyMemory(*backBufferHandle, (void*)buffer, numberOfBytes); - }; - void ReleaseBitmapHandlers(HANDLE* backBufferHandle, HANDLE* fileMappingHandle) { if (*backBufferHandle != NULL) diff --git a/CefSharp/Internals/BitmapInfo.cs b/CefSharp/Internals/BitmapInfo.cs index 7cb019466..a7256c610 100644 --- a/CefSharp/Internals/BitmapInfo.cs +++ b/CefSharp/Internals/BitmapInfo.cs @@ -18,6 +18,7 @@ namespace CefSharp.Internals public IntPtr FileMappingHandle { get; set; } public int BytesPerPixel { get; set; } + public int NumberOfBytes { get; set; } public abstract void ClearBitmap(); From 7e3d5ece25a02ef8fed0defecbee5ce71cc9bce8 Mon Sep 17 00:00:00 2001 From: amaitland Date: Thu, 29 Jan 2015 11:55:31 +1000 Subject: [PATCH 16/73] Remove unused ManagedCefBrowserAdapter deceleration --- CefSharp.Core/Internals/ClientAdapter.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/CefSharp.Core/Internals/ClientAdapter.h b/CefSharp.Core/Internals/ClientAdapter.h index abcebd05e..25d022180 100644 --- a/CefSharp.Core/Internals/ClientAdapter.h +++ b/CefSharp.Core/Internals/ClientAdapter.h @@ -15,8 +15,6 @@ using namespace System; namespace CefSharp { - ref class ManagedCefBrowserAdapter; - namespace Internals { private class ClientAdapter : public CefClient, From 9a52f082de83fdb279ae825e65aff06122f412d7 Mon Sep 17 00:00:00 2001 From: amaitland Date: Thu, 29 Jan 2015 12:04:15 +1000 Subject: [PATCH 17/73] Code cleanup - Merge ReleaseBitmapHandlers and DisposeBitmapInfo into one method --- CefSharp.Core/Internals/RenderClientAdapter.h | 37 +++++++++---------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/CefSharp.Core/Internals/RenderClientAdapter.h b/CefSharp.Core/Internals/RenderClientAdapter.h index ffd6ccc62..f6eac8794 100644 --- a/CefSharp.Core/Internals/RenderClientAdapter.h +++ b/CefSharp.Core/Internals/RenderClientAdapter.h @@ -39,12 +39,12 @@ namespace CefSharp _renderWebBrowser = nullptr; _webBrowserInternal = nullptr; - DisposeBitmapInfo(_mainBitmapInfo); + ReleaseBitmapHandlers(_mainBitmapInfo); delete _mainBitmapInfo; _mainBitmapInfo = nullptr; - DisposeBitmapInfo(_popupBitmapInfo); + ReleaseBitmapHandlers(_popupBitmapInfo); delete _popupBitmapInfo; _popupBitmapInfo = nullptr; @@ -116,7 +116,7 @@ namespace CefSharp bitmapInfo->ClearBitmap(); //Release the current handles (if not null) - ReleaseBitmapHandlers(&backBufferHandle, &fileMappingHandle); + ReleaseBitmapHandlers(bitmapInfo); // Create new fileMappingHandle fileMappingHandle = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, numberOfBytes, NULL); @@ -154,27 +154,24 @@ namespace CefSharp }; private: - void ReleaseBitmapHandlers(HANDLE* backBufferHandle, HANDLE* fileMappingHandle) - { - if (*backBufferHandle != NULL) - { - UnmapViewOfFile(*backBufferHandle); - *backBufferHandle = NULL; - } - - if (*fileMappingHandle != NULL) - { - CloseHandle(*fileMappingHandle); - *fileMappingHandle = NULL; - } - } - - void DisposeBitmapInfo(BitmapInfo^ bitmapInfo) + void ReleaseBitmapHandlers(BitmapInfo^ bitmapInfo) { auto backBufferHandle = (HANDLE)bitmapInfo->BackBufferHandle; auto fileMappingHandle = (HANDLE)bitmapInfo->FileMappingHandle; - ReleaseBitmapHandlers(&backBufferHandle, &fileMappingHandle); + if (backBufferHandle != NULL) + { + UnmapViewOfFile(backBufferHandle); + backBufferHandle = NULL; + bitmapInfo->BackBufferHandle = IntPtr::Zero; + } + + if (fileMappingHandle != NULL) + { + CloseHandle(fileMappingHandle); + fileMappingHandle = NULL; + bitmapInfo->FileMappingHandle = IntPtr::Zero; + } } IMPLEMENT_REFCOUNTING(RenderClientAdapter) From bfec2c95b11a053b5ea79de63b6ba141e65ebf8f Mon Sep 17 00:00:00 2001 From: amaitland Date: Thu, 29 Jan 2015 15:25:08 +1000 Subject: [PATCH 18/73] Add IBitmapFactory so that different Rendering methods can be plugged in (potentially a .Net 4.5 InteropBitmapInfo can be created) Move into Rendering namespace --- CefSharp.Core/Internals/RenderClientAdapter.h | 11 ++++----- CefSharp.Wpf/CefSharp.Wpf.csproj | 8 ++++--- CefSharp.Wpf/ChromiumWebBrowser.cs | 9 ++++++-- CefSharp.Wpf/Rendering/BitmapFactory.cs | 17 ++++++++++++++ .../{ => Rendering}/InteropBitmapInfo.cs | 2 +- CefSharp.Wpf/{ => Rendering}/WpfBitmapInfo.cs | 2 +- .../{ => Rendering}/WritableBitmapInfo.cs | 23 ++++++------------- CefSharp.Wpf/RenderingEventArgs.cs | 2 +- CefSharp/CefSharp.csproj | 1 + CefSharp/IBitmapFactory.cs | 13 +++++++++++ CefSharp/Internals/BitmapInfo.cs | 2 +- 11 files changed, 58 insertions(+), 32 deletions(-) create mode 100644 CefSharp.Wpf/Rendering/BitmapFactory.cs rename CefSharp.Wpf/{ => Rendering}/InteropBitmapInfo.cs (96%) rename CefSharp.Wpf/{ => Rendering}/WpfBitmapInfo.cs (92%) rename CefSharp.Wpf/{ => Rendering}/WritableBitmapInfo.cs (61%) create mode 100644 CefSharp/IBitmapFactory.cs diff --git a/CefSharp.Core/Internals/RenderClientAdapter.h b/CefSharp.Core/Internals/RenderClientAdapter.h index f6eac8794..a031b8b97 100644 --- a/CefSharp.Core/Internals/RenderClientAdapter.h +++ b/CefSharp.Core/Internals/RenderClientAdapter.h @@ -94,14 +94,11 @@ namespace CefSharp if(bitmapInfo->DirtyRectSupport) { - auto rects = gcnew List(dirtyRects.size()); + //NOTE: According to https://bitbucket.org/chromiumembedded/branches-2171-cef3/commits/ce984ddff3268a50cf9967487327e1257015b98c + // There is only one rect now that's a union of all dirty regions. API Still passes in a vector - for each(CefRect r in dirtyRects) - { - rects->Add(CefDirtyRect(r.x, r.y, r.width, r.height)); - } - - bitmapInfo->DirtyRects = rects; + CefRect r = dirtyRects.front(); + bitmapInfo->DirtyRect = CefDirtyRect(r.x, r.y, r.width, r.height); } auto backBufferHandle = (HANDLE)bitmapInfo->BackBufferHandle; diff --git a/CefSharp.Wpf/CefSharp.Wpf.csproj b/CefSharp.Wpf/CefSharp.Wpf.csproj index 79cab498c..ebc386349 100644 --- a/CefSharp.Wpf/CefSharp.Wpf.csproj +++ b/CefSharp.Wpf/CefSharp.Wpf.csproj @@ -93,7 +93,7 @@ - + Code @@ -101,9 +101,10 @@ + - - + + @@ -115,6 +116,7 @@ CefSharp + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/CefSharp.WinForms.Example/Program.cs b/CefSharp.WinForms.Example/Program.cs index 57002ad9e..1e6ea6b47 100644 --- a/CefSharp.WinForms.Example/Program.cs +++ b/CefSharp.WinForms.Example/Program.cs @@ -18,6 +18,7 @@ namespace CefSharp.WinForms.Example var browser = new BrowserForm(); //var browser = new SimpleBrowserForm(); + //var browser = new TabulationDemoForm(); Application.Run(browser); } } diff --git a/CefSharp.WinForms/CefSharp.WinForms.csproj b/CefSharp.WinForms/CefSharp.WinForms.csproj index 708d642ed..ae2bfee76 100644 --- a/CefSharp.WinForms/CefSharp.WinForms.csproj +++ b/CefSharp.WinForms/CefSharp.WinForms.csproj @@ -52,6 +52,7 @@ + Component diff --git a/CefSharp.WinForms/ChromiumWebBrowser.cs b/CefSharp.WinForms/ChromiumWebBrowser.cs index 9b0d007e8..378d5a0b1 100644 --- a/CefSharp.WinForms/ChromiumWebBrowser.cs +++ b/CefSharp.WinForms/ChromiumWebBrowser.cs @@ -389,14 +389,6 @@ namespace CefSharp.WinForms } } - /// - /// Set whether the browser is focused. - /// - public void SetFocus(bool isFocused) - { - managedCefBrowserAdapter.SetFocus(isFocused); - } - protected override void OnSizeChanged(EventArgs e) { base.OnSizeChanged(e); @@ -429,5 +421,27 @@ namespace CefSharp.WinForms { managedCefBrowserAdapter.AddWordToDictionary(word); } + + protected override void OnEnter(EventArgs e) + { + SetFocus(true); + + base.OnEnter(e); + } + + protected override void OnLeave(EventArgs e) + { + SetFocus(false); + + base.OnLeave(e); + } + + /// + /// Set whether the browser is focused. + /// + public void SetFocus(bool isFocused) + { + managedCefBrowserAdapter.SetFocus(isFocused); + } } } diff --git a/CefSharp.WinForms/Internals/ControlExtensions.cs b/CefSharp.WinForms/Internals/ControlExtensions.cs new file mode 100644 index 000000000..3649d27dc --- /dev/null +++ b/CefSharp.WinForms/Internals/ControlExtensions.cs @@ -0,0 +1,66 @@ +// Copyright © 2010-2014 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. + +using System; +using System.Windows.Forms; + +namespace CefSharp.WinForms.Internals +{ + public static class ControlExtensions + { + /// + /// Executes the Action asynchronously on the UI thread, does not block execution on the calling thread. + /// + /// the control for which the update is required + /// action to be performed on the control + public static void InvokeOnUiThreadIfRequired(this Control control, Action action) + { + if (control.InvokeRequired) + { + control.BeginInvoke(action); + } + else + { + action.Invoke(); + } + } + + public static void Activate(this Control control) + { + //Notify WinForms world that inner browser window got focus. This will trigger Leave event to previous focused control + var containerControl = control.GetContainerControl(); + if (containerControl != null) + { + containerControl.ActivateControl(control); + } + } + + public static void SelectNextControl(this Control control, bool next) + { + var containerControl = control.GetContainerControl(); + + while (containerControl != null) + { + var containerControlAsControl = containerControl as Control; + if (containerControlAsControl == null) + { + break; + } + + var activeControl = containerControl.ActiveControl; + if (containerControlAsControl.SelectNextControl(activeControl, next, true, true, false)) + { + break; + } + + if (containerControlAsControl.Parent == null) + { + break; + } + + containerControl = containerControlAsControl.Parent.GetContainerControl(); + } + } + } +} diff --git a/CefSharp.WinForms/Internals/DefaultFocusHandler.cs b/CefSharp.WinForms/Internals/DefaultFocusHandler.cs index c8f76d71c..28cc8be7c 100644 --- a/CefSharp.WinForms/Internals/DefaultFocusHandler.cs +++ b/CefSharp.WinForms/Internals/DefaultFocusHandler.cs @@ -2,31 +2,32 @@ // // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. -using System.Windows.Forms; - namespace CefSharp.WinForms.Internals { - internal class DefaultFocusHandler : IFocusHandler - { - private readonly ChromiumWebBrowser browser; + internal class DefaultFocusHandler : IFocusHandler + { + private readonly ChromiumWebBrowser browser; - public DefaultFocusHandler(ChromiumWebBrowser browser) - { - this.browser = browser; - } + public DefaultFocusHandler(ChromiumWebBrowser browser) + { + this.browser = browser; + } - public void OnGotFocus() - { - } + public virtual void OnGotFocus() + { + browser.InvokeOnUiThreadIfRequired(browser.Activate); + } - public bool OnSetFocus(CefFocusSource source) - { - return false; - } + public virtual bool OnSetFocus(CefFocusSource source) + { + //Do not let the browser take focus when a Load method has been called + return source == CefFocusSource.FocusSourceNavigation; + } - public void OnTakeFocus(bool next) - { - browser.BeginInvoke(new MethodInvoker(() => browser.SelectNextControl(browser, next, true, true, true))); - } - } + public virtual void OnTakeFocus(bool next) + { + //NOTE: OnTakeFocus means leaving focus / not taking focus + browser.InvokeOnUiThreadIfRequired(() => browser.SelectNextControl(next)); + } + } } From 0efce4e8364a092ff72320eaf5fe5ad2b2ad5415 Mon Sep 17 00:00:00 2001 From: amaitland Date: Fri, 30 Jan 2015 15:02:01 +1000 Subject: [PATCH 21/73] Add DownloadHandler to both WinForms and Wpf examples --- CefSharp.WinForms.Example/BrowserTabUserControl.cs | 4 ++-- CefSharp.Wpf.Example/Views/BrowserTabView.xaml.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CefSharp.WinForms.Example/BrowserTabUserControl.cs b/CefSharp.WinForms.Example/BrowserTabUserControl.cs index 72f841cb6..bea3bf5da 100644 --- a/CefSharp.WinForms.Example/BrowserTabUserControl.cs +++ b/CefSharp.WinForms.Example/BrowserTabUserControl.cs @@ -1,5 +1,4 @@ -using System.Threading.Tasks; -using CefSharp.Example; +using CefSharp.Example; using CefSharp.WinForms.Example.Controls; using System; using System.Windows.Forms; @@ -27,6 +26,7 @@ namespace CefSharp.WinForms.Example browser.RequestHandler = new RequestHandler(); browser.JsDialogHandler = new JsDialogHandler(); browser.GeolocationHandler = new GeolocationHandler(); + browser.DownloadHandler = new DownloadHandler(); //browser.FocusHandler = new FocusHandler(browser, urlTextBox); browser.NavStateChanged += OnBrowserNavStateChanged; browser.ConsoleMessage += OnBrowserConsoleMessage; diff --git a/CefSharp.Wpf.Example/Views/BrowserTabView.xaml.cs b/CefSharp.Wpf.Example/Views/BrowserTabView.xaml.cs index 1c5acc88a..916fcac4f 100644 --- a/CefSharp.Wpf.Example/Views/BrowserTabView.xaml.cs +++ b/CefSharp.Wpf.Example/Views/BrowserTabView.xaml.cs @@ -2,7 +2,6 @@ // // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. -using System; using System.Windows.Controls; using System.Windows.Input; using CefSharp.Example; @@ -20,6 +19,7 @@ namespace CefSharp.Wpf.Example.Views browser.MenuHandler = new Handlers.MenuHandler(); browser.GeolocationHandler = new Handlers.GeolocationHandler(); + browser.DownloadHandler = new DownloadHandler(); CefExample.RegisterTestResources(browser); } From 4405d55221fac5ab002c193b2876318dc59150b7 Mon Sep 17 00:00:00 2001 From: amaitland Date: Mon, 2 Feb 2015 07:42:25 +1000 Subject: [PATCH 22/73] Create BrowserSettings in WinForms constructor and explicitly Dispose as it wraps an unmanaged object. --- CefSharp.WinForms/ChromiumWebBrowser.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CefSharp.WinForms/ChromiumWebBrowser.cs b/CefSharp.WinForms/ChromiumWebBrowser.cs index 9b0d007e8..bae76d602 100644 --- a/CefSharp.WinForms/ChromiumWebBrowser.cs +++ b/CefSharp.WinForms/ChromiumWebBrowser.cs @@ -63,6 +63,7 @@ namespace CefSharp.WinForms FocusHandler = new DefaultFocusHandler(this); ResourceHandler = new DefaultResourceHandler(); + BrowserSettings = new BrowserSettings(); managedCefBrowserAdapter = new ManagedCefBrowserAdapter(this, false); } @@ -71,6 +72,8 @@ namespace CefSharp.WinForms { FocusHandler = null; ResourceHandler = null; + BrowserSettings.Dispose(); + BrowserSettings = null; Cef.RemoveDisposable(this); @@ -160,7 +163,7 @@ namespace CefSharp.WinForms protected override void OnHandleCreated(EventArgs e) { - managedCefBrowserAdapter.CreateBrowser(BrowserSettings ?? new BrowserSettings(), Handle, Address); + managedCefBrowserAdapter.CreateBrowser(BrowserSettings, Handle, Address); base.OnHandleCreated(e); } From c1d44dbcbb1122fa405f265dc0361f7a295c4ea4 Mon Sep 17 00:00:00 2001 From: amaitland Date: Mon, 2 Feb 2015 18:17:40 +1000 Subject: [PATCH 23/73] Add Cef.Initialize check in constructor of WinForms and OffScreen implementations - makes them consistent with the WPF version. --- CefSharp.OffScreen/ChromiumWebBrowser.cs | 5 +++++ CefSharp.WinForms/ChromiumWebBrowser.cs | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/CefSharp.OffScreen/ChromiumWebBrowser.cs b/CefSharp.OffScreen/ChromiumWebBrowser.cs index 5fa4660b0..ea69a0609 100644 --- a/CefSharp.OffScreen/ChromiumWebBrowser.cs +++ b/CefSharp.OffScreen/ChromiumWebBrowser.cs @@ -44,6 +44,11 @@ namespace CefSharp.OffScreen /// The browser settings to use. If null, the default settings are used. public ChromiumWebBrowser(string address, BrowserSettings browserSettings = null) { + if (!Cef.IsInitialized && !Cef.Initialize()) + { + throw new InvalidOperationException("Cef::Initialize() failed"); + } + ResourceHandler = new DefaultResourceHandler(); Cef.AddDisposable(this); diff --git a/CefSharp.WinForms/ChromiumWebBrowser.cs b/CefSharp.WinForms/ChromiumWebBrowser.cs index bae76d602..55f0f0b8c 100644 --- a/CefSharp.WinForms/ChromiumWebBrowser.cs +++ b/CefSharp.WinForms/ChromiumWebBrowser.cs @@ -56,6 +56,11 @@ namespace CefSharp.WinForms public ChromiumWebBrowser(string address) { + if (!Cef.IsInitialized && !Cef.Initialize()) + { + throw new InvalidOperationException("Cef::Initialize() failed"); + } + Cef.AddDisposable(this); Address = address; From 912754dd534e15b679bc0204ab6b9a986de75119 Mon Sep 17 00:00:00 2001 From: amaitland Date: Mon, 2 Feb 2015 18:46:58 +1000 Subject: [PATCH 24/73] Fix order of xml comment params --- CefSharp.Core/Cef.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CefSharp.Core/Cef.h b/CefSharp.Core/Cef.h index c8f2c6bda..2a2f88c6d 100644 --- a/CefSharp.Core/Cef.h +++ b/CefSharp.Core/Cef.h @@ -258,9 +258,9 @@ namespace CefSharp /// characters (e.g. the ';' character is disallowed within the cookie value attribute) and will return false without setting /// the cookie if such characters are found. /// The cookie URL + /// The cookie domain. /// The cookie name. /// The cookie value. - /// The cookie domain. /// The DateTime when the cookie will be treated as expired. /// false if the cookie cannot be set (e.g. if illegal charecters such as ';' are used); otherwise true. static bool SetCookie(String^ url, String^ domain, String^ name, String^ value, DateTime expires) From bd6ae9751ea875efa544fa3ac15212aedbf367af Mon Sep 17 00:00:00 2001 From: amaitland Date: Tue, 3 Feb 2015 22:41:43 +1000 Subject: [PATCH 25/73] Fix spacing --- CefSharp.WinForms/Internals/ControlExtensions.cs | 2 +- CefSharp.WinForms/Internals/DefaultFocusHandler.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CefSharp.WinForms/Internals/ControlExtensions.cs b/CefSharp.WinForms/Internals/ControlExtensions.cs index 3649d27dc..0fba09a4f 100644 --- a/CefSharp.WinForms/Internals/ControlExtensions.cs +++ b/CefSharp.WinForms/Internals/ControlExtensions.cs @@ -28,7 +28,7 @@ namespace CefSharp.WinForms.Internals public static void Activate(this Control control) { - //Notify WinForms world that inner browser window got focus. This will trigger Leave event to previous focused control + // Notify WinForms world that inner browser window got focus. This will trigger Leave event to previous focused control var containerControl = control.GetContainerControl(); if (containerControl != null) { diff --git a/CefSharp.WinForms/Internals/DefaultFocusHandler.cs b/CefSharp.WinForms/Internals/DefaultFocusHandler.cs index 28cc8be7c..0ea2b6be0 100644 --- a/CefSharp.WinForms/Internals/DefaultFocusHandler.cs +++ b/CefSharp.WinForms/Internals/DefaultFocusHandler.cs @@ -20,13 +20,13 @@ namespace CefSharp.WinForms.Internals public virtual bool OnSetFocus(CefFocusSource source) { - //Do not let the browser take focus when a Load method has been called + // Do not let the browser take focus when a Load method has been called return source == CefFocusSource.FocusSourceNavigation; } public virtual void OnTakeFocus(bool next) { - //NOTE: OnTakeFocus means leaving focus / not taking focus + // NOTE: OnTakeFocus means leaving focus / not taking focus browser.InvokeOnUiThreadIfRequired(() => browser.SelectNextControl(next)); } } From da16d9f0ebb069fb46db6bfed28da5e6b65a827a Mon Sep 17 00:00:00 2001 From: amaitland Date: Tue, 3 Feb 2015 23:05:43 +1000 Subject: [PATCH 26/73] Cleanup code as per feedback in PR #732 --- CefSharp.Core/Internals/CefDragDataWrapper.h | 6 +-- CefSharp.Core/ManagedCefBrowserAdapter.h | 15 ++---- CefSharp.Wpf/ChromiumWebBrowser.cs | 57 ++++++-------------- CefSharp/CefDragOperationsMask.cs | 24 --------- CefSharp/CefSharp.csproj | 1 - 5 files changed, 25 insertions(+), 78 deletions(-) delete mode 100644 CefSharp/CefDragOperationsMask.cs diff --git a/CefSharp.Core/Internals/CefDragDataWrapper.h b/CefSharp.Core/Internals/CefDragDataWrapper.h index 0b0ff8b68..b94730e4e 100644 --- a/CefSharp.Core/Internals/CefDragDataWrapper.h +++ b/CefSharp.Core/Internals/CefDragDataWrapper.h @@ -45,13 +45,13 @@ namespace CefSharp // Create a new CefDragData object. /// /*--cef()--*/ - static CefDragDataWrapper^ Create(){ + static CefDragDataWrapper^ Create() + { CefRefPtr cefDragData = CefDragData::Create(); return gcnew CefDragDataWrapper(cefDragData); } - - virtual property CefRefPtr* _internalDragData + virtual property CefRefPtr* InternalDragData { CefRefPtr* get() { diff --git a/CefSharp.Core/ManagedCefBrowserAdapter.h b/CefSharp.Core/ManagedCefBrowserAdapter.h index d2f257687..980323240 100644 --- a/CefSharp.Core/ManagedCefBrowserAdapter.h +++ b/CefSharp.Core/ManagedCefBrowserAdapter.h @@ -671,7 +671,8 @@ namespace CefSharp } } - CefMouseEvent GetCefMouseEvent(IMouseEvent^ mouseEvent){ + CefMouseEvent GetCefMouseEvent(IMouseEvent^ mouseEvent) + { CefMouseEvent cefMouseEvent; cefMouseEvent.x = mouseEvent->X; cefMouseEvent.y = mouseEvent->Y; @@ -679,21 +680,18 @@ namespace CefSharp return cefMouseEvent; } - void OnDragTargetDragEnter(CefDragDataWrapper^ dragData, IMouseEvent^ mouseEvent, CefDragOperationsMask allowedOperations) + void OnDragTargetDragEnter(CefDragDataWrapper^ dragData, IMouseEvent^ mouseEvent, DragOperationsMask allowedOperations) { auto browser = _clientAdapter->GetCefBrowser(); if (browser != nullptr) { dragData->ResetFileContents(); // Recommended by documentation to reset before calling DragEnter - browser->GetHost()->DragTargetDragEnter(*dragData->_internalDragData, GetCefMouseEvent(mouseEvent), (CefBrowserHost::DragOperationsMask) allowedOperations); + browser->GetHost()->DragTargetDragEnter(*dragData->InternalDragData, GetCefMouseEvent(mouseEvent), (CefBrowserHost::DragOperationsMask) allowedOperations); } } - - - - void OnDragTargetDragOver(IMouseEvent^ mouseEvent, CefDragOperationsMask allowedOperations) + void OnDragTargetDragOver(IMouseEvent^ mouseEvent, DragOperationsMask allowedOperations) { auto browser = _clientAdapter->GetCefBrowser(); @@ -703,7 +701,6 @@ namespace CefSharp } } - void OnDragTargetDragLeave() { auto browser = _clientAdapter->GetCefBrowser(); @@ -714,7 +711,6 @@ namespace CefSharp } } - void OnDragTargetDragDrop(IMouseEvent^ mouseEvent) { auto browser = _clientAdapter->GetCefBrowser(); @@ -724,6 +720,5 @@ namespace CefSharp browser->GetHost()->DragTargetDrop(GetCefMouseEvent(mouseEvent)); } } - }; } diff --git a/CefSharp.Wpf/ChromiumWebBrowser.cs b/CefSharp.Wpf/ChromiumWebBrowser.cs index 54af14015..59793619e 100644 --- a/CefSharp.Wpf/ChromiumWebBrowser.cs +++ b/CefSharp.Wpf/ChromiumWebBrowser.cs @@ -9,7 +9,6 @@ using System; using System.Collections.Generic; using System.IO; using System.Threading.Tasks; -using System.Linq; using System.Windows; using System.Windows.Controls; using System.Windows.Controls.Primitives; @@ -331,6 +330,12 @@ namespace CefSharp.Wpf GotKeyboardFocus -= OnGotKeyboardFocus; LostKeyboardFocus -= OnLostKeyboardFocus; + // Drag Drop events + DragEnter -= OnDragEnter; + DragOver -= OnDragOver; + DragLeave -= OnDragLeave; + Drop -= OnDrop; + IsVisibleChanged -= OnIsVisibleChanged; Cef.RemoveDisposable(this); @@ -467,25 +472,22 @@ namespace CefSharp.Wpf PresentationSource.AddSourceChangedHandler(this, PresentationSourceChangedHandler); } - - void OnDrop(object sender, DragEventArgs e) + private void OnDrop(object sender, DragEventArgs e) { managedCefBrowserAdapter.OnDragTargetDragDrop(GetMouseEvent(e)); } - void OnDragLeave(object sender, DragEventArgs e) + private void OnDragLeave(object sender, DragEventArgs e) { managedCefBrowserAdapter.OnDragTargetDragLeave(); } - void OnDragOver(object sender, DragEventArgs e) + private void OnDragOver(object sender, DragEventArgs e) { managedCefBrowserAdapter.OnDragTargetDragOver(GetMouseEvent(e), GetDragOperationsMask(e.AllowedEffects)); } - - - void OnDragEnter(object sender, DragEventArgs e) + private void OnDragEnter(object sender, DragEventArgs e) { managedCefBrowserAdapter.OnDragTargetDragEnter(GetDragDataWrapper(e), GetMouseEvent(e), GetDragOperationsMask(e.AllowedEffects)); } @@ -493,29 +495,28 @@ namespace CefSharp.Wpf /// /// Converts .NET drag drop effects to CEF Drag Operations /// s - private CefDragOperationsMask GetDragOperationsMask(DragDropEffects dragDropEffects) + private static DragOperationsMask GetDragOperationsMask(DragDropEffects dragDropEffects) { - var operations = CefDragOperationsMask.None; + var operations = DragOperationsMask.None; if (dragDropEffects.HasFlag(DragDropEffects.All)) { - operations |= CefDragOperationsMask.Every; + operations |= DragOperationsMask.Every; } if (dragDropEffects.HasFlag(DragDropEffects.Copy)) { - operations |= CefDragOperationsMask.Copy; + operations |= DragOperationsMask.Copy; } if (dragDropEffects.HasFlag(DragDropEffects.Move)) { - operations |= CefDragOperationsMask.Move; + operations |= DragOperationsMask.Move; } if (dragDropEffects.HasFlag(DragDropEffects.Link)) { - operations |= CefDragOperationsMask.Link; + operations |= DragOperationsMask.Link; } return operations; - } private CefDragDataWrapper GetDragDataWrapper(DragEventArgs e) @@ -530,7 +531,7 @@ namespace CefSharp.Wpf // As per documentation, we only need to specify FileNames, not FileName, when dragging into the browser (http://magpcss.org/ceforum/apidocs3/projects/(default)/CefDragData.html) foreach (var filePath in (string[])e.Data.GetData(DataFormats.FileDrop)) { - var displayName = System.IO.Path.GetFileName(filePath); + var displayName = Path.GetFileName(filePath); dragData.AddFile(filePath.Replace("\\", "/"), displayName); } @@ -552,11 +553,6 @@ namespace CefSharp.Wpf dragData.FragmentHtml = (string)e.Data.GetData(DataFormats.Html); } - - - - - return dragData; } @@ -890,22 +886,6 @@ namespace CefSharp.Wpf UiThreadRunAsync(() => { popup.IsOpen = isOpen; }); } - /// - /// Converts a .NET Mouse event to a CefSharp MouseEvent - /// - private MouseEvent GetMouseEvent(MouseEventArgs e) - { - var point = GetPixelPosition(e); - var modifiers = GetModifiers(e); - - return new MouseEvent - { - X = (int)point.X, - Y = (int)point.Y, - Modifiers = modifiers - }; - } - /// /// Converts a .NET Drag event to a CefSharp MouseEvent /// @@ -938,7 +918,6 @@ namespace CefSharp.Wpf modifiers |= CefEventFlags.RightMouseButton; } - if (Keyboard.IsKeyDown(Key.LeftCtrl)) { modifiers |= CefEventFlags.ControlDown | CefEventFlags.IsLeft; @@ -1465,7 +1444,5 @@ namespace CefSharp.Wpf { managedCefBrowserAdapter.Invalidate(type); } - - } } diff --git a/CefSharp/CefDragOperationsMask.cs b/CefSharp/CefDragOperationsMask.cs deleted file mode 100644 index 9667159e6..000000000 --- a/CefSharp/CefDragOperationsMask.cs +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright © 2010-2014 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. - -using System; - -namespace CefSharp -{ - /// - /// Drag operation mask types - /// - [Flags] - public enum CefDragOperationsMask - { - None = 0, - Copy = 1, - Link = 2, - Generic = 4, - Private = 8, - Move = 16, - Delete = 32, - Every = int.MaxValue, - } -} diff --git a/CefSharp/CefSharp.csproj b/CefSharp/CefSharp.csproj index b21c3f338..b048009e4 100644 --- a/CefSharp/CefSharp.csproj +++ b/CefSharp/CefSharp.csproj @@ -89,7 +89,6 @@ - From 6d4a766c32fd1884c490fdc54bda1e210abc0817 Mon Sep 17 00:00:00 2001 From: amaitland Date: Tue, 3 Feb 2015 23:07:00 +1000 Subject: [PATCH 27/73] Remove IMouseEvent interface - served no real purpose --- CefSharp.Core/ManagedCefBrowserAdapter.h | 8 ++++---- CefSharp/CefSharp.csproj | 1 - CefSharp/IMouseEvent.cs | 16 ---------------- CefSharp/MouseEvent.cs | 6 +----- 4 files changed, 5 insertions(+), 26 deletions(-) delete mode 100644 CefSharp/IMouseEvent.cs diff --git a/CefSharp.Core/ManagedCefBrowserAdapter.h b/CefSharp.Core/ManagedCefBrowserAdapter.h index 980323240..f4e0e677d 100644 --- a/CefSharp.Core/ManagedCefBrowserAdapter.h +++ b/CefSharp.Core/ManagedCefBrowserAdapter.h @@ -671,7 +671,7 @@ namespace CefSharp } } - CefMouseEvent GetCefMouseEvent(IMouseEvent^ mouseEvent) + CefMouseEvent GetCefMouseEvent(MouseEvent^ mouseEvent) { CefMouseEvent cefMouseEvent; cefMouseEvent.x = mouseEvent->X; @@ -680,7 +680,7 @@ namespace CefSharp return cefMouseEvent; } - void OnDragTargetDragEnter(CefDragDataWrapper^ dragData, IMouseEvent^ mouseEvent, DragOperationsMask allowedOperations) + void OnDragTargetDragEnter(CefDragDataWrapper^ dragData, MouseEvent^ mouseEvent, DragOperationsMask allowedOperations) { auto browser = _clientAdapter->GetCefBrowser(); @@ -691,7 +691,7 @@ namespace CefSharp } } - void OnDragTargetDragOver(IMouseEvent^ mouseEvent, DragOperationsMask allowedOperations) + void OnDragTargetDragOver(MouseEvent^ mouseEvent, DragOperationsMask allowedOperations) { auto browser = _clientAdapter->GetCefBrowser(); @@ -711,7 +711,7 @@ namespace CefSharp } } - void OnDragTargetDragDrop(IMouseEvent^ mouseEvent) + void OnDragTargetDragDrop(MouseEvent^ mouseEvent) { auto browser = _clientAdapter->GetCefBrowser(); diff --git a/CefSharp/CefSharp.csproj b/CefSharp/CefSharp.csproj index b048009e4..fbe47ed1a 100644 --- a/CefSharp/CefSharp.csproj +++ b/CefSharp/CefSharp.csproj @@ -90,7 +90,6 @@ - diff --git a/CefSharp/IMouseEvent.cs b/CefSharp/IMouseEvent.cs deleted file mode 100644 index 6c26fddc0..000000000 --- a/CefSharp/IMouseEvent.cs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright © 2010-2014 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. - -using System.Collections.Generic; -using System.IO; - -namespace CefSharp -{ - public interface IMouseEvent - { - int X { get; set; } - int Y { get; set; } - CefEventFlags Modifiers { get; set; } - } -} \ No newline at end of file diff --git a/CefSharp/MouseEvent.cs b/CefSharp/MouseEvent.cs index 8a4d5f72a..34130625f 100644 --- a/CefSharp/MouseEvent.cs +++ b/CefSharp/MouseEvent.cs @@ -2,13 +2,9 @@ // // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. -using System; -using System.Collections.Generic; -using System.IO; - namespace CefSharp { - public class MouseEvent : IMouseEvent + public class MouseEvent { public int X { get; set; } public int Y { get; set; } From 7c7ba1dbb654c1662262cc96c27ad3829e91cbac Mon Sep 17 00:00:00 2001 From: Bill Tutt Date: Tue, 3 Feb 2015 19:50:16 -0500 Subject: [PATCH 28/73] #785: Fix IDisposable pattern usage in WinForms ChromiumWebBrowser and WinForms.Example BrowserTabUserControl. --- .../BrowserTabUserControl.cs | 18 ----------- CefSharp.WinForms/ChromiumWebBrowser.cs | 30 +++++++++++++++++-- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/CefSharp.WinForms.Example/BrowserTabUserControl.cs b/CefSharp.WinForms.Example/BrowserTabUserControl.cs index 9eec5b56f..968fa8005 100644 --- a/CefSharp.WinForms.Example/BrowserTabUserControl.cs +++ b/CefSharp.WinForms.Example/BrowserTabUserControl.cs @@ -42,24 +42,6 @@ namespace CefSharp.WinForms.Example var version = String.Format("Chromium: {0}, CEF: {1}, CefSharp: {2}", Cef.ChromiumVersion, Cef.CefVersion, Cef.CefSharpVersion); DisplayOutput(version); - - Disposed += BrowserTabUserControlDisposed; - } - - private void BrowserTabUserControlDisposed(object sender, EventArgs e) - { - var browser = (ChromiumWebBrowser)Browser; - Disposed -= BrowserTabUserControlDisposed; - - browser.NavStateChanged -= OnBrowserNavStateChanged; - browser.ConsoleMessage -= OnBrowserConsoleMessage; - browser.TitleChanged -= OnBrowserTitleChanged; - browser.AddressChanged -= OnBrowserAddressChanged; - browser.StatusMessage -= OnBrowserStatusMessage; - browser.IsBrowserInitializedChanged -= OnIsBrowserInitializedChanged; - browser.IsLoadingChanged -= OnIsLoadingChanged; - - browser.Dispose(); } private void OnBrowserConsoleMessage(object sender, ConsoleMessageEventArgs args) diff --git a/CefSharp.WinForms/ChromiumWebBrowser.cs b/CefSharp.WinForms/ChromiumWebBrowser.cs index 3755e21d7..47e2a6b88 100644 --- a/CefSharp.WinForms/ChromiumWebBrowser.cs +++ b/CefSharp.WinForms/ChromiumWebBrowser.cs @@ -75,20 +75,46 @@ namespace CefSharp.WinForms protected override void Dispose(bool disposing) { + // Don't utilize any of the handlers anymore: + DialogHandler = null; + JsDialogHandler = null; + KeyboardHandler = null; + RequestHandler = null; + DownloadHandler = null; + LifeSpanHandler = null; + MenuHandler = null; + DragHandler = null; + GeolocationHandler = null; FocusHandler = null; ResourceHandler = null; - BrowserSettings.Dispose(); - BrowserSettings = null; Cef.RemoveDisposable(this); if (disposing) { + if (BrowserSettings != null) + { + BrowserSettings.Dispose(); + BrowserSettings = null; + } + if (managedCefBrowserAdapter != null) { managedCefBrowserAdapter.Dispose(); managedCefBrowserAdapter = null; } + + // Don't maintain a reference to event listeners anylonger: + LoadError = null; + FrameLoadStart = null; + FrameLoadEnd = null; + NavStateChanged = null; + ConsoleMessage = null; + StatusMessage = null; + AddressChanged = null; + TitleChanged = null; + IsBrowserInitializedChanged = null; + IsLoadingChanged = null; } base.Dispose(disposing); } From 08b125487980c032800b647a947b6ef867109295 Mon Sep 17 00:00:00 2001 From: Bill Tutt Date: Tue, 3 Feb 2015 19:55:24 -0500 Subject: [PATCH 29/73] #785: _browserProcessServiceHost isn't safe to call Close on if we're being finalized. (it may have already been disposed of separately on the finalizer thread) --- CefSharp.Core/ManagedCefBrowserAdapter.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CefSharp.Core/ManagedCefBrowserAdapter.h b/CefSharp.Core/ManagedCefBrowserAdapter.h index f4e0e677d..60d124a77 100644 --- a/CefSharp.Core/ManagedCefBrowserAdapter.h +++ b/CefSharp.Core/ManagedCefBrowserAdapter.h @@ -35,7 +35,9 @@ namespace CefSharp Close(true); _clientAdapter = nullptr; - if (_browserProcessServiceHost != nullptr) + + // Guard managed only member derefs by isDisposing: + if (isDisposing && _browserProcessServiceHost != nullptr) { _browserProcessServiceHost->Close(); _browserProcessServiceHost = nullptr; From 4df746dd53cdabd6dc79ba4801a9d31b1a4bf7cb Mon Sep 17 00:00:00 2001 From: Bill Tutt Date: Tue, 3 Feb 2015 19:58:19 -0500 Subject: [PATCH 30/73] #785: Fix IDisposable pattern usage in WPF ChromiumWebBrowser by: * null-ing out all handlers and event listeners * ONLY dereference a managed objects if we're disposing (and not finalizing) since the object could be already disposed before us if we're being finalized. --- CefSharp.Wpf/ChromiumWebBrowser.cs | 84 ++++++++++++++++++------------ 1 file changed, 51 insertions(+), 33 deletions(-) diff --git a/CefSharp.Wpf/ChromiumWebBrowser.cs b/CefSharp.Wpf/ChromiumWebBrowser.cs index 59793619e..5ac2b6731 100644 --- a/CefSharp.Wpf/ChromiumWebBrowser.cs +++ b/CefSharp.Wpf/ChromiumWebBrowser.cs @@ -318,40 +318,61 @@ namespace CefSharp.Wpf protected virtual void Dispose(bool isdisposing) { - PresentationSource.RemoveSourceChangedHandler(this, PresentationSourceChangedHandler); - - BrowserSettings.Dispose(); - - BrowserSettings = null; - ResourceHandler = null; - - Loaded -= OnLoaded; - - GotKeyboardFocus -= OnGotKeyboardFocus; - LostKeyboardFocus -= OnLostKeyboardFocus; - - // Drag Drop events - DragEnter -= OnDragEnter; - DragOver -= OnDragOver; - DragLeave -= OnDragLeave; - Drop -= OnDrop; - - IsVisibleChanged -= OnIsVisibleChanged; - - Cef.RemoveDisposable(this); - - foreach (var disposable in disposables) - { - disposable.Dispose(); - } - disposables.Clear(); - - UiThreadRunAsync(() => WebBrowser = null); - managedCefBrowserAdapter = null; + // No longer reference event listeners: ConsoleMessage = null; FrameLoadStart = null; FrameLoadEnd = null; LoadError = null; + NavStateChanged = null; + + // No longer reference handlers: + ResourceHandler = null; + DialogHandler = null; + JsDialogHandler = null; + KeyboardHandler = null; + RequestHandler = null; + DownloadHandler = null; + LifeSpanHandler = null; + MenuHandler = null; + FocusHandler = null; + DragHandler = null; + GeolocationHandler = null; + Rendering = null; + + if (isdisposing) + { + if (BrowserSettings != null) + { + BrowserSettings.Dispose(); + BrowserSettings = null; + } + + PresentationSource.RemoveSourceChangedHandler(this, PresentationSourceChangedHandler); + + // Release internal event listeners: + Loaded -= OnLoaded; + GotKeyboardFocus -= OnGotKeyboardFocus; + LostKeyboardFocus -= OnLostKeyboardFocus; + + // Release internal event listeners for Drag Drop events: + DragEnter -= OnDragEnter; + DragOver -= OnDragOver; + DragLeave -= OnDragLeave; + Drop -= OnDrop; + + IsVisibleChanged -= OnIsVisibleChanged; + + foreach (var disposable in disposables) + { + disposable.Dispose(); + } + disposables.Clear(); + UiThreadRunAsync(() => WebBrowser = null); + } + + Cef.RemoveDisposable(this); + + managedCefBrowserAdapter = null; } #endregion CleanupElement dependency property @@ -606,9 +627,6 @@ namespace CefSharp.Wpf return url.TrimEnd('\0'); } - - - ~ChromiumWebBrowser() { Dispose(false); From 329dad21c8267efe3a5f602027ea9a1c77fd4767 Mon Sep 17 00:00:00 2001 From: Bill Tutt Date: Tue, 3 Feb 2015 20:00:08 -0500 Subject: [PATCH 31/73] #785: Fix IDisposable pattern in Offscreen ChromiumWebBrowser by: * NULL ing out event listeners and handlers * Only derefing managed objects during a dispose (doing so during finalization is bad) * Add missing finalizer to ensure CEF gets shutdown properly. --- CefSharp.OffScreen/ChromiumWebBrowser.cs | 56 +++++++++++++++++++----- 1 file changed, 45 insertions(+), 11 deletions(-) diff --git a/CefSharp.OffScreen/ChromiumWebBrowser.cs b/CefSharp.OffScreen/ChromiumWebBrowser.cs index ea69a0609..2a2585f85 100644 --- a/CefSharp.OffScreen/ChromiumWebBrowser.cs +++ b/CefSharp.OffScreen/ChromiumWebBrowser.cs @@ -58,26 +58,60 @@ namespace CefSharp.OffScreen managedCefBrowserAdapter.CreateOffscreenBrowser(IntPtr.Zero, browserSettings ?? new BrowserSettings(), address); } + ~ChromiumWebBrowser() + { + Dispose(false); + } + public void Dispose() { + Dispose(true); + GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { + // Don't reference handlers any longer: ResourceHandler = null; + JsDialogHandler = null; + DialogHandler = null; + DownloadHandler = null; + KeyboardHandler = null; + LifeSpanHandler = null; + MenuHandler = null; + FocusHandler = null; + RequestHandler = null; + DragHandler = null; + GeolocationHandler = null; + + // Don't reference event listenets any longer: + LoadError = null; + FrameLoadStart = null; + FrameLoadEnd = null; + ConsoleMessage = null; + BrowserInitialized = null; + StatusMessage = null; + NavStateChanged = null; Cef.RemoveDisposable(this); - if (bitmap != null) + if (disposing) { - bitmap.Dispose(); - bitmap = null; - } + if (bitmap != null) + { + bitmap.Dispose(); + bitmap = null; + } - if (managedCefBrowserAdapter != null) - { - if (!managedCefBrowserAdapter.IsDisposed) - managedCefBrowserAdapter.Dispose(); - managedCefBrowserAdapter = null; + if (managedCefBrowserAdapter != null) + { + if (!managedCefBrowserAdapter.IsDisposed) + { + managedCefBrowserAdapter.Dispose(); + } + managedCefBrowserAdapter = null; + } } - - GC.SuppressFinalize(this); } /// From df03e82501146b081a53bd027f3f6ecf024959ae Mon Sep 17 00:00:00 2001 From: Bill Tutt Date: Tue, 3 Feb 2015 20:01:00 -0500 Subject: [PATCH 32/73] #785: Add a using to OffScreen.Example, now that Offscreen browser is a proper IDisposable. --- CefSharp.OffScreen.Example/Program.cs | 30 ++++++++++++++------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/CefSharp.OffScreen.Example/Program.cs b/CefSharp.OffScreen.Example/Program.cs index ae6fd9531..95ed2425e 100644 --- a/CefSharp.OffScreen.Example/Program.cs +++ b/CefSharp.OffScreen.Example/Program.cs @@ -29,22 +29,24 @@ namespace CefSharp.OffScreen.Example CefExample.Init(); // Create the offscreen Chromium browser. - browser = new ChromiumWebBrowser(testUrl); - - // An event that is fired when the first page is finished loading. - // This returns to us from another thread. - if (captureFirstRenderedImage) + using (browser = new ChromiumWebBrowser(testUrl)) { - browser.ResourceHandler.RegisterHandler(testUrl, ResourceHandler.FromString("

CefSharp OffScreen

")); - browser.ScreenshotAsync().ContinueWith(DisplayBitmap); - } - else - { - browser.FrameLoadEnd += BrowserFrameLoadEnd; - } - // We have to wait for something, otherwise the process will exit too soon. - Console.ReadKey(); + // An event that is fired when the first page is finished loading. + // This returns to us from another thread. + if (captureFirstRenderedImage) + { + browser.ResourceHandler.RegisterHandler(testUrl, ResourceHandler.FromString("

CefSharp OffScreen

")); + browser.ScreenshotAsync().ContinueWith(DisplayBitmap); + } + else + { + browser.FrameLoadEnd += BrowserFrameLoadEnd; + } + + // We have to wait for something, otherwise the process will exit too soon. + Console.ReadKey(); + } // Clean up Chromium objects. You need to call this in your application otherwise // you will get a crash when closing. From 3bb569d59655348ba20f6ea7bd513296bb626202 Mon Sep 17 00:00:00 2001 From: Bill Tutt Date: Tue, 3 Feb 2015 20:01:43 -0500 Subject: [PATCH 33/73] #785: Be paranoid about "delete " twice during dispose/finalization and only do it once. I'm not sure if this is necessary, but it looked very odd to me. --- CefSharp.Core/BrowserSettings.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CefSharp.Core/BrowserSettings.h b/CefSharp.Core/BrowserSettings.h index dc9964d9c..cf714f22a 100644 --- a/CefSharp.Core/BrowserSettings.h +++ b/CefSharp.Core/BrowserSettings.h @@ -71,13 +71,15 @@ namespace CefSharp public ref class BrowserSettings { + private: + bool _isFinalized = false; internal: CefBrowserSettings* _browserSettings; public: BrowserSettings() : _browserSettings(new CefBrowserSettings()) { } - !BrowserSettings() { delete _browserSettings; } - ~BrowserSettings() { delete _browserSettings; } + !BrowserSettings() { delete _browserSettings; _isFinalized = true; } + ~BrowserSettings() { if (!_isFinalized) this->!BrowserSettings(); } // CefBrowserSettings is private causing whole field to be private // exposing void* as a workaround From 36478a90bb35131f96368a2ff44e63042f660831 Mon Sep 17 00:00:00 2001 From: Bill Tutt Date: Tue, 3 Feb 2015 20:11:30 -0500 Subject: [PATCH 34/73] #785: Tiny build fix. --- CefSharp.Core/BrowserSettings.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CefSharp.Core/BrowserSettings.h b/CefSharp.Core/BrowserSettings.h index cf714f22a..9b9060e77 100644 --- a/CefSharp.Core/BrowserSettings.h +++ b/CefSharp.Core/BrowserSettings.h @@ -72,12 +72,12 @@ namespace CefSharp public ref class BrowserSettings { private: - bool _isFinalized = false; + bool _isFinalized; internal: CefBrowserSettings* _browserSettings; public: - BrowserSettings() : _browserSettings(new CefBrowserSettings()) { } + BrowserSettings() : _browserSettings(new CefBrowserSettings()), _isFinalized(false) { } !BrowserSettings() { delete _browserSettings; _isFinalized = true; } ~BrowserSettings() { if (!_isFinalized) this->!BrowserSettings(); } From 057925d6b8d9982bad21421bbc4fa964b925643b Mon Sep 17 00:00:00 2001 From: Bill Tutt Date: Tue, 3 Feb 2015 20:27:30 -0500 Subject: [PATCH 35/73] Fix comment spelling error. --- CefSharp.OffScreen/ChromiumWebBrowser.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CefSharp.OffScreen/ChromiumWebBrowser.cs b/CefSharp.OffScreen/ChromiumWebBrowser.cs index 2a2585f85..b6a79c2e7 100644 --- a/CefSharp.OffScreen/ChromiumWebBrowser.cs +++ b/CefSharp.OffScreen/ChromiumWebBrowser.cs @@ -84,7 +84,7 @@ namespace CefSharp.OffScreen DragHandler = null; GeolocationHandler = null; - // Don't reference event listenets any longer: + // Don't reference event listeners any longer: LoadError = null; FrameLoadStart = null; FrameLoadEnd = null; From 7894ac61d1b9f2f48d3b26a5a877b0e4e111f90b Mon Sep 17 00:00:00 2001 From: rassilon Date: Wed, 4 Feb 2015 01:44:54 -0500 Subject: [PATCH 36/73] #672: Notify CEF when our owning form moves (WM_MOVE or WM_MOVING) just like cefclient. --- CefSharp.WinForms/ChromiumWebBrowser.cs | 22 +++++++ CefSharp.WinForms/Internals/MovingListener.cs | 61 +++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 CefSharp.WinForms/Internals/MovingListener.cs diff --git a/CefSharp.WinForms/ChromiumWebBrowser.cs b/CefSharp.WinForms/ChromiumWebBrowser.cs index 3755e21d7..9cb3d2277 100644 --- a/CefSharp.WinForms/ChromiumWebBrowser.cs +++ b/CefSharp.WinForms/ChromiumWebBrowser.cs @@ -14,6 +14,7 @@ namespace CefSharp.WinForms public class ChromiumWebBrowser : Control, IWebBrowserInternal, IWinFormsWebBrowser { private ManagedCefBrowserAdapter managedCefBrowserAdapter; + private MovingListener movingListener; public BrowserSettings BrowserSettings { get; set; } public string Title { get; set; } @@ -93,10 +94,31 @@ namespace CefSharp.WinForms base.Dispose(disposing); } + void movingListener_Moving(object sender, EventArgs e) + { + if (IsBrowserInitialized) + { + NotifyMoveOrResizeStarted(); + } + } + void IWebBrowserInternal.OnInitialized() { IsBrowserInitialized = true; + // By the time this callback gets called, this control + // is most likely hooked into a parent Form of some sort. + // (Which is what MovingListener relies on.) + // Ensure the MovingListener contruction occurs on the WinForms UI thread: + if (InvokeRequired) + { + this.BeginInvoke((MethodInvoker)delegate + { + movingListener = new MovingListener(this.FindForm()); + movingListener.Moving += movingListener_Moving; + }); + } + ResizeBrowser(); var handler = IsBrowserInitializedChanged; diff --git a/CefSharp.WinForms/Internals/MovingListener.cs b/CefSharp.WinForms/Internals/MovingListener.cs new file mode 100644 index 000000000..dd7ed8a31 --- /dev/null +++ b/CefSharp.WinForms/Internals/MovingListener.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Windows.Forms; + +namespace CefSharp.WinForms.Internals +{ + internal class MovingListener : NativeWindow + { + public event EventHandler Moving; + + private Form ParentForm { get; set; } + + public MovingListener(Form parent) + { + ParentForm = parent; + if (ParentForm.IsHandleCreated) + { + OnHandleCreated(ParentForm, null); + } + else + { + ParentForm.HandleCreated += OnHandleCreated; + } + ParentForm.HandleDestroyed += OnHandleDestroyed; + } + + private void OnHandleCreated(object sender, EventArgs e) + { + AssignHandle(((Form)sender).Handle); + } + + private void OnHandleDestroyed(object sender, EventArgs e) + { + ReleaseHandle(); + } + protected override void WndProc(ref Message m) + { + // Listen for operating system messages + switch (m.Msg) + { + // WM_MOVE + case 0x3: + // WM_MOVING: + case 0x0216: + OnMoving(); + break; + } + base.WndProc(ref m); + } + + protected virtual void OnMoving() + { + if (Moving != null) + { + Moving(this, null); + } + } + } +} From b73e7003d531a2ea4504caba93997d88469986c9 Mon Sep 17 00:00:00 2001 From: rassilon Date: Wed, 4 Feb 2015 01:46:49 -0500 Subject: [PATCH 37/73] Add forgotten copyright header. --- CefSharp.WinForms/Internals/MovingListener.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CefSharp.WinForms/Internals/MovingListener.cs b/CefSharp.WinForms/Internals/MovingListener.cs index dd7ed8a31..ba0a47923 100644 --- a/CefSharp.WinForms/Internals/MovingListener.cs +++ b/CefSharp.WinForms/Internals/MovingListener.cs @@ -1,4 +1,8 @@ -using System; +// Copyright © 2014 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. + +using System; using System.Collections.Generic; using System.Linq; using System.Text; From e921b1b818cd7d10273091e7b7244f677ed9003d Mon Sep 17 00:00:00 2001 From: rassilon Date: Wed, 4 Feb 2015 02:04:05 -0500 Subject: [PATCH 38/73] Add new file to project. --- CefSharp.WinForms/CefSharp.WinForms.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/CefSharp.WinForms/CefSharp.WinForms.csproj b/CefSharp.WinForms/CefSharp.WinForms.csproj index ae2bfee76..ed11d2208 100644 --- a/CefSharp.WinForms/CefSharp.WinForms.csproj +++ b/CefSharp.WinForms/CefSharp.WinForms.csproj @@ -53,6 +53,7 @@ + Component From a961cbd76407718944d60cd6135261eaaf5db87e Mon Sep 17 00:00:00 2001 From: amaitland Date: Thu, 5 Feb 2015 07:49:05 +1000 Subject: [PATCH 39/73] Tooltips not displaying in WinForms control (#789) - Added entry to app.manifest as per http://www.magpcss.org/ceforum/viewtopic.php?f=6&t=11514&p=20387&hilit=Tooltip#p20387 Also incremented version version number (now version 39) --- CefSharp.WinForms.Example/app.manifest | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/CefSharp.WinForms.Example/app.manifest b/CefSharp.WinForms.Example/app.manifest index 399e0d2eb..12bd81018 100644 --- a/CefSharp.WinForms.Example/app.manifest +++ b/CefSharp.WinForms.Example/app.manifest @@ -8,7 +8,14 @@ xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - + + + + + + + + From 0279c41d3ca201cf80cee24464b7a8129f2e6ef5 Mon Sep 17 00:00:00 2001 From: rassilon Date: Wed, 4 Feb 2015 17:24:42 -0500 Subject: [PATCH 40/73] Much improved MovingListener that: * Tries to handle any possible cases where the ChromiumWebBrowser.Parent gets changed. (WinForms.Examples doesn't currently need this, btw) * Expose RefindParentForm as public so that the calling control has control over the call to .FindForm(). * Only indicate movement when there is actual x/y movement and we're not going from Maximized to non-Maximized since this logic ends up being handled elsewhere. * Add some debugging logic so that other folks can experiment with this scary looking change. * Cave after realizing that every ChromiumWebBrowser needs to be notified of any kind of movement. (and not JUST the visible tabs from WinForm.Examples) This means we DO NOT check ParentControl.Visible on purpose. This was tested by creating two tabs in Winforms.Example, point both at TooltipTest.html (from the custom scheme) and move/resizing around and testing both tabs after the move/resize finished. --- CefSharp.WinForms/ChromiumWebBrowser.cs | 2 +- CefSharp.WinForms/Internals/MovingListener.cs | 122 +++++++++++++++--- 2 files changed, 107 insertions(+), 17 deletions(-) diff --git a/CefSharp.WinForms/ChromiumWebBrowser.cs b/CefSharp.WinForms/ChromiumWebBrowser.cs index 9cb3d2277..ea80b8509 100644 --- a/CefSharp.WinForms/ChromiumWebBrowser.cs +++ b/CefSharp.WinForms/ChromiumWebBrowser.cs @@ -114,7 +114,7 @@ namespace CefSharp.WinForms { this.BeginInvoke((MethodInvoker)delegate { - movingListener = new MovingListener(this.FindForm()); + movingListener = new MovingListener(this); movingListener.Moving += movingListener_Moving; }); } diff --git a/CefSharp.WinForms/Internals/MovingListener.cs b/CefSharp.WinForms/Internals/MovingListener.cs index ba0a47923..1faf94210 100644 --- a/CefSharp.WinForms/Internals/MovingListener.cs +++ b/CefSharp.WinForms/Internals/MovingListener.cs @@ -2,10 +2,10 @@ // // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. +using CefSharp.Internals; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using System.Drawing; +using System.Runtime.InteropServices; using System.Windows.Forms; namespace CefSharp.WinForms.Internals @@ -14,25 +14,58 @@ namespace CefSharp.WinForms.Internals { public event EventHandler Moving; + private bool isMoving = false; + private Rectangle movingRectangle; + + private Control ParentControl { get; set; } + private Form ParentForm { get; set; } - public MovingListener(Form parent) + public MovingListener(Control parent) { - ParentForm = parent; - if (ParentForm.IsHandleCreated) + ParentControl = parent; + // Get notified if our parent window changes: + ParentControl.ParentChanged += parent_ParentChanged; + // Find the parent form to subclass to monitor WM_MOVE/WM_MOVING + RefindParentForm(); + } + + public void RefindParentForm() + { + parent_ParentChanged(ParentControl, null); + } + + private void parent_ParentChanged(object sender, EventArgs e) + { + Control control = (Control)sender; + Form oldForm = ParentForm; + Form newForm = control.FindForm(); + if (oldForm == null + || newForm == null + || oldForm.Handle != newForm.Handle + ) { - OnHandleCreated(ParentForm, null); + if (this.Handle != IntPtr.Zero) + { + ReleaseHandle(); + } + if (oldForm != null) + { + oldForm.HandleCreated -= OnHandleCreated; + oldForm.HandleDestroyed -= OnHandleDestroyed; + } + ParentForm = newForm; + if (newForm != null) + { + OnHandleCreated(newForm, null); + } } - else - { - ParentForm.HandleCreated += OnHandleCreated; - } - ParentForm.HandleDestroyed += OnHandleDestroyed; } private void OnHandleCreated(object sender, EventArgs e) { AssignHandle(((Form)sender).Handle); + Kernel32.OutputDebugString(String.Format("Attaching '{1:x}' to form '{0:x}'\r\n", ParentForm.Handle, ParentControl.Handle)); } private void OnHandleDestroyed(object sender, EventArgs e) @@ -41,25 +74,82 @@ namespace CefSharp.WinForms.Internals } protected override void WndProc(ref Message m) { + bool care = false; + + // Negative initial values keeps the compiler quiet: + int x = -1; + int y = -1; + // Listen for operating system messages switch (m.Msg) { - // WM_MOVE - case 0x3: // WM_MOVING: case 0x0216: - OnMoving(); + movingRectangle = (Rectangle)Marshal.PtrToStructure(m.LParam, typeof(Rectangle)); + x = movingRectangle.Left; + y = movingRectangle.Top; + care = true; + break; + // WM_MOVE + case 0x3: + x = (m.LParam.ToInt32() & 0xffff); + y = ((m.LParam.ToInt32() >> 16) & 0xffff); + care = true; break; } - base.WndProc(ref m); + + // Only notify about movement if: + // * ParentForm Created + // * ParentControl Created + // * ParentForm Actually moved + // * Not currently moving (on the UI thread only of course) + // * The current WindowState is Normal. + // This check is to simplify the effort here. + // Other logic already handles the maximize/minimize + // cases just fine. + // You might consider checking ParentControl.Visible and + // not notifying our parent control if the parent control isn't visible. + // However, if you do that, the non-Visible CEF tab will still + // have any SELECT drop downs rendering where they shouldn't. + if (care + && ParentForm != null + && ParentForm.IsHandleCreated + && ParentControl.IsHandleCreated + && ParentForm.WindowState == FormWindowState.Normal + && (ParentForm.Left != x + || ParentForm.Top != y) + && !isMoving) + { + // .Left & .Right are negative when the window + // is transitioning from maximized to normal. + // If we are transitioning, the form will also receive + // a WM_SIZE which can deal with the move/size combo itself. + if (ParentForm.Left > 0 + && ParentForm.Right > 0) + { + OnMoving(); + Kernel32.OutputDebugString(String.Format("Called OnMoving from control '{1:x}' to form '{0:x}'\r\n", ParentForm.Handle, ParentControl.Handle)); + } + else + { + Kernel32.OutputDebugString(String.Format("Skipped OnMoving from control '{1:x}' to form '{0:x}'\r\n", ParentForm.Handle, ParentControl.Handle)); + } + } + else if (care) + { + Kernel32.OutputDebugString(String.Format("Skipped OnMoving from control '{1:x}' to form '{0:x}'\r\n", ParentForm.Handle, ParentControl.Handle)); + } + this.DefWndProc(ref m); } protected virtual void OnMoving() { + isMoving = true; if (Moving != null) { Moving(this, null); } + isMoving = false; } } } From 0507ca52db31bf373aa612afe5ddb91ef32416a2 Mon Sep 17 00:00:00 2001 From: rassilon Date: Wed, 4 Feb 2015 19:58:28 -0500 Subject: [PATCH 41/73] Straightforward code review fixes, and correctly attach to newForm.HandleCreated/newForm.HandleDestroyed events. --- CefSharp.WinForms/ChromiumWebBrowser.cs | 15 +++---- CefSharp.WinForms/Internals/MovingListener.cs | 45 ++++++++++++------- 2 files changed, 35 insertions(+), 25 deletions(-) diff --git a/CefSharp.WinForms/ChromiumWebBrowser.cs b/CefSharp.WinForms/ChromiumWebBrowser.cs index ea80b8509..0e8ebac13 100644 --- a/CefSharp.WinForms/ChromiumWebBrowser.cs +++ b/CefSharp.WinForms/ChromiumWebBrowser.cs @@ -94,7 +94,7 @@ namespace CefSharp.WinForms base.Dispose(disposing); } - void movingListener_Moving(object sender, EventArgs e) + private void MovingListenerMoving(object sender, EventArgs e) { if (IsBrowserInitialized) { @@ -109,15 +109,12 @@ namespace CefSharp.WinForms // By the time this callback gets called, this control // is most likely hooked into a parent Form of some sort. // (Which is what MovingListener relies on.) - // Ensure the MovingListener contruction occurs on the WinForms UI thread: - if (InvokeRequired) + // Ensure the MovingListener construction occurs on the WinForms UI thread: + this.InvokeOnUiThreadIfRequired(() => { - this.BeginInvoke((MethodInvoker)delegate - { - movingListener = new MovingListener(this); - movingListener.Moving += movingListener_Moving; - }); - } + movingListener = new MovingListener(this); + movingListener.Moving += MovingListenerMoving; + }); ResizeBrowser(); diff --git a/CefSharp.WinForms/Internals/MovingListener.cs b/CefSharp.WinForms/Internals/MovingListener.cs index 1faf94210..f5a824600 100644 --- a/CefSharp.WinForms/Internals/MovingListener.cs +++ b/CefSharp.WinForms/Internals/MovingListener.cs @@ -25,17 +25,17 @@ namespace CefSharp.WinForms.Internals { ParentControl = parent; // Get notified if our parent window changes: - ParentControl.ParentChanged += parent_ParentChanged; + ParentControl.ParentChanged += ParentParentChanged; // Find the parent form to subclass to monitor WM_MOVE/WM_MOVING RefindParentForm(); } public void RefindParentForm() { - parent_ParentChanged(ParentControl, null); + ParentParentChanged(ParentControl, null); } - private void parent_ParentChanged(object sender, EventArgs e) + private void ParentParentChanged(object sender, EventArgs e) { Control control = (Control)sender; Form oldForm = ParentForm; @@ -57,7 +57,12 @@ namespace CefSharp.WinForms.Internals ParentForm = newForm; if (newForm != null) { - OnHandleCreated(newForm, null); + newForm.HandleCreated += OnHandleCreated; + newForm.HandleDestroyed += OnHandleDestroyed; + if (newForm.IsHandleCreated) + { + OnHandleCreated(newForm, null); + } } } } @@ -72,13 +77,16 @@ namespace CefSharp.WinForms.Internals { ReleaseHandle(); } + protected override void WndProc(ref Message m) { bool care = false; - // Negative initial values keeps the compiler quiet: - int x = -1; - int y = -1; + // Negative initial values keeps the compiler quiet and to + // ensure we have actual window movement to notify CEF about. + const int invalidMoveCoordinate = -1; + int x = invalidMoveCoordinate; + int y = invalidMoveCoordinate; // Listen for operating system messages switch (m.Msg) @@ -99,8 +107,13 @@ namespace CefSharp.WinForms.Internals } // Only notify about movement if: - // * ParentForm Created - // * ParentControl Created + // * ParentControl Handle Created + // NOTE: This is checked for paranoia. + // This WndProc can't be called unless ParentForm has + // its handle created, but that doesn't necessarily mean + // ParentControl has had its handle created. + // WinForm controls don't usually get eagerly created Handles + // in their constructors. // * ParentForm Actually moved // * Not currently moving (on the UI thread only of course) // * The current WindowState is Normal. @@ -112,20 +125,18 @@ namespace CefSharp.WinForms.Internals // However, if you do that, the non-Visible CEF tab will still // have any SELECT drop downs rendering where they shouldn't. if (care - && ParentForm != null - && ParentForm.IsHandleCreated && ParentControl.IsHandleCreated && ParentForm.WindowState == FormWindowState.Normal && (ParentForm.Left != x || ParentForm.Top != y) && !isMoving) { - // .Left & .Right are negative when the window + // ParentForm.Left & .Right are negative when the window // is transitioning from maximized to normal. // If we are transitioning, the form will also receive // a WM_SIZE which can deal with the move/size combo itself. - if (ParentForm.Left > 0 - && ParentForm.Right > 0) + if (ParentForm.Left >= 0 + && ParentForm.Right >= 0) { OnMoving(); Kernel32.OutputDebugString(String.Format("Called OnMoving from control '{1:x}' to form '{0:x}'\r\n", ParentForm.Handle, ParentControl.Handle)); @@ -145,9 +156,11 @@ namespace CefSharp.WinForms.Internals protected virtual void OnMoving() { isMoving = true; - if (Moving != null) + var handler = Moving; + + if (handler != null) { - Moving(this, null); + handler(this, null); } isMoving = false; } From 7a8498bb695030eac607e0874f75cb8834cc1076 Mon Sep 17 00:00:00 2001 From: rassilon Date: Wed, 4 Feb 2015 20:14:12 -0500 Subject: [PATCH 42/73] Add System.ServiceModel reference. --- CefSharp.WinForms/CefSharp.WinForms.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/CefSharp.WinForms/CefSharp.WinForms.csproj b/CefSharp.WinForms/CefSharp.WinForms.csproj index ed11d2208..b4b177cd6 100644 --- a/CefSharp.WinForms/CefSharp.WinForms.csproj +++ b/CefSharp.WinForms/CefSharp.WinForms.csproj @@ -43,6 +43,7 @@ + From 54b1520761da125b29322670504e98a2eb56c855 Mon Sep 17 00:00:00 2001 From: amaitland Date: Fri, 6 Feb 2015 21:49:54 +1000 Subject: [PATCH 43/73] Fix problem where stream was being closed and subsequent read attempts threw an exception (e.g. browser refresh) --- CefSharp.Core/Internals/StreamAdapter.cpp | 2 +- CefSharp.Core/Internals/StreamAdapter.h | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CefSharp.Core/Internals/StreamAdapter.cpp b/CefSharp.Core/Internals/StreamAdapter.cpp index 291d40e7e..9791afe1f 100644 --- a/CefSharp.Core/Internals/StreamAdapter.cpp +++ b/CefSharp.Core/Internals/StreamAdapter.cpp @@ -11,7 +11,7 @@ namespace CefSharp { StreamAdapter::~StreamAdapter() { - _stream->Close(); + //Remove the reference to the stream, must be kept open as it might be reused for subsiquent requests (e.g. refresh). _stream = nullptr; } diff --git a/CefSharp.Core/Internals/StreamAdapter.h b/CefSharp.Core/Internals/StreamAdapter.h index 9d8d73454..5b1162ac9 100644 --- a/CefSharp.Core/Internals/StreamAdapter.h +++ b/CefSharp.Core/Internals/StreamAdapter.h @@ -20,7 +20,11 @@ namespace CefSharp public: virtual ~StreamAdapter(); - StreamAdapter(Stream^ stream) : _stream(stream) { } + StreamAdapter(Stream^ stream) : _stream(stream) + { + //Reset stream position + stream->Position = 0; + } virtual size_t Read(void* ptr, size_t size, size_t n); virtual int Seek(int64 offset, int whence); From 572f2bfc7047e41da2c1229a19635e12b279dd66 Mon Sep 17 00:00:00 2001 From: amaitland Date: Sun, 8 Feb 2015 21:03:41 +1000 Subject: [PATCH 44/73] Add --enable-media-stream to CefExample (how to enable webrtc) --- CefSharp.Example/CefExample.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CefSharp.Example/CefExample.cs b/CefSharp.Example/CefExample.cs index f8ef96e27..2c4eab5de 100644 --- a/CefSharp.Example/CefExample.cs +++ b/CefSharp.Example/CefExample.cs @@ -26,6 +26,8 @@ namespace CefSharp.Example //settings.CefCommandLineArgs.Add("renderer-startup-dialog", "renderer-startup-dialog"); //settings.CefCommandLineArgs.Add("disable-gpu", "1"); //settings.CefCommandLineArgs.Add("disable-gpu-vsync", "1"); + //settings.CefCommandLineArgs.Add("enable-media-stream", "1"); //Enable WebRTC + settings.LogSeverity = LogSeverity.Verbose; if (DebuggingSubProcess) From 7c3dcb656ea368ba72a65191c2767552dffaf6ec Mon Sep 17 00:00:00 2001 From: rassilon Date: Wed, 11 Feb 2015 17:30:33 -0500 Subject: [PATCH 45/73] * Code Review changes * Add float right select drop down for additional move test. --- CefSharp.Example/Resources/TooltipTest.html | 5 + CefSharp.WinForms/CefSharp.WinForms.csproj | 3 +- CefSharp.WinForms/ChromiumWebBrowser.cs | 12 +- CefSharp.WinForms/Internals/NativeMethods.cs | 13 ++ ...ner.cs => ParentFormMessageInterceptor.cs} | 120 ++++++++++++------ 5 files changed, 108 insertions(+), 45 deletions(-) create mode 100644 CefSharp.WinForms/Internals/NativeMethods.cs rename CefSharp.WinForms/Internals/{MovingListener.cs => ParentFormMessageInterceptor.cs} (56%) diff --git a/CefSharp.Example/Resources/TooltipTest.html b/CefSharp.Example/Resources/TooltipTest.html index 6de4139d7..0295225b4 100644 --- a/CefSharp.Example/Resources/TooltipTest.html +++ b/CefSharp.Example/Resources/TooltipTest.html @@ -14,6 +14,11 @@ + \ No newline at end of file diff --git a/CefSharp.WinForms/CefSharp.WinForms.csproj b/CefSharp.WinForms/CefSharp.WinForms.csproj index b4b177cd6..c17b5eee6 100644 --- a/CefSharp.WinForms/CefSharp.WinForms.csproj +++ b/CefSharp.WinForms/CefSharp.WinForms.csproj @@ -54,7 +54,8 @@ - + + Component diff --git a/CefSharp.WinForms/ChromiumWebBrowser.cs b/CefSharp.WinForms/ChromiumWebBrowser.cs index 0e8ebac13..f028014e1 100644 --- a/CefSharp.WinForms/ChromiumWebBrowser.cs +++ b/CefSharp.WinForms/ChromiumWebBrowser.cs @@ -14,7 +14,7 @@ namespace CefSharp.WinForms public class ChromiumWebBrowser : Control, IWebBrowserInternal, IWinFormsWebBrowser { private ManagedCefBrowserAdapter managedCefBrowserAdapter; - private MovingListener movingListener; + private ParentFormMessageInterceptor parentFormMessageInterceptor; public BrowserSettings BrowserSettings { get; set; } public string Title { get; set; } @@ -107,13 +107,13 @@ namespace CefSharp.WinForms IsBrowserInitialized = true; // By the time this callback gets called, this control - // is most likely hooked into a parent Form of some sort. - // (Which is what MovingListener relies on.) - // Ensure the MovingListener construction occurs on the WinForms UI thread: + // is most likely hooked into a browser Form of some sort. + // (Which is what ParentFormMessageInterceptor relies on.) + // Ensure the ParentFormMessageInterceptor construction occurs on the WinForms UI thread: this.InvokeOnUiThreadIfRequired(() => { - movingListener = new MovingListener(this); - movingListener.Moving += MovingListenerMoving; + parentFormMessageInterceptor = new ParentFormMessageInterceptor(this); + parentFormMessageInterceptor.Moving += MovingListenerMoving; }); ResizeBrowser(); diff --git a/CefSharp.WinForms/Internals/NativeMethods.cs b/CefSharp.WinForms/Internals/NativeMethods.cs new file mode 100644 index 000000000..3710be351 --- /dev/null +++ b/CefSharp.WinForms/Internals/NativeMethods.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace CefSharp.WinForms.Internals +{ + internal static class NativeMethods + { + public const int WM_MOVE = 0x3; + public const int WM_MOVING = 0x216; + } +} diff --git a/CefSharp.WinForms/Internals/MovingListener.cs b/CefSharp.WinForms/Internals/ParentFormMessageInterceptor.cs similarity index 56% rename from CefSharp.WinForms/Internals/MovingListener.cs rename to CefSharp.WinForms/Internals/ParentFormMessageInterceptor.cs index f5a824600..62148a181 100644 --- a/CefSharp.WinForms/Internals/MovingListener.cs +++ b/CefSharp.WinForms/Internals/ParentFormMessageInterceptor.cs @@ -10,31 +10,40 @@ using System.Windows.Forms; namespace CefSharp.WinForms.Internals { - internal class MovingListener : NativeWindow + internal class ParentFormMessageInterceptor : NativeWindow, IDisposable { public event EventHandler Moving; private bool isMoving = false; private Rectangle movingRectangle; - private Control ParentControl { get; set; } + private ChromiumWebBrowser Browser { get; set; } private Form ParentForm { get; set; } - public MovingListener(Control parent) + public ParentFormMessageInterceptor(ChromiumWebBrowser browser) { - ParentControl = parent; - // Get notified if our parent window changes: - ParentControl.ParentChanged += ParentParentChanged; - // Find the parent form to subclass to monitor WM_MOVE/WM_MOVING + Browser = browser; + // Get notified if our browser window parent changes: + Browser.ParentChanged += ParentParentChanged; + // Find the browser form to subclass to monitor WM_MOVE/WM_MOVING RefindParentForm(); } + /// + /// Call to force refinding of the parent Form. + /// (i.e. top level window that owns the ChromiumWebBrowserControl) + /// public void RefindParentForm() { - ParentParentChanged(ParentControl, null); + ParentParentChanged(Browser, null); } + /// + /// Adjust the form to listen to if the ChromiumWebBrowserControl's parent changes. + /// + /// The ChromiumWebBrowser whose parent has changed. + /// private void ParentParentChanged(object sender, EventArgs e) { Control control = (Control)sender; @@ -59,6 +68,8 @@ namespace CefSharp.WinForms.Internals { newForm.HandleCreated += OnHandleCreated; newForm.HandleDestroyed += OnHandleDestroyed; + // If newForm's Handle has been created already, + // our event listener won't be called, so call it now. if (newForm.IsHandleCreated) { OnHandleCreated(newForm, null); @@ -70,7 +81,6 @@ namespace CefSharp.WinForms.Internals private void OnHandleCreated(object sender, EventArgs e) { AssignHandle(((Form)sender).Handle); - Kernel32.OutputDebugString(String.Format("Attaching '{1:x}' to form '{0:x}'\r\n", ParentForm.Handle, ParentControl.Handle)); } private void OnHandleDestroyed(object sender, EventArgs e) @@ -80,7 +90,7 @@ namespace CefSharp.WinForms.Internals protected override void WndProc(ref Message m) { - bool care = false; + bool isMovingMessage = false; // Negative initial values keeps the compiler quiet and to // ensure we have actual window movement to notify CEF about. @@ -91,27 +101,29 @@ namespace CefSharp.WinForms.Internals // Listen for operating system messages switch (m.Msg) { - // WM_MOVING: - case 0x0216: - movingRectangle = (Rectangle)Marshal.PtrToStructure(m.LParam, typeof(Rectangle)); - x = movingRectangle.Left; - y = movingRectangle.Top; - care = true; - break; - // WM_MOVE - case 0x3: - x = (m.LParam.ToInt32() & 0xffff); - y = ((m.LParam.ToInt32() >> 16) & 0xffff); - care = true; - break; + case NativeMethods.WM_MOVING: + { + movingRectangle = (Rectangle)Marshal.PtrToStructure(m.LParam, typeof(Rectangle)); + x = movingRectangle.Left; + y = movingRectangle.Top; + isMovingMessage = true; + break; + } + case NativeMethods.WM_MOVE: + { + x = (m.LParam.ToInt32() & 0xffff); + y = ((m.LParam.ToInt32() >> 16) & 0xffff); + isMovingMessage = true; + break; + } } // Only notify about movement if: - // * ParentControl Handle Created + // * Browser Handle Created // NOTE: This is checked for paranoia. // This WndProc can't be called unless ParentForm has // its handle created, but that doesn't necessarily mean - // ParentControl has had its handle created. + // Browser has had its handle created. // WinForm controls don't usually get eagerly created Handles // in their constructors. // * ParentForm Actually moved @@ -120,12 +132,12 @@ namespace CefSharp.WinForms.Internals // This check is to simplify the effort here. // Other logic already handles the maximize/minimize // cases just fine. - // You might consider checking ParentControl.Visible and - // not notifying our parent control if the parent control isn't visible. + // You might consider checking Browser.Visible and + // not notifying our browser control if the browser control isn't visible. // However, if you do that, the non-Visible CEF tab will still // have any SELECT drop downs rendering where they shouldn't. - if (care - && ParentControl.IsHandleCreated + if (isMovingMessage + && Browser.IsHandleCreated && ParentForm.WindowState == FormWindowState.Normal && (ParentForm.Left != x || ParentForm.Top != y) @@ -139,16 +151,7 @@ namespace CefSharp.WinForms.Internals && ParentForm.Right >= 0) { OnMoving(); - Kernel32.OutputDebugString(String.Format("Called OnMoving from control '{1:x}' to form '{0:x}'\r\n", ParentForm.Handle, ParentControl.Handle)); } - else - { - Kernel32.OutputDebugString(String.Format("Skipped OnMoving from control '{1:x}' to form '{0:x}'\r\n", ParentForm.Handle, ParentControl.Handle)); - } - } - else if (care) - { - Kernel32.OutputDebugString(String.Format("Skipped OnMoving from control '{1:x}' to form '{0:x}'\r\n", ParentForm.Handle, ParentControl.Handle)); } this.DefWndProc(ref m); } @@ -164,5 +167,46 @@ namespace CefSharp.WinForms.Internals } isMoving = false; } + + public void Dispose() + { + Dispose(true); + } + + protected virtual void Dispose(bool disposing) + { + if (disposing) + { + if (ParentForm != null) + { + ParentForm.HandleCreated -= OnHandleCreated; + ParentForm.HandleDestroyed -= OnHandleDestroyed; + ParentForm = null; + } + + // Unmanaged resource, but release here anyway. + // NativeWindow has its own finalization logic + // that should be run if this instance isn't disposed + // properly before arriving at the finalization thread. + // See: http://referencesource.microsoft.com/#System.Windows.Forms/winforms/Managed/System/WinForms/NativeWindow.cs,147 + // for the gruesome details. + if (this.Handle != IntPtr.Zero) + { + ReleaseHandle(); + } + + if (Browser != null) + { + Browser.ParentChanged -= ParentParentChanged; + Browser = null; + } + } + } + + protected override void OnThreadException(Exception e) + { + // TODO: Do something more interesting here, logging, whatever, something. + base.OnThreadException(e); + } } } From e41c8488aaf361f05780ce4f8ad688f33c05b2b9 Mon Sep 17 00:00:00 2001 From: Per Lundberg Date: Thu, 12 Feb 2015 07:40:33 +0200 Subject: [PATCH 46/73] Fixed incorrect link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4f968c245..7ea181ccc 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Binary releases contain everything needed to embed Chromium in your .Net/CLR app ![CefSharp.Wpf](http://img.shields.io/nuget/v/CefSharp.Wpf.svg?style=flat) for either [WPF](http://www.nuget.org/packages/CefSharp.Wpf/) or [WinForms](http://www.nuget.org/packages/CefSharp.WinForms/) based on Chromium 37 now **including** JS Binding. -**Ultra stable/LTS** Read "He's dead Jim", based on Chromium 25. See the [CefSharp1](https://github.com/jornh/CefSharp/tree/CefSharp1#binary-release) branch README for CefSharp1 info. Please note that this version is no longer supported. +**Ultra stable/LTS** Read "He's dead Jim", based on Chromium 25. See the [CefSharp1](https://github.com/cefsharp/CefSharp/tree/CefSharp1#binary-release) branch README for CefSharp1 info. Please note that this version is no longer supported. # Branches & Forks From fb6d2c50cfeab38cfb2110e44ec6212cab57837f Mon Sep 17 00:00:00 2001 From: Alex Maitland Date: Thu, 12 Feb 2015 20:26:40 +1000 Subject: [PATCH 47/73] Add MyGet reference to Readme.md Add MyGet reference to Readme.md for those looking for CI `nuget` packages --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 7ea181ccc..11a944325 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,9 @@ Apart from code samples mentioned above work-in-progress documentation can be fo Binary releases contain everything needed to embed Chromium in your .Net/CLR application. For usage see [FAQ #8](https://github.com/cefsharp/CefSharp/wiki/Frequently-asked-questions#CefSharp_binaries) item. +**CI Builds**
+Every commit on `master` produces a `Nuget` package. Use at your own risk! [CefSharp MyGet Feed](https://www.myget.org/F/cefsharp/) + **Stable**
![CefSharp.Wpf](http://img.shields.io/nuget/v/CefSharp.Wpf.svg?style=flat) for either [WPF](http://www.nuget.org/packages/CefSharp.Wpf/) or [WinForms](http://www.nuget.org/packages/CefSharp.WinForms/) based on Chromium 37 now **including** JS Binding. From 00b25f5e3fac20b94b3022019fdeefbac6f9e271 Mon Sep 17 00:00:00 2001 From: amaitland Date: Thu, 12 Feb 2015 21:25:10 +1000 Subject: [PATCH 48/73] Split SchemeHandlerFactoryWrapper out into it's own .h/.cpp files --- CefSharp.Core/CefSharp.Core.vcxproj | 2 ++ CefSharp.Core/CefSharp.Core.vcxproj.filters | 6 ++++ CefSharp.Core/Internals/CefSharpApp.h | 1 + CefSharp.Core/SchemeHandlerFactoryWrapper.cpp | 23 +++++++++++++++ CefSharp.Core/SchemeHandlerFactoryWrapper.h | 29 +++++++++++++++++++ CefSharp.Core/SchemeHandlerWrapper.cpp | 11 ------- CefSharp.Core/SchemeHandlerWrapper.h | 13 --------- 7 files changed, 61 insertions(+), 24 deletions(-) create mode 100644 CefSharp.Core/SchemeHandlerFactoryWrapper.cpp create mode 100644 CefSharp.Core/SchemeHandlerFactoryWrapper.h diff --git a/CefSharp.Core/CefSharp.Core.vcxproj b/CefSharp.Core/CefSharp.Core.vcxproj index 7ce9d5629..6f10b405c 100644 --- a/CefSharp.Core/CefSharp.Core.vcxproj +++ b/CefSharp.Core/CefSharp.Core.vcxproj @@ -225,6 +225,7 @@ + @@ -257,6 +258,7 @@ + diff --git a/CefSharp.Core/CefSharp.Core.vcxproj.filters b/CefSharp.Core/CefSharp.Core.vcxproj.filters index 89770fcb7..65c5e8ad7 100644 --- a/CefSharp.Core/CefSharp.Core.vcxproj.filters +++ b/CefSharp.Core/CefSharp.Core.vcxproj.filters @@ -53,6 +53,9 @@ Source Files + + Source Files +
@@ -133,6 +136,9 @@ Header Files + + Header Files + diff --git a/CefSharp.Core/Internals/CefSharpApp.h b/CefSharp.Core/Internals/CefSharpApp.h index bd675a223..1225acb08 100644 --- a/CefSharp.Core/Internals/CefSharpApp.h +++ b/CefSharp.Core/Internals/CefSharpApp.h @@ -7,6 +7,7 @@ #include "include/cef_app.h" #include "CefSettings.h" #include "SchemeHandlerWrapper.h" +#include "SchemeHandlerFactoryWrapper.h" namespace CefSharp { diff --git a/CefSharp.Core/SchemeHandlerFactoryWrapper.cpp b/CefSharp.Core/SchemeHandlerFactoryWrapper.cpp new file mode 100644 index 000000000..33685451f --- /dev/null +++ b/CefSharp.Core/SchemeHandlerFactoryWrapper.cpp @@ -0,0 +1,23 @@ +// Copyright © 2010-2014 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. + +#include "Stdafx.h" +#include "SchemeHandlerFactoryWrapper.h" + +using namespace System::Runtime::InteropServices; +using namespace System::IO; + +namespace CefSharp +{ + CefRefPtr SchemeHandlerFactoryWrapper::Create( + CefRefPtr browser, + CefRefPtr frame, + const CefString& scheme_name, + CefRefPtr request) + { + ISchemeHandler^ handler = _factory->Create(); + CefRefPtr wrapper = new SchemeHandlerWrapper(handler); + return static_cast>(wrapper); + } +} \ No newline at end of file diff --git a/CefSharp.Core/SchemeHandlerFactoryWrapper.h b/CefSharp.Core/SchemeHandlerFactoryWrapper.h new file mode 100644 index 000000000..90823f2e1 --- /dev/null +++ b/CefSharp.Core/SchemeHandlerFactoryWrapper.h @@ -0,0 +1,29 @@ +// Copyright © 2010-2014 The CefSharp Authors. All rights reserved. +// +// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. + +#pragma once + +#include "Stdafx.h" +#include "include/cef_scheme.h" +#include "Internals/AutoLock.h" + +using namespace System; +using namespace System::IO; +using namespace System::Collections::Specialized; + +namespace CefSharp +{ + class SchemeHandlerFactoryWrapper : public CefSchemeHandlerFactory + { + gcroot _factory; + + public: + SchemeHandlerFactoryWrapper(ISchemeHandlerFactory^ factory) + : _factory(factory) {} + + virtual CefRefPtr Create(CefRefPtr browser, CefRefPtr frame, const CefString& scheme_name, CefRefPtr request); + + IMPLEMENT_REFCOUNTING(SchemeHandlerFactoryWrapper); + }; +} \ No newline at end of file diff --git a/CefSharp.Core/SchemeHandlerWrapper.cpp b/CefSharp.Core/SchemeHandlerWrapper.cpp index 43619b1bd..7adab6a07 100644 --- a/CefSharp.Core/SchemeHandlerWrapper.cpp +++ b/CefSharp.Core/SchemeHandlerWrapper.cpp @@ -142,15 +142,4 @@ namespace CefSharp } return -1; } - - CefRefPtr SchemeHandlerFactoryWrapper::Create( - CefRefPtr browser, - CefRefPtr frame, - const CefString& scheme_name, - CefRefPtr request) - { - ISchemeHandler^ handler = _factory->Create(); - CefRefPtr wrapper = new SchemeHandlerWrapper(handler); - return static_cast>(wrapper); - } } \ No newline at end of file diff --git a/CefSharp.Core/SchemeHandlerWrapper.h b/CefSharp.Core/SchemeHandlerWrapper.h index e84a48b4b..ac00b8545 100644 --- a/CefSharp.Core/SchemeHandlerWrapper.h +++ b/CefSharp.Core/SchemeHandlerWrapper.h @@ -49,17 +49,4 @@ namespace CefSharp IMPLEMENT_REFCOUNTING(SchemeHandlerWrapper); }; - - class SchemeHandlerFactoryWrapper : public CefSchemeHandlerFactory - { - gcroot _factory; - - public: - SchemeHandlerFactoryWrapper(ISchemeHandlerFactory^ factory) - : _factory(factory) {} - - virtual CefRefPtr Create(CefRefPtr browser, CefRefPtr frame, const CefString& scheme_name, CefRefPtr request); - - IMPLEMENT_REFCOUNTING(SchemeHandlerFactoryWrapper); - }; } \ No newline at end of file From b678ff168dbad98440e0111e7217a9db6894e17c Mon Sep 17 00:00:00 2001 From: amaitland Date: Sat, 14 Feb 2015 12:13:24 +1000 Subject: [PATCH 49/73] Until WPF zoom issues can be resolved (problems with setting zoom using dependency property). Expose the SetZoomLevel method directly --- CefSharp.Wpf/ChromiumWebBrowser.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CefSharp.Wpf/ChromiumWebBrowser.cs b/CefSharp.Wpf/ChromiumWebBrowser.cs index 5ac2b6731..862f77db7 100644 --- a/CefSharp.Wpf/ChromiumWebBrowser.cs +++ b/CefSharp.Wpf/ChromiumWebBrowser.cs @@ -1462,5 +1462,14 @@ namespace CefSharp.Wpf { managedCefBrowserAdapter.Invalidate(type); } + + /// + /// Change the zoom level to the specified value. Specify 0.0 to reset the zoom level. + /// + /// zoom level + public void SetZoomLevel(double zoomLevel) + { + managedCefBrowserAdapter.SetZoomLevel(zoomLevel); + } } } From ea83684f1881eaee98b4dfc011896e6b3e175159 Mon Sep 17 00:00:00 2001 From: Trever Jones Date: Fri, 13 Feb 2015 23:41:47 -0600 Subject: [PATCH 50/73] Check for null object to prevent NullException in SetFocus --- CefSharp.WinForms/ChromiumWebBrowser.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CefSharp.WinForms/ChromiumWebBrowser.cs b/CefSharp.WinForms/ChromiumWebBrowser.cs index 47e2a6b88..0533f6888 100644 --- a/CefSharp.WinForms/ChromiumWebBrowser.cs +++ b/CefSharp.WinForms/ChromiumWebBrowser.cs @@ -475,7 +475,10 @@ namespace CefSharp.WinForms ///
public void SetFocus(bool isFocused) { - managedCefBrowserAdapter.SetFocus(isFocused); + if (IsBrowserInitialized && managedCefBrowserAdapter != null) + { + managedCefBrowserAdapter.SetFocus(isFocused); + } } } } From 5002b8cb51d78c317984362b702c13e2aa3a58ed Mon Sep 17 00:00:00 2001 From: amaitland Date: Sun, 15 Feb 2015 17:35:56 +1000 Subject: [PATCH 51/73] Set IsBrowserInitialized to false when disposing and then simplify null checks for managedCefBrowserAdapter It's now initialized in the constructor, the relevant check is has the browser been initialized? --- CefSharp.WinForms/ChromiumWebBrowser.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/CefSharp.WinForms/ChromiumWebBrowser.cs b/CefSharp.WinForms/ChromiumWebBrowser.cs index 0533f6888..cd63d92c1 100644 --- a/CefSharp.WinForms/ChromiumWebBrowser.cs +++ b/CefSharp.WinForms/ChromiumWebBrowser.cs @@ -92,6 +92,8 @@ namespace CefSharp.WinForms if (disposing) { + IsBrowserInitialized = false; + if (BrowserSettings != null) { BrowserSettings.Dispose(); @@ -432,7 +434,7 @@ namespace CefSharp.WinForms private void ResizeBrowser() { - if (IsBrowserInitialized && managedCefBrowserAdapter != null) + if (IsBrowserInitialized) { managedCefBrowserAdapter.Resize(Width, Height); } @@ -440,7 +442,7 @@ namespace CefSharp.WinForms public void NotifyMoveOrResizeStarted() { - if (IsBrowserInitialized && managedCefBrowserAdapter != null) + if (IsBrowserInitialized) { managedCefBrowserAdapter.NotifyMoveOrResizeStarted(); } @@ -475,7 +477,7 @@ namespace CefSharp.WinForms /// public void SetFocus(bool isFocused) { - if (IsBrowserInitialized && managedCefBrowserAdapter != null) + if (IsBrowserInitialized) { managedCefBrowserAdapter.SetFocus(isFocused); } From 396eeb41b1b1d6c587f34cd8a3caf9665ce1b6d9 Mon Sep 17 00:00:00 2001 From: amaitland Date: Sun, 15 Feb 2015 22:29:09 +1000 Subject: [PATCH 52/73] Untabify --- CefSharp.Wpf/Rendering/BitmapFactory.cs | 16 ++++++++-------- CefSharp.Wpf/Rendering/WpfBitmapInfo.cs | 10 +++++----- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/CefSharp.Wpf/Rendering/BitmapFactory.cs b/CefSharp.Wpf/Rendering/BitmapFactory.cs index ce08e3861..1c34b777e 100644 --- a/CefSharp.Wpf/Rendering/BitmapFactory.cs +++ b/CefSharp.Wpf/Rendering/BitmapFactory.cs @@ -6,12 +6,12 @@ using CefSharp.Internals; namespace CefSharp.Wpf.Rendering { - public class BitmapFactory : IBitmapFactory - { - public BitmapInfo CreateBitmap(bool isPopup) - { - //return new WritableBitmapInfo { IsPopup = isPopup }; - return new InteropBitmapInfo { IsPopup = isPopup }; - } - } + public class BitmapFactory : IBitmapFactory + { + public BitmapInfo CreateBitmap(bool isPopup) + { + //return new WritableBitmapInfo { IsPopup = isPopup }; + return new InteropBitmapInfo { IsPopup = isPopup }; + } + } } diff --git a/CefSharp.Wpf/Rendering/WpfBitmapInfo.cs b/CefSharp.Wpf/Rendering/WpfBitmapInfo.cs index d77a557d6..6d5e6fd89 100644 --- a/CefSharp.Wpf/Rendering/WpfBitmapInfo.cs +++ b/CefSharp.Wpf/Rendering/WpfBitmapInfo.cs @@ -7,9 +7,9 @@ using CefSharp.Internals; namespace CefSharp.Wpf.Rendering { - public abstract class WpfBitmapInfo : BitmapInfo - { - public abstract void Invalidate(); - public abstract BitmapSource CreateBitmap(); - } + public abstract class WpfBitmapInfo : BitmapInfo + { + public abstract void Invalidate(); + public abstract BitmapSource CreateBitmap(); + } } From 89a04abef9bc7eae93ef48ecac90b8ce86140969 Mon Sep 17 00:00:00 2001 From: amaitland Date: Sun, 15 Feb 2015 22:29:59 +1000 Subject: [PATCH 53/73] Untabify --- CefSharp/IBitmapFactory.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CefSharp/IBitmapFactory.cs b/CefSharp/IBitmapFactory.cs index 446061a80..b989daf69 100644 --- a/CefSharp/IBitmapFactory.cs +++ b/CefSharp/IBitmapFactory.cs @@ -6,8 +6,8 @@ using CefSharp.Internals; namespace CefSharp { - public interface IBitmapFactory - { - BitmapInfo CreateBitmap(bool isPopup); - } + public interface IBitmapFactory + { + BitmapInfo CreateBitmap(bool isPopup); + } } From a3b833efd7f801b5a9ea9d0e5ca9611ea2caa6a7 Mon Sep 17 00:00:00 2001 From: amaitland Date: Tue, 27 Jan 2015 15:28:35 +1000 Subject: [PATCH 54/73] Added ClearSchemeHandlerFactories method incase anyone wants to remove their factories --- CefSharp.Core/Cef.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CefSharp.Core/Cef.h b/CefSharp.Core/Cef.h index 2a2f88c6d..329d01328 100644 --- a/CefSharp.Core/Cef.h +++ b/CefSharp.Core/Cef.h @@ -348,5 +348,14 @@ namespace CefSharp IsInitialized = false; } } + + /// + /// Clear all registered scheme handler factories. + /// + /// Returns false on error. + static bool ClearSchemeHandlerFactories() + { + return CefClearSchemeHandlerFactories(); + } }; } From 415e9ab2c8f62cf37f6cf49d7a9bbe09e244db8b Mon Sep 17 00:00:00 2001 From: amaitland Date: Tue, 27 Jan 2015 15:29:37 +1000 Subject: [PATCH 55/73] Allow setting IsLocal and IsDisplayIsolated for a CustomScheme Added relevant xml comments --- CefSharp.Core/Internals/CefSharpApp.h | 2 +- CefSharp/CefCustomScheme.cs | 58 +++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/CefSharp.Core/Internals/CefSharpApp.h b/CefSharp.Core/Internals/CefSharpApp.h index 1225acb08..1237a1941 100644 --- a/CefSharp.Core/Internals/CefSharpApp.h +++ b/CefSharp.Core/Internals/CefSharpApp.h @@ -57,7 +57,7 @@ namespace CefSharp // when the process is shutting down. // TOOD: Consider adding error handling here. But where do we report any errors that may have occurred? - registrar->AddCustomScheme(StringUtils::ToNative(cefCustomScheme->SchemeName), cefCustomScheme->IsStandard, false, false); + registrar->AddCustomScheme(StringUtils::ToNative(cefCustomScheme->SchemeName), cefCustomScheme->IsStandard, cefCustomScheme->IsLocal, cefCustomScheme->IsDisplayIsolated); } }; diff --git a/CefSharp/CefCustomScheme.cs b/CefSharp/CefCustomScheme.cs index 18c5bf0e9..54034cae5 100644 --- a/CefSharp/CefCustomScheme.cs +++ b/CefSharp/CefCustomScheme.cs @@ -6,14 +6,72 @@ namespace CefSharp { public class CefCustomScheme { + /// + /// Schema Name e.g. custom + /// public string SchemeName { get; set; } + + /// + /// Optional Domain Name. An empty value for a standard scheme + /// will cause the factory to match all domain names. The |domain_name| value + /// will be ignored for non-standard schemes. + /// public string DomainName { get; set; } + + /// + /// If true the scheme will be treated as a standard scheme. + /// Standard schemes are subject to URL canonicalization and parsing rules as + /// defined in the Common Internet Scheme Syntax RFC 1738 Section 3.1 available + /// at http://www.ietf.org/rfc/rfc1738.txt + /// + /// In particular, the syntax for standard scheme URLs must be of the form: + ///
+        ///  [scheme]://[username]:[password]@[host]:[port]/[url-path]
+        /// 
+ /// Standard scheme URLs must have a host component that is a fully qualified + /// domain name as defined in Section 3.5 of RFC 1034 [13] and Section 2.1 of + /// RFC 1123. These URLs will be canonicalized to "scheme://host/path" in the + /// simplest case and "scheme://username:password@host:port/path" in the most + /// explicit case. For example, "scheme:host/path" and "scheme:///host/path" + /// will both be canonicalized to "scheme://host/path". The origin of a + /// standard scheme URL is the combination of scheme, host and port (i.e., + /// "scheme://host:port" in the most explicit case). + /// + /// For non-standard scheme URLs only the "scheme:" component is parsed and + /// canonicalized. The remainder of the URL will be passed to the handler + /// as-is. For example, "scheme:///some%20text" will remain the same. + /// Non-standard scheme URLs cannot be used as a target for form submission. + ///
public bool IsStandard { get; set; } + + /// + /// If true the scheme will be treated as local (i.e. with the + /// same security rules as those applied to "file" URLs). Normal pages cannot + /// link to or access local URLs. Also, by default, local URLs can only perform + /// XMLHttpRequest calls to the same URL (origin + path) that originated the + /// request. To allow XMLHttpRequest calls from a local URL to other URLs with + /// the same origin set the CefSettings.file_access_from_file_urls_allowed + /// value to true. To allow XMLHttpRequest calls from a local URL to all + /// origins set the CefSettings.universal_access_from_file_urls_allowed value + /// to true. + /// + public bool IsLocal { get; set; } + + /// + /// If true the scheme will be treated as display-isolated. + /// This means that pages cannot display these URLs unless they are + /// from the same scheme. For example, pages in another origin cannot create + /// iframes or hyperlinks to URLs with this scheme. + /// + public bool IsDisplayIsolated { get; set; } + public ISchemeHandlerFactory SchemeHandlerFactory { get; set; } public CefCustomScheme() { IsStandard = true; + IsLocal = false; + IsDisplayIsolated = false; } } } From ffe8302921269a1dc4d053eb9564bbb96482c4d9 Mon Sep 17 00:00:00 2001 From: amaitland Date: Sun, 15 Feb 2015 22:37:37 +1000 Subject: [PATCH 56/73] Add license disclaimer --- CefSharp.Wpf/Rendering/InteropBitmapInfo.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CefSharp.Wpf/Rendering/InteropBitmapInfo.cs b/CefSharp.Wpf/Rendering/InteropBitmapInfo.cs index 2b0a52dd4..d0571c64a 100644 --- a/CefSharp.Wpf/Rendering/InteropBitmapInfo.cs +++ b/CefSharp.Wpf/Rendering/InteropBitmapInfo.cs @@ -1,4 +1,8 @@ -using System.Windows.Interop; +// Copyright © 2010-2014 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. + +using System.Windows.Interop; using System.Windows.Media; using System.Windows.Media.Imaging; From 77076b8bbeb97259b15ed8459319572de4384c7f Mon Sep 17 00:00:00 2001 From: amaitland Date: Tue, 17 Feb 2015 12:00:49 +1000 Subject: [PATCH 57/73] Minor code cleanups, add braces, remove extra lines, make methods static --- CefSharp.Wpf/ChromiumWebBrowser.cs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/CefSharp.Wpf/ChromiumWebBrowser.cs b/CefSharp.Wpf/ChromiumWebBrowser.cs index 862f77db7..c01427ade 100644 --- a/CefSharp.Wpf/ChromiumWebBrowser.cs +++ b/CefSharp.Wpf/ChromiumWebBrowser.cs @@ -464,7 +464,6 @@ namespace CefSharp.Wpf toolTip.Visibility = Visibility.Collapsed; toolTip.Closed += OnTooltipClosed; - BackCommand = new DelegateCommand(Back, () => CanGoBack); ForwardCommand = new DelegateCommand(Forward, () => CanGoForward); ReloadCommand = new DelegateCommand(Reload, () => CanReload); @@ -493,6 +492,7 @@ namespace CefSharp.Wpf PresentationSource.AddSourceChangedHandler(this, PresentationSourceChangedHandler); } + private void OnDrop(object sender, DragEventArgs e) { managedCefBrowserAdapter.OnDragTargetDragDrop(GetMouseEvent(e)); @@ -577,7 +577,7 @@ namespace CefSharp.Wpf return dragData; } - private string GetLink(IDataObject data) + private static string GetLink(IDataObject data) { const string asciiUrlDataFormatName = "UniformResourceLocator"; const string unicodeUrlDataFormatName = "UniformResourceLocatorW"; @@ -594,28 +594,27 @@ namespace CefSharp.Wpf } // Try ASCII - if (data.GetDataPresent(asciiUrlDataFormatName)){ + if (data.GetDataPresent(asciiUrlDataFormatName)) + { // Try to read an ASCII URL from the data return ReadUrlFromDragDropData(data, asciiUrlDataFormatName, Encoding.ASCII); } // Not a valid link return null; - } - /// Reads a URL using a particular text encoding from drag-and-drop data. /// The drag-and-drop data. /// The data format name of the URL type. /// The text encoding of the URL type. /// A URL, or if does not contain a URL /// of the correct type. - private string ReadUrlFromDragDropData(IDataObject data, string urlDataFormatName, Encoding urlEncoding) + private static string ReadUrlFromDragDropData(IDataObject data, string urlDataFormatName, Encoding urlEncoding) { // Read the URL from the data string url; - using (Stream urlStream = (Stream)data.GetData(urlDataFormatName)) + using (var urlStream = (Stream)data.GetData(urlDataFormatName)) { using (TextReader reader = new StreamReader(urlStream, urlEncoding)) { @@ -1157,19 +1156,24 @@ namespace CefSharp.Wpf switch (e.ChangedButton) { case MouseButton.Left: + { mouseButtonType = MouseButtonType.Left; break; - + } case MouseButton.Middle: + { mouseButtonType = MouseButtonType.Middle; break; - + } case MouseButton.Right: + { mouseButtonType = MouseButtonType.Right; break; - + } default: + { return; + } } var modifiers = GetModifiers(e); From 5223bbb794bde9b3e41a421c68532850dba8b4c8 Mon Sep 17 00:00:00 2001 From: amaitland Date: Thu, 19 Feb 2015 15:10:22 +1000 Subject: [PATCH 58/73] Add --disable-direct-write command line example --- CefSharp.Example/CefExample.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CefSharp.Example/CefExample.cs b/CefSharp.Example/CefExample.cs index 2c4eab5de..e5c90eaf3 100644 --- a/CefSharp.Example/CefExample.cs +++ b/CefSharp.Example/CefExample.cs @@ -28,6 +28,10 @@ namespace CefSharp.Example //settings.CefCommandLineArgs.Add("disable-gpu-vsync", "1"); //settings.CefCommandLineArgs.Add("enable-media-stream", "1"); //Enable WebRTC + //Disables the DirectWrite font rendering system on windows. + //Possibly useful when experiencing blury fonts. + //settings.CefCommandLineArgs.Add("disable-direct-write", "1"); + settings.LogSeverity = LogSeverity.Verbose; if (DebuggingSubProcess) From 0e230aa957369efec8101e399017b609801c9b65 Mon Sep 17 00:00:00 2001 From: amaitland Date: Thu, 19 Feb 2015 15:11:55 +1000 Subject: [PATCH 59/73] Add link to chromium command line args --- CefSharp.Example/CefExample.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CefSharp.Example/CefExample.cs b/CefSharp.Example/CefExample.cs index e5c90eaf3..d2552d39a 100644 --- a/CefSharp.Example/CefExample.cs +++ b/CefSharp.Example/CefExample.cs @@ -20,6 +20,10 @@ namespace CefSharp.Example // Environment.SetEnvironmentVariable("GOOGLE_DEFAULT_CLIENT_ID", ""); // Environment.SetEnvironmentVariable("GOOGLE_DEFAULT_CLIENT_SECRET", ""); + //Chromium Command Line args + //http://peter.sh/experiments/chromium-command-line-switches/ + //NOTE: Note all relevant in relation to `CefSharp`, use for reference purposes only. + var settings = new CefSettings(); settings.RemoteDebuggingPort = 8088; //settings.CefCommandLineArgs.Add("renderer-process-limit", "1"); From 66dabdbf33a0aa903243b43b0f57fad1880318ea Mon Sep 17 00:00:00 2001 From: dmrzn Date: Fri, 20 Feb 2015 15:21:22 +0300 Subject: [PATCH 60/73] Fixed memory leak issues: 1. Unsubscription from CleanupElement.Unloaded event 2. Unsubscription from tooltipTimer.Tick event 3. Removing source hook --- CefSharp.Wpf/ChromiumWebBrowser.cs | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/CefSharp.Wpf/ChromiumWebBrowser.cs b/CefSharp.Wpf/ChromiumWebBrowser.cs index 862f77db7..248d700e5 100644 --- a/CefSharp.Wpf/ChromiumWebBrowser.cs +++ b/CefSharp.Wpf/ChromiumWebBrowser.cs @@ -362,6 +362,16 @@ namespace CefSharp.Wpf IsVisibleChanged -= OnIsVisibleChanged; + if (tooltipTimer != null) + { + tooltipTimer.Tick -= OnTooltipTimerTick; + } + + if (CleanupElement != null) + { + CleanupElement.Unloaded -= OnCleanupElementUnloaded; + } + foreach (var disposable in disposables) { disposable.Dispose(); @@ -372,6 +382,8 @@ namespace CefSharp.Wpf Cef.RemoveDisposable(this); + RemoveSourceHook(); + managedCefBrowserAdapter = null; } @@ -651,12 +663,20 @@ namespace CefSharp.Wpf { if (source != null && sourceHook != null) { - source.RemoveHook(sourceHook); - source = null; + RemoveSourceHook(); } } } + private void RemoveSourceHook() + { + if (source != null && sourceHook != null) + { + source.RemoveHook(sourceHook); + source = null; + } + } + private void CreateOffscreenBrowserWhenActualSizeChanged() { if (browserCreated || System.ComponentModel.DesignerProperties.GetIsInDesignMode(this)) @@ -1192,6 +1212,11 @@ namespace CefSharp.Wpf //Added null check -> binding-triggered changes of Address will lead to a nullref after Dispose has been called. if (managedCefBrowserAdapter != null) { + if (tooltipTimer != null) + { + tooltipTimer.Tick -= OnTooltipTimerTick; + } + // TODO: Consider making the delay here configurable. tooltipTimer = new DispatcherTimer( TimeSpan.FromSeconds(0.5), From 36d364951c2d7e157d489c5d0dfaca6e5b6d3126 Mon Sep 17 00:00:00 2001 From: amaitland Date: Tue, 24 Feb 2015 10:48:45 +1000 Subject: [PATCH 61/73] Upgrade cef reference to 3.2171.1979 (strange that it wasn't already) --- build.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.ps1 b/build.ps1 index 321ea2f3c..ee2c3cf5a 100644 --- a/build.ps1 +++ b/build.ps1 @@ -3,11 +3,11 @@ param( [Parameter(Position = 0)] [string] $Target = "nupkg", [Parameter(Position = 1)] - [string] $Version = "39.0.0-pre01", + [string] $Version = "39.0.0-pre03", [Parameter(Position = 2)] [string] $AssemblyVersion = "39.0.0", [Parameter(Position = 3)] - [string] $RedistVersion = "3.2171.1972" + [string] $RedistVersion = "3.2171.1979" ) $WorkingDir = split-path -parent $MyInvocation.MyCommand.Definition From 80b4580fad9793173aa35441b5a31120dd943b29 Mon Sep 17 00:00:00 2001 From: amaitland Date: Tue, 24 Feb 2015 11:58:32 +1000 Subject: [PATCH 62/73] Remove duplicate null check --- CefSharp.Wpf/ChromiumWebBrowser.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/CefSharp.Wpf/ChromiumWebBrowser.cs b/CefSharp.Wpf/ChromiumWebBrowser.cs index 5551ed784..fd7ef6189 100644 --- a/CefSharp.Wpf/ChromiumWebBrowser.cs +++ b/CefSharp.Wpf/ChromiumWebBrowser.cs @@ -662,10 +662,7 @@ namespace CefSharp.Wpf } else if (args.OldSource != null) { - if (source != null && sourceHook != null) - { - RemoveSourceHook(); - } + RemoveSourceHook(); } } From 8b41c8ec986e8953fd3bb97b659dec69dafd705c Mon Sep 17 00:00:00 2001 From: amaitland Date: Tue, 24 Feb 2015 12:12:14 +1000 Subject: [PATCH 63/73] Cleanup DPI transform code slightly - removed unused methods Tempting to remove the popup code as it's not actually used - leaving for now --- CefSharp.Wpf/ChromiumWebBrowser.cs | 38 ++++++++---------------------- 1 file changed, 10 insertions(+), 28 deletions(-) diff --git a/CefSharp.Wpf/ChromiumWebBrowser.cs b/CefSharp.Wpf/ChromiumWebBrowser.cs index fd7ef6189..73e08e48d 100644 --- a/CefSharp.Wpf/ChromiumWebBrowser.cs +++ b/CefSharp.Wpf/ChromiumWebBrowser.cs @@ -34,7 +34,6 @@ namespace CefSharp.Wpf private Image image; private Image popupImage; private Popup popup; - private ScaleTransform dpiTransform; private readonly List disposables = new List(); public BrowserSettings BrowserSettings { get; set; } @@ -728,26 +727,25 @@ namespace CefSharp.Wpf { base.OnApplyTemplate(); - CheckIsNonStandardDpi(); - // Create main window Content = image = CreateImage(); - Transform(image); popup = CreatePopup(); - Transform(popup); } - private static Image CreateImage() + private Image CreateImage() { - var temp = new Image(); + var img = new Image(); - RenderOptions.SetBitmapScalingMode(temp, BitmapScalingMode.NearestNeighbor); + RenderOptions.SetBitmapScalingMode(img, BitmapScalingMode.NearestNeighbor); - temp.Stretch = Stretch.None; - temp.HorizontalAlignment = HorizontalAlignment.Left; - temp.VerticalAlignment = VerticalAlignment.Top; - return temp; + img.Stretch = Stretch.None; + img.HorizontalAlignment = HorizontalAlignment.Left; + img.VerticalAlignment = VerticalAlignment.Top; + //Scale Image based on DPI settings + img.LayoutTransform = new ScaleTransform(1 / matrix.M11, 1 / matrix.M22); + + return img; } private Popup CreatePopup() @@ -765,22 +763,6 @@ namespace CefSharp.Wpf return newPopup; } - private void Transform(FrameworkElement element) - { - if (dpiTransform != null) - { - element.LayoutTransform = dpiTransform; - } - } - - private void CheckIsNonStandardDpi() - { - dpiTransform = new ScaleTransform( - 1 / matrix.M11, - 1 / matrix.M22 - ); - } - private IntPtr SourceHook(IntPtr hWnd, int message, IntPtr wParam, IntPtr lParam, ref bool handled) { if(handled) From 6b51d5759d53d15d0ad5b32a550784b8a08043d1 Mon Sep 17 00:00:00 2001 From: rassilon Date: Mon, 23 Feb 2015 22:15:37 -0500 Subject: [PATCH 64/73] Notify browser control directly instead of using an event. --- .../Internals/ParentFormMessageInterceptor.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/CefSharp.WinForms/Internals/ParentFormMessageInterceptor.cs b/CefSharp.WinForms/Internals/ParentFormMessageInterceptor.cs index 62148a181..1d7318900 100644 --- a/CefSharp.WinForms/Internals/ParentFormMessageInterceptor.cs +++ b/CefSharp.WinForms/Internals/ParentFormMessageInterceptor.cs @@ -12,9 +12,14 @@ namespace CefSharp.WinForms.Internals { internal class ParentFormMessageInterceptor : NativeWindow, IDisposable { - public event EventHandler Moving; - + /// + /// Keep track of whether a move is in progress. + /// private bool isMoving = false; + + /// + /// Used to determine the coordinates involved in the move + /// private Rectangle movingRectangle; private ChromiumWebBrowser Browser { get; set; } @@ -159,12 +164,7 @@ namespace CefSharp.WinForms.Internals protected virtual void OnMoving() { isMoving = true; - var handler = Moving; - - if (handler != null) - { - handler(this, null); - } + Browser.NotifyMoveOrResizeStarted(); isMoving = false; } From e649e2e64bc6e493fe36953895bd94ab4a7dd532 Mon Sep 17 00:00:00 2001 From: amaitland Date: Tue, 24 Feb 2015 13:22:06 +1000 Subject: [PATCH 65/73] Moving event was removed, now calls NotifyMoveOrResizeStarted directly --- CefSharp.WinForms/ChromiumWebBrowser.cs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/CefSharp.WinForms/ChromiumWebBrowser.cs b/CefSharp.WinForms/ChromiumWebBrowser.cs index df7c0a7cd..1c2beddaa 100644 --- a/CefSharp.WinForms/ChromiumWebBrowser.cs +++ b/CefSharp.WinForms/ChromiumWebBrowser.cs @@ -122,14 +122,6 @@ namespace CefSharp.WinForms base.Dispose(disposing); } - private void MovingListenerMoving(object sender, EventArgs e) - { - if (IsBrowserInitialized) - { - NotifyMoveOrResizeStarted(); - } - } - void IWebBrowserInternal.OnInitialized() { IsBrowserInitialized = true; @@ -141,7 +133,6 @@ namespace CefSharp.WinForms this.InvokeOnUiThreadIfRequired(() => { parentFormMessageInterceptor = new ParentFormMessageInterceptor(this); - parentFormMessageInterceptor.Moving += MovingListenerMoving; }); ResizeBrowser(); From d9e84a5a10aa77d4d628c8990edaffca0d111317 Mon Sep 17 00:00:00 2001 From: rassilon Date: Mon, 23 Feb 2015 22:25:41 -0500 Subject: [PATCH 66/73] Expose Cross-Origin Whitelist from Cef.XXX as static methods. --- CefSharp.Core/Cef.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/CefSharp.Core/Cef.h b/CefSharp.Core/Cef.h index 329d01328..b3e335d8d 100644 --- a/CefSharp.Core/Cef.h +++ b/CefSharp.Core/Cef.h @@ -7,6 +7,7 @@ #include #include #include +#include #include "Internals/CefSharpApp.h" #include "Internals/CookieVisitor.h" @@ -168,6 +169,49 @@ namespace CefSharp return success; } + /// + // See documentation in cef_origin_whitelist.h + /// + /*--cef(optional_param=target_domain)--*/ + static bool AddCrossOriginWhitelistEntry(String^ source_origin, + String^ target_protocol, + String^ target_domain, + bool allow_target_subdomains) + { + return CefAddCrossOriginWhitelistEntry( + StringUtils::ToNative(source_origin), + StringUtils::ToNative(target_protocol), + StringUtils::ToNative(target_domain), + allow_target_subdomains); + } + + /// + // Remove an entry from the cross-origin access whitelist. Returns false if + // |source_origin| is invalid or the whitelist cannot be accessed. + /// + /*--cef(optional_param=target_domain)--*/ + static bool RemoveCrossOriginWhitelistEntry(String^ source_origin, + String^ target_protocol, + String^ target_domain, + bool allow_target_subdomains) + { + return CefRemoveCrossOriginWhitelistEntry( + StringUtils::ToNative(source_origin), + StringUtils::ToNative(target_protocol), + StringUtils::ToNative(target_domain), + allow_target_subdomains); + } + + /// + // Remove all entries from the cross-origin access whitelist. Returns false if + // the whitelist cannot be accessed. + /// + /*--cef()--*/ + static bool ClearCrossOriginWhitelist() + { + return CefClearCrossOriginWhitelist(); + } + /// Visits all cookies using the provided Cookie Visitor. The returned cookies are sorted by longest path, then by earliest creation date. /// A user-provided Cookie Visitor implementation. /// Returns false if the CookieManager is not available; otherwise, true. From 9060ca8183650199cad36c2310e1d7ad2788b80a Mon Sep 17 00:00:00 2001 From: amaitland Date: Tue, 24 Feb 2015 13:28:14 +1000 Subject: [PATCH 67/73] Resharper inspired cleanups Change line wrapping slightly (no need to be so aggressive when wrapping when < 132 columns) --- .../Internals/ParentFormMessageInterceptor.cs | 37 ++++++++----------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/CefSharp.WinForms/Internals/ParentFormMessageInterceptor.cs b/CefSharp.WinForms/Internals/ParentFormMessageInterceptor.cs index 1d7318900..45a86b4e6 100644 --- a/CefSharp.WinForms/Internals/ParentFormMessageInterceptor.cs +++ b/CefSharp.WinForms/Internals/ParentFormMessageInterceptor.cs @@ -2,7 +2,6 @@ // // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. -using CefSharp.Internals; using System; using System.Drawing; using System.Runtime.InteropServices; @@ -15,7 +14,7 @@ namespace CefSharp.WinForms.Internals /// /// Keep track of whether a move is in progress. /// - private bool isMoving = false; + private bool isMoving; /// /// Used to determine the coordinates involved in the move @@ -51,15 +50,13 @@ namespace CefSharp.WinForms.Internals /// private void ParentParentChanged(object sender, EventArgs e) { - Control control = (Control)sender; - Form oldForm = ParentForm; - Form newForm = control.FindForm(); - if (oldForm == null - || newForm == null - || oldForm.Handle != newForm.Handle - ) + var control = (Control)sender; + var oldForm = ParentForm; + var newForm = control.FindForm(); + + if (oldForm == null || newForm == null || oldForm.Handle != newForm.Handle) { - if (this.Handle != IntPtr.Zero) + if (Handle != IntPtr.Zero) { ReleaseHandle(); } @@ -95,18 +92,18 @@ namespace CefSharp.WinForms.Internals protected override void WndProc(ref Message m) { - bool isMovingMessage = false; + var isMovingMessage = false; // Negative initial values keeps the compiler quiet and to // ensure we have actual window movement to notify CEF about. const int invalidMoveCoordinate = -1; - int x = invalidMoveCoordinate; - int y = invalidMoveCoordinate; + var x = invalidMoveCoordinate; + var y = invalidMoveCoordinate; // Listen for operating system messages switch (m.Msg) { - case NativeMethods.WM_MOVING: + case NativeMethods.WM_MOVING: { movingRectangle = (Rectangle)Marshal.PtrToStructure(m.LParam, typeof(Rectangle)); x = movingRectangle.Left; @@ -114,7 +111,7 @@ namespace CefSharp.WinForms.Internals isMovingMessage = true; break; } - case NativeMethods.WM_MOVE: + case NativeMethods.WM_MOVE: { x = (m.LParam.ToInt32() & 0xffff); y = ((m.LParam.ToInt32() >> 16) & 0xffff); @@ -144,21 +141,19 @@ namespace CefSharp.WinForms.Internals if (isMovingMessage && Browser.IsHandleCreated && ParentForm.WindowState == FormWindowState.Normal - && (ParentForm.Left != x - || ParentForm.Top != y) + && (ParentForm.Left != x || ParentForm.Top != y) && !isMoving) { // ParentForm.Left & .Right are negative when the window // is transitioning from maximized to normal. // If we are transitioning, the form will also receive // a WM_SIZE which can deal with the move/size combo itself. - if (ParentForm.Left >= 0 - && ParentForm.Right >= 0) + if (ParentForm.Left >= 0 && ParentForm.Right >= 0) { OnMoving(); } } - this.DefWndProc(ref m); + DefWndProc(ref m); } protected virtual void OnMoving() @@ -190,7 +185,7 @@ namespace CefSharp.WinForms.Internals // properly before arriving at the finalization thread. // See: http://referencesource.microsoft.com/#System.Windows.Forms/winforms/Managed/System/WinForms/NativeWindow.cs,147 // for the gruesome details. - if (this.Handle != IntPtr.Zero) + if (Handle != IntPtr.Zero) { ReleaseHandle(); } From 113512c3dbcda9a37e57059083d01e6ea13c2281 Mon Sep 17 00:00:00 2001 From: amaitland Date: Tue, 24 Feb 2015 13:30:26 +1000 Subject: [PATCH 68/73] Re-add Browser.IsBrowserInitialized check (IsBrowserInitialized is now set to false when disposing, so just avoids any potential null pointer exceptions) --- .../Internals/ParentFormMessageInterceptor.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CefSharp.WinForms/Internals/ParentFormMessageInterceptor.cs b/CefSharp.WinForms/Internals/ParentFormMessageInterceptor.cs index 45a86b4e6..25bb2a3db 100644 --- a/CefSharp.WinForms/Internals/ParentFormMessageInterceptor.cs +++ b/CefSharp.WinForms/Internals/ParentFormMessageInterceptor.cs @@ -159,7 +159,12 @@ namespace CefSharp.WinForms.Internals protected virtual void OnMoving() { isMoving = true; - Browser.NotifyMoveOrResizeStarted(); + + if (Browser.IsBrowserInitialized) + { + Browser.NotifyMoveOrResizeStarted(); + } + isMoving = false; } From e582c6cf8e433941ec771ecf0658a4dd3114ad42 Mon Sep 17 00:00:00 2001 From: rassilon Date: Mon, 23 Feb 2015 23:13:00 -0500 Subject: [PATCH 69/73] Adjust parameter names and reformat CEF docs to .net notation. --- CefSharp.Core/Cef.h | 103 +++++++++++++++++++++++++++++++------------- 1 file changed, 74 insertions(+), 29 deletions(-) diff --git a/CefSharp.Core/Cef.h b/CefSharp.Core/Cef.h index b3e335d8d..d5ff05a07 100644 --- a/CefSharp.Core/Cef.h +++ b/CefSharp.Core/Cef.h @@ -169,44 +169,89 @@ namespace CefSharp return success; } + /// Add an entry to the cross-origin whitelist. + /// The origin allowed to be accessed by the target protocol/domain. + /// The target protocol allowed to access the source origin. + /// The optional target domain allowed to access the source origin. + /// If set to true would allow a blah.example.com if the + /// URL (like http://www.example.com) will be allowed access to + /// all resources hosted on the specified and . + /// If is non-empty and if false only + /// exact domain matches will be allowed. If contains a top- + /// level domain component (like "example.com") and is + /// true sub-domain matches will be allowed. If is empty and + /// "/> if true all domains and IP addresses will be + /// allowed. + // + /// This method cannot be used to bypass the restrictions on local or display + /// isolated schemes. See the comments on for more + /// information. /// - // See documentation in cef_origin_whitelist.h - /// - /*--cef(optional_param=target_domain)--*/ - static bool AddCrossOriginWhitelistEntry(String^ source_origin, - String^ target_protocol, - String^ target_domain, - bool allow_target_subdomains) + /// This function may be called on any thread. Returns false if + /// is invalid or the whitelist cannot be accessed. + /// + static bool AddCrossOriginWhitelistEntry( + String^ sourceOrigin, + String^ targetProtocol, + String^ targetDomain, + bool allowTargetSubdomains) { return CefAddCrossOriginWhitelistEntry( - StringUtils::ToNative(source_origin), - StringUtils::ToNative(target_protocol), - StringUtils::ToNative(target_domain), - allow_target_subdomains); + StringUtils::ToNative(sourceOrigin), + StringUtils::ToNative(targetProtocol), + StringUtils::ToNative(targetDomain), + allowTargetSubdomains); } - /// - // Remove an entry from the cross-origin access whitelist. Returns false if - // |source_origin| is invalid or the whitelist cannot be accessed. - /// - /*--cef(optional_param=target_domain)--*/ - static bool RemoveCrossOriginWhitelistEntry(String^ source_origin, - String^ target_protocol, - String^ target_domain, - bool allow_target_subdomains) + /// Remove entry from cross-origin whitelist + /// The origin allowed to be accessed by the target protocol/domain. + /// The target protocol allowed to access the source origin. + /// The optional target domain allowed to access the source origin. + /// If set to true would allow a blah.example.com if the + /// is invalid or the whitelist cannot be accessed. + /// + static bool RemoveCrossOriginWhitelistEntry(String^ sourceOrigin, + String^ targetProtocol, + String^ targetDomain, + bool allowTargetSubdomains) + { return CefRemoveCrossOriginWhitelistEntry( - StringUtils::ToNative(source_origin), - StringUtils::ToNative(target_protocol), - StringUtils::ToNative(target_domain), - allow_target_subdomains); + StringUtils::ToNative(sourceOrigin), + StringUtils::ToNative(targetProtocol), + StringUtils::ToNative(targetDomain), + allowTargetSubdomains); } - /// - // Remove all entries from the cross-origin access whitelist. Returns false if - // the whitelist cannot be accessed. - /// - /*--cef()--*/ + /// Remove all entries from the cross-origin access whitelist. + /// + /// Remove all entries from the cross-origin access whitelist. Returns false if + /// the whitelist cannot be accessed. + /// static bool ClearCrossOriginWhitelist() { return CefClearCrossOriginWhitelist(); From cbe4abd327fc38a64b0d99865594ef03654aba74 Mon Sep 17 00:00:00 2001 From: amaitland Date: Tue, 24 Feb 2015 14:40:19 +1000 Subject: [PATCH 70/73] Explicitly dispose parentFormMessageInterceptor --- CefSharp.WinForms/ChromiumWebBrowser.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CefSharp.WinForms/ChromiumWebBrowser.cs b/CefSharp.WinForms/ChromiumWebBrowser.cs index 1c2beddaa..a5115036d 100644 --- a/CefSharp.WinForms/ChromiumWebBrowser.cs +++ b/CefSharp.WinForms/ChromiumWebBrowser.cs @@ -101,6 +101,12 @@ namespace CefSharp.WinForms BrowserSettings = null; } + if (parentFormMessageInterceptor != null) + { + parentFormMessageInterceptor.Dispose(); + parentFormMessageInterceptor = null; + } + if (managedCefBrowserAdapter != null) { managedCefBrowserAdapter.Dispose(); From a247e1b149f8b4ab43e5e61e255d3636cd9f9afa Mon Sep 17 00:00:00 2001 From: rassilon Date: Tue, 24 Feb 2015 01:34:36 -0500 Subject: [PATCH 71/73] Some more edits for the NuGet readme. --- NuGet/Readme.txt | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/NuGet/Readme.txt b/NuGet/Readme.txt index 90ce4ee03..b220c7e4e 100644 --- a/NuGet/Readme.txt +++ b/NuGet/Readme.txt @@ -1,16 +1,29 @@ CefSharp Nuget Package +CefSharp is a .Net wrapping library for CEF (Chromium Embedded Framework) https://code.google.com/p/chromiumembedded/ +CEF is a C/C++ library that allows developers to embed the HTML content rendering strengths of Google's Chrome open source WebKit engine (Chromium). + - Make sure you set either `x86` or x64`. (Won't work with `AnyCpu`) - After installing the `Nuget` package we recommend closing Visual Studio completely and then reopening (This ensures your references show up and you have full intellisense). - Check your output `\bin` directory to make sure the appropriate references have been copied. Basic Troubleshooting -- Info about missing dependencies -- +- Please ensure your binaries directory contains these required dependencies: + * libcef.dll (CEF code) + * icudtl.dat (Unicode Support data) + * CefSharp.Core.dll, CefSharp.dll, + CefSharp.BrowserSubprocess.exe, CefSharp.BrowserSubProcess.Core.dll + - These are required CefSharp binaries that are the common core logic binaries of CefSharp. + * One of the following UI presentation approaches: + * CefSharp.WinForms.dll + * CefSharp.Wpf.dll +- Additional optional CEF files are described at: https://github.com/cefsharp/cef-binary/blob/master/README.txt#L88 + NOTE: CefSharp does not currently support CEF sandboxing so wow_helper.exe is not currently useful. -For further help please read the following +For further help please read the following content: +- CefSharp's Wiki on github: https://github.com/cefsharp/CefSharp/wiki - Minimal Example Links -- FAQ +- FAQ: https://github.com/cefsharp/CefSharp/wiki/Frequently-asked-questions - Troubleshooting guide - Google Groups - Regular Example Links From b22c0ec736d185bda914af7b6ba7f0336f99b20a Mon Sep 17 00:00:00 2001 From: amaitland Date: Tue, 24 Feb 2015 23:16:56 +1000 Subject: [PATCH 72/73] Add some more links and refinements to nuget Readme.txt --- NuGet/Readme.txt | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/NuGet/Readme.txt b/NuGet/Readme.txt index b220c7e4e..0c06f0542 100644 --- a/NuGet/Readme.txt +++ b/NuGet/Readme.txt @@ -1,14 +1,16 @@ CefSharp Nuget Package -CefSharp is a .Net wrapping library for CEF (Chromium Embedded Framework) https://code.google.com/p/chromiumembedded/ -CEF is a C/C++ library that allows developers to embed the HTML content rendering strengths of Google's Chrome open source WebKit engine (Chromium). +Background: + CefSharp is a .Net wrapping library for CEF (Chromium Embedded Framework) https://code.google.com/p/chromiumembedded/ + CEF is a C/C++ library that allows developers to embed the HTML content rendering strengths of Google's Chrome open source WebKit engine (Chromium). -- Make sure you set either `x86` or x64`. (Won't work with `AnyCpu`) -- After installing the `Nuget` package we recommend closing Visual Studio completely and then reopening (This ensures your references show up and you have full intellisense). -- Check your output `\bin` directory to make sure the appropriate references have been copied. +Post Installation: + - Make sure you set either `x86` or x64`. (Won't work with `AnyCpu`) + - After installing the `Nuget` package we recommend closing Visual Studio completely and then reopening (This ensures your references show up and you have full intellisense). + - Check your output `\bin` directory to make sure the appropriate references have been copied. -Basic Troubleshooting -- Please ensure your binaries directory contains these required dependencies: +Basic Troubleshooting: + - Please ensure your binaries directory contains these required dependencies: * libcef.dll (CEF code) * icudtl.dat (Unicode Support data) * CefSharp.Core.dll, CefSharp.dll, @@ -17,18 +19,19 @@ Basic Troubleshooting * One of the following UI presentation approaches: * CefSharp.WinForms.dll * CefSharp.Wpf.dll -- Additional optional CEF files are described at: https://github.com/cefsharp/cef-binary/blob/master/README.txt#L88 - NOTE: CefSharp does not currently support CEF sandboxing so wow_helper.exe is not currently useful. + * CefSharp.OffScreen.dll + - Additional optional CEF files are described at: https://github.com/cefsharp/cef-binary/blob/master/README.txt#L88 + NOTE: CefSharp does not currently support CEF sandboxing so wow_helper.exe is not currently useful. For further help please read the following content: -- CefSharp's Wiki on github: https://github.com/cefsharp/CefSharp/wiki -- Minimal Example Links -- FAQ: https://github.com/cefsharp/CefSharp/wiki/Frequently-asked-questions -- Troubleshooting guide -- Google Groups -- Regular Example Links -- Only when you've exhausted all other options then open an issue on `GitHub` - + - CefSharp GitHub https://github.com/cefsharp/CefSharp + - CefSharp's Wiki on github (https://github.com/cefsharp/CefSharp/wiki) + - Minimal Example Projects showing the browser in action (https://github.com/cefsharp/CefSharp.MinimalExample) + - FAQ: https://github.com/cefsharp/CefSharp/wiki/Frequently-asked-questions + - Troubleshooting guide (https://github.com/cefsharp/CefSharp/wiki/Trouble-Shooting) + - Google Groups (https://groups.google.com/forum/#!forum/cefsharp) + - CefSharp vs Cef (https://github.com/cefsharp/CefSharp/blob/master/CONTRIBUTING.md#cefsharp-vs-cef) + - Only when you've exhausted all other options then open an issue on `GitHub` Please consider giving back, it's only with your help will this project to continue. From e6c2e13078dee058a02d37be27da33b15fdd13e0 Mon Sep 17 00:00:00 2001 From: amaitland Date: Tue, 24 Feb 2015 23:45:47 +1000 Subject: [PATCH 73/73] Add no-proxy-server example command line args --- CefSharp.Example/CefExample.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/CefSharp.Example/CefExample.cs b/CefSharp.Example/CefExample.cs index d2552d39a..103aecea1 100644 --- a/CefSharp.Example/CefExample.cs +++ b/CefSharp.Example/CefExample.cs @@ -31,6 +31,7 @@ namespace CefSharp.Example //settings.CefCommandLineArgs.Add("disable-gpu", "1"); //settings.CefCommandLineArgs.Add("disable-gpu-vsync", "1"); //settings.CefCommandLineArgs.Add("enable-media-stream", "1"); //Enable WebRTC + //settings.CefCommandLineArgs.Add("no-proxy-server", "1"); //Don't use a proxy server, always make direct connections. Overrides any other proxy server flags that are passed. //Disables the DirectWrite font rendering system on windows. //Possibly useful when experiencing blury fonts.