diff --git a/mozilla/docshell/base/nsDocShell.cpp b/mozilla/docshell/base/nsDocShell.cpp index f31cd17ce77..ef5e8aca4a9 100644 --- a/mozilla/docshell/base/nsDocShell.cpp +++ b/mozilla/docshell/base/nsDocShell.cpp @@ -158,6 +158,7 @@ nsDocShell::nsDocShell(): mAllowJavascript(PR_TRUE), mAllowMetaRedirects(PR_TRUE), mAllowSubframes(PR_TRUE), + mAllowImages(PR_TRUE), mAppType(nsIDocShell::APP_TYPE_UNKNOWN), mBusyFlags(BUSY_FLAGS_NONE), mEODForCurrentDocument(PR_FALSE), @@ -1154,6 +1155,20 @@ NS_IMETHODIMP nsDocShell::SetAllowSubframes(PRBool aAllowSubframes) return NS_OK; } +NS_IMETHODIMP nsDocShell::GetAllowImages(PRBool * aAllowImages) +{ + NS_ENSURE_ARG_POINTER(aAllowImages); + + *aAllowImages = mAllowImages; + return NS_OK; +} + +NS_IMETHODIMP nsDocShell::SetAllowImages(PRBool aAllowImages) +{ + mAllowImages = aAllowImages; + return NS_OK; +} + NS_IMETHODIMP nsDocShell::GetDocShellEnumerator(PRInt32 aItemType, PRInt32 aDirection, nsISimpleEnumerator **outEnum) { diff --git a/mozilla/docshell/base/nsDocShell.h b/mozilla/docshell/base/nsDocShell.h index 27b29d572c7..90931d67332 100644 --- a/mozilla/docshell/base/nsDocShell.h +++ b/mozilla/docshell/base/nsDocShell.h @@ -302,6 +302,7 @@ protected: PRBool mAllowJavascript; PRBool mAllowMetaRedirects; PRBool mAllowSubframes; + PRBool mAllowImages; PRUint32 mAppType; PRInt32 mChildOffset; // Offset in the parent's child list. PRUint32 mBusyFlags; diff --git a/mozilla/docshell/base/nsIDocShell.idl b/mozilla/docshell/base/nsIDocShell.idl index 61044278224..fbbc448a482 100644 --- a/mozilla/docshell/base/nsIDocShell.idl +++ b/mozilla/docshell/base/nsIDocShell.idl @@ -189,6 +189,11 @@ interface nsIDocShell : nsISupports */ attribute boolean allowSubframes; + /** + * Attribute stating whether or not images should be loaded. + */ + attribute boolean allowImages; + /** * Get an enumerator over this docShell and its children. * diff --git a/mozilla/embedding/browser/build/nsWebBrowserModule.cpp b/mozilla/embedding/browser/build/nsWebBrowserModule.cpp index 86c269f02ee..daf60811236 100644 --- a/mozilla/embedding/browser/build/nsWebBrowserModule.cpp +++ b/mozilla/embedding/browser/build/nsWebBrowserModule.cpp @@ -22,26 +22,64 @@ #include "nsIModule.h" #include "nsIGenericFactory.h" +#include "nsICategoryManager.h" +#include "nsXPIDLString.h" #include "nsWebBrowser.h" #include "nsCommandHandler.h" - +#include "nsWebBrowserContentPolicy.h" // Factory Constructors NS_GENERIC_FACTORY_CONSTRUCTOR(nsWebBrowser) -//NS_GENERIC_FACTORY_CONSTRUCTOR(nsWebBrowserSetup) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsWebBrowserContentPolicy) NS_GENERIC_FACTORY_CONSTRUCTOR(nsCommandHandler) +static NS_METHOD +RegisterContentPolicy(nsIComponentManager *aCompMgr, nsIFile *aPath, + const char *registryLocation, const char *componentType, + const nsModuleComponentInfo *info) +{ + nsresult rv; + nsCOMPtr catman = + do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv); + if (NS_FAILED(rv)) return rv; + nsXPIDLCString previous; + return catman->AddCategoryEntry("content-policy", + NS_WEBBROWSERCONTENTPOLICY_CONTRACTID, + NS_WEBBROWSERCONTENTPOLICY_CONTRACTID, + PR_TRUE, PR_TRUE, getter_Copies(previous)); +} + +static NS_METHOD +UnregisterContentPolicy(nsIComponentManager *aCompMgr, nsIFile *aPath, + const char *registryLocation, + const nsModuleComponentInfo *info) +{ + nsresult rv; + nsCOMPtr catman = + do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv); + if (NS_FAILED(rv)) return rv; + + nsXPIDLCString previous; + return catman->DeleteCategoryEntry("content-policy", + NS_WEBBROWSERCONTENTPOLICY_CONTRACTID, + PR_TRUE, getter_Copies(previous)); +} // Component Table static nsModuleComponentInfo components[] = { { "WebBrowser Component", NS_WEBBROWSER_CID, - NS_WEBBROWSER_CONTRACTID, nsWebBrowserConstructor }, + NS_WEBBROWSER_CONTRACTID, nsWebBrowserConstructor }, { "CommandHandler Component", NS_COMMANDHANDLER_CID, - NS_COMMANDHANDLER_CONTRACTID, nsCommandHandlerConstructor } + NS_COMMANDHANDLER_CONTRACTID, nsCommandHandlerConstructor }, + { "nsIWebBrowserSetup content policy enforcer", + NS_WEBBROWSERCONTENTPOLICY_CID, + NS_WEBBROWSERCONTENTPOLICY_CONTRACTID, + nsWebBrowserContentPolicyConstructor, + RegisterContentPolicy, UnregisterContentPolicy } // { "WebBrowserSetup Component", NS_WEBBROWSER_SETUP_CID, // NS_WEBBROWSER_SETUP_CONTRACTID, nsWebBrowserSetupConstructor } }; diff --git a/mozilla/embedding/browser/webBrowser/Makefile.in b/mozilla/embedding/browser/webBrowser/Makefile.in index d9114df96c1..4074e74c878 100644 --- a/mozilla/embedding/browser/webBrowser/Makefile.in +++ b/mozilla/embedding/browser/webBrowser/Makefile.in @@ -26,7 +26,7 @@ VPATH = @srcdir@ MODULE = webbrwsr XPIDL_MODULE = webBrowser_core LIBRARY_NAME = nsWebBrowser_s -REQUIRES = xpcom string docshell widget layout dom js locale necko uriloader shistory webshell mimetype exthandler timer windowwatcher txtsvc gfx2 wallet appcomps +REQUIRES = xpcom string docshell widget layout dom js locale necko uriloader shistory webshell mimetype exthandler timer windowwatcher txtsvc gfx2 wallet appcomps content include $(DEPTH)/config/autoconf.mk @@ -51,7 +51,8 @@ CPPSRCS = \ nsCommandHandler.cpp \ nsWebBrowserPersist.cpp \ nsDOMWalker.cpp \ - nsNonPersistAuthPrompt.cpp \ + nsNonPersistAuthPrompt.cpp \ + nsWebBrowserContentPolicy.cpp \ $(NULL) # we don't want the shared lib, but we want to force the creation of a diff --git a/mozilla/embedding/browser/webBrowser/makefile.win b/mozilla/embedding/browser/webBrowser/makefile.win index f413349b1e8..31dddf32bfa 100644 --- a/mozilla/embedding/browser/webBrowser/makefile.win +++ b/mozilla/embedding/browser/webBrowser/makefile.win @@ -46,6 +46,7 @@ CPP_OBJS= \ .\$(OBJDIR)\nsWebBrowserPersist.obj \ .\$(OBJDIR)\nsDOMWalker.obj \ .\$(OBJDIR)\nsNonPersistAuthPrompt.obj \ + .\$(OBJDIR)\nsWebBrowserContentPolicy.obj \ $(NULL) include <$(DEPTH)\config\rules.mak> diff --git a/mozilla/embedding/browser/webBrowser/nsIWebBrowserSetup.idl b/mozilla/embedding/browser/webBrowser/nsIWebBrowserSetup.idl index f9921b97e7d..4d86c63528f 100644 --- a/mozilla/embedding/browser/webBrowser/nsIWebBrowserSetup.idl +++ b/mozilla/embedding/browser/webBrowser/nsIWebBrowserSetup.idl @@ -32,12 +32,23 @@ [scriptable, uuid(F15398A0-8018-11d3-AF70-00A024FFC08C)] interface nsIWebBrowserSetup : nsISupports { - const unsigned long SETUP_ALLOW_PLUGINS = 1; - const unsigned long SETUP_ALLOW_JAVASCRIPT = 2; - const unsigned long SETUP_ALLOW_META_REDIRECTS = 3; - const unsigned long SETUP_ALLOW_SUBFRAMES = 4; - - const unsigned long SETUP_USE_GLOBAL_HISTORY = 256; + const unsigned long SETUP_ALLOW_PLUGINS = 1; + const unsigned long SETUP_ALLOW_JAVASCRIPT = 2; + const unsigned long SETUP_ALLOW_META_REDIRECTS = 3; + const unsigned long SETUP_ALLOW_SUBFRAMES = 4; + + /** + * SETUP_ALLOW_IMAGES enables/disables image loading for a given webBrowser + * window. If you disable the images, load a page, then enable the images, + * the page will *not* automatically load the images for the previously + * loaded page. This flag controls the state of a webBrowser at load time + * and does not automatcially re-load a page when the state is toggled. + * Reloading must be done by hand, or by walking through the DOM tree and + * re-setting the src attributes. + */ + const unsigned long SETUP_ALLOW_IMAGES = 5; + const unsigned long SETUP_USE_GLOBAL_HISTORY = 256; void setProperty(in unsigned long aId, in unsigned long aValue); -}; \ No newline at end of file +}; + diff --git a/mozilla/embedding/browser/webBrowser/nsWebBrowser.cpp b/mozilla/embedding/browser/webBrowser/nsWebBrowser.cpp index 8ce1f5532e4..75f45a063c3 100644 --- a/mozilla/embedding/browser/webBrowser/nsWebBrowser.cpp +++ b/mozilla/embedding/browser/webBrowser/nsWebBrowser.cpp @@ -656,6 +656,12 @@ NS_IMETHODIMP nsWebBrowser::SetProperty(PRUint32 aId, PRUint32 aValue) mDocShell->SetAllowSubframes(aValue); } break; + case nsIWebBrowserSetup::SETUP_ALLOW_IMAGES: + { + NS_ENSURE_STATE(mDocShell); + NS_ENSURE_TRUE((aValue == PR_TRUE || aValue == PR_FALSE), NS_ERROR_INVALID_ARG); + mDocShell->SetAllowImages(aValue); + } case nsIWebBrowserSetup::SETUP_USE_GLOBAL_HISTORY: { NS_ENSURE_STATE(mDocShell); diff --git a/mozilla/embedding/browser/webBrowser/nsWebBrowserContentPolicy.cpp b/mozilla/embedding/browser/webBrowser/nsWebBrowserContentPolicy.cpp new file mode 100644 index 00000000000..10d65a9de1d --- /dev/null +++ b/mozilla/embedding/browser/webBrowser/nsWebBrowserContentPolicy.cpp @@ -0,0 +1,88 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Mozilla Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is embedding content-control code. + * + * The Initial Developer of the Original Code is Mike Shaver. + * Portions created by Mike Shaver are Copyright (C) 2001 Mike Shaver. + * All Rights Reserved. + * + */ + +#include "nsWebBrowserContentPolicy.h" +#include "nsIScriptGlobalObject.h" +#include "nsIDocShell.h" +#include "nsCOMPtr.h" +#include "nsIDOMWindow.h" + +nsWebBrowserContentPolicy::nsWebBrowserContentPolicy() +{ + MOZ_COUNT_CTOR(nsWebBrowserContentPolicy); + NS_INIT_REFCNT(); +} + +nsWebBrowserContentPolicy::~nsWebBrowserContentPolicy() +{ + MOZ_COUNT_DTOR(nsWebBrowserContentPolicy); +} + +NS_IMPL_ISUPPORTS1(nsWebBrowserContentPolicy, nsIContentPolicy) + +NS_IMETHODIMP +nsWebBrowserContentPolicy::ShouldLoad(PRInt32 contentType, + nsIURI *contentLocation, + nsISupports *context, + nsIDOMWindow *window, PRBool *shouldLoad) +{ + *shouldLoad = PR_TRUE; + + nsCOMPtr scriptGlobal = + do_QueryInterface(window); + if (!scriptGlobal) + return NS_OK; + + nsCOMPtr shell; + if (NS_FAILED(scriptGlobal->GetDocShell(getter_AddRefs(shell)))) + return NS_OK; + + switch (contentType) { + case nsIContentPolicy::OBJECT: + return shell->GetAllowPlugins(shouldLoad); + case nsIContentPolicy::SCRIPT: + return shell->GetAllowJavascript(shouldLoad); + case nsIContentPolicy::SUBDOCUMENT: + return shell->GetAllowSubframes(shouldLoad); +#if 0 + /* need to actually check that it's a meta tag, maybe */ + case nsIContentPolicy::CONTROL_TAG: + return shell->GetAllowMetaRedirects(shouldLoad); /* meta _refresh_ */ +#endif + case nsIContentPolicy::IMAGE: + return shell->GetAllowImages(shouldLoad); + default: + return NS_OK; + } + +} + +NS_IMETHODIMP +nsWebBrowserContentPolicy::ShouldProcess(PRInt32 contentType, + nsIURI *contentLocation, + nsISupports *context, + nsIDOMWindow *window, + PRBool *shouldProcess) +{ + /* XXX use this for AllowJavascript (sic) control? */ + *shouldProcess = PR_TRUE; + return NS_OK; +} + diff --git a/mozilla/embedding/browser/webBrowser/nsWebBrowserContentPolicy.h b/mozilla/embedding/browser/webBrowser/nsWebBrowserContentPolicy.h new file mode 100644 index 00000000000..a34dcd4968e --- /dev/null +++ b/mozilla/embedding/browser/webBrowser/nsWebBrowserContentPolicy.h @@ -0,0 +1,38 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Mozilla Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is embedding content-control code. + * + * The Initial Developer of the Original Code is Mike Shaver. + * Portions created by Mike Shaver are Copyright (C) 2001 Mike Shaver. + * All Rights Reserved. + * + */ + +#include "nsIContentPolicy.h" + +/* f66bc334-1dd1-11b2-bab2-90e04fe15c19 */ +#define NS_WEBBROWSERCONTENTPOLICY_CID \ +{ 0xf66bc334, 0x1dd1, 0x11b2, { 0xba, 0xb2, 0x90, 0xe0, 0x4f, 0xe1, 0x5c, 0x19 } } + +#define NS_WEBBROWSERCONTENTPOLICY_CONTRACTID "@mozilla.org/embedding/browser/content-policy;1" + +class nsWebBrowserContentPolicy : public nsIContentPolicy +{ +public: + nsWebBrowserContentPolicy(); + virtual ~nsWebBrowserContentPolicy(); + + NS_DECL_ISUPPORTS + NS_DECL_NSICONTENTPOLICY +}; +