Bug 1304792: Use borrowed types for ServoImportRule. r?Manishearth r?heycam
MozReview-Commit-ID: HKjsOaE2qAp
--- a/layout/style/Loader.cpp
+++ b/layout/style/Loader.cpp
@@ -1402,17 +1402,17 @@ Loader::InsertSheetInDoc(StyleSheet* aSh
* want to insert the sheet at the correct position, we'll need to
* restore CSSStyleSheet::InsertStyleSheetAt, which was removed in
* bug 1220506.)
*/
nsresult
Loader::InsertChildSheet(StyleSheet* aSheet,
StyleSheet* aParentSheet,
ImportRule* aGeckoParentRule,
- RawServoImportRule* aServoParentRule)
+ const RawServoImportRule* aServoParentRule)
{
LOG(("css::Loader::InsertChildSheet"));
MOZ_ASSERT(aSheet, "Nothing to insert");
MOZ_ASSERT(aParentSheet, "Need a parent to insert into");
MOZ_ASSERT_IF(aSheet->IsGecko(), aGeckoParentRule && !aServoParentRule);
MOZ_ASSERT_IF(aSheet->IsServo(), aServoParentRule && !aGeckoParentRule);
if (aSheet->IsGecko()) {
// child sheets should always start out enabled, even if they got
@@ -2193,17 +2193,17 @@ HaveAncestorDataWithURI(SheetLoadData *a
return false;
}
nsresult
Loader::LoadChildSheet(StyleSheet* aParentSheet,
nsIURI* aURL,
nsMediaList* aMedia,
ImportRule* aGeckoParentRule,
- RawServoImportRule* aServoParentRule,
+ const RawServoImportRule* aServoParentRule,
LoaderReusableStyleSheets* aReusableSheets)
{
LOG(("css::Loader::LoadChildSheet"));
NS_PRECONDITION(aURL, "Must have a URI to load");
NS_PRECONDITION(aParentSheet, "Must have a parent sheet");
// Servo doesn't support reusable sheets.
MOZ_ASSERT_IF(aReusableSheets, aParentSheet->IsGecko());
--- a/layout/style/Loader.h
+++ b/layout/style/Loader.h
@@ -292,17 +292,17 @@ public:
* Servo's style system.
* @param aSavedSheets any saved style sheets which could be reused
* for this load
*/
nsresult LoadChildSheet(StyleSheet* aParentSheet,
nsIURI* aURL,
nsMediaList* aMedia,
ImportRule* aGeckoParentRule,
- RawServoImportRule* aServoParentRule,
+ const RawServoImportRule* aServoParentRule,
LoaderReusableStyleSheets* aSavedSheets);
/**
* Synchronously load and return the stylesheet at aURL. Any child sheets
* will also be loaded synchronously. Note that synchronous loads over some
* protocols may involve spinning up a new event loop, so use of this method
* does NOT guarantee not receiving any events before the sheet loads. This
* method can be used to load sheets not associated with a document.
@@ -484,17 +484,17 @@ private:
nsresult InsertSheetInDoc(StyleSheet* aSheet,
nsIContent* aLinkingContent,
nsIDocument* aDocument);
nsresult InsertChildSheet(StyleSheet* aSheet,
StyleSheet* aParentSheet,
ImportRule* aGeckoParentRule,
- RawServoImportRule* aServoParentRule);
+ const RawServoImportRule* aServoParentRule);
nsresult InternalLoadNonDocumentSheet(nsIURI* aURL,
bool aIsPreload,
SheetParsingMode aParsingMode,
bool aUseSystemPrincipal,
nsIPrincipal* aOriginPrincipal,
const nsCString& aCharset,
RefPtr<StyleSheet>* aSheet,
--- a/layout/style/ServoBindings.cpp
+++ b/layout/style/ServoBindings.cpp
@@ -1021,17 +1021,17 @@ nsCSSValueBorrowedMut
Gecko_CSSValue_GetArrayItem(nsCSSValueBorrowedMut aCSSValue, int32_t aIndex)
{
return &aCSSValue->GetArrayValue()->Item(aIndex);
}
void
Gecko_LoadStyleSheet(css::Loader* aLoader,
ServoStyleSheet* aParent,
- RawServoImportRuleStrong aImportRule,
+ RawServoImportRuleBorrowed aImportRule,
const uint8_t* aURLString,
uint32_t aURLStringLength,
const uint8_t* aMediaString,
uint32_t aMediaStringLength)
{
MOZ_ASSERT(aLoader, "Should've catched this before");
MOZ_ASSERT(aParent, "Only used for @import, so parent should exist!");
MOZ_ASSERT(aURLString, "Invalid URLs shouldn't be loaded!");
@@ -1049,18 +1049,17 @@ Gecko_LoadStyleSheet(css::Loader* aLoade
nsDependentCSubstring urlSpec(reinterpret_cast<const char*>(aURLString),
aURLStringLength);
// Servo's loader guarantees that the URL is valid.
nsCOMPtr<nsIURI> uri;
MOZ_ALWAYS_SUCCEEDS(NS_NewURI(getter_AddRefs(uri), urlSpec));
- RefPtr<RawServoImportRule> import = aImportRule.Consume();
- aLoader->LoadChildSheet(aParent, uri, media, nullptr, import, nullptr);
+ aLoader->LoadChildSheet(aParent, uri, media, nullptr, aImportRule, nullptr);
}
NS_IMPL_THREADSAFE_FFI_REFCOUNTING(nsCSSValueSharedList, CSSValueSharedList);
#define STYLE_STRUCT(name, checkdata_cb) \
\
void \
Gecko_Construct_nsStyle##name(nsStyle##name* ptr) \
--- a/layout/style/ServoBindings.h
+++ b/layout/style/ServoBindings.h
@@ -92,17 +92,17 @@ RawGeckoNodeBorrowedOrNull Gecko_GetNext
RawGeckoElementBorrowedOrNull Gecko_GetParentElement(RawGeckoElementBorrowed element);
RawGeckoElementBorrowedOrNull Gecko_GetFirstChildElement(RawGeckoElementBorrowed element);
RawGeckoElementBorrowedOrNull Gecko_GetLastChildElement(RawGeckoElementBorrowed element);
RawGeckoElementBorrowedOrNull Gecko_GetPrevSiblingElement(RawGeckoElementBorrowed element);
RawGeckoElementBorrowedOrNull Gecko_GetNextSiblingElement(RawGeckoElementBorrowed element);
RawGeckoElementBorrowedOrNull Gecko_GetDocumentElement(RawGeckoDocumentBorrowed document);
void Gecko_LoadStyleSheet(mozilla::css::Loader* loader,
mozilla::ServoStyleSheet* parent,
- RawServoImportRuleStrong import_rule,
+ RawServoImportRuleBorrowed import_rule,
const uint8_t* url_bytes,
uint32_t url_length,
const uint8_t* media_bytes,
uint32_t media_length);
// 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
--- a/servo/components/style/gecko_bindings/bindings.rs
+++ b/servo/components/style/gecko_bindings/bindings.rs
@@ -323,17 +323,17 @@ extern "C" {
}
extern "C" {
pub fn Gecko_GetDocumentElement(document: RawGeckoDocumentBorrowed)
-> RawGeckoElementBorrowedOrNull;
}
extern "C" {
pub fn Gecko_LoadStyleSheet(loader: *mut Loader,
parent: *mut ServoStyleSheet,
- import_rule: RawServoImportRuleStrong,
+ import_rule: RawServoImportRuleBorrowed,
url_bytes: *const u8, url_length: u32,
media_bytes: *const u8, media_length: u32);
}
extern "C" {
pub fn Gecko_MaybeCreateStyleChildrenIterator(node: RawGeckoNodeBorrowed)
-> StyleChildrenIteratorOwnedOrNull;
}
extern "C" {
--- a/servo/components/style/gecko_bindings/sugar/ownership.rs
+++ b/servo/components/style/gecko_bindings/sugar/ownership.rs
@@ -104,16 +104,22 @@ pub unsafe trait HasArcFFI : HasFFI {
/// &GeckoType -> &Arc<ServoType>
fn as_arc<'a>(ptr: &'a &Self::FFIType) -> &'a Arc<Self> {
debug_assert!(!(ptr as *const _).is_null());
unsafe {
transmute::<&&Self::FFIType, &Arc<Self>>(ptr)
}
}
+ fn arc_as_borrowed<'a>(arc: &'a Arc<Self>) -> &'a &Self::FFIType {
+ unsafe {
+ transmute::<&Arc<Self>, &&Self::FFIType>(arc)
+ }
+ }
+
#[inline]
fn arc_from_borrowed<'a>(ptr: &'a Option<&Self::FFIType>) -> Option<&'a Arc<Self>> {
unsafe {
if let Some(ref reference) = *ptr {
Some(transmute::<&&Self::FFIType, &Arc<_>>(reference))
} else {
None
}
--- a/servo/ports/geckolib/stylesheet_loader.rs
+++ b/servo/ports/geckolib/stylesheet_loader.rs
@@ -1,17 +1,17 @@
/* 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/. */
use parking_lot::RwLock;
-use std::mem;
use std::sync::Arc;
use style::gecko_bindings::bindings::Gecko_LoadStyleSheet;
use style::gecko_bindings::structs::{Loader, ServoStyleSheet};
+use style::gecko_bindings::sugar::ownership::HasArcFFI;
use style::stylesheets::{ImportRule, StylesheetLoader as StyleStylesheetLoader};
use style_traits::ToCss;
pub struct StylesheetLoader(*mut Loader, *mut ServoStyleSheet);
impl StylesheetLoader {
pub fn new(loader: *mut Loader, parent: *mut ServoStyleSheet) -> Self {
StylesheetLoader(loader, parent)
@@ -32,16 +32,16 @@ impl StyleStylesheetLoader for Styleshee
// evaluate them on the main thread.
//
// Meanwhile, this works.
let media = import.stylesheet.media.read().to_css_string();
unsafe {
Gecko_LoadStyleSheet(self.0,
self.1,
- mem::transmute(import_rule.clone()),
+ HasArcFFI::arc_as_borrowed(import_rule),
spec_bytes,
spec_len as u32,
media.as_bytes().as_ptr(),
media.len() as u32);
}
}
}