From: Zhenbo Li Subject: [PATCH 1/2] mshtml: Add IHTMLXMLHttpRequestFactory::create() method implementation. Message-Id: <559251C4.5050008@gmail.com> Date: Tue, 30 Jun 2015 16:22:28 +0800 --- dlls/mshtml/htmlwindow.c | 14 ++++---- dlls/mshtml/mshtml_private.h | 5 ++- dlls/mshtml/nsembed.c | 51 ++++++++++++++++++++++++++ dlls/mshtml/nsiface.idl | 85 ++++++++++++++++++++++++++++++++++++++++++++ dlls/mshtml/xmlhttprequest.c | 12 ++++++- 5 files changed, 159 insertions(+), 8 deletions(-) diff --git a/dlls/mshtml/htmlwindow.c b/dlls/mshtml/htmlwindow.c index d7c5d04..b5b906a 100644 --- a/dlls/mshtml/htmlwindow.c +++ b/dlls/mshtml/htmlwindow.c @@ -256,8 +256,9 @@ static void release_inner_window(HTMLInnerWindow *This) IHTMLOptionElementFactory_Release(&This->option_factory->IHTMLOptionElementFactory_iface); } - if(This->xml_factory) { - IHTMLXMLHttpRequestFactory_Release(&This->xml_factory->IHTMLXMLHttpRequestFactory_iface); + if(This->xhr_factory) { + This->xhr_factory->window = NULL; + IHTMLXMLHttpRequestFactory_Release(&This->xhr_factory->IHTMLXMLHttpRequestFactory_iface); } if(This->screen) @@ -1973,16 +1974,17 @@ static HRESULT WINAPI HTMLWindow5_get_XMLHttpRequest(IHTMLWindow5 *iface, VARIAN TRACE("(%p)->(%p)\n", This, p); - if(!window->xml_factory) { + if(!window->xhr_factory) { HRESULT hres; - hres = HTMLXMLHttpRequestFactory_Create(window, &window->xml_factory); - if(FAILED(hres)) + hres = HTMLXMLHttpRequestFactory_Create(window, &window->xhr_factory); + if(FAILED(hres)) { return hres; + } } V_VT(p) = VT_DISPATCH; - V_DISPATCH(p) = (IDispatch*)&window->xml_factory->IHTMLXMLHttpRequestFactory_iface; + V_DISPATCH(p) = (IDispatch*)&window->xhr_factory->IHTMLXMLHttpRequestFactory_iface; IDispatch_AddRef(V_DISPATCH(p)); return S_OK; diff --git a/dlls/mshtml/mshtml_private.h b/dlls/mshtml/mshtml_private.h index 288d4b5..ca021ba 100644 --- a/dlls/mshtml/mshtml_private.h +++ b/dlls/mshtml/mshtml_private.h @@ -359,6 +359,8 @@ typedef struct { IHTMLXMLHttpRequestFactory IHTMLXMLHttpRequestFactory_iface; LONG ref; + + HTMLInnerWindow *window; } HTMLXMLHttpRequestFactory; struct HTMLLocation { @@ -447,7 +449,7 @@ struct HTMLInnerWindow { HTMLImageElementFactory *image_factory; HTMLOptionElementFactory *option_factory; - HTMLXMLHttpRequestFactory *xml_factory; + HTMLXMLHttpRequestFactory *xhr_factory; IHTMLScreen *screen; OmHistory *history; IHTMLStorage *session_storage; @@ -876,6 +878,7 @@ HRESULT nsnode_to_nsstring(nsIDOMNode*,nsAString*) DECLSPEC_HIDDEN; void get_editor_controller(NSContainer*) DECLSPEC_HIDDEN; nsresult get_nsinterface(nsISupports*,REFIID,void**) DECLSPEC_HIDDEN; nsIWritableVariant *create_nsvariant(void) DECLSPEC_HIDDEN; +nsIXMLHttpRequest *create_nsxhr(nsIDOMWindow *nswindow) DECLSPEC_HIDDEN; nsresult create_nsfile(const PRUnichar*,nsIFile**) DECLSPEC_HIDDEN; char *get_nscategory_entry(const char*,const char*) DECLSPEC_HIDDEN; diff --git a/dlls/mshtml/nsembed.c b/dlls/mshtml/nsembed.c index d166ef3..7055635 100644 --- a/dlls/mshtml/nsembed.c +++ b/dlls/mshtml/nsembed.c @@ -48,6 +48,8 @@ WINE_DECLARE_DEBUG_CHANNEL(gecko); #define NS_PREFERENCES_CONTRACTID "@mozilla.org/preferences;1" #define NS_VARIANT_CONTRACTID "@mozilla.org/variant;1" #define NS_CATEGORYMANAGER_CONTRACTID "@mozilla.org/categorymanager;1" +#define NS_XMLHTTPREQUEST_CONTRACTID "@mozilla.org/xmlextras/xmlhttprequest;1" +#define NS_SCRIPTSECURITYMANAGER_CONTRACTID "@mozilla.org/scriptsecuritymanager;1" #define PR_UINT32_MAX 0xffffffff @@ -2160,3 +2162,52 @@ void NSContainer_Release(NSContainer *This) nsIWebBrowserChrome_Release(&This->nsIWebBrowserChrome_iface); } + +nsIXMLHttpRequest *create_nsxhr(nsIDOMWindow *nswindow) +{ + nsIScriptSecurityManager *secman; + nsIPrincipal *nspri; + nsIGlobalObject *nsglo; + nsIXMLHttpRequest *nsxhr; + nsresult nsres; + + nsres = nsIServiceManager_GetServiceByContractID(pServMgr, + NS_SCRIPTSECURITYMANAGER_CONTRACTID, + &IID_nsIScriptSecurityManager, (void**)&secman); + if(NS_FAILED(nsres)) { + ERR("Could not get sec manager service: %08x\n", nsres); + return NULL; + } + + nsres = nsIScriptSecurityManager_GetSystemPrincipal(secman, &nspri); + nsIScriptSecurityManager_Release(secman); + if(NS_FAILED(nsres)) { + ERR("GetSystemPrincipal failed: %08x\n", nsres); + return NULL; + } + + nsres = nsIDOMWindow_QueryInterface(nswindow, &IID_nsIGlobalObject, (void **)&nsglo); + assert(nsres == NS_OK); + + nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, + NS_XMLHTTPREQUEST_CONTRACTID, NULL, &IID_nsIXMLHttpRequest, + (void**)&nsxhr); + if(NS_FAILED(nsres)) { + ERR("Could not get nsIXMLHttpRequest: %08x\n", nsres); + nsISupports_Release(nspri); + nsIGlobalObject_Release(nsglo); + return NULL; + } + + nsres = nsIXMLHttpRequest_Init(nsxhr, nspri, NULL, nsglo, NULL); + + nsISupports_Release(nspri); + nsIGlobalObject_Release(nsglo); + if(NS_FAILED(nsres)) { + ERR("nsIXMLHttpRequest_Init failed: %08x\n", nsres); + nsIXMLHttpRequest_Release(nsxhr); + return NULL; + } + return nsxhr; +} + diff --git a/dlls/mshtml/nsiface.idl b/dlls/mshtml/nsiface.idl index 7cc898c..5da113e 100644 --- a/dlls/mshtml/nsiface.idl +++ b/dlls/mshtml/nsiface.idl @@ -196,6 +196,14 @@ typedef nsISupports nsIDOMPkcs11; typedef nsISupports nsIDocShellTreeOwner; typedef nsISupports nsIArray; typedef nsISupports nsILoadInfo; +typedef nsISupports nsIContentSecurityPolicy; +typedef nsISupports nsIXMLHttpRequestUpload; +typedef nsISupports nsIClassInfo; +typedef nsISupports nsILoadContext; +typedef nsISupports nsIDomainPolicy; +typedef nsISupports nsIScriptContext; +typedef nsISupports nsIObjectInputStream; +typedef nsISupports nsIObjectOutputStream; typedef void *JSContext; typedef void *JSObject; @@ -4015,4 +4023,81 @@ interface nsIPluginInstance : nsISupports nsresult GetDOMElement(nsIDOMElement **aDOMElement); } +[ + object, + uuid(e2538ded-13ef-4f4d-946b-65d333b4f03c), + local +] +interface nsIGlobalObject : nsISupports +{ +} + +[ + object, + uuid(2e91e088-e9fa-4ba4-9887-2a0b7cf27a3e), + local +] +interface nsIXMLHttpRequest : nsISupports +{ + nsresult GetChannel(nsIChannel **aChannel); + nsresult GetResponseXML(nsIDOMDocument **aResponseXML); + nsresult GetResponseText(nsAString *aResponseText); + nsresult GetResponseType(nsAString *aResponseType); + nsresult SetResponseType(const nsAString *aResponseType); + nsresult GetResponse(JSContext*cx, int /*JS::MutableHandleValue*/ aResponse); + nsresult GetStatus(uint32_t *aStatus); + nsresult GetStatusText(nsACString *aStatusText); + nsresult SlowAbort(); + nsresult GetAllResponseHeaders(nsACString *_retval); + nsresult GetResponseHeader(const nsACString *header, nsACString *_retval); + nsresult Open(const nsACString *method, const nsACString *url, bool async, const nsAString *user, const nsAString *password, uint8_t _argc); + nsresult Send(nsIVariant *body); + nsresult SendAsBinary(const nsAString *body); + nsresult SetRequestHeader(const nsACString *header, const nsACString *value); + nsresult GetTimeout(uint32_t *aTimeout); + nsresult SetTimeout(uint32_t aTimeout); + nsresult GetReadyState(uint16_t *aReadyState); + nsresult SlowOverrideMimeType(const nsAString *mimetype); + nsresult GetMozBackgroundRequest(bool *aMozBackgroundRequest); + nsresult SetMozBackgroundRequest(bool aMozBackgroundRequest); + nsresult GetWithCredentials(bool *aWithCredentials); + nsresult SetWithCredentials(bool aWithCredentials); + nsresult Init(nsIPrincipal *principal, nsIScriptContext *scriptContext, nsIGlobalObject *globalObject, nsIURI *baseURI); + nsresult GetUpload(nsIXMLHttpRequestUpload **aUpload); + nsresult GetOnreadystatechange(JSContext*cx, int /*JS::MutableHandleValue*/ aOnreadystatechange); + nsresult SetOnreadystatechange(JSContext*cx, int /*JS::HandleValue*/ aOnreadystatechange); + nsresult GetMozAnon(bool *aMozAnon); + nsresult GetMozSystem(bool *aMozSystem); +} + +[ + object, + uuid(f649959d-dae3-4027-83fd-5b7f8c8a8815), + local +] +interface nsIScriptSecurityManager : nsISupports { + nsresult CanCreateWrapper(JSContext *aJSContext, const nsIID *aIID, nsISupports *aObj, nsIClassInfo *aClassInfo); + nsresult CanCreateInstance(JSContext *aJSContext, const nsCID *aCID); + nsresult CanGetService(JSContext *aJSContext, const nsCID *aCID); + nsresult CheckLoadURIFromScript(JSContext *cx, nsIURI *uri); + nsresult CheckLoadURIWithPrincipal(nsIPrincipal *aPrincipal, nsIURI *uri, uint32_t flags); + nsresult CheckLoadURIStrWithPrincipal(nsIPrincipal *aPrincipal, const nsACString *uri, uint32_t flags); + nsresult ScriptAllowed(JSObject *aGlobal); + nsresult GetSystemPrincipal(nsIPrincipal **_retval); + nsresult GetSimpleCodebasePrincipal(nsIURI *aURI, nsIPrincipal **_retval); + nsresult GetAppCodebasePrincipal(nsIURI *uri, uint32_t appId, bool inMozBrowser, nsIPrincipal **_retval); + nsresult GetLoadContextCodebasePrincipal(nsIURI *uri, nsILoadContext *loadContext, nsIPrincipal **_retval); + nsresult GetDocShellCodebasePrincipal(nsIURI *uri, nsIDocShell *docShell, nsIPrincipal **_retval); + nsresult GetNoAppCodebasePrincipal(nsIURI *uri, nsIPrincipal **_retval); + nsresult GetCodebasePrincipal(nsIURI *uri, nsIPrincipal **_retval); + nsresult CheckSameOriginURI(nsIURI *aSourceURI, nsIURI *aTargetURI, bool reportError); + nsresult GetChannelResultPrincipal(nsIChannel *aChannel, nsIPrincipal **_retval); + nsresult GetChannelURIPrincipal(nsIChannel *aChannel, nsIPrincipal **_retval); + nsresult IsSystemPrincipal(nsIPrincipal *aPrincipal, bool *_retval); + nsresult GetJarPrefix(uint32_t appId, bool inMozBrowser, nsACString *_retval); + nsresult ActivateDomainPolicy(nsIDomainPolicy **_retval); + nsresult GetDomainPolicyActive(bool *aDomainPolicyActive); + nsresult PolicyAllowsScript(nsIURI *aDomain, bool *_retval); +} + cpp_quote("DEFINE_GUID(IID_nsCycleCollectionISupports, 0xc61eac14,0x5f7a,0x4481,0x96,0x5e,0x7e,0xaa,0x6e,0xff,0xa8,0x5f);") diff --git a/dlls/mshtml/xmlhttprequest.c b/dlls/mshtml/xmlhttprequest.c index 4cb3fda..0f7bc9a 100644 --- a/dlls/mshtml/xmlhttprequest.c +++ b/dlls/mshtml/xmlhttprequest.c @@ -38,6 +38,7 @@ typedef struct { EventTarget event_target; IHTMLXMLHttpRequest IHTMLXMLHttpRequest_iface; LONG ref; + nsIXMLHttpRequest *nsxhr; } HTMLXMLHttpRequest; static inline HTMLXMLHttpRequest *impl_from_IHTMLXMLHttpRequest(IHTMLXMLHttpRequest *iface) @@ -378,12 +379,20 @@ static HRESULT WINAPI HTMLXMLHttpRequestFactory_create(IHTMLXMLHttpRequestFactor { HTMLXMLHttpRequestFactory *This = impl_from_IHTMLXMLHttpRequestFactory(iface); HTMLXMLHttpRequest *ret; + nsIXMLHttpRequest *nsxhr; TRACE("(%p)->(%p)\n", This, p); + nsxhr = create_nsxhr(This->window->base.outer_window->nswindow); + if(!nsxhr) + return E_FAIL; + ret = heap_alloc_zero(sizeof(*ret)); - if(!ret) + if(!ret) { + nsIXMLHttpRequest_Release(nsxhr); return E_OUTOFMEMORY; + } + ret->nsxhr = nsxhr; ret->IHTMLXMLHttpRequest_iface.lpVtbl = &HTMLXMLHttpRequestVtbl; init_dispex(&ret->event_target.dispex, (IUnknown*)&ret->IHTMLXMLHttpRequest_iface, @@ -426,6 +435,7 @@ HRESULT HTMLXMLHttpRequestFactory_Create(HTMLInnerWindow* window, HTMLXMLHttpReq ret->IHTMLXMLHttpRequestFactory_iface.lpVtbl = &HTMLXMLHttpRequestFactoryVtbl; ret->ref = 1; + ret->window = window; init_dispex(&ret->dispex, (IUnknown*)&ret->IHTMLXMLHttpRequestFactory_iface, &HTMLXMLHttpRequestFactory_dispex);