Bug 1325028 part 1. Remove IsCallerChrome use from nsGlobalWindow's .content getter. r=bkelly

This commit is contained in:
Boris Zbarsky 2016-12-22 11:05:55 -08:00
parent 61f31dce10
commit d6423562a1
3 changed files with 16 additions and 26 deletions

View File

@ -4261,12 +4261,13 @@ nsGlobalWindow::GetTop()
void
nsGlobalWindow::GetContentOuter(JSContext* aCx,
JS::MutableHandle<JSObject*> aRetval,
CallerType aCallerType,
ErrorResult& aError)
{
MOZ_RELEASE_ASSERT(IsOuterWindow());
nsCOMPtr<nsPIDOMWindowOuter> content =
GetContentInternal(aError, !nsContentUtils::IsCallerChrome());
GetContentInternal(aError, aCallerType);
if (aError.Failed()) {
return;
}
@ -4289,13 +4290,15 @@ nsGlobalWindow::GetContentOuter(JSContext* aCx,
void
nsGlobalWindow::GetContent(JSContext* aCx,
JS::MutableHandle<JSObject*> aRetval,
CallerType aCallerType,
ErrorResult& aError)
{
FORWARD_TO_OUTER_OR_THROW(GetContentOuter, (aCx, aRetval, aError), aError, );
FORWARD_TO_OUTER_OR_THROW(GetContentOuter,
(aCx, aRetval, aCallerType, aError), aError, );
}
already_AddRefed<nsPIDOMWindowOuter>
nsGlobalWindow::GetContentInternal(ErrorResult& aError, bool aUnprivilegedCaller)
nsGlobalWindow::GetContentInternal(ErrorResult& aError, CallerType aCallerType)
{
MOZ_ASSERT(IsOuterWindow());
@ -4313,7 +4316,7 @@ nsGlobalWindow::GetContentInternal(ErrorResult& aError, bool aUnprivilegedCaller
}
nsCOMPtr<nsIDocShellTreeItem> primaryContent;
if (aUnprivilegedCaller) {
if (aCallerType != CallerType::System) {
// If we're called by non-chrome code, make sure we don't return
// the primary content window if the calling tab is hidden. In
// such a case we return the same-type root in the hidden tab,
@ -4365,19 +4368,6 @@ nsGlobalWindow::GetMozSelfSupport(ErrorResult& aError)
return mMozSelfSupport;
}
nsresult
nsGlobalWindow::GetScriptableContent(JSContext* aCx, JS::MutableHandle<JS::Value> aVal)
{
ErrorResult rv;
JS::Rooted<JSObject*> content(aCx);
GetContent(aCx, &content, rv);
if (!rv.Failed()) {
aVal.setObjectOrNull(content);
}
return rv.StealNSResult();
}
nsresult
nsGlobalWindow::GetPrompter(nsIPrompt** aPrompt)
{

View File

@ -338,8 +338,6 @@ public:
void ReleaseEvents();
void Dump(const nsAString& aStr);
void SetResizable(bool aResizable) const;
nsresult GetScriptableContent(JSContext* aCx,
JS::MutableHandle<JS::Value> aVal);
// nsIDOMEventTarget
NS_DECL_NSIDOMEVENTTARGET
@ -1173,31 +1171,33 @@ public:
mozilla::ThrottledEventQueue* GetThrottledEventQueue() override;
already_AddRefed<nsPIDOMWindowOuter>
GetContentInternal(mozilla::ErrorResult& aError, bool aUnprivilegedCaller);
GetContentInternal(mozilla::ErrorResult& aError,
mozilla::dom::CallerType aCallerType);
void GetContentOuter(JSContext* aCx,
JS::MutableHandle<JSObject*> aRetval,
mozilla::ErrorResult& aError);
void GetContent(JSContext* aCx,
JS::MutableHandle<JSObject*> aRetval,
mozilla::dom::CallerType aCallerType,
mozilla::ErrorResult& aError);
already_AddRefed<nsPIDOMWindowOuter> GetContent()
{
MOZ_ASSERT(IsOuterWindow());
mozilla::ErrorResult ignored;
mozilla::IgnoredErrorResult ignored;
nsCOMPtr<nsPIDOMWindowOuter> win =
GetContentInternal(ignored, /* aUnprivilegedCaller = */ false);
ignored.SuppressException();
GetContentInternal(ignored, mozilla::dom::CallerType::System);
return win.forget();
}
void Get_content(JSContext* aCx,
JS::MutableHandle<JSObject*> aRetval,
mozilla::dom::CallerType aCallerType,
mozilla::ErrorResult& aError)
{
if (mDoc) {
mDoc->WarnOnceAbout(nsIDocument::eWindow_Content);
}
GetContent(aCx, aRetval, aError);
GetContent(aCx, aRetval, aCallerType, aError);
}
already_AddRefed<mozilla::dom::Promise>

View File

@ -374,9 +374,9 @@ partial interface Window {
optional DOMString options = "",
any... extraArguments);
[Replaceable, Throws] readonly attribute object? content;
[Replaceable, Throws, NeedsCallerType] readonly attribute object? content;
[ChromeOnly, Throws] readonly attribute object? __content;
[ChromeOnly, Throws, NeedsCallerType] readonly attribute object? __content;
[Throws, ChromeOnly] any getInterface(IID iid);