protected override bool OnProcessMessageReceived(CefBrowser browser, CefProcessId sourceProcess, CefProcessMessage message) { Console.WriteLine("Client::OnProcessMessageReceived: SourceProcess={0}", sourceProcess); Console.WriteLine("Message Name={0} IsValid={1} IsReadOnly={2}", message.Name, message.IsValid, message.IsReadOnly); var arguments = message.Arguments; for (var i = 0; i < arguments.Count; i++) { var type = arguments.GetValueType(i); object value; switch (type) { case CefValueType.Null: value = null; break; case CefValueType.String: value = arguments.GetString(i); break; case CefValueType.Int: value = arguments.GetInt(i); break; case CefValueType.Double: value = arguments.GetDouble(i); break; case CefValueType.Bool: value = arguments.GetBool(i); break; default: value = null; break; } Console.WriteLine(" [{0}] ({1}) = {2}", i, type, value); } if (message.Name == "myMessage2" || message.Name == "myMessage3") return true; return false; }
private int on_process_message_received(cef_render_process_handler_t *self, cef_browser_t *browser, CefProcessId source_process, cef_process_message_t *message) { CheckSelf(self); var m_browser = CefBrowser.FromNative(browser); var m_message = CefProcessMessage.FromNative(message); var result = OnProcessMessageReceived(m_browser, source_process, m_message); m_message.Dispose(); return(result ? 1 : 0); }
/// <summary> /// Called when a new message is received from a different process. Return true /// if the message was handled or false otherwise. Do not keep a reference to /// or attempt to access the message outside of this callback. /// </summary> protected virtual bool OnProcessMessageReceived(CefBrowser browser, CefProcessId sourceProcess, CefProcessMessage message) { return(false); }
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; }
/// <summary> /// Returns a writable copy of this object. /// </summary> public CefProcessMessage Copy() { return(CefProcessMessage.FromNative( cef_process_message_t.copy(_self) )); }
/// <summary> /// Called when a new message is received from a different process. Return true /// if the message was handled or false otherwise. Do not keep a reference to /// or attempt to access the message outside of this callback. /// </summary> protected virtual bool OnProcessMessageReceived(CefBrowser browser, CefProcessId sourceProcess, CefProcessMessage message) { return false; }
/// <summary> /// Send a message to the specified |target_process|. Returns true if the /// message was sent successfully. /// </summary> public bool SendProcessMessage(CefProcessId target, CefProcessMessage message) { if (message == null) throw new ArgumentNullException("message"); return cef_browser_t.send_process_message(_self, target, message.ToNative()) != 0; }