public WinFormsWindow(WebviewBridge bridge)
        {
            if (bridge == null)
            {
                throw new ArgumentNullException(nameof(bridge));
            }

            var webviewType = ChooseWebview();

            switch (webviewType)
            {
            case WebviewType.InternetExplorer:
                webview = new WinFormsLegacyWebview(WindowsApplication.ContentServerAddress, bridge);
                break;

            case WebviewType.Edge:
                webview = new WinFormsWebview(bridge);
                break;

            default:
                throw new InvalidOperationException($"Invalid webview type of {webviewType}");
            }

            webview.Control.Location = new System.Drawing.Point(0, 0);
            webview.Control.Dock     = DockStyle.Fill;
            Controls.Add(webview.Control);
        }
Esempio n. 2
0
        public CocoaWindow(WindowConfiguration config, WebviewBridge bridge)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }
            if (bridge == null)
            {
                throw new ArgumentNullException(nameof(bridge));
            }

            Handle = AppKit.Call("NSWindow", "alloc");

            canResizeField = config.CanResize;
            var style = GetWantedStyleMask();

            ObjC.SendMessage(
                Handle,
                ObjC.RegisterName("initWithContentRect:styleMask:backing:defer:"),
                new CGRect(0, 0, config.Size.Width, config.Size.Height),
                new UIntPtr((uint)style),
                new UIntPtr(2),
                false);

            webview = new CocoaWebview(bridge);
            ObjC.Call(Handle, "setContentView:", webview.Handle);

            webview.TitleChanged += Webview_TitleChanged;

            windowDelegate = WindowDelegateDefinition.CreateInstance(this);
            ObjC.Call(Handle, "setDelegate:", windowDelegate.Handle);
        }
Esempio n. 3
0
        public WinFormsWindow(WebviewBridge bridge)
        {
            if (bridge == null)
            {
                throw new ArgumentNullException(nameof(bridge));
            }

            var webviewType = ChooseWebview();

            switch (webviewType)
            {
            case WebviewType.InternetExplorer:
                webview = new IeLegacyWebview(WindowsApplication.ContentServerAddress, bridge);
                break;

            case WebviewType.EdgeChromium:
                var edgium = new EdgiumWebview(bridge);
                edgium.TitleChanged += Webview_TitleChanged;
                webview              = edgium;
                break;

            default:
                throw new InvalidOperationException($"Invalid webview type of {webviewType}");
            }

            // hide control until first page is loaded to prevent ugly flicker
            // Edgium and IE don't (properly) support setting a webview background color so this is a workaround
            webview.Control.Visible = false;
            webview.PageLoaded     += Webview_PageLoaded;

            webview.Control.Location = new System.Drawing.Point(0, 0);
            webview.Control.Dock     = DockStyle.Fill;
            Controls.Add(webview.Control);
        }
Esempio n. 4
0
        public EdgeHtmlWebview(WebviewBridge bridge)
        {
            this.bridge = bridge ?? throw new ArgumentNullException(nameof(bridge));

            var version = Native.GetOsVersion();

            supportsInitializeScript = version.MajorVersion >= 10 && version.BuildNumber >= 17763;

            var process = new WebViewControlProcess();
            var bounds  = new global::Windows.Foundation.Rect(Bounds.X, Bounds.Y, Bounds.Width, Bounds.Height);

            webview = process.CreateWebViewControlAsync(Handle.ToInt64(), bounds)
                      .AsTask()
                      .RunSyncWithPump();

            UpdateSize();

            if (supportsInitializeScript)
            {
                string initScript = Resources.GetInitScript("Windows");
                webview.AddInitializeScript(initScript);
            }

            webview.ScriptNotify += Webview_ScriptNotify;

            webview.NavigationStarting  += Webview_NavigationStarting;
            webview.NavigationCompleted += Webview_NavigationCompleted;
            Layout += (s, e) => UpdateSize();
        }
