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