diff --git a/dlls/mshtml/htmlscript.h b/dlls/mshtml/htmlscript.h index e63e97319b7..5b8b90e57a2 100644 --- a/dlls/mshtml/htmlscript.h +++ b/dlls/mshtml/htmlscript.h @@ -44,6 +44,6 @@ void connect_scripts(HTMLInnerWindow*) DECLSPEC_HIDDEN; void doc_insert_script(HTMLInnerWindow*,HTMLScriptElement*,BOOL) DECLSPEC_HIDDEN; IDispatch *script_parse_event(HTMLInnerWindow*,LPCWSTR) DECLSPEC_HIDDEN; HRESULT exec_script(HTMLInnerWindow*,const WCHAR*,const WCHAR*,VARIANT*) DECLSPEC_HIDDEN; -void set_script_mode(HTMLOuterWindow*,SCRIPTMODE) DECLSPEC_HIDDEN; +void update_browser_script_mode(GeckoBrowser*,IUri*) DECLSPEC_HIDDEN; BOOL find_global_prop(HTMLInnerWindow*,BSTR,DWORD,ScriptHost**,DISPID*) DECLSPEC_HIDDEN; IDispatch *get_script_disp(ScriptHost*) DECLSPEC_HIDDEN; diff --git a/dlls/mshtml/htmlwindow.c b/dlls/mshtml/htmlwindow.c index e5d08c96f2c..8caf90ed94d 100644 --- a/dlls/mshtml/htmlwindow.c +++ b/dlls/mshtml/htmlwindow.c @@ -3560,7 +3560,6 @@ HRESULT create_outer_window(GeckoBrowser *browser, mozIDOMWindowProxy *mozwindow nsres = mozIDOMWindowProxy_QueryInterface(mozwindow, &IID_nsIDOMWindow, (void**)&window->nswindow); assert(nsres == NS_OK); - window->scriptmode = parent ? parent->scriptmode : SCRIPTMODE_GECKO; window->readystate = READYSTATE_UNINITIALIZED; window->task_magic = get_task_target_magic(); diff --git a/dlls/mshtml/mshtml_private.h b/dlls/mshtml/mshtml_private.h index 1fdedcee3ba..950f1ccf064 100644 --- a/dlls/mshtml/mshtml_private.h +++ b/dlls/mshtml/mshtml_private.h @@ -381,11 +381,6 @@ typedef struct HTMLFrameBase HTMLFrameBase; typedef struct GeckoBrowser GeckoBrowser; typedef struct HTMLAttributeCollection HTMLAttributeCollection; -typedef enum { - SCRIPTMODE_GECKO, - SCRIPTMODE_ACTIVESCRIPT -} SCRIPTMODE; - typedef struct ScriptHost ScriptHost; typedef enum { @@ -500,8 +495,6 @@ struct HTMLOuterWindow { BSTR url; DWORD load_flags; - SCRIPTMODE scriptmode; - struct list sibling_entry; struct wine_rb_entry entry; }; @@ -699,6 +692,12 @@ struct HTMLDocumentObj { typedef struct nsWeakReference nsWeakReference; + +typedef enum { + SCRIPTMODE_GECKO, + SCRIPTMODE_ACTIVESCRIPT +} SCRIPTMODE; + struct GeckoBrowser { nsIWebBrowserChrome nsIWebBrowserChrome_iface; nsIContextMenuListener nsIContextMenuListener_iface; @@ -727,6 +726,7 @@ struct GeckoBrowser { nsIURIContentListener *content_listener; HWND hwnd; + SCRIPTMODE script_mode; struct list document_nodes; struct list outer_windows; @@ -998,6 +998,10 @@ HRESULT HTMLDOMTextNode_Create(HTMLDocumentNode*,nsIDOMNode*,HTMLDOMNode**) DECL BOOL variant_to_nscolor(const VARIANT *v, nsAString *nsstr) DECLSPEC_HIDDEN; HRESULT nscolor_to_str(LPCWSTR color, BSTR *ret) DECLSPEC_HIDDEN; +static inline BOOL is_main_content_window(HTMLOuterWindow *window) +{ + return window->browser && window == window->browser->content_window; +} struct HTMLAttributeCollection { DispatchEx dispex; diff --git a/dlls/mshtml/nsembed.c b/dlls/mshtml/nsembed.c index c05c83aabe2..397011a5585 100644 --- a/dlls/mshtml/nsembed.c +++ b/dlls/mshtml/nsembed.c @@ -2167,6 +2167,7 @@ HRESULT create_gecko_browser(HTMLDocumentObj *doc, GeckoBrowser **_ret) ret->doc = doc; ret->ref = 1; + ret->script_mode = SCRIPTMODE_ACTIVESCRIPT; list_init(&ret->document_nodes); list_init(&ret->outer_windows); diff --git a/dlls/mshtml/persist.c b/dlls/mshtml/persist.c index 926689d783b..64aa8126205 100644 --- a/dlls/mshtml/persist.c +++ b/dlls/mshtml/persist.c @@ -57,21 +57,6 @@ typedef struct { LPOLESTR url; } download_proc_task_t; -static BOOL use_gecko_script(HTMLOuterWindow *window) -{ - DWORD zone; - HRESULT hres; - - hres = IInternetSecurityManager_MapUrlToZone(get_security_manager(), window->url, &zone, 0); - if(FAILED(hres)) { - WARN("Could not map %s to zone: %08x\n", debugstr_w(window->url), hres); - return TRUE; - } - - TRACE("zone %d\n", zone); - return zone == URLZONE_UNTRUSTED; -} - static void notify_travellog_update(HTMLDocumentObj *doc) { IOleCommandTarget *cmdtrg; @@ -179,7 +164,9 @@ void set_current_mon(HTMLOuterWindow *This, IMoniker *mon, DWORD flags) set_current_uri(This, uri); if(uri) IUri_Release(uri); - set_script_mode(This, use_gecko_script(This) ? SCRIPTMODE_GECKO : SCRIPTMODE_ACTIVESCRIPT); + + if(is_main_content_window(This)) + update_browser_script_mode(This->browser, uri); } HRESULT create_uri(const WCHAR *uri_str, DWORD flags, IUri **uri) diff --git a/dlls/mshtml/script.c b/dlls/mshtml/script.c index de2bb7f2d4e..6ad5c48d506 100644 --- a/dlls/mshtml/script.c +++ b/dlls/mshtml/script.c @@ -1269,8 +1269,7 @@ static ScriptHost *get_elem_script_host(HTMLInnerWindow *window, HTMLScriptEleme return NULL; } - if(IsEqualGUID(&CLSID_JScript, &guid) - && (!window->base.outer_window || window->base.outer_window->scriptmode != SCRIPTMODE_ACTIVESCRIPT)) { + if(IsEqualGUID(&CLSID_JScript, &guid) && (!window->doc->browser || window->doc->browser->script_mode != SCRIPTMODE_ACTIVESCRIPT)) { TRACE("Ignoring JScript\n"); return NULL; } @@ -1343,7 +1342,7 @@ IDispatch *script_parse_event(HTMLInnerWindow *window, LPCWSTR text) } if(IsEqualGUID(&CLSID_JScript, &guid) - && (!window->base.outer_window || window->base.outer_window->scriptmode != SCRIPTMODE_ACTIVESCRIPT)) { + && (!window->doc->browser || window->doc->browser->script_mode != SCRIPTMODE_ACTIVESCRIPT)) { TRACE("Ignoring JScript\n"); return NULL; } @@ -1670,27 +1669,44 @@ static BOOL is_jscript_available(void) return available; } -void set_script_mode(HTMLOuterWindow *window, SCRIPTMODE mode) +static BOOL use_gecko_script(IUri *uri) +{ + BSTR display_uri; + DWORD zone; + HRESULT hres; + + hres = IUri_GetDisplayUri(uri, &display_uri); + if(FAILED(hres)) + return FALSE; + + hres = IInternetSecurityManager_MapUrlToZone(get_security_manager(), display_uri, &zone, 0); + SysFreeString(display_uri); + if(FAILED(hres)) { + WARN("Could not map %s to zone: %08x\n", debugstr_w(display_uri), hres); + return TRUE; + } + + TRACE("zone %d\n", zone); + return zone == URLZONE_UNTRUSTED; +} + +void update_browser_script_mode(GeckoBrowser *browser, IUri *uri) { nsIWebBrowserSetup *setup; nsresult nsres; - if(mode == SCRIPTMODE_ACTIVESCRIPT && !is_jscript_available()) { + if(!is_jscript_available()) { TRACE("jscript.dll not available\n"); - window->scriptmode = SCRIPTMODE_GECKO; + browser->script_mode = SCRIPTMODE_GECKO; return; } - window->scriptmode = mode; + browser->script_mode = use_gecko_script(uri) ? SCRIPTMODE_GECKO : SCRIPTMODE_ACTIVESCRIPT; - if(!window->doc_obj->nscontainer || !window->doc_obj->nscontainer->webbrowser) - return; - - nsres = nsIWebBrowser_QueryInterface(window->doc_obj->nscontainer->webbrowser, - &IID_nsIWebBrowserSetup, (void**)&setup); + nsres = nsIWebBrowser_QueryInterface(browser->webbrowser, &IID_nsIWebBrowserSetup, (void**)&setup); if(NS_SUCCEEDED(nsres)) { nsres = nsIWebBrowserSetup_SetProperty(setup, SETUP_ALLOW_JAVASCRIPT, - window->scriptmode == SCRIPTMODE_GECKO); + browser->script_mode == SCRIPTMODE_GECKO); if(NS_SUCCEEDED(nsres)) nsres = nsIWebBrowserSetup_SetProperty(setup, SETUP_DISABLE_NOSCRIPT, TRUE);