mshtml: Moved HTMLLocation object to HTMLWindow.

This commit is contained in:
Jacek Caban 2009-09-16 22:05:50 +02:00 committed by Alexandre Julliard
parent c9f6aaa2f7
commit 74f28d4a20
4 changed files with 66 additions and 48 deletions

View File

@ -196,9 +196,6 @@ static ULONG WINAPI HTMLDocument_Release(IHTMLDocument2 *iface)
if(This->hwnd) if(This->hwnd)
DestroyWindow(This->hwnd); DestroyWindow(This->hwnd);
if(This->location)
This->location->doc = NULL;
if(This->window) if(This->window)
IHTMLWindow2_Release(HTMLWINDOW2(This->window)); IHTMLWindow2_Release(HTMLWINDOW2(This->window));
@ -733,13 +730,7 @@ static HRESULT WINAPI HTMLDocument_get_location(IHTMLDocument2 *iface, IHTMLLoca
TRACE("(%p)->(%p)\n", This, p); TRACE("(%p)->(%p)\n", This, p);
if(This->location) return IHTMLWindow2_get_location(HTMLWINDOW2(This->window), p);
IHTMLLocation_AddRef(HTMLLOCATION(This->location));
else
This->location = HTMLLocation_Create(This);
*p = HTMLLOCATION(This->location);
return S_OK;
} }
static HRESULT WINAPI HTMLDocument_get_lastModified(IHTMLDocument2 *iface, BSTR *p) static HRESULT WINAPI HTMLDocument_get_lastModified(IHTMLDocument2 *iface, BSTR *p)

View File