Esempio n. 5
0
 internal AndroidWebView(Context context, WebviewBridge bridge) : base(context)
 {
     this.Settings.JavaScriptEnabled = true;
     this.AddJavascriptInterface(new JSInterFace(this), "XamarinBridge");
     this.SetWebViewClient(new AndroidWebViewClient(this));
     this.bridge = bridge;
 }
Esempio n. 6
0
        public IeLegacyWebview(string hostAddress, WebviewBridge bridge)
        {
            if (hostAddress == null)
            {
                throw new ArgumentNullException(nameof(hostAddress));
            }
            if (bridge == null)
            {
                throw new ArgumentNullException(nameof(bridge));
            }

            this.hostAddress = new Uri(hostAddress, UriKind.Absolute);

            webview = new WebBrowser
            {
                IsWebBrowserContextMenuEnabled = false,
                TabStop                    = false,
                AllowNavigation            = true,
                AllowWebBrowserDrop        = false,
                ScriptErrorsSuppressed     = true,
                WebBrowserShortcutsEnabled = false,
            };

            scriptInterface            = new ScriptInterface(bridge);
            webview.Navigating        += Webview_Navigating;
            webview.DocumentCompleted += Webview_DocumentCompleted;
        }
Esempio n. 7
0
        public CocoaWebview(WindowConfiguration config, IContentProvider contentProvider, WebviewBridge bridge)
        {
            this.config          = config ?? throw new ArgumentNullException(nameof(config));
            this.contentProvider = contentProvider ?? throw new ArgumentNullException(nameof(contentProvider));
            this.bridge          = bridge ?? throw new ArgumentNullException(nameof(bridge));

            Interlocked.Increment(ref count);

            // need to keep the delegates around or they will get garbage collected
            loadDelegate                 = LoadCallback;
            loadFailedDelegate           = LoadFailedCallback;
            observedValueChangedDelegate = ObservedValueChanged;
            scriptDelegate               = ScriptCallback;
            uriSchemeStartDelegate       = UriSchemeStartCallback;
            uriSchemeStopDelegate        = UriSchemeStopCallback;


            IntPtr configuration = WebKit.Call("WKWebViewConfiguration", "new");
            IntPtr manager       = ObjC.Call(configuration, "userContentController");
            IntPtr callbackClass = CreateCallbackClass();

            customHost = CreateSchemeHandler(configuration);

            if (config.EnableScriptInterface)
            {
                ObjC.Call(manager, "addScriptMessageHandler:name:", callbackClass, NSString.Create("external"));
                IntPtr script = WebKit.Call("WKUserScript", "alloc");
                ObjC.Call(
                    script,
                    "initWithSource:injectionTime:forMainFrameOnly:",
                    NSString.Create(Resources.GetInitScript("Mac")),
                    IntPtr.Zero,
                    IntPtr.Zero);
                ObjC.Call(manager, "addUserScript:", script);
            }

            Handle = WebKit.Call("WKWebView", "alloc");
            ObjC.Call(Handle, "initWithFrame:configuration:", CGRect.Zero, configuration);
            ObjC.Call(Handle, "setNavigationDelegate:", callbackClass);

            IntPtr bgColor = NSColor.FromHex(config.BackgroundColor);

            ObjC.Call(Handle, "setBackgroundColor:", bgColor);

            IntPtr boolValue = Foundation.Call("NSNumber", "numberWithBool:", 0);

            ObjC.Call(Handle, "setValue:forKey:", boolValue, NSString.Create("drawsBackground"));

            if (config.UseBrowserTitle)
            {
                ObjC.Call(Handle, "addObserver:forKeyPath:options:context:", callbackClass, NSString.Create("title"), IntPtr.Zero, IntPtr.Zero);
            }

            if (enableDevTools)
            {
                var preferences = ObjC.Call(configuration, "preferences");
                ObjC.Call(preferences, "setValue:forKey:", new IntPtr(1), NSString.Create("developerExtrasEnabled"));
            }
        }
