Commit Graph

297 Commits

Author SHA1 Message Date
Alex Maitland b8dbb0c0c5 WinForms - Throw InvalidOperationException if Load() called on invalid IBrowser
- When IBrowser.IsValid == false throw an InvalidOperationException when an attempt to
  call Load() is made.

Resolves #4368
2023-01-24 10:55:03 +10:00
Alex Maitland ec282d4c4f WinForms - Set Initial Focus on UI Thread
- Call CefBrowserHost.SetFocus(true) on the WinForms UI Thread to
  workaround upstream issue, see code comment for more detail.
- Add OnSetInitialFocus to allow for providing custom behaviour
- MultiThreadedMessageLoop = false gets focus correctly from parent, no need
  to call SetFocus(true)

https://bitbucket.org/chromiumembedded/cef/issues/3436/chromium-based-browser-loses-focus-when
2023-01-11 06:51:09 +10:00
Alex Maitland aa582e83e1 WinForms/WPF - Add ChromiumWebBrowser.UnregisterShutdownHandler
Resolves #4096
2022-10-25 13:12:20 +10:00
Alex Maitland 7eb6d6f3b7 OffScreen - CaptureScreenshotAsync change to Scale default
- Previously when no Scale was specified, then the previous ChromiumWebBrowser scale was used.
- Now Viewport defaults to a scale of 1, so the behaviour has been changed so the scale passed as
  the param is always used.
- Test updated

This is a minor breaking change.

Resolves #4091
2022-05-05 19:27:29 +10:00
Alex Maitland f201c694c6 WinForms - Add CaptureScreenshotAsync
- Simplification of calling the DevTools method
- Moved GetContentSizeAsync from OffScreen into partial class (now accessible from WinForms/WPF/OffScreen).
- Added menu option

Resolves #4081
2022-05-03 11:29:11 +10:00
Alex Maitland c20bc9b87f WinForms - Improve designer support for UserControl
Current DesignMode property is only true when the control is directly interacting with the designer.
This checks if an ancestor is in design mode to allow support for UserControls

Issue #4057
2022-04-05 15:52:59 +10:00
Alex Maitland 71d07dfd41 WinForms - Remove obsolete from Paramater less constructor
- Causes a warning in the build log when used via the designer
- Instead update the comment and set EditorBrowsableState.Never
2022-03-18 09:28:24 +10:00
Alex Maitland 8b9a5e21c1 WinForms - Designer avoid calling Cef.Shutdown on Application.Exit 2022-02-23 11:06:00 +10:00
Alex Maitland 409c8a85f4 WinForms - Add ChromiumWebBrowser.FromBrowser static method
- Can be used to get ChromiumWebBrowser instance from IBrowser instance
- Added generic base implementation to reduce code duplication
2022-01-10 14:10:26 +10:00
Alex Maitland cbe0e855c6 WinForms - check if MainFrame.IsValid before calling LoadUrl
- Rewrite to directly use BrowserCore checking for null and IsDisposed to
avoid exceptions if at all possible.
- Check MainFrame.IsValid

As yet I've not seen a way to reproduce the actual problem, single reported case
so far at https://github.com/TV-Rename/tvrename/issues/862
2021-12-15 09:27:18 +10:00
Alex Maitland ba7c855353 WinForms - NullReferenceException in ChromiumWebBrowser.OnHandleDestroyed
- Check browserHost is not null

Resolves #3931
2021-12-15 09:11:18 +10:00
Alex Maitland b72d41353e WinForms - Improve hosting of popups using ChromiumHostControl
- Add IChromiumWebBrowserBase which is can be used for ChromiumWebBrowser instances and ChromiumHostControl
- Reduce code duplication for extensions methods
- Update WinForms Example
2021-11-30 13:47:42 +10:00
Alex Maitland 165a05071d WinForms - ChromiumHostControl now has basic events
- Create ChromiumHostControlBase as common base class for ChromiumHostControl and ChromiumWebBrowser
- ChromiumHostControl is now the specific implementation for hosting popups
  Has AddressChanged, LoadingStateChanged, etc events
2021-11-30 13:47:41 +10:00
Alex Maitland 6e9e4a90a2 WinForms - ChromiumHostControl add BrowserCore and IsBrowserInitialized event
- Can now access the IBrowser property via ChromiumHostControl.BrowserCore
- The ChromiumHostControl.IsBrowserInitialized event will be raised when
the underlying CEF browser has been created.
2021-11-25 10:55:31 +10:00
Alex Maitland 4a07af26e9 Core - Rename WaitForBrowserInitialLoadAsync to WaitForInitialLoadAsync and simplify
- Initial intention was to have a reusable method that could be used CefSharp.Wpf.HwndHost,
  upon further deliberation I've decided to build the functionality into the ChromiumWebBrowser.Partial.cs
  and will need to duplicate the functionality in CefSharp.Wpf.HwndHost. This guarantees that the
  Task will be resolved in all cases. The previous implementation there was a theoretical change we'd
  miss subscribing to the relevant events
