Exemplo 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));
        }
Exemplo n.º 2
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));
        }
 public override void OnPageStop(GeckoSession session, bool success)
 {
     base.OnPageStop(session, success);
 }
 public override GeckoResult OnLoadRequest(GeckoSession session, GeckoSession.avigationDelegateClassLoadRequest request)
 {
     return(base.OnLoadRequest(session, request));
 }
 public override GeckoResult OnNewSession(GeckoSession session, string uri)
 {
     return(base.OnNewSession(session, uri));
 }
Exemplo n.º 6
0
 public virtual void OnAuthPrompt(GeckoSession session, string title, string msg, GeckoSession.romptDelegateClassAuthOptions options, GeckoSession.PromptDelegateClassAuthCallback callback)
 {
 }
 public override void OnCanGoForward(GeckoSession session, bool canGoForward)
 {
     base.OnCanGoForward(session, canGoForward);
 }
Exemplo n.º 8
0
 public override void OnFirstComposite(GeckoSession session)
 {
     base.OnFirstComposite(session);
 }
Exemplo n.º 9
0
 public override void OnFullScreen(GeckoSession session, bool fullScreen)
 {
     base.OnFullScreen(session, fullScreen);
 }
Exemplo n.º 10
0
 public override void OnCloseRequest(GeckoSession session)
 {
     base.OnCloseRequest(session);
 }
Exemplo n.º 11
0
 public override void OnCrash(GeckoSession session)
 {
     base.OnCrash(session);
 }
Exemplo n.º 12
0
 public virtual void OnTextPrompt(GeckoSession session, string title, string msg, string value, GeckoSession.PromptDelegateClassTextCallback callback)
 {
 }
 public override void OnPageStart(GeckoSession session, string url)
 {
     base.OnPageStart(session, url);
 }
Exemplo n.º 14
0
 public virtual GeckoResult OnPopupRequest(GeckoSession session, string targetUri)
 {
     //TODO
     throw new NotImplementedException();
 }
Exemplo n.º 15
0
        public virtual void OnFilePrompt(GeckoSession session, string title, int type, string[] mimeTypes, GeckoSession.PromptDelegateClassFileCallback callback)
        {
            var currentActivity = BlazorWebViewService.GetCurrentActivity();

            AlertDialog _futureDialog = null; //Workaround dismiss method not available on AlertDialog.Builder before Show();

            bool shouldDismiss = true;

            var dialogBuilder = new Android.App.AlertDialog.Builder(_renderer.Context);
            BlazorFileDialogDismissListener onDismissEvent = new BlazorFileDialogDismissListener();

            onDismissEvent.SetDismissHandler(() =>
            {
                if (shouldDismiss)
                {
                    callback.Dismiss();
                }

                dialogBuilder.Dispose();
            });

            dialogBuilder.SetOnDismissListener(onDismissEvent);

            GetContentCompatibleIntents(type, out List <IntentMetadata> intentList, out List <ResolveInfo> activitiesInfo);
            dialogBuilder.SetAdapter(BuilderAdapter(currentActivity, activitiesInfo),
                                     (sender, e) =>
            {
                //On Intent click

                shouldDismiss = false;
                IntentMetadata selectedIntent = intentList.ElementAt(e.Which);

                //Check for Android permissions for intents
                RequestPermissionHelper.CheckForPermission(selectedIntent.RequiredPermissions, () =>
                {
                    //On Intent permission availables

                    //We must manage multiple file selection too

                    //TODO: Even by adding this intent
                    //this seem to not working yet. Not sure if possible through launching external intents
                    if (type == FilePromptType.MULTIPLE)
                    {
                        selectedIntent.Intent.PutExtra(Intent.ExtraAllowMultiple, true);
                    }

                    currentActivity.StartActivityForResult(selectedIntent.Intent, 1, (int requestCode, Result resultCode, Intent data) =>
                    {
                        if (resultCode != Result.Ok)
                        {
                            //Do nothing as the user is still now on the Intent dialog box chooser

                            //As on Permission not granted, see comment below =>
                            //We should reset this value to true if denied, as the user may don't click on Cancel but use a back button instead
                            //As the back button will call the Dialog dismiss internally, we should emulate the cancel behavior (see SetNeutralButton code)
                            shouldDismiss = true;
                        }
                        else
                        {
                            try
                            {
                                callback.Confirm(currentActivity, GetFileForBrowser(data.Data));
                            }
                            catch (System.Exception e)
                            {
                                ConsoleHelper.WriteException(e);
                                callback.Dismiss();
                            }

                            _futureDialog.Dismiss();
                        }
                    });
                }, () =>
                {
                    //On Intent permission unavailable

                    //We should reset this value to true if denied, as the user may don't click on Cancel but use a back button instead
                    //As the back button will call the Dialog dismiss internally, we should emulate the cancel behavior (see SetNeutralButton code)
                    shouldDismiss = true;
                });
            });


            dialogBuilder.SetNeutralButton(currentActivity.Resources.GetString(Android.Resource.String.Cancel),
                                           (sender, e) =>
            {
                shouldDismiss = true;
                _futureDialog.Dismiss();
            });
            shouldDismiss = true;
            _futureDialog = dialogBuilder.Show();
        }
