|
|
|
|
| 216 |
#include "nsIWebBrowserPrint.h" |
216 |
#include "nsIWebBrowserPrint.h" |
| 217 |
#endif |
217 |
#endif |
| 218 |
|
218 |
|
| 219 |
#include "nsPluginError.h" |
219 |
#include "nsPluginError.h" |
| 220 |
#include "nsContentUtils.h" |
220 |
#include "nsContentUtils.h" |
| 221 |
#include "nsContentErrors.h" |
221 |
#include "nsContentErrors.h" |
| 222 |
#include "nsIChannelPolicy.h" |
222 |
#include "nsIChannelPolicy.h" |
| 223 |
#include "nsIContentSecurityPolicy.h" |
223 |
#include "nsIContentSecurityPolicy.h" |
|
|
224 |
#include "nsSandboxFlags.h" |
| 224 |
|
225 |
|
| 225 |
#include "nsXULAppAPI.h" |
226 |
#include "nsXULAppAPI.h" |
| 226 |
|
227 |
|
| 227 |
#include "nsDOMNavigationTiming.h" |
228 |
#include "nsDOMNavigationTiming.h" |
| 228 |
#include "nsITimedChannel.h" |
229 |
#include "nsITimedChannel.h" |
| 229 |
#include "mozilla/StartupTimeline.h" |
230 |
#include "mozilla/StartupTimeline.h" |
| 230 |
|
231 |
|
| 231 |
static NS_DEFINE_CID(kDOMScriptObjectFactoryCID, |
232 |
static NS_DEFINE_CID(kDOMScriptObjectFactoryCID, |
|
Lines 766-781
nsDocShell::nsDocShell():
|
Link Here
|
|---|
|
| 766 |
mBusyFlags(BUSY_FLAGS_NONE), |
767 |
mBusyFlags(BUSY_FLAGS_NONE), |
| 767 |
mAppType(nsIDocShell::APP_TYPE_UNKNOWN), |
768 |
mAppType(nsIDocShell::APP_TYPE_UNKNOWN), |
| 768 |
mLoadType(0), |
769 |
mLoadType(0), |
| 769 |
mMarginWidth(-1), |
770 |
mMarginWidth(-1), |
| 770 |
mMarginHeight(-1), |
771 |
mMarginHeight(-1), |
| 771 |
mItemType(typeContent), |
772 |
mItemType(typeContent), |
| 772 |
mPreviousTransIndex(-1), |
773 |
mPreviousTransIndex(-1), |
| 773 |
mLoadedTransIndex(-1), |
774 |
mLoadedTransIndex(-1), |
|
|
775 |
mSandboxFlags(0), |
| 774 |
mCreated(false), |
776 |
mCreated(false), |
| 775 |
mAllowSubframes(true), |
777 |
mAllowSubframes(true), |
| 776 |
mAllowPlugins(true), |
778 |
mAllowPlugins(true), |
| 777 |
mAllowJavascript(true), |
779 |
mAllowJavascript(true), |
| 778 |
mAllowMetaRedirects(true), |
780 |
mAllowMetaRedirects(true), |
| 779 |
mAllowImages(true), |
781 |
mAllowImages(true), |
| 780 |
mAllowDNSPrefetch(true), |
782 |
mAllowDNSPrefetch(true), |
| 781 |
mAllowWindowControl(true), |
783 |
mAllowWindowControl(true), |
|
Lines 2986-3001
nsDocShell::FindItemWithName(const PRUni
|
Link Here
|
|---|
|
| 2986 |
foundItem = nsnull; |
2988 |
foundItem = nsnull; |
| 2987 |
} |
2989 |
} |
| 2988 |
|
2990 |
|
| 2989 |
if (foundItem) { |
2991 |
if (foundItem) { |
| 2990 |
// We return foundItem here even if it's not an active |
2992 |
// We return foundItem here even if it's not an active |
| 2991 |
// item since all the names we've dealt with so far are |
2993 |
// item since all the names we've dealt with so far are |
| 2992 |
// special cases that we won't bother looking for further. |
2994 |
// special cases that we won't bother looking for further. |
| 2993 |
|
2995 |
|
|
|
2996 |
// If our document is sandboxed, we need to do some extra checks. |
| 2997 |
PRUint32 sandboxFlags = 0; |
| 2998 |
|
| 2999 |
nsCOMPtr<nsIDocument> doc = do_GetInterface(aOriginalRequestor); |
| 3000 |
|
| 3001 |
if (doc) { |
| 3002 |
sandboxFlags = doc->SandboxFlags(); |
| 3003 |
} |
| 3004 |
|
| 3005 |
if (sandboxFlags) { |
| 3006 |
nsCOMPtr<nsIDocShellTreeItem> root; |
| 3007 |
GetSameTypeRootTreeItem(getter_AddRefs(root)); |
| 3008 |
|
| 3009 |
// Is the found item not a top level browsing context and not ourself ? |
| 3010 |
nsCOMPtr<nsIDocShellTreeItem> selfAsItem = static_cast<nsIDocShellTreeItem *>(this); |
| 3011 |
if (foundItem != root && foundItem != selfAsItem) { |
| 3012 |
// Are we an ancestor of the foundItem ? |
| 3013 |
bool isAncestor = false; |
| 3014 |
|
| 3015 |
nsCOMPtr<nsIDocShellTreeItem> parentAsItem; |
| 3016 |
GetSameTypeParent(getter_AddRefs(parentAsItem)); |
| 3017 |
|
| 3018 |
while (parentAsItem) { |
| 3019 |
nsCOMPtr<nsIDocShellTreeItem> tmp; |
| 3020 |
parentAsItem->GetParent(getter_AddRefs(tmp)); |
| 3021 |
|
| 3022 |
if (tmp && tmp == selfAsItem) { |
| 3023 |
isAncestor = true; |
| 3024 |
break; |
| 3025 |
} |
| 3026 |
parentAsItem = tmp; |
| 3027 |
} |
| 3028 |
|
| 3029 |
if (!isAncestor) { |
| 3030 |
// No, we are not an ancestor and our document is |
| 3031 |
// sandboxed, we can't allow this. |
| 3032 |
foundItem = nsnull; |
| 3033 |
} |
| 3034 |
} else { |
| 3035 |
// Top level browsing context - is it an ancestor of ours ? |
| 3036 |
nsCOMPtr<nsIDocShellTreeItem> tmp; |
| 3037 |
GetSameTypeParent(getter_AddRefs(tmp)); |
| 3038 |
|
| 3039 |
while (tmp) { |
| 3040 |
if (tmp && tmp == foundItem) { |
| 3041 |
// This is an ancestor, and we are sandboxed. |
| 3042 |
// Unless allow-top-navigation is set, we can't allow this. |
| 3043 |
if (sandboxFlags & SANDBOXED_TOPLEVEL_NAVIGATION) { |
| 3044 |
foundItem = nsnull; |
| 3045 |
} |
| 3046 |
break; |
| 3047 |
} |
| 3048 |
tmp->GetParent(getter_AddRefs(tmp)); |
| 3049 |
} |
| 3050 |
} |
| 3051 |
} |
| 3052 |
|
| 2994 |
foundItem.swap(*_retval); |
3053 |
foundItem.swap(*_retval); |
| 2995 |
return NS_OK; |
3054 |
return NS_OK; |
| 2996 |
} |
3055 |
} |
| 2997 |
} |
3056 |
} |
| 2998 |
|
3057 |
|
| 2999 |
// Keep looking |
3058 |
// Keep looking |
| 3000 |
|
3059 |
|
| 3001 |
// First we check our name. |
3060 |
// First we check our name. |
|
Lines 5026-5041
nsDocShell::SetIsAppTab(bool aIsAppTab)
|
Link Here
|
|---|
|
| 5026 |
NS_IMETHODIMP |
5085 |
NS_IMETHODIMP |
| 5027 |
nsDocShell::GetIsAppTab(bool *aIsAppTab) |
5086 |
nsDocShell::GetIsAppTab(bool *aIsAppTab) |
| 5028 |
{ |
5087 |
{ |
| 5029 |
*aIsAppTab = mIsAppTab; |
5088 |
*aIsAppTab = mIsAppTab; |
| 5030 |
return NS_OK; |
5089 |
return NS_OK; |
| 5031 |
} |
5090 |
} |
| 5032 |
|
5091 |
|
| 5033 |
NS_IMETHODIMP |
5092 |
NS_IMETHODIMP |
|
|
5093 |
nsDocShell::SetSandboxFlags(PRUint32 aSandboxFlags) |
| 5094 |
{ |
| 5095 |
mSandboxFlags = aSandboxFlags; |
| 5096 |
return NS_OK; |
| 5097 |
} |
| 5098 |
|
| 5099 |
NS_IMETHODIMP |
| 5100 |
nsDocShell::GetSandboxFlags(PRUint32 *aSandboxFlags) |
| 5101 |
{ |
| 5102 |
*aSandboxFlags = mSandboxFlags; |
| 5103 |
return NS_OK; |
| 5104 |
} |
| 5105 |
|
| 5106 |
NS_IMETHODIMP |
| 5034 |
nsDocShell::SetVisibility(bool aVisibility) |
5107 |
nsDocShell::SetVisibility(bool aVisibility) |
| 5035 |
{ |
5108 |
{ |
| 5036 |
if (!mContentViewer) |
5109 |
if (!mContentViewer) |
| 5037 |
return NS_OK; |
5110 |
return NS_OK; |
| 5038 |
if (aVisibility) { |
5111 |
if (aVisibility) { |
| 5039 |
mContentViewer->Show(); |
5112 |
mContentViewer->Show(); |
| 5040 |
} |
5113 |
} |
| 5041 |
else { |
5114 |
else { |
|
Lines 8247-8262
nsDocShell::InternalLoad(nsIURI * aURI,
|
Link Here
|
|---|
|
| 8247 |
nsCOMPtr<nsIDocShellTreeItem> targetItem; |
8320 |
nsCOMPtr<nsIDocShellTreeItem> targetItem; |
| 8248 |
FindItemWithName(aWindowTarget, nsnull, this, |
8321 |
FindItemWithName(aWindowTarget, nsnull, this, |
| 8249 |
getter_AddRefs(targetItem)); |
8322 |
getter_AddRefs(targetItem)); |
| 8250 |
|
8323 |
|
| 8251 |
nsCOMPtr<nsIDocShell> targetDocShell = do_QueryInterface(targetItem); |
8324 |
nsCOMPtr<nsIDocShell> targetDocShell = do_QueryInterface(targetItem); |
| 8252 |
|
8325 |
|
| 8253 |
bool isNewWindow = false; |
8326 |
bool isNewWindow = false; |
| 8254 |
if (!targetDocShell) { |
8327 |
if (!targetDocShell) { |
|
|
8328 |
// If the docshell's document is sandboxed and was trying to |
| 8329 |
// navigate/load a frame it wasn't allowed to access, the |
| 8330 |
// FindItemWithName above will have returned null for the target |
| 8331 |
// item - we don't want to actually open a new window in this case |
| 8332 |
// though. Check if we are sandboxed and bail out here if so. |
| 8333 |
NS_ENSURE_TRUE(mContentViewer, NS_ERROR_FAILURE); |
| 8334 |
nsIDocument* doc = mContentViewer->GetDocument(); |
| 8335 |
PRUint32 sandboxFlags = 0; |
| 8336 |
sandboxFlags = doc->SandboxFlags(); |
| 8337 |
if (sandboxFlags & SANDBOXED_NAVIGATION) { |
| 8338 |
return NS_ERROR_FAILURE; |
| 8339 |
} |
| 8340 |
|
| 8255 |
nsCOMPtr<nsIDOMWindow> win = |
8341 |
nsCOMPtr<nsIDOMWindow> win = |
| 8256 |
do_GetInterface(GetAsSupports(this)); |
8342 |
do_GetInterface(GetAsSupports(this)); |
| 8257 |
NS_ENSURE_TRUE(win, NS_ERROR_NOT_AVAILABLE); |
8343 |
NS_ENSURE_TRUE(win, NS_ERROR_NOT_AVAILABLE); |
| 8258 |
|
8344 |
|
| 8259 |
nsDependentString name(aWindowTarget); |
8345 |
nsDependentString name(aWindowTarget); |
| 8260 |
nsCOMPtr<nsIDOMWindow> newWin; |
8346 |
nsCOMPtr<nsIDOMWindow> newWin; |
| 8261 |
rv = win->Open(EmptyString(), // URL to load |
8347 |
rv = win->Open(EmptyString(), // URL to load |
| 8262 |
name, // window name |
8348 |
name, // window name |
|
Lines 9034-9051
nsDocShell::DoURILoad(nsIURI * aURI,
|
Link Here
|
|---|
|
| 9034 |
} |
9120 |
} |
| 9035 |
// Set the referrer explicitly |
9121 |
// Set the referrer explicitly |
| 9036 |
if (aReferrerURI && aSendReferrer) { |
9122 |
if (aReferrerURI && aSendReferrer) { |
| 9037 |
// Referrer is currenly only set for link clicks here. |
9123 |
// Referrer is currenly only set for link clicks here. |
| 9038 |
httpChannel->SetReferrer(aReferrerURI); |
9124 |
httpChannel->SetReferrer(aReferrerURI); |
| 9039 |
} |
9125 |
} |
| 9040 |
} |
9126 |
} |
| 9041 |
|
9127 |
|
| 9042 |
nsCOMPtr<nsIPrincipal> ownerPrincipal(do_QueryInterface(aOwner)); |
9128 |
nsCOMPtr<nsIPrincipal> ownerPrincipal; |
| 9043 |
nsContentUtils::SetUpChannelOwner(ownerPrincipal, channel, aURI, true); |
9129 |
|
|
|
9130 |
// If the content being loaded should be sandboxed with respect to origin |
| 9131 |
// we need to create a new null principal here, and then tell |
| 9132 |
// nsContentUtils::SetUpChannelOwner to force it to be set as the |
| 9133 |
// channel owner. |
| 9134 |
if (mSandboxFlags & SANDBOXED_ORIGIN) { |
| 9135 |
ownerPrincipal = do_CreateInstance("@mozilla.org/nullprincipal;1"); |
| 9136 |
} else { |
| 9137 |
// Not sandboxed - we allow the content to assume its natural owner. |
| 9138 |
ownerPrincipal = do_QueryInterface(aOwner); |
| 9139 |
} |
| 9140 |
|
| 9141 |
nsContentUtils::SetUpChannelOwner(ownerPrincipal, channel, aURI, true, |
| 9142 |
(mSandboxFlags & SANDBOXED_ORIGIN)); |
| 9044 |
|
9143 |
|
| 9045 |
nsCOMPtr<nsIScriptChannel> scriptChannel = do_QueryInterface(channel); |
9144 |
nsCOMPtr<nsIScriptChannel> scriptChannel = do_QueryInterface(channel); |
| 9046 |
if (scriptChannel) { |
9145 |
if (scriptChannel) { |
| 9047 |
// Allow execution against our context if the principals match |
9146 |
// Allow execution against our context if the principals match |
| 9048 |
scriptChannel-> |
9147 |
scriptChannel-> |
| 9049 |
SetExecutionPolicy(nsIScriptChannel::EXECUTE_NORMAL); |
9148 |
SetExecutionPolicy(nsIScriptChannel::EXECUTE_NORMAL); |
| 9050 |
} |
9149 |
} |
| 9051 |
|
9150 |
|