Esempio n. 8
0
        public CocoaWindow(WindowConfiguration config, IUiFactory windowFactory)
        {
            if (windowFactory == null)
            {
                throw new ArgumentNullException(nameof(windowFactory));
            }

            this.config = config ?? throw new ArgumentNullException(nameof(config));

            Interlocked.Increment(ref count);

            // need to keep the delegates around or they will get garbage collected
            windowShouldCloseDelegate = WindowShouldCloseCallback;
            windowWillCloseDelegate   = WindowWillCloseCallback;

            Handle = AppKit.Call("NSWindow", "alloc");

            var style = NSWindowStyleMask.Titled | NSWindowStyleMask.Closable | NSWindowStyleMask.Miniaturizable;

            if (config.CanResize)
            {
                style |= NSWindowStyleMask.Resizable;
            }

            ObjC.SendMessage(
                Handle,
                ObjC.RegisterName("initWithContentRect:styleMask:backing:defer:"),
                new CGRect(0, 0, config.Width, config.Height),
                (int)style,
                2,
                0);

            Title = config.Title;

            IntPtr bgColor = NSColor.FromHex(config.BackgroundColor);

            ObjC.Call(Handle, "setBackgroundColor:", bgColor);

            var contentProvider = new EmbeddedFileProvider(config.ContentAssembly, config.ContentFolder);

            bridge  = new WebviewBridge();
            webview = new CocoaWebview(config, contentProvider, bridge);
            ObjC.Call(Handle, "setContentView:", webview.Handle);

            if (config.EnableScriptInterface)
            {
                bridge.Init(this, webview, windowFactory);
            }

            if (config.UseBrowserTitle)
            {
                webview.TitleChanged += Webview_TitleChanged;
                bridge.TitleChanged  += Webview_TitleChanged;
            }

            SetWindowDelegate(Handle);
        }
Esempio n. 9
0
        public WinFormsWindow(WindowConfiguration config, IUiFactory windowFactory)
        {
            if (windowFactory == null)
            {
                throw new ArgumentNullException(nameof(windowFactory));
            }

            this.config = config ?? throw new ArgumentNullException(nameof(config));

            bridge = new WebviewBridge();
            var contentProvider = new EmbeddedFileProvider(config.ContentAssembly, config.ContentFolder);

            if (!config.ForceWindowsLegacyWebview && IsEdgeAvailable())
            {
                webview = new WinFormsWebview(config, contentProvider, bridge);
            }
            else
            {
                string hostAddress;
                if (string.IsNullOrWhiteSpace(config.ExternalHost))
                {
                    server = new ContentServer(contentProvider);
                    server.Start();
                    hostAddress = server.HostAddress;
                }
                else
                {
                    hostAddress = config.ExternalHost;
                }

                webview = new WinFormsLegacyWebview(config, hostAddress, bridge);
            }

            webview.Control.Location = new Point(0, 0);
            webview.Control.Dock     = DockStyle.Fill;
            Controls.Add(webview.Control);

            Text      = config.Title;
            Width     = config.Width;
            Height    = config.Height;
            CanResize = config.CanResize;

            ColorTools.ParseHex(config.BackgroundColor, out byte r, out byte g, out byte b);
            BackColor = Color.FromArgb(r, g, b);

            if (config.EnableScriptInterface)
            {
                bridge.Init(this, webview, windowFactory);
            }

            if (config.UseBrowserTitle)
            {
                bridge.TitleChanged += Webview_TitleChanged;
            }

            SetIcon(config.Icon);
        }
Esempio n. 10
0
        public AndroidWindow(Activity activity, WebviewBridge bridge)
        {
            this._activity = activity;
            var layout = new LinearLayout(this._activity);

            layout.Orientation = Orientation.Vertical;
            this.webView       = new AndroidWebView(this._activity, bridge);
            layout.AddView(this.webView);
            this._activity.SetContentView(layout);
        }
