Example #1
0
 public CwbDOMVisitor(CefBrowser browser, CwbBusinStyle businID, string elementID, string elementValue)
 {
     _businID = businID;
     _elementID = elementID;
     _elementValue = elementValue;
     this.browser = browser;
 }
 public CwbDOMVisitor(CefBrowser browser, CwbBusinStyle businID, string elementID, string elementValue)
 {
     _businID = businID;
     _elementID = elementID;
     _elementValue = elementValue;
     this.browser = browser;
 }
Example #3
0
 protected override void Visit(CefDomDocument document)
 {
     CefDomNode element;
     switch (_businID)
     {
         case CwbBusinStyle.bsGetElementValue:
             
             Global.Result = "";
             element = document.GetElementById(_elementID);
             if (element == null)
             {
                 Global.flag = true;
                 return;
             }
             Global.Result = element.Value;
             if (element.ElementTagName.ToLower() != "input")
                 Global.Result = element.InnerText;
             Global.flag = true;
             break;
         case CwbBusinStyle.bsSetElementValue:
             element = document.GetElementById(_elementID);
             if (element == null) return;
             if (element.IsEditable)
                 element.SetAttribute("value", _elementValue);
             else
             {
                 string code = "document.getElementById('{0}').innerHTML = '{1}';";
                 code = string.Format(code,_elementID,_elementValue);
                 Global.instance.ExecuteScript(code);
             }
             break;
         case CwbBusinStyle.bsAddElementEvent:
             element = document.GetElementById(_item.id);
             if (element == null) return;
             element.AddEventListener(_item.eventName,new RSEventListener(_item.elementListener),true);
             break;
         case CwbBusinStyle.bsVisitDocument:
             Global.flag = false;
             CefDomNode root = document.Root;
             CwbElement Root = CreateElement(root);
             if (Global.RootList.ContainsKey(browser.Identifier))
             {
                 Global.RootList[ browser.Identifier ] = Root;
             }
             else
             {
                 Global.RootList.Add(browser.Identifier, Root);
             }
             string indexPath = "0";
             Root.IndexPath = indexPath;
             AppendAllChildElement(root, Root, indexPath);
             Global.flag = true;
             break;
         case CwbBusinStyle.bsAttachElementEvent:
             CefDomNode root1 = document.Root;
             string indexPath1 = "0";
             AttachEventHandler(root1, indexPath1, new RSEventListener(_item.elementListener));
             Global.flag = true;
             break;
     }
     _businID = CwbBusinStyle.bsNone;
 }
Example #4
0
 public CwbDOMVisitor(CefBrowser browser, CwbBusinStyle businID, CwbListenerItem item)
 {
     this.browser = browser;
     _businID = businID;
     _item = item;
 }
 protected override void Visit(CefDomDocument document)
 {
     CefDomNode element;
     switch (_businID)
     {
         case CwbBusinStyle.bsGetElementValue:
             
             Global.Result = "";
             element = document.GetElementById(_elementID);
             if (element == null)
             {
                 Global.flag = true;
                 return;
             }
             Global.Result = element.Value;
             if (element.ElementTagName.ToLower() != "input")
                 Global.Result = element.InnerText;
             Global.flag = true;
             break;
         case CwbBusinStyle.bsSetElementValue:
             element = document.GetElementById(_elementID);
             if (element == null) return;
             if (element.IsEditable)
                 element.SetAttribute("value", _elementValue);
             else
             {
                 string code = "document.getElementById('{0}').innerHTML = '{1}';";
                 code = string.Format(code,_elementID,_elementValue);
                 Global.instance.ExecuteScript(code);
             }
             break;
         case CwbBusinStyle.bsAddElementEvent:
             element = document.GetElementById(_item.id);
             if (element == null) return;
             element.AddEventListener(_item.eventName,new RSEventListener(_item.elementListener),true);
             break;
         case CwbBusinStyle.bsVisitDocument:
             Global.flag = false;
             CefDomNode root = document.Root;
             CwbElement Root = CreateElement(root);
             if (Global.RootList.ContainsKey(browser.Identifier))
             {
                 Global.RootList[ browser.Identifier ] = Root;
             }
             else
             {
                 Global.RootList.Add(browser.Identifier, Root);
             }
             string indexPath = "0";
             Root.IndexPath = indexPath;
             AppendAllChildElement(root, Root, indexPath);
             Global.flag = true;
             break;
         case CwbBusinStyle.bsAttachElementEvent:
             CefDomNode root1 = document.Root;
             string indexPath1 = "0";
             AttachEventHandler(root1, indexPath1, new RSEventListener(_item.elementListener));
             Global.flag = true;
             break;
     }
     _businID = CwbBusinStyle.bsNone;
 }
 public CwbDOMVisitor(CefBrowser browser, CwbBusinStyle businID, CwbListenerItem item)
 {
     this.browser = browser;
     _businID = businID;
     _item = item;
 }
