2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2000-05-05 09:28:49 +04:00
|
|
|
|
|
|
|
/*
|
2004-05-13 22:34:18 +04:00
|
|
|
* Utility routines for checking content load/process policy settings,
|
|
|
|
* and routines helpful for content policy implementors.
|
2007-08-08 05:16:09 +04:00
|
|
|
*
|
|
|
|
* XXXbz it would be nice if some of this stuff could be out-of-lined in
|
|
|
|
* nsContentUtils. That would work for almost all the callers...
|
2000-05-05 09:28:49 +04:00
|
|
|
*/
|
|
|
|
|
2004-05-13 22:34:18 +04:00
|
|
|
#ifndef __nsContentPolicyUtils_h__
|
|
|
|
#define __nsContentPolicyUtils_h__
|
|
|
|
|
2015-10-02 04:51:18 +03:00
|
|
|
#include "nsContentUtils.h"
|
2000-05-05 09:28:49 +04:00
|
|
|
#include "nsIContentPolicy.h"
|
2004-10-11 20:29:42 +04:00
|
|
|
#include "nsIContent.h"
|
2007-08-08 05:16:09 +04:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
2013-08-24 06:42:40 +04:00
|
|
|
#include "nsIURI.h"
|
2013-10-22 01:23:33 +04:00
|
|
|
#include "nsServiceManagerUtils.h"
|
2017-08-17 02:48:52 +03:00
|
|
|
#include "nsStringFwd.h"
|
2000-05-05 09:28:49 +04:00
|
|
|
|
2004-05-13 22:34:18 +04:00
|
|
|
// XXXtw sadly, this makes consumers of nsContentPolicyUtils depend on widget
|
|
|
|
#include "nsIDocument.h"
|
2005-11-29 02:56:44 +03:00
|
|
|
#include "nsPIDOMWindow.h"
|
2000-05-05 09:28:49 +04:00
|
|
|
|
2013-10-22 01:23:33 +04:00
|
|
|
class nsIPrincipal;
|
2006-03-22 21:36:36 +03:00
|
|
|
|
2000-09-14 03:57:52 +04:00
|
|
|
#define NS_CONTENTPOLICY_CONTRACTID "@mozilla.org/layout/content-policy;1"
|
2000-05-05 09:28:49 +04:00
|
|
|
#define NS_CONTENTPOLICY_CATEGORY "content-policy"
|
2004-05-13 22:34:18 +04:00
|
|
|
#define NS_CONTENTPOLICY_CID \
|
2018-11-30 13:46:48 +03:00
|
|
|
{ \
|
2004-05-13 22:34:18 +04:00
|
|
|
0x0e3afd3d, 0xeb60, 0x4c2b, { \
|
|
|
|
0x96, 0x3b, 0x56, 0xd7, 0xc4, 0x39, 0xf1, 0x24 \
|
|
|
|
} \
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2004-05-13 22:34:18 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Evaluates to true if val is ACCEPT.
|
|
|
|
*
|
|
|
|
* @param val the status returned from shouldProcess/shouldLoad
|
|
|
|
*/
|
|
|
|
#define NS_CP_ACCEPTED(val) ((val) == nsIContentPolicy::ACCEPT)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Evaluates to true if val is a REJECT_* status
|
|
|
|
*
|
|
|
|
* @param val the status returned from shouldProcess/shouldLoad
|
|
|
|
*/
|
|
|
|
#define NS_CP_REJECTED(val) ((val) != nsIContentPolicy::ACCEPT)
|
|
|
|
|
|
|
|
// Offer convenient translations of constants -> const char*
|
|
|
|
|
|
|
|
// convenience macro to reduce some repetative typing...
|
|
|
|
// name is the name of a constant from this interface
|
|
|
|
#define CASE_RETURN(name) \
|
|
|
|
case nsIContentPolicy::name: \
|
|
|
|
return #name
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a string corresponding to the name of the response constant, or
|
|
|
|
* "<Unknown Response>" if an unknown response value is given.
|
|
|
|
*
|
|
|
|
* The return value is static and must not be freed.
|
|
|
|
*
|
|
|
|
* @param response the response code
|
|
|
|
* @return the name of the given response code
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
inline const char *NS_CP_ResponseName(int16_t response) {
|
2004-05-13 22:34:18 +04:00
|
|
|
switch (response) {
|
|
|
|
CASE_RETURN(REJECT_REQUEST);
|
|
|
|
CASE_RETURN(REJECT_TYPE);
|
|
|
|
CASE_RETURN(REJECT_SERVER);
|
|
|
|
CASE_RETURN(REJECT_OTHER);
|
|
|
|
CASE_RETURN(ACCEPT);
|
|
|
|
default:
|
|
|
|
return "<Unknown Response>";
|
|
|
|
}
|
|
|
|
}
|
2000-05-05 09:28:49 +04:00
|
|
|
|
2004-05-13 22:34:18 +04:00
|
|
|
/**
|
|
|
|
* Returns a string corresponding to the name of the content type constant, or
|
|
|
|
* "<Unknown Type>" if an unknown content type value is given.
|
|
|
|
*
|
|
|
|
* The return value is static and must not be freed.
|
|
|
|
*
|
|
|
|
* @param contentType the content type code
|
|
|
|
* @return the name of the given content type code
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
inline const char *NS_CP_ContentTypeName(uint32_t contentType) {
|
2004-05-13 22:34:18 +04:00
|
|
|
switch (contentType) {
|
2015-09-21 00:55:44 +03:00
|
|
|
CASE_RETURN(TYPE_OTHER);
|
|
|
|
CASE_RETURN(TYPE_SCRIPT);
|
|
|
|
CASE_RETURN(TYPE_IMAGE);
|
|
|
|
CASE_RETURN(TYPE_STYLESHEET);
|
|
|
|
CASE_RETURN(TYPE_OBJECT);
|
|
|
|
CASE_RETURN(TYPE_DOCUMENT);
|
|
|
|
CASE_RETURN(TYPE_SUBDOCUMENT);
|
|
|
|
CASE_RETURN(TYPE_REFRESH);
|
|
|
|
CASE_RETURN(TYPE_XBL);
|
|
|
|
CASE_RETURN(TYPE_PING);
|
|
|
|
CASE_RETURN(TYPE_XMLHTTPREQUEST);
|
|
|
|
CASE_RETURN(TYPE_OBJECT_SUBREQUEST);
|
|
|
|
CASE_RETURN(TYPE_DTD);
|
|
|
|
CASE_RETURN(TYPE_FONT);
|
|
|
|
CASE_RETURN(TYPE_MEDIA);
|
|
|
|
CASE_RETURN(TYPE_WEBSOCKET);
|
|
|
|
CASE_RETURN(TYPE_CSP_REPORT);
|
|
|
|
CASE_RETURN(TYPE_XSLT);
|
|
|
|
CASE_RETURN(TYPE_BEACON);
|
|
|
|
CASE_RETURN(TYPE_FETCH);
|
|
|
|
CASE_RETURN(TYPE_IMAGESET);
|
|
|
|
CASE_RETURN(TYPE_WEB_MANIFEST);
|
|
|
|
CASE_RETURN(TYPE_INTERNAL_SCRIPT);
|
|
|
|
CASE_RETURN(TYPE_INTERNAL_WORKER);
|
|
|
|
CASE_RETURN(TYPE_INTERNAL_SHARED_WORKER);
|
|
|
|
CASE_RETURN(TYPE_INTERNAL_EMBED);
|
|
|
|
CASE_RETURN(TYPE_INTERNAL_OBJECT);
|
|
|
|
CASE_RETURN(TYPE_INTERNAL_FRAME);
|
|
|
|
CASE_RETURN(TYPE_INTERNAL_IFRAME);
|
|
|
|
CASE_RETURN(TYPE_INTERNAL_AUDIO);
|
|
|
|
CASE_RETURN(TYPE_INTERNAL_VIDEO);
|
|
|
|
CASE_RETURN(TYPE_INTERNAL_TRACK);
|
|
|
|
CASE_RETURN(TYPE_INTERNAL_XMLHTTPREQUEST);
|
|
|
|
CASE_RETURN(TYPE_INTERNAL_EVENTSOURCE);
|
|
|
|
CASE_RETURN(TYPE_INTERNAL_SERVICE_WORKER);
|
|
|
|
CASE_RETURN(TYPE_INTERNAL_SCRIPT_PRELOAD);
|
|
|
|
CASE_RETURN(TYPE_INTERNAL_IMAGE);
|
|
|
|
CASE_RETURN(TYPE_INTERNAL_IMAGE_PRELOAD);
|
2016-10-13 10:43:54 +03:00
|
|
|
CASE_RETURN(TYPE_INTERNAL_IMAGE_FAVICON);
|
2015-09-21 00:55:44 +03:00
|
|
|
CASE_RETURN(TYPE_INTERNAL_STYLESHEET);
|
|
|
|
CASE_RETURN(TYPE_INTERNAL_STYLESHEET_PRELOAD);
|
2017-02-15 17:55:58 +03:00
|
|
|
CASE_RETURN(TYPE_INTERNAL_WORKER_IMPORT_SCRIPTS);
|
2018-03-24 01:27:08 +03:00
|
|
|
CASE_RETURN(TYPE_SAVEAS_DOWNLOAD);
|
|
|
|
CASE_RETURN(TYPE_SPECULATIVE);
|
2007-06-17 17:50:50 +04:00
|
|
|
default:
|
2004-05-13 22:34:18 +04:00
|
|
|
return "<Unknown Type>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef CASE_RETURN
|
|
|
|
|
|
|
|
/* Passes on parameters from its "caller"'s context. */
|
|
|
|
#define CHECK_CONTENT_POLICY(action) \
|
2005-08-19 19:00:01 +04:00
|
|
|
PR_BEGIN_MACRO \
|
2001-05-22 02:40:10 +04:00
|
|
|
nsCOMPtr<nsIContentPolicy> policy = \
|
|
|
|
do_GetService(NS_CONTENTPOLICY_CONTRACTID); \
|
|
|
|
if (!policy) return NS_ERROR_FAILURE; \
|
2000-05-05 09:28:49 +04:00
|
|
|
\
|
2018-03-29 13:16:23 +03:00
|
|
|
return policy->action(contentLocation, loadInfo, mimeType, decision); \
|
2005-08-19 19:00:01 +04:00
|
|
|
PR_END_MACRO
|
|
|
|
|
|
|
|
/* Passes on parameters from its "caller"'s context. */
|
|
|
|
#define CHECK_CONTENT_POLICY_WITH_SERVICE(action, _policy) \
|
|
|
|
PR_BEGIN_MACRO \
|
2018-03-29 13:16:23 +03:00
|
|
|
return _policy->action(contentLocation, loadInfo, mimeType, decision); \
|
2005-08-19 19:00:01 +04:00
|
|
|
PR_END_MACRO
|
2000-05-05 09:28:49 +04:00
|
|
|
|
2004-05-13 22:34:18 +04:00
|
|
|
/**
|
2007-08-08 05:16:09 +04:00
|
|
|
* Check whether we can short-circuit this check and bail out. If not, get the
|
|
|
|
* origin URI to use.
|
|
|
|
*
|
|
|
|
* Note: requestOrigin is scoped outside the PR_BEGIN_MACRO/PR_END_MACRO on
|
|
|
|
* purpose */
|
2013-01-08 21:16:28 +04:00
|
|
|
#define CHECK_PRINCIPAL_AND_DATA(action) \
|
2007-08-08 05:16:09 +04:00
|
|
|
nsCOMPtr<nsIURI> requestOrigin; \
|
|
|
|
PR_BEGIN_MACRO \
|
Bug 1407056: Part 1 - Provide more consistent principal/origin URL to content policies. r=bz,ckerschb
We're currently fairly vague and inconsistent about the values we provide to
content policy implementations for requestOrigin and requestPrincipal. In some
cases they're the triggering principal, sometimes the loading principal,
sometimes the channel principal.
Our existing content policy implementations which require or expect a loading
principal currently retrieve it from the context node. Since no current
callers require the principal to be the loading principal, and some already
expect it to be the triggering principal (which there's currently no other way
to retrieve), I chose to pass the triggering principal whenever possible, but
use the loading principal to determine the origin URL.
As a follow-up, I'd like to change the nsIContentPolicy interface to
explicitly receive loading and triggering principals, or possibly just
LoadInfo instances, rather than poorly-defined request
origin/principal/context args. But since that may cause trouble for
comm-central, I'd rather not do it as part of this bug.
MozReview-Commit-ID: LqD9GxdzMte
--HG--
extra : rebase_source : 41ce439912ae7b895e0a3b0e660fa6ba571eb50f
2017-10-13 01:43:55 +03:00
|
|
|
if (loadingPrincipal) { \
|
|
|
|
/* We exempt most loads into any document with the system principal \
|
|
|
|
* from content policy checks, mostly as an optimization. Which means \
|
|
|
|
* that we need to apply this check to the loading principal, not the \
|
|
|
|
* principal that triggered the load. */ \
|
|
|
|
bool isSystem = loadingPrincipal->GetIsSystemPrincipal(); \
|
2017-07-11 01:00:03 +03:00
|
|
|
if (isSystem && contentType != nsIContentPolicy::TYPE_DOCUMENT) { \
|
|
|
|
*decision = nsIContentPolicy::ACCEPT; \
|
|
|
|
nsCOMPtr<nsINode> n = do_QueryInterface(context); \
|
|
|
|
if (!n) { \
|
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> win = do_QueryInterface(context); \
|
|
|
|
n = win ? win->GetExtantDoc() : nullptr; \
|
|
|
|
} \
|
|
|
|
if (n) { \
|
|
|
|
nsIDocument *d = n->OwnerDoc(); \
|
|
|
|
if (d->IsLoadedAsData() || d->IsBeingUsedAsImage() || \
|
|
|
|
d->IsResourceDoc()) { \
|
|
|
|
nsCOMPtr<nsIContentPolicy> dataPolicy = \
|
2013-01-08 21:16:28 +04:00
|
|
|
do_GetService("@mozilla.org/data-document-content-policy;1"); \
|
2017-07-11 01:00:03 +03:00
|
|
|
if (dataPolicy) { \
|
2018-03-29 13:16:23 +03:00
|
|
|
dataPolicy->action(contentLocation, loadInfo, mimeType, decision); \
|
2013-01-08 21:16:28 +04:00
|
|
|
} \
|
|
|
|
} \
|
2007-08-08 05:16:09 +04:00
|
|
|
} \
|
2017-07-11 01:00:03 +03:00
|
|
|
return NS_OK; \
|
2007-08-08 05:16:09 +04:00
|
|
|
} \
|
Bug 1407056: Part 1 - Provide more consistent principal/origin URL to content policies. r=bz,ckerschb
We're currently fairly vague and inconsistent about the values we provide to
content policy implementations for requestOrigin and requestPrincipal. In some
cases they're the triggering principal, sometimes the loading principal,
sometimes the channel principal.
Our existing content policy implementations which require or expect a loading
principal currently retrieve it from the context node. Since no current
callers require the principal to be the loading principal, and some already
expect it to be the triggering principal (which there's currently no other way
to retrieve), I chose to pass the triggering principal whenever possible, but
use the loading principal to determine the origin URL.
As a follow-up, I'd like to change the nsIContentPolicy interface to
explicitly receive loading and triggering principals, or possibly just
LoadInfo instances, rather than poorly-defined request
origin/principal/context args. But since that may cause trouble for
comm-central, I'd rather not do it as part of this bug.
MozReview-Commit-ID: LqD9GxdzMte
--HG--
extra : rebase_source : 41ce439912ae7b895e0a3b0e660fa6ba571eb50f
2017-10-13 01:43:55 +03:00
|
|
|
nsresult rv = loadingPrincipal->GetURI(getter_AddRefs(requestOrigin)); \
|
2007-08-08 05:16:09 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv); \
|
|
|
|
} \
|
|
|
|
PR_END_MACRO
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Alias for calling ShouldLoad on the content policy service. Parameters are
|
Bug 1407056: Part 1 - Provide more consistent principal/origin URL to content policies. r=bz,ckerschb
We're currently fairly vague and inconsistent about the values we provide to
content policy implementations for requestOrigin and requestPrincipal. In some
cases they're the triggering principal, sometimes the loading principal,
sometimes the channel principal.
Our existing content policy implementations which require or expect a loading
principal currently retrieve it from the context node. Since no current
callers require the principal to be the loading principal, and some already
expect it to be the triggering principal (which there's currently no other way
to retrieve), I chose to pass the triggering principal whenever possible, but
use the loading principal to determine the origin URL.
As a follow-up, I'd like to change the nsIContentPolicy interface to
explicitly receive loading and triggering principals, or possibly just
LoadInfo instances, rather than poorly-defined request
origin/principal/context args. But since that may cause trouble for
comm-central, I'd rather not do it as part of this bug.
MozReview-Commit-ID: LqD9GxdzMte
--HG--
extra : rebase_source : 41ce439912ae7b895e0a3b0e660fa6ba571eb50f
2017-10-13 01:43:55 +03:00
|
|
|
* the same as nsIContentPolicy::shouldLoad, except for the loadingPrincipal
|
|
|
|
* and triggeringPrincipal parameters (which should be non-null if possible,
|
|
|
|
* and have the same semantics as in nsLoadInfo), and the last parameter,
|
2017-07-11 01:00:03 +03:00
|
|
|
* which can be used to pass in a pointer to a useful service if the caller
|
|
|
|
* already has it. The origin URI to pass to shouldLoad will be the URI of
|
Bug 1407056: Part 1 - Provide more consistent principal/origin URL to content policies. r=bz,ckerschb
We're currently fairly vague and inconsistent about the values we provide to
content policy implementations for requestOrigin and requestPrincipal. In some
cases they're the triggering principal, sometimes the loading principal,
sometimes the channel principal.
Our existing content policy implementations which require or expect a loading
principal currently retrieve it from the context node. Since no current
callers require the principal to be the loading principal, and some already
expect it to be the triggering principal (which there's currently no other way
to retrieve), I chose to pass the triggering principal whenever possible, but
use the loading principal to determine the origin URL.
As a follow-up, I'd like to change the nsIContentPolicy interface to
explicitly receive loading and triggering principals, or possibly just
LoadInfo instances, rather than poorly-defined request
origin/principal/context args. But since that may cause trouble for
comm-central, I'd rather not do it as part of this bug.
MozReview-Commit-ID: LqD9GxdzMte
--HG--
extra : rebase_source : 41ce439912ae7b895e0a3b0e660fa6ba571eb50f
2017-10-13 01:43:55 +03:00
|
|
|
* loadingPrincipal, unless loadingPrincipal is null (in which case a null
|
|
|
|
* origin URI will be passed).
|
2004-05-13 22:34:18 +04:00
|
|
|
*/
|
2018-03-29 13:16:23 +03:00
|
|
|
inline nsresult NS_CheckContentLoadPolicy(
|
2004-05-13 22:34:18 +04:00
|
|
|
nsIURI *contentLocation, nsILoadInfo *loadInfo, const nsACString &mimeType,
|
2017-07-11 01:00:03 +03:00
|
|
|
int16_t *decision, nsIContentPolicy *policyService = nullptr) {
|
2018-03-29 13:16:23 +03:00
|
|
|
nsIPrincipal *loadingPrincipal = loadInfo->LoadingPrincipal();
|
|
|
|
nsCOMPtr<nsISupports> context = loadInfo->GetLoadingContext();
|
|
|
|
nsContentPolicyType contentType = loadInfo->InternalContentPolicyType();
|
2013-01-08 21:16:28 +04:00
|
|
|
CHECK_PRINCIPAL_AND_DATA(ShouldLoad);
|
2005-08-19 19:00:01 +04:00
|
|
|
if (policyService) {
|
|
|
|
CHECK_CONTENT_POLICY_WITH_SERVICE(ShouldLoad, policyService);
|
|
|
|
}
|
2004-05-13 22:34:18 +04:00
|
|
|
CHECK_CONTENT_POLICY(ShouldLoad);
|
2000-05-05 09:28:49 +04:00
|
|
|
}
|
|
|
|
|
2004-05-13 22:34:18 +04:00
|
|
|
/**
|
2018-03-29 13:16:23 +03:00
|
|
|
* Alias for calling ShouldProcess on the content policy service.
|
2004-05-13 22:34:18 +04:00
|
|
|
*/
|
2018-03-29 13:16:23 +03:00
|
|
|
inline nsresult NS_CheckContentProcessPolicy(
|
2004-05-13 22:34:18 +04:00
|
|
|
nsIURI *contentLocation, nsILoadInfo *loadInfo, const nsACString &mimeType,
|
2017-07-11 01:00:03 +03:00
|
|
|
int16_t *decision, nsIContentPolicy *policyService = nullptr) {
|
2018-03-29 13:16:23 +03:00
|
|
|
nsIPrincipal *loadingPrincipal = loadInfo->LoadingPrincipal();
|
|
|
|
nsCOMPtr<nsISupports> context = loadInfo->GetLoadingContext();
|
|
|
|
nsContentPolicyType contentType = loadInfo->InternalContentPolicyType();
|
2013-01-08 21:16:28 +04:00
|
|
|
CHECK_PRINCIPAL_AND_DATA(ShouldProcess);
|
2005-08-19 19:00:01 +04:00
|
|
|
if (policyService) {
|
|
|
|
CHECK_CONTENT_POLICY_WITH_SERVICE(ShouldProcess, policyService);
|
|
|
|
}
|
2004-05-13 22:34:18 +04:00
|
|
|
CHECK_CONTENT_POLICY(ShouldProcess);
|
2000-05-05 09:28:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#undef CHECK_CONTENT_POLICY
|
2005-08-19 19:00:01 +04:00
|
|
|
#undef CHECK_CONTENT_POLICY_WITH_SERVICE
|
2000-05-05 09:28:49 +04:00
|
|
|
|
2004-05-13 22:34:18 +04:00
|
|
|
/**
|
2004-07-27 21:15:53 +04:00
|
|
|
* Helper function to get an nsIDocShell given a context.
|
|
|
|
* If the context is a document or window, the corresponding docshell will be
|
2004-05-13 22:34:18 +04:00
|
|
|
* returned.
|
2004-07-27 21:15:53 +04:00
|
|
|
* If the context is a non-document DOM node, the docshell of its ownerDocument
|
|
|
|
* will be returned.
|
2004-05-13 22:34:18 +04:00
|
|
|
*
|
2004-07-27 21:15:53 +04:00
|
|
|
* @param aContext the context to find a docshell for (can be null)
|
2009-02-18 07:32:57 +03:00
|
|
|
*
|
2012-07-30 18:20:58 +04:00
|
|
|
* @return a WEAK pointer to the docshell, or nullptr if it could
|
2004-05-13 22:34:18 +04:00
|
|
|
* not be obtained
|
2017-07-06 15:00:35 +03:00
|
|
|
*
|
2009-02-18 07:32:57 +03:00
|
|
|
* @note As of this writing, calls to nsIContentPolicy::Should{Load,Process}
|
|
|
|
* for TYPE_DOCUMENT and TYPE_SUBDOCUMENT pass in an aContext that either
|
|
|
|
* points to the frameElement of the window the load is happening in
|
|
|
|
* (in which case NS_CP_GetDocShellFromContext will return the parent of the
|
|
|
|
* docshell the load is happening in), or points to the window the load is
|
|
|
|
* happening in (in which case NS_CP_GetDocShellFromContext will return
|
|
|
|
* the docshell the load is happening in). It's up to callers to QI aContext
|
|
|
|
* and handle things accordingly if they want the docshell the load is
|
|
|
|
* happening in. These are somewhat odd semantics, and bug 466687 has been
|
|
|
|
* filed to consider improving them.
|
2004-05-13 22:34:18 +04:00
|
|
|
*/
|
2004-07-27 21:15:53 +04:00
|
|
|
inline nsIDocShell *NS_CP_GetDocShellFromContext(nsISupports *aContext) {
|
|
|
|
if (!aContext) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2004-05-13 22:34:18 +04:00
|
|
|
}
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> window = do_QueryInterface(aContext);
|
2004-05-13 22:34:18 +04:00
|
|
|
|
2005-11-29 02:56:44 +03:00
|
|
|
if (!window) {
|
2018-05-30 05:58:49 +03:00
|
|
|
// Our context might be a document.
|
2004-07-27 21:15:53 +04:00
|
|
|
nsCOMPtr<nsIDocument> doc = do_QueryInterface(aContext);
|
|
|
|
if (!doc) {
|
|
|
|
// we were not a document after all, get our ownerDocument,
|
|
|
|
// hopefully
|
2004-10-11 20:29:42 +04:00
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(aContext);
|
|
|
|
if (content) {
|
2011-10-18 14:53:36 +04:00
|
|
|
doc = content->OwnerDoc();
|
2004-07-27 21:15:53 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (doc) {
|
2008-11-27 07:10:28 +03:00
|
|
|
if (doc->GetDisplayDocument()) {
|
|
|
|
doc = doc->GetDisplayDocument();
|
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2005-11-29 02:56:44 +03:00
|
|
|
window = doc->GetWindow();
|
2004-05-13 22:34:18 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2004-05-13 22:34:18 +04:00
|
|
|
|
2005-11-29 02:56:44 +03:00
|
|
|
if (!window) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2004-05-13 22:34:18 +04:00
|
|
|
}
|
|
|
|
|
2005-11-29 02:56:44 +03:00
|
|
|
return window->GetDocShell();
|
2004-05-13 22:34:18 +04:00
|
|
|
}
|
|
|
|
|
2000-05-05 09:28:49 +04:00
|
|
|
#endif /* __nsContentPolicyUtils_h__ */
|