Esempio n. 11
0
        public GtkWindow(WindowConfiguration config, IUiFactory windowFactory)
        {
            if (windowFactory == null)
            {
                throw new ArgumentNullException(nameof(windowFactory));
            }

            this.config = config ?? throw new ArgumentNullException(nameof(config));

            var contentProvider = new EmbeddedFileProvider(config.ContentAssembly, config.ContentFolder);

            bridge  = new WebviewBridge();
            webview = new GtkWebview(config, contentProvider, bridge);
            Handle  = Gtk.Window.Create(GtkWindowType.Toplevel);

            Title = config.Title;
            Gtk.Window.SetResizable(Handle, config.CanResize);
            Gtk.Window.SetDefaultSize(Handle, config.Width, config.Height);

            string backgroundColor = config.BackgroundColor;

            if (string.IsNullOrWhiteSpace(backgroundColor))
            {
                backgroundColor = "#FFFFFF";
            }
            SetBackgroundColor(backgroundColor);

            IntPtr scroller = Gtk.Window.CreateScrolled(IntPtr.Zero, IntPtr.Zero);

            Gtk.Widget.ContainerAdd(Handle, scroller);
            Gtk.Widget.ContainerAdd(scroller, webview.Handle);

            // need to keep the delegates around or they will get garbage collected
            deleteDelegate  = DeleteCallback;
            destroyDelegate = DestroyCallback;

            GLib.ConnectSignal(Handle, "delete-event", deleteDelegate, IntPtr.Zero);
            GLib.ConnectSignal(Handle, "destroy", destroyDelegate, IntPtr.Zero);

            webview.CloseRequested += Webview_CloseRequested;

            if (config.EnableScriptInterface)
            {
                bridge.Init(this, webview, windowFactory);
            }

            if (config.UseBrowserTitle)
            {
                webview.TitleChanged += Webview_TitleChanged;
                bridge.TitleChanged  += Webview_TitleChanged;
            }

            SetIcon(config.Icon);
        }
Esempio n. 12
0
        public WinFormsWindow(WebviewBridge bridge)
        {
            if (bridge == null)
            {
                throw new ArgumentNullException(nameof(bridge));
            }

            webview = new WinFormsWebview(bridge);
            webview.Control.Location = new Point(0, 0);
            webview.Control.Dock     = DockStyle.Fill;
            webview.Control.KeyDown += WebViewKeyDown;
            Controls.Add(webview.Control);
        }
Esempio n. 13
0
        public WinFormsWebview(WebviewBridge bridge)
        {
            this.bridge = bridge ?? throw new ArgumentNullException(nameof(bridge));

            webview = new WebView2();
            InitializeWebView();

            webview.WebMessageReceived += Webview_WebMessageReceived;

            webview.NavigationStarting += Webview_NavigationStarting;
            webview.CoreWebView2InitializationCompleted += WebViewInitializationCompleted;

            customHost = new Uri(UriTools.GetRandomResourceUrl(CustomScheme));
        }
Esempio n. 14
0
        public GtkWindow(WebviewBridge bridge)
        {
            this.bridge = bridge ?? throw new ArgumentNullException(nameof(bridge));

            try
            {
                webview = new GtkWebview(bridge);
            }
            catch (DllNotFoundException)
            {
                var dialog = new GtkMessageBox
                {
                    Title   = "Missing dependency",
                    Message = "The dependency 'libwebkit2gtk-4.0' is missing. Make sure it is installed correctly.",
                    Buttons = MessageBoxButtons.Ok,
                };
                dialog.Show();
                Environment.Exit(-1);
            }

            Handle = Gtk.Window.Create(GtkWindowType.Toplevel);

            IntPtr contentBox = Gtk.Box.Create(GtkOrientationType.Vertical, 0);

            Gtk.Widget.ContainerAdd(Handle, contentBox);
            Gtk.Widget.Show(contentBox);

            // Do not show the menu bar, since it could be empty
            menuBarHandle = Gtk.MenuBar.Create();
            Gtk.Box.AddChild(contentBox, menuBarHandle, false, false, 0);

            Gtk.Box.AddChild(contentBox, webview.Handle, true, true, 0);
            Gtk.Widget.Show(webview.Handle);

            accelGroup = Gtk.AccelGroup.Create();
            Gtk.Window.AddAccelGroup(Handle, accelGroup);

            // need to keep the delegates around or they will get garbage collected
            showDelegate    = ShowCallback;
            deleteDelegate  = DeleteCallback;
            destroyDelegate = DestroyCallback;

            GLib.ConnectSignal(Handle, "show", showDelegate, IntPtr.Zero);
            GLib.ConnectSignal(Handle, "delete-event", deleteDelegate, IntPtr.Zero);
            GLib.ConnectSignal(Handle, "destroy", destroyDelegate, IntPtr.Zero);

            webview.CloseRequested += Webview_CloseRequested;
            webview.TitleChanged   += Webview_TitleChanged;
        }
