зеркало из https://github.com/mozilla/pjs.git
r=ccarlen, sr=rpotts on the mozilla/docshell/* and mozilla/embedding/* mods (81263). embedding apps can now control whether or not images are loaded in a specific nsWebBrowser window. This is done via nsIWebBrowserSetup. shaver@mozilla.org provided a nsWebBrowserContentPolicy implementation which registers for, and responds to, nsIContentPolicy callbacks giving nsIContentPolicies an opportunity to cancel a load or the processing of an element. processing isn't hooked up yet, and some of the content policy types in the switch statement won't become relevant until further nsIContentPolicy hookup is done. Those cases are handled inside the docshell/webshell until the content policy hook-up is made.
This commit is contained in:
Родитель
3eaab0afb9
Коммит
47dde24cd0
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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<nsICategoryManager> 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<nsICategoryManager> 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 }
|
||||
};
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -46,6 +46,7 @@ CPP_OBJS= \
|
|||
.\$(OBJDIR)\nsWebBrowserPersist.obj \
|
||||
.\$(OBJDIR)\nsDOMWalker.obj \
|
||||
.\$(OBJDIR)\nsNonPersistAuthPrompt.obj \
|
||||
.\$(OBJDIR)\nsWebBrowserContentPolicy.obj \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<nsIScriptGlobalObject> scriptGlobal =
|
||||
do_QueryInterface(window);
|
||||
if (!scriptGlobal)
|
||||
return NS_OK;
|
||||
|
||||
nsCOMPtr<nsIDocShell> 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;
|
||||
}
|
||||
|
|
@ -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
|
||||
};
|
||||
|
Загрузка…
Ссылка в новой задаче