419 Commits

Author SHA1 Message Date
amaitland 9de4b8242a WinForms - Possible null reference when Dispose
If you've somehow managed to set BrowserSettings to null then Dispose would throw a NullReferenceException
2020-07-02 10:03:25 +10:00
amaitland 545cbce36d WinForms - Form minimise set browser size to 0,0
When the form is minimized set the browser window size to 0x0 to reduce resource usage.

https://github.com/chromiumembedded/cef/blob/c7701b8a6168f105f2c2d6b239ce3958da3e3f13/tests/cefclient/browser/browser_window_std_win.cc#L89

Issue #2922
2020-05-05 08:30:27 +10:00
amaitland 1824a0334d WPF/WinForms/OffScreen - CanExecuteJavascriptInMainFrame incorrectly false after loading page with different origin
Proof of concept for a workaround. The frameId for the second OnContextReleased that arrives after the OnContextCreated from
the old render process strangely has a frameId greater than the new frameId

TODO: Unit tests

Issue #3021
2020-05-04 12:34:47 +10:00
amaitland 73e7c5de13 Core - Rename AbstractCefSettings to CefSettingsBase
This is a somewhat cosmetic change so the API Doc looks better, the
classes appear next to each other (CefSettings, CefSettingsBase)
when sorted alphabetically.

Resolves #3093
2020-04-06 14:59:33 +10:00
amaitland defc2c3af6 WinForms - Remove WS_EX_NOACTIVATE style on initial page Load
- When LoadingStateChanged occurs we remove the ExStyle WS_EX_NOACTIVATE flag
- Previous change to the FocusHandler was reverted in 917480da3b

Updated to match the cefclient example
https://github.com/chromiumembedded/cef/blob/9df4a54308a88fd80c5774d91c62da35afb5fd1b/tests/cefclient/browser/root_window_win.cc#L1088

Resolves #2776
2020-04-06 10:48:53 +10:00
amaitland 917480da3b Revert "WinForms - DefaultFocusHandler now allows browser to take focus on initial load"
This reverts commit f725ab3907.

Issue #2776
2020-04-06 10:28:54 +10:00
amaitland 4cac03bb93 WinForms - Add ParkControlOnHandleDestroyed property.
When true the browser will always be moved to a parking control when the ChromiumWebBrowser handle is destroyed.
By default it's only moved when RecreatingHandle = true;

Resolves #2840
2020-04-02 11:34:05 +10:00
amaitland 270b5c496e WinForms - Dispose of FrameworkCreated BrowserSettings when Control Disposed
If BrowserSettings is FrameworkCreated we dispose of the BrowserSettings object immediately,
this code was in ManagedCefBrowserAdapter::CreateBrowser, now it's duplicated in WPF/OffScreen

The WinForms version has a slightly different behaviour, we keep the browserSettings reference
until the Control is Disposed incase the Control handle is destroyed then Created again.