Esempio n. 15
0
        public EdgiumWebview(WebviewBridge bridge)
        {
            this.bridge = bridge ?? throw new ArgumentNullException(nameof(bridge));

            const string scheme = "http";

            customHost = new Uri(UriTools.GetRandomResourceUrl(scheme));

            webview = new WebView2();
            webview.NavigationStarting  += Webview_NavigationStarting;
            webview.NavigationCompleted += Webview_NavigationCompleted;
            webview.WebMessageReceived  += Webview_WebMessageReceived;

            InitWebview().RunSyncWithPump();
        }
Esempio n. 16
0
        public WinFormsWebview(WindowConfiguration config, IContentProvider contentProvider, WebviewBridge bridge)
        {
            if (contentProvider == null)
            {
                throw new ArgumentNullException(nameof(contentProvider));
            }

            this.config    = config ?? throw new ArgumentNullException(nameof(config));
            this.bridge    = bridge ?? throw new ArgumentNullException(nameof(bridge));
            streamResolver = new EdgeUriToStreamResolver(contentProvider);

            Layout += (s, e) => UpdateSize();

            Init();
        }
Esempio n. 17
0
        public GtkWebview(WebviewBridge bridge)
        {
            this.bridge     = bridge ?? throw new ArgumentNullException(nameof(bridge));
            scriptCallbacks = new ConcurrentDictionary <Guid, GAsyncReadyDelegate>();

            // need to keep the delegates around or they will get garbage collected
            scriptDelegate      = ScriptCallback;
            loadFailedDelegate  = LoadFailedCallback;
            loadDelegate        = LoadCallback;
            contextMenuDelegate = ContextMenuCallback;
            closeDelegate       = CloseCallback;
            titleChangeDelegate = TitleChangeCallback;
            uriSchemeCallback   = UriSchemeCallback;

            manager = WebKit.Manager.Create();
            GLib.ConnectSignal(manager, "script-message-received::external", scriptDelegate, IntPtr.Zero);

            using (GLibString name = "external")
            {
                WebKit.Manager.RegisterScriptMessageHandler(manager, name);
            }

            using (GLibString initScript = Resources.GetInitScript("Linux"))
            {
                var script = WebKit.Manager.CreateScript(initScript, WebKitInjectedFrames.AllFrames, WebKitInjectionTime.DocumentStart, IntPtr.Zero, IntPtr.Zero);
                WebKit.Manager.AddScript(manager, script);
                WebKit.Manager.UnrefScript(script);
            }

            Handle    = WebKit.CreateWithUserContentManager(manager);
            settings  = WebKit.Settings.Get(Handle);
            inspector = WebKit.Inspector.Get(Handle);

            GLib.ConnectSignal(Handle, "load-failed", loadFailedDelegate, IntPtr.Zero);
            GLib.ConnectSignal(Handle, "load-changed", loadDelegate, IntPtr.Zero);
            GLib.ConnectSignal(Handle, "context-menu", contextMenuDelegate, IntPtr.Zero);
            GLib.ConnectSignal(Handle, "close", closeDelegate, IntPtr.Zero);
            GLib.ConnectSignal(Handle, "notify::title", titleChangeDelegate, IntPtr.Zero);

            customHost = new Uri(UriTools.GetRandomResourceUrl(CustomScheme));

            IntPtr context = WebKit.Context.Get(Handle);

            using (GLibString gscheme = CustomScheme)
            {
                WebKit.Context.RegisterUriScheme(context, gscheme, uriSchemeCallback, IntPtr.Zero, IntPtr.Zero);
            }
        }