@ -35,6 +35,18 @@
WINE_DEFAULT_DEBUG_CHANNEL(mshtml); WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
static HRESULT get_url(HTMLLocation *This, const WCHAR **ret)
{
if(!This->window || !This->window->doc || !This->window->doc->url) {
FIXME("No current URL\n");
return E_NOTIMPL;
}
*ret = This->window->doc->url;
return S_OK;
}
#define HTMLLOCATION_THIS(iface) DEFINE_THIS(HTMLLocation, HTMLLocation, iface) #define HTMLLOCATION_THIS(iface) DEFINE_THIS(HTMLLocation, HTMLLocation, iface)
static HRESULT WINAPI HTMLLocation_QueryInterface(IHTMLLocation *iface, REFIID riid, void **ppv) static HRESULT WINAPI HTMLLocation_QueryInterface(IHTMLLocation *iface, REFIID riid, void **ppv)
@ -80,8 +92,8 @@ static ULONG WINAPI HTMLLocation_Release(IHTMLLocation *iface)
TRACE("(%p) ref=%d\n", This, ref); TRACE("(%p) ref=%d\n", This, ref);
if(!ref) { if(!ref) {
if(This->doc && This->doc->location == This) if(This->window)
This->doc->location = NULL; This->window->location = NULL;
release_dispex(&This->dispex); release_dispex(&This->dispex);
heap_free(This); heap_free(This);
} }
@ -129,20 +141,20 @@ static HRESULT WINAPI HTMLLocation_put_href(IHTMLLocation *iface, BSTR v)
static HRESULT WINAPI HTMLLocation_get_href(IHTMLLocation *iface, BSTR *p) static HRESULT WINAPI HTMLLocation_get_href(IHTMLLocation *iface, BSTR *p)
{ {
HTMLLocation *This = HTMLLOCATION_THIS(iface); HTMLLocation *This = HTMLLOCATION_THIS(iface);
const WCHAR *url;
HRESULT hres;
TRACE("(%p)->(%p)\n", This, p); TRACE("(%p)->(%p)\n", This, p);
if(!p) if(!p)
return E_POINTER; return E_POINTER;
if(!This->doc || !This->doc->url) { hres = get_url(This, &url);
FIXME("No current URL\n"); if(FAILED(hres))
return E_NOTIMPL; return hres;
}
*p = SysAllocString(This->doc->url); *p = SysAllocString(url);
return *p ? S_OK : E_OUTOFMEMORY;
return S_OK;
} }
static HRESULT WINAPI HTMLLocation_put_protocol(IHTMLLocation *iface, BSTR v) static HRESULT WINAPI HTMLLocation_put_protocol(IHTMLLocation *iface, BSTR v)
@ -213,17 +225,17 @@ static HRESULT WINAPI HTMLLocation_get_pathname(IHTMLLocation *iface, BSTR *p)
HTMLLocation *This = HTMLLOCATION_THIS(iface); HTMLLocation *This = HTMLLOCATION_THIS(iface);
WCHAR buf[INTERNET_MAX_PATH_LENGTH]; WCHAR buf[INTERNET_MAX_PATH_LENGTH];
URL_COMPONENTSW url = {sizeof(url)}; URL_COMPONENTSW url = {sizeof(url)};
const WCHAR *doc_url;
DWORD size = 0; DWORD size = 0;
HRESULT hres; HRESULT hres;
TRACE("(%p)->(%p)\n", This, p); TRACE("(%p)->(%p)\n", This, p);
if(!This->doc || !This->doc->url) { hres = get_url(This, &doc_url);
FIXME("No current URL\n"); if(FAILED(hres))
return E_NOTIMPL; return hres;
}
hres = CoInternetParseUrl(This->doc->url, PARSE_PATH_FROM_URL, 0, buf, sizeof(buf), &size, 0); hres = CoInternetParseUrl(doc_url, PARSE_PATH_FROM_URL, 0, buf, sizeof(buf), &size, 0);
if(SUCCEEDED(hres)) { if(SUCCEEDED(hres)) {
*p = SysAllocString(buf); *p = SysAllocString(buf);
if(!*p) if(!*p)
@ -232,7 +244,7 @@ static HRESULT WINAPI HTMLLocation_get_pathname(IHTMLLocation *iface, BSTR *p)
} }
url.dwUrlPathLength = 1; url.dwUrlPathLength = 1;
if(!InternetCrackUrlW(This->doc->url, 0, 0, &url)) { if(!InternetCrackUrlW(doc_url, 0, 0, &url)) {
FIXME("InternetCrackUrl failed\n"); FIXME("InternetCrackUrl failed\n");
return E_FAIL; return E_FAIL;
} }
@ -382,15 +394,20 @@ static dispex_static_data_t HTMLLocation_dispex = {
}; };
HTMLLocation *HTMLLocation_Create(HTMLDocument *doc) HRESULT HTMLLocation_Create(HTMLWindow *window, HTMLLocation **ret)
{ {
HTMLLocation *ret = heap_alloc(sizeof(*ret)); HTMLLocation *location;
ret->lpHTMLLocationVtbl = &HTMLLocationVtbl; location = heap_alloc(sizeof(*location));
ret->ref = 1; if(!location)
ret->doc = doc; return E_OUTOFMEMORY;
init_dispex(&ret->dispex, (IUnknown*)HTMLLOCATION(ret), &HTMLLocation_dispex); location->lpHTMLLocationVtbl = &HTMLLocationVtbl;
location->ref = 1;
location->window = window;
return ret; init_dispex(&location->dispex, (IUnknown*)HTMLLOCATION(location), &HTMLLocation_dispex);
*ret = location;
return S_OK;
} }

View File

