|
|
|
|
| 213 |
#include "nsIWebBrowserPrint.h" |
213 |
#include "nsIWebBrowserPrint.h" |
| 214 |
#endif |
214 |
#endif |
| 215 |
|
215 |
|
| 216 |
#include "nsPluginError.h" |
216 |
#include "nsPluginError.h" |
| 217 |
#include "nsContentUtils.h" |
217 |
#include "nsContentUtils.h" |
| 218 |
#include "nsContentErrors.h" |
218 |
#include "nsContentErrors.h" |
| 219 |
#include "nsIChannelPolicy.h" |
219 |
#include "nsIChannelPolicy.h" |
| 220 |
#include "nsIContentSecurityPolicy.h" |
220 |
#include "nsIContentSecurityPolicy.h" |
|
|
221 |
#include "nsSandboxFlags.h" |
| 221 |
|
222 |
|
| 222 |
#include "nsXULAppAPI.h" |
223 |
#include "nsXULAppAPI.h" |
| 223 |
|
224 |
|
| 224 |
#include "nsDOMNavigationTiming.h" |
225 |
#include "nsDOMNavigationTiming.h" |
| 225 |
#include "nsITimedChannel.h" |
226 |
#include "nsITimedChannel.h" |
| 226 |
#include "mozilla/StartupTimeline.h" |
227 |
#include "mozilla/StartupTimeline.h" |
| 227 |
|
228 |
|
| 228 |
static NS_DEFINE_CID(kDOMScriptObjectFactoryCID, |
229 |
static NS_DEFINE_CID(kDOMScriptObjectFactoryCID, |
|
Lines 727-742
nsDocShell::nsDocShell():
|
Link Here
|
|---|
|
| 727 |
mBusyFlags(BUSY_FLAGS_NONE), |
728 |
mBusyFlags(BUSY_FLAGS_NONE), |
| 728 |
mAppType(nsIDocShell::APP_TYPE_UNKNOWN), |
729 |
mAppType(nsIDocShell::APP_TYPE_UNKNOWN), |
| 729 |
mLoadType(0), |
730 |
mLoadType(0), |
| 730 |
mMarginWidth(-1), |
731 |
mMarginWidth(-1), |
| 731 |
mMarginHeight(-1), |
732 |
mMarginHeight(-1), |
| 732 |
mItemType(typeContent), |
733 |
mItemType(typeContent), |
| 733 |
mPreviousTransIndex(-1), |
734 |
mPreviousTransIndex(-1), |
| 734 |
mLoadedTransIndex(-1), |
735 |
mLoadedTransIndex(-1), |
|
|
736 |
mSandboxFlags(0), |
| 735 |
mCreated(false), |
737 |
mCreated(false), |
| 736 |
mAllowSubframes(true), |
738 |
mAllowSubframes(true), |
| 737 |
mAllowPlugins(true), |
739 |
mAllowPlugins(true), |
| 738 |
mAllowJavascript(true), |
740 |
mAllowJavascript(true), |
| 739 |
mAllowMetaRedirects(true), |
741 |
mAllowMetaRedirects(true), |
| 740 |
mAllowImages(true), |
742 |
mAllowImages(true), |
| 741 |
mAllowDNSPrefetch(true), |
743 |
mAllowDNSPrefetch(true), |
| 742 |
mAllowWindowControl(true), |
744 |
mAllowWindowControl(true), |
|
Lines 2907-2922
nsDocShell::FindItemWithName(const PRUni
|
Link Here
|
|---|
|
| 2907 |
foundItem = nsnull; |
2909 |
foundItem = nsnull; |
| 2908 |
} |
2910 |
} |
| 2909 |
|
2911 |
|
| 2910 |
if (foundItem) { |
2912 |
if (foundItem) { |
| 2911 |
// We return foundItem here even if it's not an active |
2913 |
// We return foundItem here even if it's not an active |
| 2912 |
// item since all the names we've dealt with so far are |
2914 |
// item since all the names we've dealt with so far are |
| 2913 |
// special cases that we won't bother looking for further. |
2915 |
// special cases that we won't bother looking for further. |
| 2914 |
|
2916 |
|
|
|
2917 |
// If our document is sandboxed, we need to do some extra checks. |
| 2918 |
PRUint32 sandboxFlags = 0; |
| 2919 |
|
| 2920 |
nsCOMPtr<nsIDocument> doc = do_GetInterface(aOriginalRequestor); |
| 2921 |
|
| 2922 |
if (doc) { |
| 2923 |
sandboxFlags = doc->SandboxFlags(); |
| 2924 |
} |
| 2925 |
|
| 2926 |
if (sandboxFlags) { |
| 2927 |
nsCOMPtr<nsIDocShellTreeItem> root; |
| 2928 |
GetSameTypeRootTreeItem(getter_AddRefs(root)); |
| 2929 |
|
| 2930 |
// Is the found item not a top level browsing context and not ourself ? |
| 2931 |
nsCOMPtr<nsIDocShellTreeItem> selfAsItem = static_cast<nsIDocShellTreeItem *>(this); |
| 2932 |
if (foundItem != root && foundItem != selfAsItem) { |
| 2933 |
// Are we an ancestor of the foundItem ? |
| 2934 |
bool isAncestor = false; |
| 2935 |
|
| 2936 |
nsCOMPtr<nsIDocShellTreeItem> parentAsItem; |
| 2937 |
GetSameTypeParent(getter_AddRefs(parentAsItem)); |
| 2938 |
|
| 2939 |
while (parentAsItem) { |
| 2940 |
nsCOMPtr<nsIDocShellTreeItem> tmp; |
| 2941 |
parentAsItem->GetParent(getter_AddRefs(tmp)); |
| 2942 |
|
| 2943 |
if (tmp && tmp == selfAsItem) { |
| 2944 |
isAncestor = true; |
| 2945 |
break; |
| 2946 |
} |
| 2947 |
parentAsItem = tmp; |
| 2948 |
} |
| 2949 |
|
| 2950 |
if (!isAncestor) { |
| 2951 |
// No, we are not an ancestor and our document is |
| 2952 |
// sandboxed, we can't allow this. |
| 2953 |
foundItem = nsnull; |
| 2954 |
} |
| 2955 |
} else { |
| 2956 |
// Top level browsing context - is it an ancestor of ours ? |
| 2957 |
nsCOMPtr<nsIDocShellTreeItem> tmp; |
| 2958 |
GetSameTypeParent(getter_AddRefs(tmp)); |
| 2959 |
|
| 2960 |
while (tmp) { |
| 2961 |
if (tmp && tmp == foundItem) { |
| 2962 |
// This is an ancestor, and we are sandboxed. |
| 2963 |
// Unless allow-top-navigation is set, we can't allow this. |
| 2964 |
if (sandboxFlags & SANDBOXED_TOPLEVEL_NAVIGATION) { |
| 2965 |
foundItem = nsnull; |
| 2966 |
} |
| 2967 |
break; |
| 2968 |
} |
| 2969 |
tmp->GetParent(getter_AddRefs(tmp)); |
| 2970 |
} |
| 2971 |
} |
| 2972 |
} |
| 2973 |
|
| 2915 |
foundItem.swap(*_retval); |
2974 |
foundItem.swap(*_retval); |
| 2916 |
return NS_OK; |
2975 |
return NS_OK; |
| 2917 |
} |
2976 |
} |
| 2918 |
} |
2977 |
} |
| 2919 |
|
2978 |
|
| 2920 |
// Keep looking |
2979 |
// Keep looking |
| 2921 |
|
2980 |
|
| 2922 |
// First we check our name. |
2981 |
// First we check our name. |
|
Lines 4943-4958
nsDocShell::SetIsAppTab(bool aIsAppTab)
|
Link Here
|
|---|
|
| 4943 |
NS_IMETHODIMP |
5002 |
NS_IMETHODIMP |
| 4944 |
nsDocShell::GetIsAppTab(bool *aIsAppTab) |
5003 |
nsDocShell::GetIsAppTab(bool *aIsAppTab) |
| 4945 |
{ |
5004 |
{ |
| 4946 |
*aIsAppTab = mIsAppTab; |
5005 |
*aIsAppTab = mIsAppTab; |
| 4947 |
return NS_OK; |
5006 |
return NS_OK; |
| 4948 |
} |
5007 |
} |
| 4949 |
|
5008 |
|
| 4950 |
NS_IMETHODIMP |
5009 |
NS_IMETHODIMP |
|
|
5010 |
nsDocShell::SetSandboxFlags(PRUint32 aSandboxFlags) |
| 5011 |
{ |
| 5012 |
mSandboxFlags = aSandboxFlags; |
| 5013 |
return NS_OK; |
| 5014 |
} |
| 5015 |
|
| 5016 |
NS_IMETHODIMP |
| 5017 |
nsDocShell::GetSandboxFlags(PRUint32 *aSandboxFlags) |
| 5018 |
{ |
| 5019 |
*aSandboxFlags = mSandboxFlags; |
| 5020 |
return NS_OK; |
| 5021 |
} |
| 5022 |
|
| 5023 |
NS_IMETHODIMP |
| 4951 |
nsDocShell::SetVisibility(bool aVisibility) |
5024 |
nsDocShell::SetVisibility(bool aVisibility) |
| 4952 |
{ |
5025 |
{ |
| 4953 |
if (!mContentViewer) |
5026 |
if (!mContentViewer) |
| 4954 |
return NS_OK; |
5027 |
return NS_OK; |
| 4955 |
if (aVisibility) { |
5028 |
if (aVisibility) { |
| 4956 |
mContentViewer->Show(); |
5029 |
mContentViewer->Show(); |
| 4957 |
} |
5030 |
} |
| 4958 |
else { |
5031 |
else { |
|
Lines 8132-8147
nsDocShell::InternalLoad(nsIURI * aURI,
|
Link Here
|
|---|
|
| 8132 |
nsCOMPtr<nsIDocShellTreeItem> targetItem; |
8205 |
nsCOMPtr<nsIDocShellTreeItem> targetItem; |
| 8133 |
FindItemWithName(aWindowTarget, nsnull, this, |
8206 |
FindItemWithName(aWindowTarget, nsnull, this, |
| 8134 |
getter_AddRefs(targetItem)); |
8207 |
getter_AddRefs(targetItem)); |
| 8135 |
|
8208 |
|
| 8136 |
nsCOMPtr<nsIDocShell> targetDocShell = do_QueryInterface(targetItem); |
8209 |
nsCOMPtr<nsIDocShell> targetDocShell = do_QueryInterface(targetItem); |
| 8137 |
|
8210 |
|
| 8138 |
bool isNewWindow = false; |
8211 |
bool isNewWindow = false; |
| 8139 |
if (!targetDocShell) { |
8212 |
if (!targetDocShell) { |
|
|
8213 |
// If the docshell's document is sandboxed and was trying to |
| 8214 |
// navigate/load a frame it wasn't allowed to access, the |
| 8215 |
// FindItemWithName above will have returned null for the target |
| 8216 |
// item - we don't want to actually open a new window in this case |
| 8217 |
// though. Check if we are sandboxed and bail out here if so. |
| 8218 |
NS_ENSURE_TRUE(mContentViewer, NS_ERROR_FAILURE); |
| 8219 |
nsIDocument* doc = mContentViewer->GetDocument(); |
| 8220 |
PRUint32 sandboxFlags = 0; |
| 8221 |
sandboxFlags = doc->SandboxFlags(); |
| 8222 |
if (sandboxFlags & SANDBOXED_NAVIGATION) { |
| 8223 |
return NS_ERROR_FAILURE; |
| 8224 |
} |
| 8225 |
|
| 8140 |
nsCOMPtr<nsIDOMWindow> win = |
8226 |
nsCOMPtr<nsIDOMWindow> win = |
| 8141 |
do_GetInterface(GetAsSupports(this)); |
8227 |
do_GetInterface(GetAsSupports(this)); |
| 8142 |
NS_ENSURE_TRUE(win, NS_ERROR_NOT_AVAILABLE); |
8228 |
NS_ENSURE_TRUE(win, NS_ERROR_NOT_AVAILABLE); |
| 8143 |
|
8229 |
|
| 8144 |
nsDependentString name(aWindowTarget); |
8230 |
nsDependentString name(aWindowTarget); |
| 8145 |
nsCOMPtr<nsIDOMWindow> newWin; |
8231 |
nsCOMPtr<nsIDOMWindow> newWin; |
| 8146 |
rv = win->Open(EmptyString(), // URL to load |
8232 |
rv = win->Open(EmptyString(), // URL to load |
| 8147 |
name, // window name |
8233 |
name, // window name |
|
Lines 8913-8930
nsDocShell::DoURILoad(nsIURI * aURI,
|
Link Here
|
|---|
|
| 8913 |
} |
8999 |
} |
| 8914 |
// Set the referrer explicitly |
9000 |
// Set the referrer explicitly |
| 8915 |
if (aReferrerURI && aSendReferrer) { |
9001 |
if (aReferrerURI && aSendReferrer) { |
| 8916 |
// Referrer is currenly only set for link clicks here. |
9002 |
// Referrer is currenly only set for link clicks here. |
| 8917 |
httpChannel->SetReferrer(aReferrerURI); |
9003 |
httpChannel->SetReferrer(aReferrerURI); |
| 8918 |
} |
9004 |
} |
| 8919 |
} |
9005 |
} |
| 8920 |
|
9006 |
|
| 8921 |
nsCOMPtr<nsIPrincipal> ownerPrincipal(do_QueryInterface(aOwner)); |
9007 |
nsCOMPtr<nsIPrincipal> ownerPrincipal; |
| 8922 |
nsContentUtils::SetUpChannelOwner(ownerPrincipal, channel, aURI, true); |
9008 |
|
|
|
9009 |
// If the content being loaded should be sandboxed with respect to origin |
| 9010 |
// we need to create a new null principal here, and then tell |
| 9011 |
// nsContentUtils::SetUpChannelOwner to force it to be set as the |
| 9012 |
// channel owner. |
| 9013 |
if (mSandboxFlags & SANDBOXED_ORIGIN) { |
| 9014 |
ownerPrincipal = do_CreateInstance("@mozilla.org/nullprincipal;1"); |
| 9015 |
} else { |
| 9016 |
// Not sandboxed - we allow the content to assume its natural owner. |
| 9017 |
ownerPrincipal = do_QueryInterface(aOwner); |
| 9018 |
} |
| 9019 |
|
| 9020 |
nsContentUtils::SetUpChannelOwner(ownerPrincipal, channel, aURI, true, |
| 9021 |
(mSandboxFlags & SANDBOXED_ORIGIN)); |
| 8923 |
|
9022 |
|
| 8924 |
nsCOMPtr<nsIScriptChannel> scriptChannel = do_QueryInterface(channel); |
9023 |
nsCOMPtr<nsIScriptChannel> scriptChannel = do_QueryInterface(channel); |
| 8925 |
if (scriptChannel) { |
9024 |
if (scriptChannel) { |
| 8926 |
// Allow execution against our context if the principals match |
9025 |
// Allow execution against our context if the principals match |
| 8927 |
scriptChannel-> |
9026 |
scriptChannel-> |
| 8928 |
SetExecutionPolicy(nsIScriptChannel::EXECUTE_NORMAL); |
9027 |
SetExecutionPolicy(nsIScriptChannel::EXECUTE_NORMAL); |
| 8929 |
} |
9028 |
} |
| 8930 |
|
9029 |
|