Esempio n. 1
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. 2
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);
            }
        }
Esempio n. 3
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);
            }
        }