Exemplo n.º 16
0
 public virtual void OnDateTimePrompt(GeckoSession session, string title, int type, string value, string min, string max, GeckoSession.PromptDelegateClassTextCallback callback)
 {
 }
Exemplo n.º 17
0
        public virtual void OnChoicePrompt(GeckoSession session, string title, string msg, int type, GeckoSession.romptDelegateClassChoice[] choices, GeckoSession.PromptDelegateClassChoiceCallback prompt)
        {
            //This code is highly inspired of https://github.com/mozilla-mobile/focus-android/blob/f5b22ff78fca22765b8b873b4f70693943ae559a/app/src/main/java/org/mozilla/focus/gecko/GeckoViewPrompt.java#L265

            var currentActivity = BlazorWebViewService.GetCurrentActivity();

            if (currentActivity == null)
            {
                prompt.Dismiss();
                return;
            }

            var builder = new Android.App.AlertDialog.Builder(currentActivity);

            AddStandardLayout(builder, title, msg);

            Android.Widget.ListView list = new Android.Widget.ListView(builder.Context);
            if (type == GeckoSession.romptDelegateClassChoice.ChoiceTypeMultiple)
            {
                list.ChoiceMode = ChoiceMode.Multiple;
            }

            ModifiableChoiceArrayAdapter <ModifiableChoice> adapter = new ModifiableChoiceArrayAdapter <ModifiableChoice>(builder.Context, Android.Resource.Layout.SimpleListItem1, type, builder, list);

            AddChoiceItems(type, adapter, choices, /* indent */ null);

            list.SetAdapter(adapter);
            builder.SetView(list);

            AlertDialog dialog;

            if (type == GeckoSession.romptDelegateClassChoice.ChoiceTypeSingle || type == GeckoSession.romptDelegateClassChoice.ChoiceTypeMenu)
            {
                dialog = CreateStandardDialog(builder, prompt);

                list.ItemClick += (sender, e) =>
                {
                    ModifiableChoice item = adapter.GetItem(e.Position);
                    if (type == GeckoSession.romptDelegateClassChoice.ChoiceTypeMenu)
                    {
                        GeckoSession.romptDelegateClassChoice[] children = item.Choice.Items?.ToArray();
                        if (children != null)
                        {
                            // Show sub-menu.
                            dialog.SetOnDismissListener(null);
                            dialog.Dismiss();
                            OnChoicePrompt(session, item.ModifiableLabel, /* msg */ null,
                                           type, children, prompt);
                            return;
                        }
                    }
                    prompt.Confirm(item.Choice);
                    dialog.Dismiss();
                };
            }
            else if (type == GeckoSession.romptDelegateClassChoice.ChoiceTypeMultiple)
            {
                list.ItemClick += (sender, e) =>
                {
                    ModifiableChoice item = adapter.GetItem(e.Position);
                    item.ModifiableSelected = ((CheckedTextView)e.View).Checked;
                };
                builder
                .SetNegativeButton(Android.Resource.String.Cancel, /* listener */ (IDialogInterfaceOnClickListener)null)
                .SetPositiveButton(Android.Resource.String.Ok, (sender, e) =>
                {
                    int len             = adapter.Count;
                    List <string> items = new List <string>(len);
                    for (int i = 0; i < len; i++)
                    {
                        ModifiableChoice item = adapter.GetItem(i);
                        if (item.ModifiableSelected)
                        {
                            items.Add(item.Choice.Id);
                        }
                    }
                    prompt.Confirm(items.ToArray());
                });
                dialog = CreateStandardDialog(builder, prompt);
            }
            else
            {
                throw new UnsupportedOperationException();
            }
            dialog.Show();

            //TODO: Don't forget to Dispose dialogbuilder
        }
Exemplo n.º 18
0
 public virtual void OnButtonPrompt(GeckoSession session, string title, string msg, string[] btnMsg, GeckoSession.PromptDelegateClassButtonCallback callback)
 {
 }
Exemplo n.º 19
0
 public override void OnContextMenu(GeckoSession session, int screenX, int screenY, GeckoSession.ContentDelegateContextElement element)
 {
     base.OnContextMenu(session, screenX, screenY, element);
 }
 public override void OnProgressChange(GeckoSession session, int progress)
 {
     base.OnProgressChange(session, progress);
 }
Exemplo n.º 21
0
 public override void OnExternalResponse(GeckoSession session, GeckoSession.WebResponseInfo response)
 {
     base.OnExternalResponse(session, response);
 }
 public override void OnSecurityChange(GeckoSession session, GeckoSession.ProgressDelegateSecurityInformation securityInfo)
 {
     base.OnSecurityChange(session, securityInfo);
 }
Exemplo n.º 23
0
 public override void OnFocusRequest(GeckoSession session)
 {
     base.OnFocusRequest(session);
 }
 public override void OnCanGoBack(GeckoSession session, bool canGoBack)
 {
     base.OnCanGoBack(session, canGoBack);
 }
Exemplo n.º 25
0
 public override void OnTitleChange(GeckoSession session, string title)
 {
     base.OnTitleChange(session, title);
 }
Exemplo n.º 26
0
 public virtual void OnAlert(GeckoSession session, string title, string msg, GeckoSession.PromptDelegateClassAlertCallback callback)
 {
 }