From 1789589121b56bff6e44ba49620720314d7e1c6a Mon Sep 17 00:00:00 2001 From: Wes Kocher Date: Mon, 6 Jan 2014 18:10:34 -0800 Subject: [PATCH] Backed out changeset e451b39305f6 (bug 949488) for breaking mochitest-8 on at least b2g --- dom/base/ScriptSettings.cpp | 20 ---- dom/base/ScriptSettings.h | 5 - dom/base/moz.build | 1 - dom/base/nsGlobalWindow.cpp | 68 +++++--------- dom/base/nsIGlobalObject.cpp | 18 ---- dom/base/nsIGlobalObject.h | 5 - dom/base/test/iframe_postMessage_solidus.html | 15 --- dom/base/test/mochitest.ini | 2 - dom/base/test/test_postMessage_solidus.html | 93 ------------------- .../localstorage/test_clear_browser_data.html | 2 +- 10 files changed, 24 insertions(+), 205 deletions(-) delete mode 100644 dom/base/nsIGlobalObject.cpp delete mode 100644 dom/base/test/iframe_postMessage_solidus.html delete mode 100644 dom/base/test/test_postMessage_solidus.html diff --git a/dom/base/ScriptSettings.cpp b/dom/base/ScriptSettings.cpp index 748a9a6e781..c4ebb9aa888 100644 --- a/dom/base/ScriptSettings.cpp +++ b/dom/base/ScriptSettings.cpp @@ -15,7 +15,6 @@ #include "nsIScriptContext.h" #include "nsContentUtils.h" #include "nsTArray.h" -#include "nsJSUtils.h" namespace mozilla { namespace dom { @@ -93,25 +92,6 @@ void DestroyScriptSettings() delete ptr; } -// This mostly gets the entry global, but doesn't entirely match the spec in -// certain edge cases. It's good enough for some purposes, but not others. If -// you want to call this function, ping bholley and describe your use-case. -nsIGlobalObject* -BrokenGetEntryGlobal() -{ - // We need the current JSContext in order to check the JS for - // scripted frames that may have appeared since anyone last - // manipulated the stack. If it's null, that means that there - // must be no entry point on the stack. - JSContext *cx = nsContentUtils::GetCurrentJSContextForThread(); - if (!cx) { - MOZ_ASSERT(ScriptSettingsStack::Ref().EntryPoint() == nullptr); - return nullptr; - } - - return nsJSUtils::GetDynamicScriptGlobal(cx); -} - // Note: When we're ready to expose it, GetEntryGlobal will look similar to // GetIncumbentGlobal below. diff --git a/dom/base/ScriptSettings.h b/dom/base/ScriptSettings.h index f9e1645df4d..fd0f44b4e97 100644 --- a/dom/base/ScriptSettings.h +++ b/dom/base/ScriptSettings.h @@ -27,11 +27,6 @@ namespace dom { void InitScriptSettings(); void DestroyScriptSettings(); -// This mostly gets the entry global, but doesn't entirely match the spec in -// certain edge cases. It's good enough for some purposes, but not others. If -// you want to call this function, ping bholley and describe your use-case. -nsIGlobalObject* BrokenGetEntryGlobal(); - // Note: We don't yet expose GetEntryGlobal, because in order for it to be // correct, we first need to replace a bunch of explicit cx pushing in the // browser with AutoEntryScript. But GetIncumbentGlobal is simpler, because it diff --git a/dom/base/moz.build b/dom/base/moz.build index bceedb65198..b6c0ee9cd98 100644 --- a/dom/base/moz.build +++ b/dom/base/moz.build @@ -84,7 +84,6 @@ UNIFIED_SOURCES += [ 'nsFocusManager.cpp', 'nsGlobalWindowCommands.cpp', 'nsHistory.cpp', - 'nsIGlobalObject.cpp', 'nsJSTimeoutHandler.cpp', 'nsJSUtils.cpp', 'nsLocation.cpp', diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 96d51915771..9145301449d 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -7485,14 +7485,14 @@ class PostMessageEvent : public nsRunnable PostMessageEvent(nsGlobalWindow* aSource, const nsAString& aCallerOrigin, nsGlobalWindow* aTargetWindow, - nsIPrincipal* aProvidedPrincipal, + nsIURI* aProvidedOrigin, bool aTrustedCaller) : mSource(aSource), mCallerOrigin(aCallerOrigin), mMessage(nullptr), mMessageLen(0), mTargetWindow(aTargetWindow), - mProvidedPrincipal(aProvidedPrincipal), + mProvidedOrigin(aProvidedOrigin), mTrustedCaller(aTrustedCaller) { MOZ_COUNT_CTOR(PostMessageEvent); @@ -7522,7 +7522,7 @@ class PostMessageEvent : public nsRunnable uint64_t* mMessage; size_t mMessageLen; nsRefPtr mTargetWindow; - nsCOMPtr mProvidedPrincipal; + nsCOMPtr mProvidedOrigin; bool mTrustedCaller; nsTArray > mSupportsArray; }; @@ -7691,22 +7691,32 @@ PostMessageEvent::Run() // intercept messages intended for another site by carefully timing navigation // of the target window so it changed location after postMessage but before // now. - if (mProvidedPrincipal) { + if (mProvidedOrigin) { // Get the target's origin either from its principal or, in the case the // principal doesn't carry a URI (e.g. the system principal), the target's // document. nsIPrincipal* targetPrin = targetWindow->GetPrincipal(); - if (NS_WARN_IF(!targetPrin)) + if (!targetPrin) return NS_OK; + nsCOMPtr targetURI; + if (NS_FAILED(targetPrin->GetURI(getter_AddRefs(targetURI)))) + return NS_OK; + if (!targetURI) { + targetURI = targetWindow->mDoc->GetDocumentURI(); + if (!targetURI) + return NS_OK; + } // Note: This is contrary to the spec with respect to file: URLs, which // the spec groups into a single origin, but given we intentionally // don't do that in other places it seems better to hold the line for // now. Long-term, we want HTML5 to address this so that we can // be compliant while being safer. - if (!targetPrin->EqualsIgnoringDomain(mProvidedPrincipal)) { + nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager(); + nsresult rv = + ssm->CheckSameOriginURI(mProvidedOrigin, targetURI, true); + if (NS_FAILED(rv)) return NS_OK; - } } // Deserialize the structured clone data @@ -7839,47 +7849,15 @@ nsGlobalWindow::PostMessageMoz(JSContext* aCx, JS::Handle aMessage, } // Convert the provided origin string into a URI for comparison purposes. - nsCOMPtr providedPrincipal; - - if (aTargetOrigin.EqualsASCII("/")) { - providedPrincipal = BrokenGetEntryGlobal()->PrincipalOrNull(); - if (NS_WARN_IF(!providedPrincipal)) - return; - } - // "*" indicates no specific origin is required. - else if (!aTargetOrigin.EqualsASCII("*")) { - nsCOMPtr originURI; - if (NS_FAILED(NS_NewURI(getter_AddRefs(originURI), aTargetOrigin))) { + nsCOMPtr providedOrigin; + if (!aTargetOrigin.EqualsASCII("*")) { + if (NS_FAILED(NS_NewURI(getter_AddRefs(providedOrigin), aTargetOrigin))) { aError.Throw(NS_ERROR_DOM_SYNTAX_ERR); return; } - - if (NS_FAILED(originURI->SetUserPass(EmptyCString())) || - NS_FAILED(originURI->SetPath(EmptyCString()))) { - return; - } - - nsCOMPtr ssm = - nsContentUtils::GetSecurityManager(); - MOZ_ASSERT(ssm); - - nsCOMPtr principal = nsContentUtils::GetSubjectPrincipal(); - MOZ_ASSERT(principal); - - uint32_t appId; - if (NS_WARN_IF(NS_FAILED(principal->GetAppId(&appId)))) - return; - - bool isInBrowser; - if (NS_WARN_IF(NS_FAILED(principal->GetIsInBrowserElement(&isInBrowser)))) - return; - - // Create a nsIPrincipal inheriting the app/browser attributes from the - // caller. - nsresult rv = ssm->GetAppCodebasePrincipal(originURI, appId, isInBrowser, - getter_AddRefs(providedPrincipal)); - if (NS_WARN_IF(NS_FAILED(rv))) { + if (NS_FAILED(providedOrigin->SetUserPass(EmptyCString())) || + NS_FAILED(providedOrigin->SetPath(EmptyCString()))) { return; } } @@ -7892,7 +7870,7 @@ nsGlobalWindow::PostMessageMoz(JSContext* aCx, JS::Handle aMessage, : callerInnerWin->GetOuterWindowInternal(), origin, this, - providedPrincipal, + providedOrigin, nsContentUtils::IsCallerChrome()); // We *must* clone the data here, or the JS::Value could be modified diff --git a/dom/base/nsIGlobalObject.cpp b/dom/base/nsIGlobalObject.cpp deleted file mode 100644 index 0c0f1d92a9b..00000000000 --- a/dom/base/nsIGlobalObject.cpp +++ /dev/null @@ -1,18 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "nsIGlobalObject.h" -#include "nsContentUtils.h" - -nsIPrincipal* -nsIGlobalObject::PrincipalOrNull() -{ - JSObject *global = GetGlobalJSObject(); - if (NS_WARN_IF(!global)) - return nullptr; - - return nsContentUtils::GetObjectPrincipal(global); -} diff --git a/dom/base/nsIGlobalObject.h b/dom/base/nsIGlobalObject.h index c5b28041acc..6acb86d0c0f 100644 --- a/dom/base/nsIGlobalObject.h +++ b/dom/base/nsIGlobalObject.h @@ -13,17 +13,12 @@ { 0xe2538ded, 0x13ef, 0x4f4d, \ { 0x94, 0x6b, 0x65, 0xd3, 0x33, 0xb4, 0xf0, 0x3c } } -class nsIPrincipal; - class nsIGlobalObject : public nsISupports { public: NS_DECLARE_STATIC_IID_ACCESSOR(NS_IGLOBALOBJECT_IID) virtual JSObject* GetGlobalJSObject() = 0; - - // This method is not meant to be overridden. - nsIPrincipal* PrincipalOrNull(); }; NS_DEFINE_STATIC_IID_ACCESSOR(nsIGlobalObject, diff --git a/dom/base/test/iframe_postMessage_solidus.html b/dom/base/test/iframe_postMessage_solidus.html deleted file mode 100644 index b5cf33b4027..00000000000 --- a/dom/base/test/iframe_postMessage_solidus.html +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - diff --git a/dom/base/test/mochitest.ini b/dom/base/test/mochitest.ini index 61a915c49f9..ab46010005f 100644 --- a/dom/base/test/mochitest.ini +++ b/dom/base/test/mochitest.ini @@ -4,7 +4,6 @@ support-files = iframe_messageChannel_pingpong.html iframe_messageChannel_post.html file_empty.html - iframe_postMessage_solidus.html [test_Image_constructor.html] [test_appname_override.html] @@ -46,5 +45,4 @@ support-files = [test_openDialogChromeOnly.html] [test_messagemanager_targetchain.html] [test_url_empty_port.html] -[test_postMessage_solidus.html] [test_urlSearchParams.html] diff --git a/dom/base/test/test_postMessage_solidus.html b/dom/base/test/test_postMessage_solidus.html deleted file mode 100644 index ab3e4ecec46..00000000000 --- a/dom/base/test/test_postMessage_solidus.html +++ /dev/null @@ -1,93 +0,0 @@ - - - - - - - Test for Bug 949488 - basic support - - - - - Mozilla Bug 949488 -
- - - diff --git a/dom/tests/mochitest/localstorage/test_clear_browser_data.html b/dom/tests/mochitest/localstorage/test_clear_browser_data.html index 3444b0dc8d2..26a48a06872 100644 --- a/dom/tests/mochitest/localstorage/test_clear_browser_data.html +++ b/dom/tests/mochitest/localstorage/test_clear_browser_data.html @@ -191,7 +191,7 @@ function browserLoadEvent() { setupStorage(gBrowserStorage.localStorage); setupStorage(gBrowserStorage.sessionStorage); - frames[1].postMessage("clear", "*"); + frames[1].postMessage("clear", "http://www.example.com"); waitForClearBrowserData(); };