Example #7
0
        protected override bool OnProcessMessageReceived(CefBrowser browser, CefProcessId sourceProcess, CefProcessMessage message)
        {
            string[] items = message.Name.Split(new char[] { '|' });
            if (items.Length == 0)
            {
                return(false);
            }

            switch (items[0])
            {
            case "GetElementValue":
            {
                string elementID = items[1];
                long[] frameIDs  = browser.GetFrameIdentifiers();
                foreach (long frameID in frameIDs)
                {
                    CefFrame frame = browser.GetFrame(frameID);
                    if (frame == null)
                    {
                        continue;
                    }
                    frame.VisitDom(new CwbDOMVisitor(browser, CwbBusinStyle.bsGetElementValue, elementID));
                }
                browser.GetMainFrame().VisitDom(new CwbDOMVisitor(browser, CwbBusinStyle.bsGetElementValue, elementID));
                return(true);
            }

            case "SetElementValue":
            {
                string elementID    = items[1];
                string elementValue = items[2];
                long[] frameIDs     = browser.GetFrameIdentifiers();
                foreach (long frameID in frameIDs)
                {
                    CefFrame frame = browser.GetFrame(frameID);
                    if (frame == null)
                    {
                        continue;
                    }
                    frame.VisitDom(new CwbDOMVisitor(browser, CwbBusinStyle.bsGetElementValue, elementID, elementValue));
                }
                browser.GetMainFrame().VisitDom(new CwbDOMVisitor(browser, CwbBusinStyle.bsSetElementValue, elementID, elementValue));
                return(true);
            }

            case "EvaluateScript":
            {
                CefV8Value     value = CefV8Value.CreateString("t");
                CefV8Exception exp;
                browser.GetMainFrame().V8Context.TryEval(items[1], out value, out exp);
                Global.JsEvaResult = null;
                if (value.IsString)
                {
                    Global.JsEvaResult = value.GetStringValue();
                }
                if (value.IsInt)
                {
                    Global.JsEvaResult = value.GetIntValue();
                }
                if (value.IsDouble)
                {
                    Global.JsEvaResult = value.GetDoubleValue();
                }
                if (value.IsBool)
                {
                    Global.JsEvaResult = value.GetBoolValue();
                }
                if (value.IsDate)
                {
                    Global.JsEvaResult = value.GetDateValue();
                }
                Global.flag = true;
                return(true);
            }

            case "AppendListener":
            {
                CwbBusinStyle cbStyle = CwbBusinStyle.bsAddElementEvent;
                if (items.Length > 2)
                {
                    cbStyle = CwbBusinStyle.bsAttachElementEvent;
                }
                string elementID = items[1];
                long[] frameIDs  = browser.GetFrameIdentifiers();
                foreach (long frameID in frameIDs)
                {
                    CefFrame frame = browser.GetFrame(frameID);
                    if (frame == null)
                    {
                        continue;
                    }
                    frame.VisitDom(new CwbDOMVisitor(browser, cbStyle, webBrowser.getEventListener(elementID)));
                }
                browser.GetMainFrame().VisitDom(new CwbDOMVisitor(browser, cbStyle, webBrowser.getEventListener(elementID)));
                return(true);
            }

            case "GetDocument":
            {
                browser.GetMainFrame().VisitDom(new CwbDOMVisitor(browser, CwbBusinStyle.bsVisitDocument, ""));
                return(true);
            }
            }
            return(false);
        }