Bug 1343964 part 2 - Move dummy url data to be a static member of URLExtraData. r=heycam
MozReview-Commit-ID: I6pc9WmrLW0
--- a/layout/build/nsLayoutStatics.cpp
+++ b/layout/build/nsLayoutStatics.cpp
@@ -127,16 +127,17 @@ using namespace mozilla::system;
#include "mozilla/IMEStateManager.h"
#include "mozilla/dom/HTMLVideoElement.h"
#include "TouchManager.h"
#include "MediaDecoder.h"
#include "MediaPrefs.h"
#include "mozilla/ServoBindings.h"
#include "mozilla/StaticPresData.h"
#include "mozilla/dom/WebIDLGlobalNameHash.h"
+#include "mozilla/URLExtraData.h"
using namespace mozilla;
using namespace mozilla::net;
using namespace mozilla::dom;
using namespace mozilla::dom::ipc;
nsrefcnt nsLayoutStatics::sLayoutStaticRefcnt = 0;
@@ -307,17 +308,18 @@ nsLayoutStatics::Initialize()
MediaDecoder::InitStatics();
PromiseDebugging::Init();
mozilla::dom::WebCryptoThreadPool::Initialize();
#ifdef MOZ_STYLO
- Servo_Initialize();
+ URLExtraData::InitDummy();
+ Servo_Initialize(URLExtraData::Dummy());
#endif
#ifndef MOZ_WIDGET_ANDROID
// On Android, we instantiate it when constructing AndroidBridge.
MediaPrefs::GetSingleton();
#endif
return NS_OK;
@@ -326,16 +328,17 @@ nsLayoutStatics::Initialize()
void
nsLayoutStatics::Shutdown()
{
// Don't need to shutdown nsWindowMemoryReporter, that will be done by the
// memory reporter manager.
#ifdef MOZ_STYLO
Servo_Shutdown();
+ URLExtraData::ReleaseDummy();
#endif
nsMessageManagerScriptExecutor::Shutdown();
nsFocusManager::Shutdown();
#ifdef MOZ_XUL
nsXULPopupManager::Shutdown();
#endif
StorageObserver::Shutdown();
--- a/layout/style/ServoBindingList.h
+++ b/layout/style/ServoBindingList.h
@@ -281,17 +281,18 @@ SERVO_BINDING_FUNC(Servo_ComputedValues_
ServoComputedValuesBorrowedOrNull parent_style_or_null,
nsIAtom* pseudoTag, bool skip_display_fixup,
RawServoStyleSetBorrowed set)
SERVO_BINDING_FUNC(Servo_ComputedValues_Inherit, ServoComputedValuesStrong,
RawServoStyleSetBorrowed set,
ServoComputedValuesBorrowedOrNull parent_style)
// Initialize Servo components. Should be called exactly once at startup.
-SERVO_BINDING_FUNC(Servo_Initialize, void)
+SERVO_BINDING_FUNC(Servo_Initialize, void,
+ RawGeckoURLExtraData* dummy_url_data)
// Shut down Servo components. Should be called exactly once at shutdown.
SERVO_BINDING_FUNC(Servo_Shutdown, void)
// Gets the snapshot for the element. This will return null if the element
// has never been styled, since snapshotting in that case is wasted work.
SERVO_BINDING_FUNC(Servo_Element_GetSnapshot, ServoElementSnapshot*,
RawGeckoElementBorrowed element)
--- a/layout/style/ServoBindings.cpp
+++ b/layout/style/ServoBindings.cpp
@@ -2,17 +2,16 @@
/* 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 "mozilla/ServoBindings.h"
#include "ChildIterator.h"
-#include "NullPrincipalURI.h"
#include "gfxFontFamilyList.h"
#include "nsAnimationManager.h"
#include "nsAttrValueInlines.h"
#include "nsCSSFrameConstructor.h"
#include "nsCSSProps.h"
#include "nsCSSParser.h"
#include "nsCSSPseudoElements.h"
#include "nsCSSRuleProcessor.h"
@@ -1622,25 +1621,16 @@ Gecko_LoadStyleSheet(css::Loader* aLoade
// silently do nothing. Eventually we should be able to assert that the
// NS_NewURI succeeds, here.
return;
}
aLoader->LoadChildSheet(aParent, uri, media, nullptr, aChildSheet, nullptr);
}
-RawGeckoURLExtraData*
-Gecko_URLExtraData_CreateDummy()
-{
- RefPtr<URLExtraData> data = new URLExtraData(NullPrincipalURI::Create(),
- nullptr,
- NullPrincipal::Create());
- return data.forget().take();
-}
-
const nsMediaFeature*
Gecko_GetMediaFeatures()
{
return nsMediaFeatures::features;
}
nsCSSFontFaceRule*
Gecko_CSSFontFaceRule_Create()
--- a/layout/style/ServoBindings.h
+++ b/layout/style/ServoBindings.h
@@ -114,20 +114,16 @@ void Gecko_LoadStyleSheet(mozilla::css::
mozilla::ServoStyleSheet* parent,
RawServoStyleSheetBorrowed child_sheet,
RawGeckoURLExtraData* base_url_data,
const uint8_t* url_bytes,
uint32_t url_length,
const uint8_t* media_bytes,
uint32_t media_length);
-// URLExtraData
-// Create a new addrefed URLExtraData.
-RawGeckoURLExtraData* Gecko_URLExtraData_CreateDummy();
-
// By default, Servo walks the DOM by traversing the siblings of the DOM-view
// first child. This generally works, but misses anonymous children, which we
// want to traverse during styling. To support these cases, we create an
// optional heap-allocated iterator for nodes that need it. If the creation
// method returns null, Servo falls back to the aforementioned simpler (and
// faster) sibling traversal.
StyleChildrenIteratorOwnedOrNull Gecko_MaybeCreateStyleChildrenIterator(RawGeckoNodeBorrowed node);
void Gecko_DropStyleChildrenIterator(StyleChildrenIteratorOwned it);
--- a/layout/style/URLExtraData.cpp
+++ b/layout/style/URLExtraData.cpp
@@ -4,19 +4,36 @@
* 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/. */
/* thread-safe container of information for resolving url values */
#include "mozilla/URLExtraData.h"
#include "nsProxyRelease.h"
+#include "NullPrincipalURI.h"
namespace mozilla {
+StaticRefPtr<URLExtraData> URLExtraData::sDummy;
+
+/* static */ void
+URLExtraData::InitDummy()
+{
+ sDummy = new URLExtraData(NullPrincipalURI::Create(),
+ nullptr,
+ NullPrincipal::Create());
+}
+
+/* static */ void
+URLExtraData::ReleaseDummy()
+{
+ sDummy = nullptr;
+}
+
URLExtraData::~URLExtraData()
{
if (!NS_IsMainThread()) {
NS_ReleaseOnMainThread(mBaseURI.forget());
NS_ReleaseOnMainThread(mReferrer.forget());
NS_ReleaseOnMainThread(mPrincipal.forget());
}
}
--- a/layout/style/URLExtraData.h
+++ b/layout/style/URLExtraData.h
@@ -5,16 +5,17 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* thread-safe container of information for resolving url values */
#ifndef mozilla_URLExtraData_h
#define mozilla_URLExtraData_h
#include "mozilla/Move.h"
+#include "mozilla/StaticPtr.h"
#include "nsCOMPtr.h"
#include "nsIPrincipal.h"
#include "nsIURI.h"
namespace mozilla {
struct URLExtraData
@@ -35,19 +36,28 @@ struct URLExtraData
do_AddRef(aPrincipal)) {}
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(URLExtraData)
nsIURI* BaseURI() const { return mBaseURI; }
nsIURI* GetReferrer() const { return mReferrer; }
nsIPrincipal* GetPrincipal() const { return mPrincipal; }
+ static URLExtraData* Dummy() {
+ MOZ_ASSERT(sDummy);
+ return sDummy;
+ }
+ static void InitDummy();
+ static void ReleaseDummy();
+
private:
~URLExtraData();
nsCOMPtr<nsIURI> mBaseURI;
nsCOMPtr<nsIURI> mReferrer;
nsCOMPtr<nsIPrincipal> mPrincipal;
+
+ static StaticRefPtr<URLExtraData> sDummy;
};
} // namespace mozilla
#endif // mozilla_URLExtraData_h