Esempio n. 18
0
        public EdgiumWebview(string hostAddress, WebviewBridge bridge)
        {
            if (hostAddress == null)
            {
                throw new ArgumentNullException(nameof(hostAddress));
            }
            this.bridge = bridge ?? throw new ArgumentNullException(nameof(bridge));

            this.hostAddress = new Uri(hostAddress, UriKind.Absolute);

            webview = new WebView2();
            webview.NavigationStarting  += Webview_NavigationStarting;
            webview.NavigationCompleted += Webview_NavigationCompleted;
            webview.WebMessageReceived  += Webview_WebMessageReceived;

            InitWebview().RunSyncWithPump();
        }
Esempio n. 19
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Window"/> class.
        /// </summary>
        public Window()
        {
            bridge       = new WebviewBridge(this);
            NativeWindow = Application.Factory.CreateWindow(DefaultConfig, bridge);

            Title                 = DefaultConfig.Title;
            Size                  = DefaultConfig.Size;
            MinSize               = DefaultConfig.MinSize;
            MaxSize               = DefaultConfig.MaxSize;
            BackgroundColor       = DefaultConfig.BackgroundColor;
            CanResize             = DefaultConfig.CanResize;
            EnableScriptInterface = DefaultConfig.EnableScriptInterface;
            UseBrowserTitle       = DefaultConfig.UseBrowserTitle;
            EnableDevTools        = DefaultConfig.EnableDevTools;

            bridge.TitleChanged += Bridge_TitleChanged;
            NativeWindow.Shown  += NativeWindow_Shown;
            NativeWindow.Closed += NativeWindow_Closed;
        }
Esempio n. 20
0
        public GtkWebview(WebviewBridge bridge)
        {
            this.bridge = bridge ?? throw new ArgumentNullException(nameof(bridge));

            // need to keep the delegates around or they will get garbage collected
            scriptDelegate      = ScriptCallback;
            loadFailedDelegate  = LoadFailedCallback;
            loadDelegate        = LoadCallback;
            contextMenuDelegate = ContextMenuCallback;
            closeDelegate       = CloseCallback;
            titleChangeDelegate = TitleChangeCallback;

            manager = WebKit.Manager.Create();
            GLib.ConnectSignal(manager, "script-message-received::external", scriptDelegate, IntPtr.Zero);

            using (GLibString name = "external")
            {
                WebKit.Manager.RegisterScriptMessageHandler(manager, name);
            }

            Handle    = WebKit.CreateWithUserContentManager(manager);
            settings  = WebKit.Settings.Get(Handle);
            inspector = WebKit.Inspector.Get(Handle);

            GLib.ConnectSignal(Handle, "load-failed", loadFailedDelegate, IntPtr.Zero);
            GLib.ConnectSignal(Handle, "load-changed", loadDelegate, IntPtr.Zero);
            GLib.ConnectSignal(Handle, "context-menu", contextMenuDelegate, IntPtr.Zero);
            GLib.ConnectSignal(Handle, "close", closeDelegate, IntPtr.Zero);
            GLib.ConnectSignal(Handle, "notify::title", titleChangeDelegate, IntPtr.Zero);

            const string scheme = "spidereye";

            customHost = new Uri(UriTools.GetRandomResourceUrl(scheme));

            IntPtr context = WebKit.Context.Get(Handle);

            using (GLibString gscheme = scheme)
            {
                WebKit.Context.RegisterUriScheme(context, gscheme, UriSchemeCallback, IntPtr.Zero, IntPtr.Zero);
            }
        }
        public WinFormsLegacyWebview(WindowConfiguration config, string hostAddress, WebviewBridge scriptingApi)
        {
            if (scriptingApi == null)
            {
                throw new ArgumentNullException(nameof(scriptingApi));
            }

            this.config      = config ?? throw new ArgumentNullException(nameof(config));
            this.hostAddress = hostAddress ?? throw new ArgumentNullException(nameof(hostAddress));

            webview = new WebBrowser();
            webview.IsWebBrowserContextMenuEnabled = false;

            if (config.EnableScriptInterface)
            {
                scriptInterface            = new ScriptInterface(scriptingApi);
                webview.ObjectForScripting = scriptInterface;
            }

            webview.DocumentCompleted += Webview_DocumentCompleted;
        }
