Exemple #1
0
        private void OnNextPromiseResult(PromiseResult promiseResult)
        {
            var id = Int64.Parse(promiseResult.Id);

            if (pendingPromises.Has(id))
            {
                var pendingPromise = pendingPromises.Get(id);
                pendingPromise.Continuation(promiseResult);
            }
        }
        public bool Execute(string name, ICefV8Value obj, ICefV8Value[] arguments, out ICefV8Value returnValue, out string exception)
        {
            returnValue = CefV8Value.CreateNull();
            exception   = null;
            var result = false;

            if (name == "bindingRequire")
            {
                var browser = CefV8Context.GetCurrentContext().GetBrowser();

                if (browserControllers.TryGetValue(browser.Identifier, out var browserController))
                {
                    returnValue = browserController.OnBindingRequire(arguments[0]);
                }

                result = true;
            }
            else if (name == "setPromiseInteractions")
            {
                var context            = CefV8Context.GetCurrentContext();
                var global             = context.GetGlobal();
                var promiseDataStorage = CefV8Value.CreateObject();
                global.SetValue(PromiseService.HelperObjectName, promiseDataStorage,
                                CefV8PropertyAttribute.DontDelete | CefV8PropertyAttribute.DontEnum |
                                CefV8PropertyAttribute.ReadOnly);

                promiseDataStorage.SetUserData(new PromiseUserData(arguments[0], arguments[1], arguments[2]));

                result = true;
            }
            else if (name == "promiseDone")
            {
                using (var id = arguments[0])
                    using (var success = arguments[1])
                        using (var error = arguments[3])
                        {
                            var res = arguments[2];
                            PromiseResult?.Invoke(new PromiseResult
                            {
                                Id      = id.GetStringValue(),
                                Success = success.GetBoolValue(),
                                Error   = error.IsString ? error.GetStringValue() : null,
                                Result  = res,
                                Context = CefV8Context.GetCurrentContext()
                            });
                        }

                result = true;
            }

            return(result);
        }
Exemple #3
0
 protected override void OnActivityResult(Int32 requestCode, Result resultCode, Intent data)
 {
     try
     {
         PromiseResult result = PluginBridge.GetPromiseResultFromActivityResult(this, requestCode, (int)resultCode, data);
         if (result.IsError)
         {
             currentTask?.TrySetException(new Exception(result.ErrorMessage));
         }
         else
         {
             var pdfUrl = result.Result["pdfUrl"].ToString();
             currentTask?.TrySetResult(pdfUrl);
         }
     }
     catch (Exception e)
     {
         currentTask?.TrySetException(e);
     }
 }