- Remove CancellationToken as it's not possible to cancel

Issue #3842
2021-10-28 10:31:03 +10:00
Alex Maitland b82fa05291 WinForms/WPF/OffScreen - Update Load(string url) behaviour
- All three implementations updated to include an IsDisposed check which
  will simply return immediately
- OffScreen updated to match the WinForms behaviour
- WPF is more complex because of the initialAddress and Address properties
  initialAddress will be set if the browser hasn't been created, if the browserCreated
  has been created and OnAfterBrowserCreated hasn't been called then we'll set the Address
  dependency property.

NOTE: For WinForms/OffScreen there's a small window
here between CreateBrowser and OnAfterBrowserCreated
where the Address prop will be updated, though LoadUrl
won't be called.
2021-10-08 12:40:54 +10:00
Alex Maitland c226d344b1 WinForms/WPF/OffScreen - Add LoadUrl method (Same as Load(string)).
A more meaningful name for the method, matches the LoadUrlAsync method
that was added recently.
2021-10-08 10:21:31 +10:00
Alex Maitland e5f2381351 WinForms/WPF/OffScreen - Use custom FocusHandler when disposing to block taking focus
This was added as a workaround for Issue #3715 which is specific to WinForms
and will hopefully be fixed upstream.

I've added the logic to all three implementations as I think the behaviour should be
consistent across all implementations.
2021-07-27 13:13:17 +10:00
Alex Maitland a6ff42ee6f Core - IAudioHandler now implements IDisposable
IAudioHandler.Dispose is called when the ChromiumWebBrowser instance is being Disposed.

This is a breaking change.