Esempio n. 22
0
        public CocoaWebview(WebviewBridge bridge)
        {
            this.bridge = bridge ?? throw new ArgumentNullException(nameof(bridge));

            IntPtr configuration = WebKit.Call("WKWebViewConfiguration", "new");
            IntPtr manager       = ObjC.Call(configuration, "userContentController");

            callbackClass = CallbackClassDefinition.CreateInstance(this);
            schemeHandler = SchemeHandlerDefinition.CreateInstance(this);

            const string scheme = "spidereye";

            customHost = new Uri(UriTools.GetRandomResourceUrl(scheme));
            ObjC.Call(configuration, "setURLSchemeHandler:forURLScheme:", schemeHandler.Handle, NSString.Create(scheme));

            ObjC.Call(manager, "addScriptMessageHandler:name:", callbackClass.Handle, NSString.Create("external"));
            IntPtr script = WebKit.Call("WKUserScript", "alloc");

            ObjC.Call(
                script,
                "initWithSource:injectionTime:forMainFrameOnly:",
                NSString.Create(Resources.GetInitScript("Mac")),
                IntPtr.Zero,
                IntPtr.Zero);
            ObjC.Call(manager, "addUserScript:", script);

            Handle = WebKit.Call("WKWebView", "alloc");
            ObjC.Call(Handle, "initWithFrame:configuration:", CGRect.Zero, configuration);
            ObjC.Call(Handle, "setNavigationDelegate:", callbackClass.Handle);

            IntPtr boolValue = Foundation.Call("NSNumber", "numberWithBool:", false);

            ObjC.Call(Handle, "setValue:forKey:", boolValue, NSString.Create("drawsBackground"));
            ObjC.Call(Handle, "addObserver:forKeyPath:options:context:", callbackClass.Handle, NSString.Create("title"), IntPtr.Zero, IntPtr.Zero);

            preferences = ObjC.Call(configuration, "preferences");
        }
Esempio n. 23
0
        public GtkWindow(WebviewBridge bridge)
        {
            this.bridge = bridge ?? throw new ArgumentNullException(nameof(bridge));

            webview = new GtkWebview(bridge);
            Handle  = Gtk.Window.Create(GtkWindowType.Toplevel);

            IntPtr scroller = Gtk.Window.CreateScrolled(IntPtr.Zero, IntPtr.Zero);

            Gtk.Widget.ContainerAdd(Handle, scroller);
            Gtk.Widget.ContainerAdd(scroller, webview.Handle);

            // need to keep the delegates around or they will get garbage collected
            showDelegate    = ShowCallback;
            deleteDelegate  = DeleteCallback;
            destroyDelegate = DestroyCallback;

            GLib.ConnectSignal(Handle, "show", showDelegate, IntPtr.Zero);
            GLib.ConnectSignal(Handle, "delete-event", deleteDelegate, IntPtr.Zero);
            GLib.ConnectSignal(Handle, "destroy", destroyDelegate, IntPtr.Zero);

            webview.CloseRequested += Webview_CloseRequested;
            webview.TitleChanged   += Webview_TitleChanged;
        }
