Ejemplo n.º 1
0
        public override Tuple <GeckoSession, GeckoRuntime> CreateNewSession()
        {
            var settings = new GeckoSessionSettings.Builder()
                           .UsePrivateMode(true) //Use private mode in order to never cache anything at each app session
                           .UseTrackingProtection(true)
                           .UserAgentMode(GeckoSessionSettings.UserAgentModeMobile)
                           .SuspendMediaWhenInactive(true)
                           .AllowJavascript(true)
                           .Build();

            GeckoSession _session = new GeckoSession(settings);
            GeckoRuntime _runtime = GeckoRuntime.Create(Context);

            _session.Open(_runtime);
            _session.ProgressDelegate = new ProgressDelegate(this);
            _session.ContentDelegate  = new ContentDelegate(this);

            if (WebApplicationFactory._debugFeatures)
            {
                _runtime.Settings.SetRemoteDebuggingEnabled(true);
                _runtime.Settings.SetConsoleOutputEnabled(true);
            }

            return(Tuple.Create(_session, _runtime));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Register the given WebExtension to the given runtime instance of a GeckoView
        /// This method is used to forward event based on WebExtension id to the right GeckoView instance
        /// The WebExtension id will be generated by this method
        /// </summary>
        internal static void RegisterWebExtension(BlazorGeckoView blazorGeckoView, GeckoRuntime runtime, string webExtensionLocation)
        {
            if (blazorGeckoView == null)
            {
                throw new ArgumentNullException(nameof(blazorGeckoView));
            }

            if (runtime == null)
            {
                throw new ArgumentNullException(nameof(runtime));
            }

            //We do a preliminary check if a same runtime on another GeckoView is used. We must not register a WebExtension twice if it is already present on a runtime. We assume that we are using our BlazorWebview as a solo-instance behavior
            if (RuntimeHasWebExtension(runtime, webExtensionLocation))
            {
                //Already registered. Ignore registration
                return;
            }

            //Get an unique identity
            int identity = GenerateWebExtensionIdentity();

            WebExtension webExtension = new WebExtension(webExtensionLocation, identity.ToString());

            //Register the given WebExtension to the runtime
            runtime.RegisterWebExtension(webExtension);

            //Register the WebExtension registration in our dictionnary
            AddRuntimeWebExtensionReference(runtime, webExtension);

            //Register the Webview with this identity attached to retrieve it later by WebExtension identity
            WebViewHelper.RegisterWebView(blazorGeckoView, identity);
        }
Ejemplo n.º 3
0
        private static void AddRuntimeWebExtensionReference(GeckoRuntime runtime, WebExtension webExtension)
        {
            int runtimeIdentity = runtime.GetHashCode();

            if (!_runtimeExtensionDico.ContainsKey(runtimeIdentity))
            {
                _runtimeExtensionDico.Add(runtimeIdentity, new List <WebExtensionMetadata>());
            }

            _runtimeExtensionDico[runtimeIdentity].Add(new WebExtensionMetadata(webExtension.Id, webExtension.Location));
        }
Ejemplo n.º 4
0
        public override Tuple <GeckoSession, GeckoRuntime> CreateNewSession(bool needSessionOpening, string uri)
        {
            if (!_firstCall)
            {
                GeckoSession newSession = new GeckoSession();
                GeckoRuntime newRuntime = GeckoRuntime.GetDefault(Context);

                //With our scenario this should not happen, but enforcing rule just for sanity check
                if (needSessionOpening)
                {
                    newSession.Open(newRuntime);
                }

                return(new Tuple <GeckoSession, GeckoRuntime>(newSession, newRuntime));
            }

            var settings = new GeckoSessionSettings.Builder()
                           .UsePrivateMode(true) //Use private mode in order to never cache anything at each app session
                           .UseTrackingProtection(true)
                           .UserAgentMode(GeckoSessionSettings.UserAgentModeMobile)
                           .SuspendMediaWhenInactive(true)
                           .AllowJavascript(true)
                           .Build();

            GeckoSession _session = new GeckoSession(settings);
            GeckoRuntime _runtime = GeckoRuntime.GetDefault(Context);

            //Register BlazorMobile iframe listener WebExtension, as GeckoView LoadRequest does not bubble up when navigating through an iFrame.
            //NOTE: Delegate for WebExtension handling seem missing from current Xamarin.GeckoView generated bindings, but the handling will be workarounded through the local BlazorMobile server

            //WARNING: With our implementation, registering a WebExtension is per WebView if the same runtime object is used, not per session
            WebExtensionHelper.RegisterWebExtension(Element as BlazorGeckoView, _runtime, "resource://android/assets/obj/BlazorMobile/web_extensions/iframe_listener/");

            if (needSessionOpening)
            {
                _session.Open(_runtime);
            }

            _session.PromptDelegate     = new BlazorGeckoViewPromptDelegate(this);
            _session.ProgressDelegate   = new BlazorProgressDelegate(this);
            _session.ContentDelegate    = new BlazorContentDelegate(this);
            _session.NavigationDelegate = new BlazorNavigationDelegate(this);

            if (WebApplicationFactory._debugFeatures)
            {
                _runtime.Settings.SetRemoteDebuggingEnabled(true);
                _runtime.Settings.SetConsoleOutputEnabled(true);
            }

            _firstCall = false;

            return(Tuple.Create(_session, _runtime));
        }
Ejemplo n.º 5
0
        private static bool RuntimeHasWebExtension(GeckoRuntime runtime, string webExtensionLocation)
        {
            int runtimeIdentity = runtime.GetHashCode();

            return(_runtimeExtensionDico.ContainsKey(runtimeIdentity) && _runtimeExtensionDico[runtimeIdentity].Any(p => p.Location == webExtensionLocation));
        }