Issue #2840
2020-04-01 09:42:56 +10:00
Alex Maitland 81871ff4bb WinForms - RecreatingHandle re-parent browser to parkingControl (#3090)
Use a parkingControl as a temporary parent for the CefBrowser while the handle is recreating.

https://docs.microsoft.com/en-us/archive/blogs/sburke/flashback-windows-forms-parking-window

Issue #2840 should now create a new browser correctly when the MdiParent is changed,
the browser state won't be persisted, I believe this is expected as detailed in the .Net Source
https://referencesource.microsoft.com/#System.Windows.Forms/winforms/Managed/System/WinForms/Form.cs,1925

When toggling ShowInTaskbar when the browser is hosted in a TabControl then the handle isn't
actually recreated yet the browser is effectively parked, perhaps the .Net source has some tricks
we can use to further improve the case when using  MdiParent

Resolves #2042
2020-04-01 07:44:42 +10:00
amaitland 3ba0290676 WPF - Add IWebBrowser.IsBrowserInitialized explicit interface implementation
Can be called from any Thread, the ChromiumWebBrowser.IsBrowserInitialized property remains
as Dependency property.

Issue #3033
2020-03-26 09:10:36 +10:00
Gilberto Stankiewicz 29e6a6d03a Fix a typo in an error message (#3087) 2020-03-26 08:37:02 +10:00
amaitland 82836e0aee WinForms - Update xml doc Dock = DockStyle.Fill is the default
Make it clear we are setting the default to DockStyle.Fill, this may not be expected
by some. It has been that way for 5+ years, so changing the default would be difficult
and unexpected, instead we make it clearer this is the case.

Resolves #3019
2020-02-01 20:48:30 +10:00
amaitland d82caeaceb WinForms - override Control.DefaultSize return 200x100
When ChromiumWebBrowser is hosted in a FlowLayoutPanel the Dock = DockStyle.Fill
ends up with a browser having no width/height depending on the option layout.

As Control.DefaultSize returns Size.Empty, looking at WebBrowserBase it defaults to Size(75, 23)
which seems way too small to be meaningful. We'll default to 200x100 for now.

https://referencesource.microsoft.com/#System.Windows.Forms/winforms/Managed/System/WinForms/Control.cs,17f6db7866977c1a

Related to issue #3019
2020-02-01 20:43:40 +10:00
amaitland 38c7941ab6 xml doc - remove seealso internal interface references 2020-01-29 10:22:17 +10:00
amaitland 79c99878c5 Xml Doc improvements 2020-01-29 05:37:45 +10:00
amaitland 19a70727f2 WinForms/WPF/OffScreen - Improve Dispose/BrowserInitialized error messaging
- Set CanExecuteJavascriptInMainFrame to false when disposing
- Throw exception if Disposed when calling GetBrowser method
- Improve error messaging
2020-01-15 11:16:06 +10:00
amaitland 1e88322b7d WinForms - Rename WinFormsWebBrowserExtensions to WebBrowserExtensions
Let's just keep it simple, we're in the WinForms namesapce, so we already know the context.
2019-12-10 08:09:22 +10:00
amaitland 6793ff2355 Core - Add WinFormsWebBrowserExtensions.DestroyWindow helper function
Used to manually destroy a browser instance (can be used to avoid having CEF send a WM_Close message).
MUST BE CALLED ON THE CEF UI Thread, see xml doc example
2019-12-10 07:54:14 +10:00
amaitland daeb4fb13f WinForms - Improve handling of Load method when called after CreateBrowser and before OnAfterBrowserCreated
Call MainFrame.Load after the browser has been created if the Address property has been set after CreateBrowser and before OnAfterBrowserCreated
2019-12-03 07:08:08 +10:00
amaitland ca2837f928 WinForms - Make ControlExtensions.InvokeOnUiThreadIfRequired internal
- Additional check is control is being Disposed
- Add copy and paste version of ControlExtensions.InvokeOnUiThreadIfRequired to example project

Resolves #2983
2019-12-02 20:37:41 +10:00
amaitland 0c06026371 WinForms - ControlExtensions.InvokeOnUiThreadIfRequired perform no action if control disposed/ishandlecreated false 2019-12-02 19:03:12 +10:00
amaitland 802bb7f43c Remove IAudioHandler
The Chromium implementation has changed so dramatically that CEF has removed support see https://bitbucket.org/chromiumembedded/cef/commits/1f893c76a97eaa88e3ff782b8e2e47dd0f5d27b2

Track https://bitbucket.org/chromiumembedded/cef/issues/2755/reimplement-audio-mirroring-for for details on when it will be reimplemented

Original Issue #2727
2019-10-01 20:06:37 +10:00
amaitland 6f32aa1a0a WinForms - Only use DefaultFocusHandler when !MultiThreadedMessageLoop
If the WinForms UI thread and CEF UI thread are one in the same then we're not using MultiThreadedMessageLoop
2019-07-26 14:13:58 +10:00
amaitland f8972c6c45 WinForms - Add new constructor overload (HtmlString html, RequestContext context = null)
- New HtmlString class can be used to create a DataUri encoded string for use with the WinForms
ChromiumWebBrowser constructor
- Remove duplication in WebBrowserExtensions extensions, use new HtmlString class

Related issue is #2668
2019-07-11 12:44:57 +10:00
Eklavya df680aec3c Add Shift+Tab as inputs to browser when MultiThreadedMessage loop is disabled. (#2814)
When MultiThreaded message loop is disabled, we use the winform message loop. We want to ensure that Shift+Tab (cycle selection back) is recognized as a valid input in this case or it breaks keyboard accessibility.
2019-07-08 08:32:06 +10:00
amaitland 73a156fdc5 Initial version 75 upgrade and NetworkService changes
Compiles, that's about it at this point, there are major CEF breaking changes, and lots to be addressed.

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

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

The BrowserSubprocess changes for this upgrade should be complete
2019-06-25 19:24:57 +10:00
amaitland f725ab3907 WinForms - DefaultFocusHandler now allows browser to take focus on initial load
Previously on LoadUrl etc we didn't take focus, we now take focus on the initial Load so touch screens work
The behaviour when using ChromiumWebBrowser.ActivateBrowserOnCreation = true is still the same as versions prior to 73 (version 73 is the only different version)

Issue #2776
2019-06-04 20:10:47 +10:00
amaitland 7c3d66817b WinForms - Add ChromiumWebBrowser.ActivateBrowserOnCreation
Set ActivateBrowserOnCreation = true to restore the old behaviour where the browser was activated upon creation.

Issue #2776
2019-06-04 19:50:16 +10:00
Alex Maitland 1a2c8ffcb6 Add CefSharp.PostMessage (#2799)
- JavascriptMessageReceived event added to ChromiumWebBrowser/IWebBrowser
- CefSharp.PostMessage and cefSharp.postMessage added to V8Context on creation for use in Javascript
- Add PostMessageTest.html
2019-06-03 21:08:03 +10:00
amaitland b09b5fd959 WinForms - Replace EditorBrowsable(EditorBrowsableState.Never) with DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
Was hiding the methods from Intellisense

Resolves #2784
2019-05-28 13:56:24 +10:00
Alex Maitland 76e5a8d5c0 Add IAudioHandler (#2727)
* Feature Request - Add IAudioHandler

- For performance reasons we return NULL if no audiohandler is assigned
- No example is provided currently

Initial implementation for #2714
2019-05-03 12:54:40 +10:00
amaitland 3cff24cf1f DefaultFocusHandler.OnGotFocus - Add browser null check
For the print dialog we appear to be passed a CefRefPtr<CefBrowser> reference which doesn't appear to trigger an OnAfterCreated call
so we have no reference to it. Looking at the `CefBrowser`, there's no real data of value, empty url, no frame information (just an invalid frame id)
so for now we'll just ignore it in DefaultFocusHandler, we don't want to handle for popups anyway

Resolves #2725
2019-04-17 20:34:47 +10:00
Chris e22d1c2fd2 Removed IsBrowserInitializedChangedEventArgs (#2710) 2019-04-10 19:51:34 +10:00
Alex Maitland c3bbd37cce Reorder dispose pattern in ChromiumWebBrowser (#2701)
* WinForms/Wpf/OffScreen - Reorder Dispose methods

- Set browser initialized to false
- Release event handlers
- Dispose managedCefBrowserAdapter
- Set handlers to null

* WinForms/WPF/OffScreen - Set Handlers to null immediately after event handlers cleared

The one exception is LifeSpanHandler which is released after managedCefBrowserAdapter.Dispose
2019-03-26 20:14:13 +10:00
Chris 987f988dac Refactoring - Moved RegisterJsObject and RegisterAsyncJsObject to WebBrowserExtensions (#2703) 2019-03-23 13:31:09 +10:00
Chris 86b2d8cecd Improved dispose pattern in ChromiumWebBrowser (#2651)
* Code Cleanup - Improved ChromiumWebBrowser Dispose/Finalise

* Added thread safe dispose pattern
* Added IsDisposed

* Wpf - Cleanup and improvements to the dispose pattern

* WinForms - Cleanup and improvements to the dispose pattern

* OffScreen - Cleanup and improvements to the dispose pattern

* Added IsDisposed to IWebBrowser

* Fixed comments

* WinForms - Removed Finalizer and Dispose()

* WPF - ChromiumWebBrowser.Dispose add comment for Interlocked.CompareExchange

* WinForms - ChromiumWebBrowser.Dispose add comment for Interlocked.CompareExchange
2019-03-22 21:49:02 +10:00
amaitland d2d1e6f879 WPF/WinForms/OffScreen - Move BrowserSettings Dispose into ManagedCefBrowserAdapter::CreateBrowser
- Improve BrowserSettings disposed check message

Follow up to #2643
2019-03-22 10:46:54 +10:00
amaitland 3423670740 WinForms/WPF/OffScreen - Dispose of BrowserSettings only if created by CefSharp framework
- Add OffScreen project to internals visible to list for CefSharp.Core
- Add BrowserSettings.FrameworkCreated property which can only be set through an internal constructor
- Dispose of BrowserSettings immediately after call to CreateBrowser if created by CefSharp framework
- managedCefBrowserAdapter::CreateBrowser  throw exception if browserSettings already disposed

Resolves #2643
2019-03-21 20:13:02 +10:00
Chris 16115724a4 EditorConfig: Added missing csharp_indent_case_contents_when_block (#2699) 2019-03-21 10:23:30 +10:00
amaitland f3d4fe8b20 WinForms - Add example to xml doc of CreateBrowserWindowInfo 2019-03-21 10:07:56 +10:00
amaitland a7a73dc930 WinForms - Disable Window Activation by default
WS_EX_NOACTIVATE added to WindowInfo.ExStyle

To re-enable Window activation when the browser is created inherit from ChromiumWebBrowser and override CreateBrowserWindowInfo
and remove WS_EX_NOACTIVATE from WindowInfo.ExStyle

Resolves #1811
2019-03-21 09:56:09 +10:00
amaitland 1c5d4000fa WinForms/WPF - Dispose of IFrame after calling LoadUrl 2019-03-18 20:11:48 +10:00
amaitland 2c9155f1cb WinForms/WPF - Change browserSettings to use the private field to avoid throw exception in dispose
- Changed to expose only the public interface (this is better for scenarios where the designer attempts to query the property and subsequently attempts to load libcef and fails).
- Make IBrowserSettings implement IDisposable
- ManagedCefBrowserAdapter::CreateBrowser now throws exception if browserSettings param is null

The WPF version won't actually throw an exception, just standardised it's code so they're both the same.

Issue #2638
2019-02-08 10:14:32 +10:00
campersau b31069633e add spaces in exception messages (#2620) 2019-01-11 08:57:28 +10:00
amaitland 4a41fdfd07 WinForms - Dispose of BrowserSettings after browser created
BrowserSettings must be set before the call to CefBrowserHost::CreateBrowser for this reason we enforce these checks.
Throw exception if attempt to set BrowserSettings after browser has been created

Initially I was going to make BrowserSettings a private set, unfortunately that probably won't work if you are using the designer
as there would be no way to instantiate a new instance. It was possible to lazy initialize in the get method, that doesn't really provide
a descriptive error message, I could have updated the documentation to describe the behaviour, unfortunately people just don't really the docs.
2019-01-09 17:12:28 +10:00
amaitland 821a44fecc WinForms - ChromiumWebBrowser remove workaround for address not always loading correctly when passed into CreateBrowser
Manually reverts commit https://github.com/cefsharp/CefSharp/commit/1ab416895845e07706d8b798a78945d72b72871f
2018-12-31 13:27:50 +10:00
Alex Maitland 02e3084af3 Add Chromium Extension Support (#2613)
* Add Chromium Extension Support

Add IRequestContext.LoadExtension
Add IExtensionHandler
Add IExtension
Add example (import from cefclient) - was added to CefSharp.WinForms.Example projct
Add RequestContextExtensions - to make loading an extension slightly easier
2018-12-31 13:12:10 +10:00
amaitland bbf7795d80 WPF/OffScreen - Add OnAcceleratedPaint
Exposes the CEF API for Shared D3D11 Texture support. This should be considered experimental as there are quite a few known bugs in the CEF implementation
(PDF Viewer not working correctly)

OffScreen.ChromiumWebBrowser.CreateBrowser API changed (breaking change) now pass in `WindowInfo` to customise settings
Refactor CreateBrowser to support windowed and OSR rendering (now accepts IWindowInfo)

Resolves #2527
2018-12-16 19:37:12 +10:00
Chris ac6e6356b8 WinForms - Added missing Browsable Attribute on JavascriptObjectRepository (#2590)
WinForms - Added missing Browsable attribute on JavascriptObjectRepository + Updated DefaultValue attribute on UseParentFormMessageInterceptor
2018-12-07 04:40:36 +01:00
Alex Sukhovy 304a300b0c Call OnContextCreated and OnContextReleased for each frame (#2373)
* ContextEvents for each frame

* set CanExecuteJavascriptOnMainFrame

* example and comments

* whitespace fix

* comments

* whitespace

* update comments
2018-10-28 16:48:50 +10:00