Esempio n. 24
0
 public IWindow CreateWindow(WindowConfiguration config, WebviewBridge bridge)
 {
     return(new CocoaWindow(config, bridge));
 }
Esempio n. 25
0
 /// <summary>
 /// Adds a custom handler to be called from any webview of the application.
 /// </summary>
 /// <typeparam name="T">The handler type.</typeparam>
 public static void AddGlobalHandler <T>()
 {
     WebviewBridge.AddGlobalHandler <T>();
 }
Esempio n. 26
0
 internal ScriptInterface(WebviewBridge bridge)
 {
     this.bridge = bridge ?? throw new ArgumentNullException(nameof(bridge));
 }
Esempio n. 27
0
 public IWindow CreateWindow(WindowConfiguration config, WebviewBridge bridge)
 {
     return(new WinFormsWindow(bridge));
 }
Esempio n. 28
0
 /// <summary>
 /// Adds a custom handler to be called from any webview of the application.
 /// </summary>
 /// <param name="handler">The handler instance.</param>
 public static void AddGlobalHandler(object handler)
 {
     WebviewBridge.AddGlobalHandlerStatic(handler);
 }
Esempio n. 29
0
        public GtkWebview(WindowConfiguration config, IContentProvider contentProvider, WebviewBridge bridge)
        {
            this.config          = config ?? throw new ArgumentNullException(nameof(config));
            this.contentProvider = contentProvider ?? throw new ArgumentNullException(nameof(contentProvider));
            this.bridge          = bridge ?? throw new ArgumentNullException(nameof(bridge));

            // need to keep the delegates around or they will get garbage collected
            scriptDelegate      = ScriptCallback;
            loadFailedDelegate  = LoadFailedCallback;
            loadDelegate        = LoadCallback;
            contextMenuDelegate = ContextMenuCallback;
            closeDelegate       = CloseCallback;
            titleChangeDelegate = TitleChangeCallback;

            if (config.EnableScriptInterface)
            {
                manager = WebKit.Manager.Create();
                GLib.ConnectSignal(manager, "script-message-received::external", scriptDelegate, IntPtr.Zero);

                using (GLibString name = "external")
                {
                    WebKit.Manager.RegisterScriptMessageHandler(manager, name);
                }

                Handle = WebKit.CreateWithUserContentManager(manager);
            }
            else
            {
                Handle = WebKit.Create();
            }

            GLib.ConnectSignal(Handle, "load-failed", loadFailedDelegate, IntPtr.Zero);
            GLib.ConnectSignal(Handle, "load-changed", loadDelegate, IntPtr.Zero);
            GLib.ConnectSignal(Handle, "context-menu", contextMenuDelegate, IntPtr.Zero);
            GLib.ConnectSignal(Handle, "close", closeDelegate, IntPtr.Zero);

            if (config.UseBrowserTitle)
            {
                GLib.ConnectSignal(Handle, "notify::title", titleChangeDelegate, IntPtr.Zero);
            }

            if (string.IsNullOrWhiteSpace(config.ExternalHost))
            {
                const string scheme = "spidereye";
                customHost = UriTools.GetRandomResourceUrl(scheme);

                IntPtr context = WebKit.Context.Get(Handle);
                using (GLibString gscheme = scheme)
                {
                    WebKit.Context.RegisterUriScheme(context, gscheme, UriSchemeCallback, IntPtr.Zero, IntPtr.Zero);
                }
            }

            var bgColor = new GdkColor(config.BackgroundColor);

            WebKit.SetBackgroundColor(Handle, ref bgColor);

            if (enableDevTools)
            {
                var settings = WebKit.Settings.Get(Handle);
                WebKit.Settings.SetEnableDeveloperExtras(settings, true);
                var inspector = WebKit.Inspector.Get(Handle);
                WebKit.Inspector.Show(inspector);
            }
        }
Esempio n. 30
0
 public IWindow CreateWindow(WindowConfiguration config, WebviewBridge bridge)
 {
     return(new AndroidWindow(this._mainActivity, bridge));
 }