コード例 #1
0
ファイル: Hybrid.cs プロジェクト: futureplatforms/Kirin
        void browser_ScriptNotify(object sender, INotifyEventArgsWrapper e)
        {
            if (e.Value.StartsWith("native"))
            {
                _Browser.InvokeScriptAsync("eval", "window.api.setReady(true);");

                string schemelessUri = e.Value.Substring("native://".Length);

                int    slash      = schemelessUri.IndexOf('/');
                string method     = schemelessUri.Substring(0, slash);
                string parameters = schemelessUri.Substring(slash + 1);

                Debug.WriteLine("about to invoke webViewSaid: " + method + ", " + parameters);
                _WebViewSaid.Invoke(_Module, new object[] { method, parameters });
            }
        }
コード例 #2
0
        void wb_ScriptNotify(object sender, INotifyEventArgsWrapper e)
        {
            if (!navigated && e.Value.StartsWith("ready"))
            {
                navigated = true;
                while (queue.Count > 0)
                {
                    ActuallyInvokeIt(queue.Dequeue());
                }
                return;
            }
            if (!e.Value.StartsWith("native"))
            {
                Debug.WriteLine(e.Value);
                return;
            }

            // Here's an example URI:
            // native://DebugConsole.log_atLevel_/?%5B%22Javascript%20says%3A%20windaes%20webview%20loaded%22%2C%22INFO%22%5D

            // We need to parse the URI ourselves because uri.host loses string case information
            string schemelessUri = e.Value.Substring("native://".Length);

            // ok our string now looks like this:
            // DebugConsole.log_atLevel_/?%5B%22Javascript%20says%3A%20windaes%20webview%20loaded%22%2C%22INFO%22%5D
            // everything before /? is class and method, everything after /? is the parameters
            int    slash          = schemelessUri.IndexOf('/');
            string classAndMethod = schemelessUri.Substring(0, slash);
            string parameters     = schemelessUri.Substring(slash + 2);

            // before the . is the classname, after the . is the method
            int    dot       = classAndMethod.IndexOf('.');
            string className = classAndMethod.Substring(0, dot);
            string method    = classAndMethod.Substring(dot + 1);

            context.PerformMethod(className, method, parameters);
            wb.InvokeScriptAsync("eval", "EXPOSED_TO_NATIVE.runNext();");
        }