Resolves #3598
2021-06-04 15:49:52 +10:00
Alex Maitland 3dc37b2dd2 WinForms - Add LifeSpanHandler implementation capable of hosting popups as Tabs/Controls (#3529)
* WinForms - Add LifeSpanHandler implementation capable of hosting popups  as Tabs/Child controls in WinForms

- Update Example
- Remove PopupAsChildHelper and example LifeSpanHandler
- Examples always opens popups as tabs now.
- Improve xml doc and comments
- Make ParentFormMessageInterceptor public
- Make ChromiumHostControl public, move into CefSharp.WinForms.Host namespace
  Rather than having the class in the CefSharp.WinForms namespace and potentially
  confuse users, move into it's own namespace.
- Clarify ShowDevToolsDocked needs to be used with the new WinForms lifespan handler
2021-06-04 14:51:49 +10:00
Alex Maitland a058a3cd5e WinForms - Allow setting of Focus before underlying CEF browser has been initialized 2021-05-10 15:39:33 +10:00
Alex Maitland 047f8b838c WPF/WinForms/OffScreen - Reduce code duplication
Issue #3082
2021-04-01 16:28:20 +10:00
Alex Maitland bcc2c91e0a Core - ManagedCefBrowserAdapter::InitializeBrowserProcessServiceHost improve Dispose handling
As the browser is Disposed on a different Thread to OnAfterBrowserCreated is called there's possibility of an ObjectDisposedException.
Instead of locking just catch and ignore the error as it's extremely rare

Resolves #3437
2021-03-11 15:22:30 +10:00
Alex Maitland 30860d66d6 WinForms/WPF/OffScreen - Improve Cef.Initialize failed error message.
Direct user to check log file as the underlying CefInitialize call doesn't return an error message.
Errors are only available through the logs.
2021-02-26 12:16:49 +10:00
Alex Maitland 12e583d2ef Core - PublicApi remove references to CefSharp.Core.Runtime
- Add an UnWrap method to the interfaces (should be hidden from IntelliSense)
- For .Net 4.5.2 projects they're  not a decorator class which an inner instance of the CefSharp.Core.Runtime Type
- For Net Core we have a ref assembly which allows us to reference the CefSharp.Core.Runtime without issues
  We can potentially remove the ref assembly now and forgo any direct reference.
2021-01-13 16:56:57 +10:00
Alex Maitland 2a80b71161 WinForms/WPF - Fix BrowserSettings/RequestContext type checking
- When settings BrowserSettings/RequestContext properties the type checking needs to make sure the
CefSharp.Core.BrowserSettings and CefSharp.BrowserSettings objects are acceptable
- In WPF only the RequestContext was updated as there's no check for BrowserSettings property yet (probably should be)

https://github.com/cefsharp/CefSharp/issues/3343#issuecomment-757581368
2021-01-11 20:29:54 +10:00
Alex Maitland 8a367fbdc4 Refactor CefSharp.Core into CefSharp.Core.Runtime (#3311)
* Net Core - Rename CefSharp.Core.dll to CefSharp.Core.Runtime.dll

Partial rename, only Net Core, folder not renamed

* Net Core - Rename CefSharp.Core.RefAssembly to CefSharp.Core.netcore

Remove GenApi

* Core - Rename CefDragDataWrapper to DragData

Move into CefSharp.Core namespace

* WinForms/WPF/OffScreen - Migrate from GitLink command line to Nuget package

* Net Core - Refactor to have CefSharp.Core.dll contain only public Api

* Net Core - Remove CefSharp.Core.RefAssembly

* Net Core - Change CefSharp.Core.netcore output folder

* Net Core - Restructure nuget packages

* Net Core - Add Cefsharp.Core.Runtime.RefAssembly

* Net Core - Hide CLI/C++ classes from intellisense

Make sure users don't attempt to load them directly

* Rename CefSharp.Core to CefSharp.Core.Runtime

* Core - Restructure Net 4.5.2 packages to use CefSharp.Core.dll anycpu variant

Attempt to load CefSharp.Core.Runtime at runtime rather than having to use msbuild to copy the correct version

* Rename CefSharp.Core.netcore to CefSharp.Core

* WPF/WinForms/OffScreen - Change from x86/64 to AnyCPU

As they are all managed assemblies they can target AnyCPU.
Includes CefSharp.dll

* Convert RequestContextBuilder from C++ to C#

Now part of the CefSharp.Core PublicApi

* Update version number to 87.1.11

* Migrate more of the public Api to C#

* Net Core - Basic restructure complete

* Net Core - ModuleInitializer (Doesn't work yet)

* Remove direct references to BrowserSettings

* Net Core - ModuleInitializer load CefShar.Core.Runtime.dl

* Net Core - Load libcef.dll via CLR Module initializer

If no RID is specified then we can load libcef.dll using the module initializer

* Add version to CefSharp.Core

* Remove dependency on CefSharp.Core.Runtime
Rewrite common targets

* AnyCPU app.config transform

Improve AnyCPU support

* Improve Net Core 3 support
Only delete CefSharp.Core.Runtime.dll when AnyCPU

* Nuget - Add CefSharp.Core.Runtime reference when TargetFramework = NetCore

* Fix Typos

Based on #3306

* Net Core - Rename CefSharp.Core.Runtime RefAssembly source file

* Net Full - Generate CefSharp.Core.Runtime Ref Assembly

For now the powershell build script generates the .cs file based on a x86 release build.ps1
It's not possible to directly install GenApi as it requires a Sdk style project

* Net Core - Old packages copy files to required folders

* Test - Install newer .Net Compiler and set Lang Version to 7.3

* Net Core - Exclude Net 452 Runtime generated reference source

* Core - Add Refactoring TODO

* Ref Assembly - Generate source as part of build

- Move ref assembly source generate into GenerateRefAssemblySource.ps1
- Call before project build

Runs locally, see if Appveyor has a problem with the powershell script execution

* Core - Add more factory methods to create instances of managed wrappers

* Net Core - Make Initialzier properties internal

Not quite sure what the public API should look like as yet, so making internal for now.
2020-12-16 10:47:34 +10:00
GitHubPang 728420ca7f Fix typos (#3305) 2020-12-06 11:24:14 +10:00
amaitland 71773424dc Wpf/WinForms/OffScreen - Standardize InternalIsBrowserInitialized
- Add InternalIsBrowserInitialized to partial class
- Move ThrowExceptionIfDisposed/ThrowExceptionIfBrowserNotInitialized to partial class
- Remove checks from DevToolsExtensions.ExecuteDevToolsMethodAsync as the checks were already in GetBrowser

In WPF it's no longer necessary to have a custom implementation, will leave the Dependency property
(won't action #3033 at this point in time)
2020-09-18 13:32:22 +10:00
amaitland 3ccb0f8b10 Core - Reduce ChromiumWebBrowser Code Duplication
- Move events to partial class (where possible)
- Move other explicit interface implementation methods

Issue #3082
2020-09-16 19:44:36 +10:00
amaitland 6d62d188b7 Core - Reduce Code Duplication
Move Handler property decelerations to partial class

Issue #3082
2020-09-16 17:06:57 +10:00
amaitland 8d1afada20 WinForms - OnHandleDestroyed directly references CefSharp.Core crashing Designer
Designer attempts to load CefSharp.Core.dll which in fails, we avoid that when designMode is true

Resolves #3219
2020-08-26 14:55:51 +10:00
amaitland 0183c429e0 WPF/WinForms/OffScreen - Reduce Code Duplication Initial
- Add ChromiumWebBrowser.Partial.cs and include in all three projects
- Remove InternalsVisibleTo from Cefsharp.dll start moving code into the partial class
  (We don't want to publish our internals as part of our Ref Assembly so this goings together)

#3082
#3197
2020-08-07 14:24:07 +10:00
Alex Maitland 8d25b71490 Core - Re-Add IAudioHandler (#3153)
Resolves #3152
2020-07-08 08:06:16 +10:00
amaitland 046db62ad9 WinForms - Possible null reference when Dispose
If you've somehow managed to set BrowserSettings to null then Dispose would throw a NullReferenceException
2020-06-29 10:47:17 +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 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 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