@ -100,6 +100,11 @@ static ULONG WINAPI HTMLWindow2_Release(IHTMLWindow2 *iface)
IHTMLOptionElementFactory_Release(HTMLOPTFACTORY(This->option_factory)); IHTMLOptionElementFactory_Release(HTMLOPTFACTORY(This->option_factory));
} }
if(This->location) {
This->location->window = NULL;
IHTMLLocation_Release(HTMLLOCATION(This->location));
}
if(This->event_target) if(This->event_target)
release_event_target(This->event_target); release_event_target(This->event_target);
for(i=0; i < This->global_prop_cnt; i++) for(i=0; i < This->global_prop_cnt; i++)
@ -364,12 +369,18 @@ static HRESULT WINAPI HTMLWindow2_get_location(IHTMLWindow2 *iface, IHTMLLocatio
TRACE("(%p)->(%p)\n", This, p); TRACE("(%p)->(%p)\n", This, p);
if(!This->doc) { if(This->location) {
FIXME("This->doc is NULL\n"); IHTMLLocation_AddRef(HTMLLOCATION(This->location));
return E_FAIL; }else {
HRESULT hres;
hres = HTMLLocation_Create(This, &This->location);
if(FAILED(hres))
return hres;
} }
return IHTMLDocument2_get_location(HTMLDOC(This->doc), p); *p = HTMLLOCATION(This->location);
return S_OK;
} }
static HRESULT WINAPI HTMLWindow2_get_history(IHTMLWindow2 *iface, IOmHistory **p) static HRESULT WINAPI HTMLWindow2_get_history(IHTMLWindow2 *iface, IOmHistory **p)

View File

@ -176,6 +176,15 @@ typedef struct {
HTMLWindow *window; HTMLWindow *window;
} HTMLOptionElementFactory; } HTMLOptionElementFactory;
struct HTMLLocation {
DispatchEx dispex;
const IHTMLLocationVtbl *lpHTMLLocationVtbl;
LONG ref;
HTMLWindow *window;
};
struct HTMLWindow { struct HTMLWindow {
DispatchEx dispex; DispatchEx dispex;
const IHTMLWindow2Vtbl *lpHTMLWindow2Vtbl; const IHTMLWindow2Vtbl *lpHTMLWindow2Vtbl;
@ -194,6 +203,7 @@ struct HTMLWindow {
struct list script_hosts; struct list script_hosts;
HTMLOptionElementFactory *option_factory; HTMLOptionElementFactory *option_factory;
HTMLLocation *location;
global_prop_t *global_props; global_prop_t *global_props;
DWORD global_prop_cnt; DWORD global_prop_cnt;
@ -232,15 +242,6 @@ struct ConnectionPoint {
ConnectionPoint *next; ConnectionPoint *next;
}; };
struct HTMLLocation {
DispatchEx dispex;
const IHTMLLocationVtbl *lpHTMLLocationVtbl;
LONG ref;
HTMLDocument *doc;
};
struct HTMLDocument { struct HTMLDocument {
DispatchEx dispex; DispatchEx dispex;
const IHTMLDocument2Vtbl *lpHTMLDocument2Vtbl; const IHTMLDocument2Vtbl *lpHTMLDocument2Vtbl;
@ -307,8 +308,6 @@ struct HTMLDocument {
ConnectionPoint cp_htmldocevents2; ConnectionPoint cp_htmldocevents2;
ConnectionPoint cp_propnotif; ConnectionPoint cp_propnotif;
HTMLLocation *location;
struct list selection_list; struct list selection_list;
struct list range_list; struct list range_list;
@ -514,7 +513,7 @@ HRESULT create_doc_from_nsdoc(nsIDOMHTMLDocument*,HTMLDocument**);
HRESULT HTMLWindow_Create(HTMLDocument*,nsIDOMWindow*,HTMLWindow**); HRESULT HTMLWindow_Create(HTMLDocument*,nsIDOMWindow*,HTMLWindow**);
HTMLWindow *nswindow_to_window(const nsIDOMWindow*); HTMLWindow *nswindow_to_window(const nsIDOMWindow*);
HTMLOptionElementFactory *HTMLOptionElementFactory_Create(HTMLWindow*); HTMLOptionElementFactory *HTMLOptionElementFactory_Create(HTMLWindow*);
HTMLLocation *HTMLLocation_Create(HTMLDocument*); HRESULT HTMLLocation_Create(HTMLWindow*,HTMLLocation**);
IOmNavigator *OmNavigator_Create(void); IOmNavigator *OmNavigator_Create(void);
void HTMLDocument_HTMLDocument3_Init(HTMLDocument*); void HTMLDocument_HTMLDocument3_Init(HTMLDocument*);