mirror of
https://github.com/allankoechke/pywebview.git
synced 2026-11-30 10:58:50 +00:00
* Update change_url.md * Update api.md * Update installation.md * Add Google Analytics * Fix installation * 2.4 info * [Docs] add information about window.pywebview availability * Update debuggig info about QTWebEngine * [Docs] Add information about app architecture * Update cef.md * [CEF] Fix JS logic not persisting after navigating to another page * #169 Frameless window (#313) * Merge PR #177: [Cocoa] Implement frameless windows * [All] Add skeleton for `frameless` parameter * [Cocoa] Add `frameless` kwarg to remove the window frame. - Implement a DragBar class to enable dragging the webview - Make the drag bar stick to the top and autoresize to the width of the view. * [WinForms] Implement frameless window + easy drag * Merge PR #177: [Cocoa] Implement frameless windows * [All] Add skeleton for `frameless` parameter * [Cocoa] Add `frameless` kwarg to remove the window frame. - Implement a DragBar class to enable dragging the webview - Make the drag bar stick to the top and autoresize to the width of the view. * [WinForms] Implement frameless window + easy drag * [GTK] partial implementation of frameless window * [QT] Partial implementation of frameless window * [QT] implement easy drag * [Cocoa] Hide standard buttons and make the entire window draggable * [GTK] implement easy move * Add frameless tests * Remove unused parameter * [Cocoa] Implement free drag * Revert WebBrowserInterops * Code cleanup * Update interop DLLs * Fix interop dll * Update docs; Fix tests * Add example * Update examples * [CEF]: Implement support for pyinstaller one-file mode * [CEF] Fix typo * [All] Change api_call timeout to 15 seconds * Update setup.py * [QT] Simplify QT installation * New API Cocoa implementation Revamped tests and examples * Fix web engine force setting * Rename destroy_window to destroy * Update documentation * Add documentation for 2.4 * Refactor project structure * [GTK] New API support * Rename confirm_quit to confirm_close Split lifecycle events to shown and loaded * [GTK] Implement new API Fix tests * [QT] New API implementation * Remove multiprocessing * [Windows/CEF] New API implementation * Implement CSRF token [All] Implement get_element * Update Flask app example * Rename get_element to get_elements. Bug fixes. * [GTK] Implement propert JS-Python bridge for WebKit2 >2.2 * Update documentation * [Windows/CEF] New API implementation * Add token test * [Winforms] Fix js api initialization * [Cocoa] Fix events * Debug: print webkit version * [GTK] Check for old webkit * [GTK] Fix event issues * Catch notimlementederror in tests * Update travis conf with qt from pip * Update .travis.yml * Update .travis.yml * Update .travis.yml * Update .travis.yml * Update .travis.yml * [Windows] Preliminary implementation of EdgeHTML based on PR from @HeavenVolkoff * [docs] Add information about EdgeHTML * EdgeHTML WIP * Remove windows.web import * EdgeHTML improvements. Fix MSHTML evaluate_js * [Docs] Add information about renderer limitations * [EdgeHTML] Fix bugs and tests * Remove window from windows list after it is destroyed * Fix window object deletion after window is closed via GUI * [Docs] Add information about renderer codes * Refactor and fix JS API Remove multiprocessing example [MSHTML] Add console.log debug support * [Travis] Change conf * [WinForms] Fix fullscreen * Fix dll installation * [Windows] Fix DLL bundling * Update changelog * [CEF]: Fix JS API * Update changelog * Built-in HTTP server implementation * Add http server test * Add http server testcd * Add http server testcd * [EdgeHTML] allow localhost urls * Add video example * Bug fixing * [Cocoa] Remove media prefs * Update .travis.yml * Update .travis.yml * Update .travis.yml * [Travis] Disable QT 5.12 builds * Update html_load.md
161 lines
5.3 KiB
C#
161 lines
5.3 KiB
C#
using System;
|
|
using System.ComponentModel;
|
|
using System.Runtime.InteropServices;
|
|
using System.Security.Permissions;
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
namespace WebBrowserInterop
|
|
{
|
|
public interface IWebBrowserInterop
|
|
{
|
|
object call(string message, object param);
|
|
|
|
void alert(string message);
|
|
|
|
void console(string message);
|
|
}
|
|
|
|
[ComImport, TypeLibType(TypeLibTypeFlags.FHidden),
|
|
InterfaceType(ComInterfaceType.InterfaceIsIDispatch),
|
|
Guid("34A715A0-6587-11D0-924A-0020AFC7AC4D")]
|
|
public interface DWebBrowserEvents2
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="ppDisp">
|
|
/// An interface pointer that, optionally, receives the IDispatch interface
|
|
/// pointer of a new WebBrowser object or an InternetExplorer object.
|
|
/// </param>
|
|
/// <param name="Cancel">
|
|
/// value that determines whether the current navigation should be canceled
|
|
/// </param>
|
|
/// <param name="dwFlags">
|
|
/// The flags from the NWMF enumeration that pertain to the new window
|
|
/// See http://msdn.microsoft.com/en-us/library/bb762518(VS.85).aspx.
|
|
/// </param>
|
|
/// <param name="bstrUrlContext">
|
|
/// The URL of the page that is opening the new window.
|
|
/// </param>
|
|
/// <param name="bstrUrl">The URL that is opened in the new window.</param>
|
|
[DispId(0x111)]
|
|
void NewWindow3(
|
|
[In, Out, MarshalAs(UnmanagedType.IDispatch)] ref object ppDisp,
|
|
[In, Out] ref bool Cancel,
|
|
[In] uint dwFlags,
|
|
[In, MarshalAs(UnmanagedType.BStr)] string bstrUrlContext,
|
|
[In, MarshalAs(UnmanagedType.BStr)] string bstrUrl);
|
|
|
|
[DispId(0x68)]
|
|
void DownloadComplete();
|
|
}
|
|
|
|
public partial class WebBrowserEx : WebBrowser
|
|
{
|
|
AxHost.ConnectionPointCookie cookie;
|
|
DWebBrowserEvent2Helper helper;
|
|
[Browsable(true)]
|
|
public event EventHandler DownloadComplete;
|
|
public event EventHandler<WebBrowserNewWindowEventArgs> NewWindow3;
|
|
public const int WM_NCLBUTTONDOWN = 161;
|
|
public const int HT_CAPTION = 2;
|
|
|
|
[PermissionSetAttribute(SecurityAction.LinkDemand, Name = "FullTrust")]
|
|
public WebBrowserEx()
|
|
{
|
|
}
|
|
|
|
[DllImport("user32.dll")]
|
|
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
|
|
|
|
[DllImport("user32.dll")]
|
|
public static extern bool ReleaseCapture();
|
|
|
|
/// <summary>
|
|
/// Associates the underlying ActiveX control with a client that can
|
|
/// handle control events including NewWindow3 event.
|
|
/// </summary>
|
|
[PermissionSetAttribute(SecurityAction.LinkDemand, Name = "FullTrust")]
|
|
protected override void CreateSink()
|
|
{
|
|
base.CreateSink();
|
|
|
|
helper = new DWebBrowserEvent2Helper(this);
|
|
cookie = new AxHost.ConnectionPointCookie(
|
|
this.ActiveXInstance, helper, typeof(DWebBrowserEvents2));
|
|
}
|
|
/// <summary>
|
|
/// Releases the event-handling client attached in the CreateSink method
|
|
/// from the underlying ActiveX control
|
|
/// </summary>
|
|
[PermissionSetAttribute(SecurityAction.LinkDemand, Name = "FullTrust")]
|
|
protected override void DetachSink()
|
|
{
|
|
if (cookie != null)
|
|
{
|
|
cookie.Disconnect();
|
|
cookie = null;
|
|
}
|
|
base.DetachSink();
|
|
}
|
|
/// <summary>
|
|
/// Raises the NewWindow3 event.
|
|
/// </summary>
|
|
protected virtual void OnNewWindow3(WebBrowserNewWindowEventArgs e)
|
|
{
|
|
if (this.NewWindow3 != null)
|
|
{
|
|
this.NewWindow3(this, e);
|
|
}
|
|
}
|
|
|
|
protected virtual void OnDownloadComplete()
|
|
{
|
|
if (this.DownloadComplete != null)
|
|
{
|
|
this.DownloadComplete(this, null);
|
|
}
|
|
}
|
|
|
|
private class DWebBrowserEvent2Helper : StandardOleMarshalObject, DWebBrowserEvents2
|
|
{
|
|
private WebBrowserEx parent;
|
|
public DWebBrowserEvent2Helper(WebBrowserEx parent)
|
|
{
|
|
this.parent = parent;
|
|
}
|
|
/// <summary>
|
|
/// Raise the NewWindow3 event.
|
|
/// If an instance of WebBrowser2EventHelper is associated with the underlying
|
|
/// ActiveX control, this method will be called When the NewWindow3 event was
|
|
/// fired in the ActiveX control.
|
|
/// </summary>
|
|
public void NewWindow3(ref object ppDisp, ref bool Cancel, uint dwFlags,
|
|
string bstrUrlContext, string bstrUrl)
|
|
{
|
|
var e = new WebBrowserNewWindowEventArgs(bstrUrl, Cancel);
|
|
this.parent.OnNewWindow3(e);
|
|
Cancel = e.Cancel;
|
|
}
|
|
|
|
public void DownloadComplete()
|
|
{
|
|
this.parent.OnDownloadComplete();
|
|
}
|
|
}
|
|
}
|
|
public class WebBrowserNewWindowEventArgs : EventArgs
|
|
{
|
|
public String Url { get; set; }
|
|
public Boolean Cancel { get; set; }
|
|
public WebBrowserNewWindowEventArgs(String url, Boolean cancel)
|
|
{
|
|
this.Url = url;
|
|
this.Cancel = cancel;
|
|
}
|
|
}
|
|
}
|
|
|