private static void InitializeHostHtmlDocumentServiceProvider(DynamicScriptObject scriptObject) { // The service provider is used for Internet Explorer IDispatchEx use. if (IsHostedInIEorWebOC && scriptObject.ScriptObject is UnsafeNativeMethods.IHTMLWindow4 && _hostHtmlDocumentServiceProvider.Value == null) { // We use the IDispatch infrastructure to gain access to the document DOM node where // the IServiceProvider lives that was recommended to us by IE people. Notice during // this call the HostHtmlDocumentServiceProvider property here is still null, so this // first request is made (and succeeds properly) without the service provider in place. object document; bool foundDoc = scriptObject.TryFindMemberAndInvokeNonWrapped("document", NativeMethods.DISPATCH_PROPERTYGET, true /* cache DISPID, why not? */, null, /* arguments */ out document); // The fact the host script is required to be a IHTMLWindow4 here ensures there is // document property and because we're dealing with IE, we know it has a service // provider on it. Invariant.Assert(foundDoc); _hostHtmlDocumentServiceProvider.Value = (UnsafeNativeMethods.IServiceProvider)document; // See HostHtmlDocumentServiceProvider property get accessor for more information on the use of // this field to ensure we got a valid service provider. _initializedHostScript.Value = true; } }
private static void InitializeHostHtmlDocumentServiceProvider(DynamicScriptObject scriptObject) { if (BrowserInteropHelper.IsHostedInIEorWebOC && scriptObject.ScriptObject is UnsafeNativeMethods.IHTMLWindow4 && BrowserInteropHelper._hostHtmlDocumentServiceProvider.Value == null) { object obj; bool condition = scriptObject.TryFindMemberAndInvokeNonWrapped("document", 2, true, null, out obj); Invariant.Assert(condition); BrowserInteropHelper._hostHtmlDocumentServiceProvider.Value = (UnsafeNativeMethods.IServiceProvider)obj; BrowserInteropHelper._initializedHostScript.Value = true; } }
private bool TryFindMemberAndInvoke(string memberName, int flags, bool cacheDispId, object[] args, out object result) { if (!this.TryFindMemberAndInvokeNonWrapped(memberName, flags, cacheDispId, args, out result)) { return(false); } if (result != null && Marshal.IsComObject(result)) { result = new DynamicScriptObject((UnsafeNativeMethods.IDispatch)result); } return(true); }
/// <summary>Sets a member on the script object to the specified value.</summary> /// <param name="binder">The binder provided by the call site.</param> /// <param name="value">The value to set for the member.</param> /// <returns>Always returns <see langword="true" />.</returns> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="binder" /> is <see langword="null" />.-or- /// <paramref name="indexes" /> is <see langword="null" />.</exception> /// <exception cref="T:System.ArgumentException">The length of <paramref name="indexes" /> is not equal to 1.</exception> /// <exception cref="T:System.ArgumentOutOfRangeException">The first <paramref name="indexes" /> value is <see langword="null" />.</exception> /// <exception cref="T:System.MissingMemberException">The member does not exist.</exception> // Token: 0x060061E3 RID: 25059 RVA: 0x001B7378 File Offset: 0x001B5578 public override bool TrySetMember(SetMemberBinder binder, object value) { if (binder == null) { throw new ArgumentNullException("binder"); } int propertyPutMethod = DynamicScriptObject.GetPropertyPutMethod(value); object obj = this.InvokeAndReturn(binder.Name, propertyPutMethod, new object[] { value }); return(true); }
private bool TryFindMemberAndInvoke(string memberName, int flags, bool cacheDispId, object[] args, out object result) { if (!TryFindMemberAndInvokeNonWrapped(memberName, flags, cacheDispId, args, out result)) { return(false); } // Only wrap returned COM objects; if the object returns as a CLR object, we just return it. if (result != null && Marshal.IsComObject(result)) { // Script objects implement IDispatch. result = new DynamicScriptObject((UnsafeNativeMethods.IDispatch)result); } return(true); }
private bool TryFindMemberAndInvoke(string memberName, int flags, bool cacheDispId, object[] args, out object result) { if (!TryFindMemberAndInvokeNonWrapped(memberName, flags, cacheDispId, args, out result)) { return false; } // Only wrap returned COM objects; if the object returns as a CLR object, we just return it. if (result != null && Marshal.IsComObject(result)) { // Script objects implement IDispatch. result = new DynamicScriptObject((UnsafeNativeMethods.IDispatch)result); } return true; }
private static void InitializeHostHtmlDocumentServiceProvider(DynamicScriptObject scriptObject) { // The service provider is used for Internet Explorer IDispatchEx use. if ( IsHostedInIEorWebOC && scriptObject.ScriptObject is UnsafeNativeMethods.IHTMLWindow4 && _hostHtmlDocumentServiceProvider.Value == null) { // We use the IDispatch infrastructure to gain access to the document DOM node where // the IServiceProvider lives that was recommended to us by IE people. Notice during // this call the HostHtmlDocumentServiceProvider property here is still null, so this // first request is made (and succeeds properly) without the service provider in place. object document; bool foundDoc = scriptObject.TryFindMemberAndInvokeNonWrapped("document", NativeMethods.DISPATCH_PROPERTYGET, true /* cache DISPID, why not? */, null, /* arguments */ out document); // The fact the host script is required to be a IHTMLWindow4 here ensures there is // document property and because we're dealing with IE, we know it has a service // provider on it. Invariant.Assert(foundDoc); _hostHtmlDocumentServiceProvider.Value = (UnsafeNativeMethods.IServiceProvider)document; // See HostHtmlDocumentServiceProvider property get accessor for more information on the use of // this field to ensure we got a valid service provider. _initializedHostScript.Value = true; } }
internal unsafe bool TryFindMemberAndInvokeNonWrapped(string memberName, int flags, bool cacheDispId, object[] args, out object result) { result = null; int dispid; if (!this.TryGetDispIdForMember(memberName, cacheDispId, out dispid)) { return(false); } NativeMethods.DISPPARAMS dispparams = new NativeMethods.DISPPARAMS(); int num = -3; if (flags == 4 || flags == 8) { dispparams.cNamedArgs = 1U; dispparams.rgdispidNamedArgs = new IntPtr((void *)(&num)); } try { if (args != null) { args = (object[])args.Clone(); Array.Reverse(args); for (int i = 0; i < args.Length; i++) { DynamicScriptObject dynamicScriptObject = args[i] as DynamicScriptObject; if (dynamicScriptObject != null) { args[i] = dynamicScriptObject._scriptObject; } if (args[i] != null) { Type type = args[i].GetType(); if (type.IsArray) { type = type.GetElementType(); } if (!Marshal.IsTypeVisibleFromCom(type) && !type.IsCOMObject && type != typeof(DateTime)) { throw new ArgumentException(SR.Get("NeedToBeComVisible")); } } } dispparams.rgvarg = UnsafeNativeMethods.ArrayToVARIANTHelper.ArrayToVARIANTVector(args); dispparams.cArgs = (uint)args.Length; } NativeMethods.EXCEPINFO excepinfo = new NativeMethods.EXCEPINFO(); HRESULT hrLeft = this.InvokeOnScriptObject(dispid, flags, dispparams, excepinfo, out result); if (hrLeft.Failed) { if (hrLeft == HRESULT.DISP_E_MEMBERNOTFOUND) { return(false); } if (hrLeft == HRESULT.SCRIPT_E_REPORTED) { excepinfo.scode = hrLeft.Code; hrLeft = HRESULT.DISP_E_EXCEPTION; } string text = "[" + (memberName ?? "(default)") + "]"; Exception exception = hrLeft.GetException(); if (hrLeft == HRESULT.DISP_E_EXCEPTION) { int code = (excepinfo.scode != 0) ? excepinfo.scode : ((int)excepinfo.wCode); hrLeft = HRESULT.Make(true, Facility.Dispatch, code); string message = text + " " + (excepinfo.bstrDescription ?? string.Empty); throw new TargetInvocationException(message, exception) { HelpLink = excepinfo.bstrHelpFile, Source = excepinfo.bstrSource }; } if (hrLeft == HRESULT.DISP_E_BADPARAMCOUNT || hrLeft == HRESULT.DISP_E_PARAMNOTOPTIONAL) { throw new TargetParameterCountException(text, exception); } if (hrLeft == HRESULT.DISP_E_OVERFLOW || hrLeft == HRESULT.DISP_E_TYPEMISMATCH) { throw new ArgumentException(text, new InvalidCastException(exception.Message, hrLeft.Code)); } throw exception; } } finally { if (dispparams.rgvarg != IntPtr.Zero) { UnsafeNativeMethods.ArrayToVARIANTHelper.FreeVARIANTVector(dispparams.rgvarg, args.Length); } } return(true); }