|
|
|
|
| 214 |
#include "nsIWebBrowserPrint.h" |
214 |
#include "nsIWebBrowserPrint.h" |
| 215 |
#endif |
215 |
#endif |
| 216 |
|
216 |
|
| 217 |
#include "nsPluginError.h" |
217 |
#include "nsPluginError.h" |
| 218 |
#include "nsContentUtils.h" |
218 |
#include "nsContentUtils.h" |
| 219 |
#include "nsContentErrors.h" |
219 |
#include "nsContentErrors.h" |
| 220 |
#include "nsIChannelPolicy.h" |
220 |
#include "nsIChannelPolicy.h" |
| 221 |
#include "nsIContentSecurityPolicy.h" |
221 |
#include "nsIContentSecurityPolicy.h" |
|
|
222 |
#include "nsSandboxFlags.h" |
| 222 |
|
223 |
|
| 223 |
#include "nsXULAppAPI.h" |
224 |
#include "nsXULAppAPI.h" |
| 224 |
|
225 |
|
| 225 |
#include "nsDOMNavigationTiming.h" |
226 |
#include "nsDOMNavigationTiming.h" |
| 226 |
#include "nsITimedChannel.h" |
227 |
#include "nsITimedChannel.h" |
| 227 |
#include "mozilla/StartupTimeline.h" |
228 |
#include "mozilla/StartupTimeline.h" |
| 228 |
|
229 |
|
| 229 |
static NS_DEFINE_CID(kDOMScriptObjectFactoryCID, |
230 |
static NS_DEFINE_CID(kDOMScriptObjectFactoryCID, |
|
Lines 744-759
nsDocShell::nsDocShell():
|
Link Here
|
|---|
|
| 744 |
mBusyFlags(BUSY_FLAGS_NONE), |
745 |
mBusyFlags(BUSY_FLAGS_NONE), |
| 745 |
mAppType(nsIDocShell::APP_TYPE_UNKNOWN), |
746 |
mAppType(nsIDocShell::APP_TYPE_UNKNOWN), |
| 746 |
mLoadType(0), |
747 |
mLoadType(0), |
| 747 |
mMarginWidth(-1), |
748 |
mMarginWidth(-1), |
| 748 |
mMarginHeight(-1), |
749 |
mMarginHeight(-1), |
| 749 |
mItemType(typeContent), |
750 |
mItemType(typeContent), |
| 750 |
mPreviousTransIndex(-1), |
751 |
mPreviousTransIndex(-1), |
| 751 |
mLoadedTransIndex(-1), |
752 |
mLoadedTransIndex(-1), |
|
|
753 |
mSandboxFlags(0), |
| 752 |
mCreated(false), |
754 |
mCreated(false), |
| 753 |
mAllowSubframes(true), |
755 |
mAllowSubframes(true), |
| 754 |
mAllowPlugins(true), |
756 |
mAllowPlugins(true), |
| 755 |
mAllowJavascript(true), |
757 |
mAllowJavascript(true), |
| 756 |
mAllowMetaRedirects(true), |
758 |
mAllowMetaRedirects(true), |
| 757 |
mAllowImages(true), |
759 |
mAllowImages(true), |
| 758 |
mAllowDNSPrefetch(true), |
760 |
mAllowDNSPrefetch(true), |
| 759 |
mAllowWindowControl(true), |
761 |
mAllowWindowControl(true), |
|
Lines 2935-2950
nsDocShell::FindItemWithName(const PRUni
|
Link Here
|
|---|
|
| 2935 |
foundItem = nsnull; |
2937 |
foundItem = nsnull; |
| 2936 |
} |
2938 |
} |
| 2937 |
|
2939 |
|
| 2938 |
if (foundItem) { |
2940 |
if (foundItem) { |
| 2939 |
// We return foundItem here even if it's not an active |
2941 |
// We return foundItem here even if it's not an active |
| 2940 |
// item since all the names we've dealt with so far are |
2942 |
// item since all the names we've dealt with so far are |
| 2941 |
// special cases that we won't bother looking for further. |
2943 |
// special cases that we won't bother looking for further. |
| 2942 |
|
2944 |
|
|
|
2945 |
// If our document is sandboxed, we need to do some extra checks. |
| 2946 |
PRUint32 sandboxFlags = 0; |
| 2947 |
|
| 2948 |
nsCOMPtr<nsIDocument> doc = do_GetInterface(aOriginalRequestor); |
| 2949 |
|
| 2950 |
if (doc) { |
| 2951 |
sandboxFlags = doc->SandboxFlags(); |
| 2952 |
} |
| 2953 |
|
| 2954 |
if (sandboxFlags) { |
| 2955 |
nsCOMPtr<nsIDocShellTreeItem> root; |
| 2956 |
GetSameTypeRootTreeItem(getter_AddRefs(root)); |
| 2957 |
|
| 2958 |
// Is the found item not a top level browsing context and not ourself ? |
| 2959 |
nsCOMPtr<nsIDocShellTreeItem> selfAsItem = static_cast<nsIDocShellTreeItem *>(this); |
| 2960 |
if (foundItem != root && foundItem != selfAsItem) { |
| 2961 |
// Are we an ancestor of the foundItem ? |
| 2962 |
bool isAncestor = false; |
| 2963 |
|
| 2964 |
nsCOMPtr<nsIDocShellTreeItem> parentAsItem; |
| 2965 |
GetSameTypeParent(getter_AddRefs(parentAsItem)); |
| 2966 |
|
| 2967 |
while (parentAsItem) { |
| 2968 |
nsCOMPtr<nsIDocShellTreeItem> tmp; |
| 2969 |
parentAsItem->GetParent(getter_AddRefs(tmp)); |
| 2970 |
|
| 2971 |
if (tmp && tmp == selfAsItem) { |
| 2972 |
isAncestor = true; |
| 2973 |
break; |
| 2974 |
} |
| 2975 |
parentAsItem = tmp; |
| 2976 |
} |
| 2977 |
|
| 2978 |
if (!isAncestor) { |
| 2979 |
// No, we are not an ancestor and our document is |
| 2980 |
// sandboxed, we can't allow this. |
| 2981 |
foundItem = nsnull; |
| 2982 |
} |
| 2983 |
} else { |
| 2984 |
// Top level browsing context - is it an ancestor of ours ? |
| 2985 |
nsCOMPtr<nsIDocShellTreeItem> tmp; |
| 2986 |
GetSameTypeParent(getter_AddRefs(tmp)); |
| 2987 |
|
| 2988 |
while (tmp) { |
| 2989 |
if (tmp && tmp == foundItem) { |
| 2990 |
// This is an ancestor, and we are sandboxed. |
| 2991 |
// Unless allow-top-navigation is set, we can't allow this. |
| 2992 |
if (sandboxFlags & SANDBOXED_TOPLEVEL_NAVIGATION) { |
| 2993 |
foundItem = nsnull; |
| 2994 |
} |
| 2995 |
break; |
| 2996 |
} |
| 2997 |
tmp->GetParent(getter_AddRefs(tmp)); |
| 2998 |
} |
| 2999 |
} |
| 3000 |
} |
| 3001 |
|
| 2943 |
foundItem.swap(*_retval); |
3002 |
foundItem.swap(*_retval); |
| 2944 |
return NS_OK; |
3003 |
return NS_OK; |
| 2945 |
} |
3004 |
} |
| 2946 |
} |
3005 |
} |
| 2947 |
|
3006 |
|
| 2948 |
// Keep looking |
3007 |
// Keep looking |
| 2949 |
|
3008 |
|
| 2950 |
// First we check our name. |
3009 |
// First we check our name. |
|
Lines 4971-4986
nsDocShell::SetIsAppTab(bool aIsAppTab)
|
Link Here
|
|---|
|
| 4971 |
NS_IMETHODIMP |
5030 |
NS_IMETHODIMP |
| 4972 |
nsDocShell::GetIsAppTab(bool *aIsAppTab) |
5031 |
nsDocShell::GetIsAppTab(bool *aIsAppTab) |
| 4973 |
{ |
5032 |
{ |
| 4974 |
*aIsAppTab = mIsAppTab; |
5033 |
*aIsAppTab = mIsAppTab; |
| 4975 |
return NS_OK; |
5034 |
return NS_OK; |
| 4976 |
} |
5035 |
} |
| 4977 |
|
5036 |
|
| 4978 |
NS_IMETHODIMP |
5037 |
NS_IMETHODIMP |
|
|
5038 |
nsDocShell::SetSandboxFlags(PRUint32 aSandboxFlags) |
| 5039 |
{ |
| 5040 |
mSandboxFlags = aSandboxFlags; |
| 5041 |
return NS_OK; |
| 5042 |
} |
| 5043 |
|
| 5044 |
NS_IMETHODIMP |
| 5045 |
nsDocShell::GetSandboxFlags(PRUint32 *aSandboxFlags) |
| 5046 |
{ |
| 5047 |
*aSandboxFlags = mSandboxFlags; |
| 5048 |
return NS_OK; |
| 5049 |
} |
| 5050 |
|
| 5051 |
NS_IMETHODIMP |
| 4979 |
nsDocShell::SetVisibility(bool aVisibility) |
5052 |
nsDocShell::SetVisibility(bool aVisibility) |
| 4980 |
{ |
5053 |
{ |
| 4981 |
if (!mContentViewer) |
5054 |
if (!mContentViewer) |
| 4982 |
return NS_OK; |
5055 |
return NS_OK; |
| 4983 |
if (aVisibility) { |
5056 |
if (aVisibility) { |
| 4984 |
mContentViewer->Show(); |
5057 |
mContentViewer->Show(); |
| 4985 |
} |
5058 |
} |
| 4986 |
else { |
5059 |
else { |
|
Lines 8172-8187
nsDocShell::InternalLoad(nsIURI * aURI,
|
Link Here
|
|---|
|
| 8172 |
nsCOMPtr<nsIDocShellTreeItem> targetItem; |
8245 |
nsCOMPtr<nsIDocShellTreeItem> targetItem; |
| 8173 |
FindItemWithName(aWindowTarget, nsnull, this, |
8246 |
FindItemWithName(aWindowTarget, nsnull, this, |
| 8174 |
getter_AddRefs(targetItem)); |
8247 |
getter_AddRefs(targetItem)); |
| 8175 |
|
8248 |
|
| 8176 |
nsCOMPtr<nsIDocShell> targetDocShell = do_QueryInterface(targetItem); |
8249 |
nsCOMPtr<nsIDocShell> targetDocShell = do_QueryInterface(targetItem); |
| 8177 |
|
8250 |
|
| 8178 |
bool isNewWindow = false; |
8251 |
bool isNewWindow = false; |
| 8179 |
if (!targetDocShell) { |
8252 |
if (!targetDocShell) { |
|
|
8253 |
// If the docshell's document is sandboxed and was trying to |
| 8254 |
// navigate/load a frame it wasn't allowed to access, the |
| 8255 |
// FindItemWithName above will have returned null for the target |
| 8256 |
// item - we don't want to actually open a new window in this case |
| 8257 |
// though. Check if we are sandboxed and bail out here if so. |
| 8258 |
NS_ENSURE_TRUE(mContentViewer, NS_ERROR_FAILURE); |
| 8259 |
nsIDocument* doc = mContentViewer->GetDocument(); |
| 8260 |
PRUint32 sandboxFlags = 0; |
| 8261 |
sandboxFlags = doc->SandboxFlags(); |
| 8262 |
if (sandboxFlags & SANDBOXED_NAVIGATION) { |
| 8263 |
return NS_ERROR_FAILURE; |
| 8264 |
} |
| 8265 |
|
| 8180 |
nsCOMPtr<nsIDOMWindow> win = |
8266 |
nsCOMPtr<nsIDOMWindow> win = |
| 8181 |
do_GetInterface(GetAsSupports(this)); |
8267 |
do_GetInterface(GetAsSupports(this)); |
| 8182 |
NS_ENSURE_TRUE(win, NS_ERROR_NOT_AVAILABLE); |
8268 |
NS_ENSURE_TRUE(win, NS_ERROR_NOT_AVAILABLE); |
| 8183 |
|
8269 |
|
| 8184 |
nsDependentString name(aWindowTarget); |
8270 |
nsDependentString name(aWindowTarget); |
| 8185 |
nsCOMPtr<nsIDOMWindow> newWin; |
8271 |
nsCOMPtr<nsIDOMWindow> newWin; |
| 8186 |
rv = win->Open(EmptyString(), // URL to load |
8272 |
rv = win->Open(EmptyString(), // URL to load |
| 8187 |
name, // window name |
8273 |
name, // window name |
|
Lines 8959-8976
nsDocShell::DoURILoad(nsIURI * aURI,
|
Link Here
|
|---|
|
| 8959 |
} |
9045 |
} |
| 8960 |
// Set the referrer explicitly |
9046 |
// Set the referrer explicitly |
| 8961 |
if (aReferrerURI && aSendReferrer) { |
9047 |
if (aReferrerURI && aSendReferrer) { |
| 8962 |
// Referrer is currenly only set for link clicks here. |
9048 |
// Referrer is currenly only set for link clicks here. |
| 8963 |
httpChannel->SetReferrer(aReferrerURI); |
9049 |
httpChannel->SetReferrer(aReferrerURI); |
| 8964 |
} |
9050 |
} |
| 8965 |
} |
9051 |
} |
| 8966 |
|
9052 |
|
| 8967 |
nsCOMPtr<nsIPrincipal> ownerPrincipal(do_QueryInterface(aOwner)); |
9053 |
nsCOMPtr<nsIPrincipal> ownerPrincipal; |
| 8968 |
nsContentUtils::SetUpChannelOwner(ownerPrincipal, channel, aURI, true); |
9054 |
|
|
|
9055 |
// If the content being loaded should be sandboxed with respect to origin |
| 9056 |
// we need to create a new null principal here, and then tell |
| 9057 |
// nsContentUtils::SetUpChannelOwner to force it to be set as the |
| 9058 |
// channel owner. |
| 9059 |
if (mSandboxFlags & SANDBOXED_ORIGIN) { |
| 9060 |
ownerPrincipal = do_CreateInstance("@mozilla.org/nullprincipal;1"); |
| 9061 |
} else { |
| 9062 |
// Not sandboxed - we allow the content to assume its natural owner. |
| 9063 |
ownerPrincipal = do_QueryInterface(aOwner); |
| 9064 |
} |
| 9065 |
|
| 9066 |
nsContentUtils::SetUpChannelOwner(ownerPrincipal, channel, aURI, true, |
| 9067 |
(mSandboxFlags & SANDBOXED_ORIGIN)); |
| 8969 |
|
9068 |
|
| 8970 |
nsCOMPtr<nsIScriptChannel> scriptChannel = do_QueryInterface(channel); |
9069 |
nsCOMPtr<nsIScriptChannel> scriptChannel = do_QueryInterface(channel); |
| 8971 |
if (scriptChannel) { |
9070 |
if (scriptChannel) { |
| 8972 |
// Allow execution against our context if the principals match |
9071 |
// Allow execution against our context if the principals match |
| 8973 |
scriptChannel-> |
9072 |
scriptChannel-> |
| 8974 |
SetExecutionPolicy(nsIScriptChannel::EXECUTE_NORMAL); |
9073 |
SetExecutionPolicy(nsIScriptChannel::EXECUTE_NORMAL); |
| 8975 |
} |
9074 |
} |
| 8976 |
|
9075 |
|