зеркало из https://github.com/mozilla/gecko-dev.git
servo: Merge #7391 - Replace catch-all experimental flag with fine-grained boolean prefere… (from jdm:prefs); r=Ms2ger
…nces initialized from a JSON document. Source-Repo: https://github.com/servo/servo Source-Revision: 72125f070d7faa0f3a927cf8150fabfb382648e7
This commit is contained in:
Родитель
d9be999626
Коммит
b308b8b05e
|
@ -54,8 +54,8 @@ use style::viewport::ViewportConstraints;
|
|||
use url::Url;
|
||||
use util::cursor::Cursor;
|
||||
use util::geometry::PagePx;
|
||||
use util::opts;
|
||||
use util::task::spawn_named;
|
||||
use util::{opts, prefs};
|
||||
|
||||
/// Maintains the pipelines and navigation context and grants permission to composite.
|
||||
///
|
||||
|
@ -891,7 +891,7 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
|
|||
containing_pipeline_id: PipelineId,
|
||||
subpage_id: SubpageId,
|
||||
event: MozBrowserEvent) {
|
||||
assert!(opts::experimental_enabled());
|
||||
assert!(prefs::get_pref("dom.mozbrowser.enabled", false));
|
||||
|
||||
// Find the script channel for the given parent pipeline,
|
||||
// and pass the event to that script task.
|
||||
|
@ -1373,7 +1373,7 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
|
|||
|
||||
// https://developer.mozilla.org/en-US/docs/Web/Events/mozbrowserlocationchange
|
||||
fn trigger_mozbrowserlocationchange(&self, pipeline_id: PipelineId) {
|
||||
if opts::experimental_enabled() {
|
||||
if prefs::get_pref("dom.mozbrowser.enabled", false) {
|
||||
// Work around borrow checker
|
||||
let event_info = {
|
||||
let pipeline = self.pipeline(pipeline_id);
|
||||
|
|
|
@ -31,7 +31,7 @@ use url::Url;
|
|||
use util;
|
||||
use util::geometry::{PagePx, ViewportPx};
|
||||
use util::ipc::OptionalIpcSender;
|
||||
use util::opts;
|
||||
use util::prefs;
|
||||
|
||||
/// A uniquely-identifiable pipeline of script task, layout task, and paint task.
|
||||
pub struct Pipeline {
|
||||
|
@ -269,7 +269,7 @@ impl Pipeline {
|
|||
pub fn trigger_mozbrowser_event(&self,
|
||||
subpage_id: SubpageId,
|
||||
event: MozBrowserEvent) {
|
||||
assert!(opts::experimental_enabled());
|
||||
assert!(prefs::get_pref("dom.mozbrowser.enabled", false));
|
||||
|
||||
let event = ConstellationControlMsg::MozBrowserEvent(self.id,
|
||||
subpage_id,
|
||||
|
|
|
@ -50,7 +50,7 @@ use dom::htmlcollection::{HTMLCollection, CollectionFilter};
|
|||
use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
|
||||
use dom::htmlheadelement::HTMLHeadElement;
|
||||
use dom::htmlhtmlelement::HTMLHtmlElement;
|
||||
use dom::htmliframeelement::HTMLIFrameElement;
|
||||
use dom::htmliframeelement::{self, HTMLIFrameElement};
|
||||
use dom::htmlscriptelement::HTMLScriptElement;
|
||||
use dom::keyboardevent::KeyboardEvent;
|
||||
use dom::location::Location;
|
||||
|
@ -79,7 +79,6 @@ use net_traits::CookieSource::NonHTTP;
|
|||
use net_traits::{Metadata, PendingAsyncLoad, AsyncResponseTarget};
|
||||
use script_task::Runnable;
|
||||
use script_traits::{MouseButton, UntrustedNodeAddress};
|
||||
use util::opts;
|
||||
use util::str::{DOMString, split_html_space_chars};
|
||||
|
||||
use euclid::point::Point2D;
|
||||
|
@ -856,7 +855,7 @@ impl Document {
|
|||
}
|
||||
|
||||
pub fn trigger_mozbrowser_event(&self, event: MozBrowserEvent) {
|
||||
if opts::experimental_enabled() {
|
||||
if htmliframeelement::mozbrowser_enabled() {
|
||||
let window = self.window.root();
|
||||
|
||||
if let Some((containing_pipeline_id, subpage_id)) = window.r().parent_info() {
|
||||
|
|
|
@ -30,7 +30,7 @@ use msg::constellation_msg::IFrameSandboxState::{IFrameSandboxed, IFrameUnsandbo
|
|||
use msg::constellation_msg::Msg as ConstellationMsg;
|
||||
use msg::constellation_msg::{PipelineId, SubpageId, ConstellationChan, MozBrowserEvent, NavigationDirection};
|
||||
use string_cache::Atom;
|
||||
use util::opts;
|
||||
use util::prefs;
|
||||
use util::str::DOMString;
|
||||
|
||||
use js::jsapi::{RootedValue, JSAutoRequest, JSAutoCompartment};
|
||||
|
@ -41,6 +41,10 @@ use std::cell::Cell;
|
|||
use url::{Url, UrlParser};
|
||||
use util::str::{self, LengthOrPercentageOrAuto};
|
||||
|
||||
pub fn mozbrowser_enabled() -> bool {
|
||||
prefs::get_pref("dom.mozbrowser.enabled", false)
|
||||
}
|
||||
|
||||
#[derive(HeapSizeOf)]
|
||||
enum SandboxAllowance {
|
||||
AllowNothing = 0x00,
|
||||
|
@ -117,7 +121,7 @@ impl HTMLIFrameElement {
|
|||
old_subpage_id,
|
||||
sandboxed)).unwrap();
|
||||
|
||||
if opts::experimental_enabled() {
|
||||
if mozbrowser_enabled() {
|
||||
// https://developer.mozilla.org/en-US/docs/Web/Events/mozbrowserloadstart
|
||||
self.dispatch_mozbrowser_event(MozBrowserEvent::LoadStart);
|
||||
}
|
||||
|
@ -136,7 +140,7 @@ impl HTMLIFrameElement {
|
|||
// TODO(gw): Support mozbrowser event types that have detail which is not a string.
|
||||
// See https://developer.mozilla.org/en-US/docs/Web/API/Using_the_Browser_API
|
||||
// for a list of mozbrowser events.
|
||||
assert!(opts::experimental_enabled());
|
||||
assert!(mozbrowser_enabled());
|
||||
|
||||
if self.Mozbrowser() {
|
||||
let window = window_from_node(self);
|
||||
|
@ -298,7 +302,7 @@ impl HTMLIFrameElementMethods for HTMLIFrameElement {
|
|||
|
||||
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-mozbrowser
|
||||
fn Mozbrowser(&self) -> bool {
|
||||
if opts::experimental_enabled() {
|
||||
if mozbrowser_enabled() {
|
||||
let element = ElementCast::from_ref(self);
|
||||
element.has_attribute(&Atom::from_slice("mozbrowser"))
|
||||
} else {
|
||||
|
@ -308,7 +312,7 @@ impl HTMLIFrameElementMethods for HTMLIFrameElement {
|
|||
|
||||
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-mozbrowser
|
||||
fn SetMozbrowser(&self, value: bool) -> ErrorResult {
|
||||
if opts::experimental_enabled() {
|
||||
if mozbrowser_enabled() {
|
||||
let element = ElementCast::from_ref(self);
|
||||
element.set_bool_attribute(&Atom::from_slice("mozbrowser"), value);
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ use dom::uievent::{UIEvent, UIEventTypeId};
|
|||
use dom::window::Window;
|
||||
use std::cell::Cell;
|
||||
use std::default::Default;
|
||||
use util::opts;
|
||||
use util::prefs;
|
||||
use util::str::DOMString;
|
||||
|
||||
#[dom_struct]
|
||||
|
@ -171,7 +171,7 @@ impl MouseEventMethods for MouseEvent {
|
|||
// This returns the same result as current gecko.
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/which
|
||||
fn Which(&self) -> i32 {
|
||||
if opts::experimental_enabled() {
|
||||
if prefs::get_pref("dom.mouseevent.which.enabled", false) {
|
||||
(self.button.get() + 1) as i32
|
||||
} else {
|
||||
0
|
||||
|
|
|
@ -51,7 +51,7 @@ class Longhand(object):
|
|||
self.ident = to_rust_ident(name)
|
||||
self.camel_case = to_camel_case(self.ident)
|
||||
self.style_struct = THIS_STYLE_STRUCT
|
||||
self.experimental = experimental
|
||||
self.experimental = ("layout.%s.enabled" % name) if experimental else None
|
||||
self.custom_cascade = custom_cascade
|
||||
if derived_from is None:
|
||||
self.derived_from = None
|
||||
|
@ -64,7 +64,7 @@ class Shorthand(object):
|
|||
self.ident = to_rust_ident(name)
|
||||
self.camel_case = to_camel_case(self.ident)
|
||||
self.derived_from = None
|
||||
self.experimental = experimental
|
||||
self.experimental = ("layout.%s.enabled" % name) if experimental else None
|
||||
self.sub_properties = [LONGHANDS_BY_NAME[s] for s in sub_properties]
|
||||
|
||||
class StyleStruct(object):
|
||||
|
@ -450,7 +450,9 @@ pub mod longhands {
|
|||
% for value in values[:-1]:
|
||||
"${value}" => {
|
||||
% if value in experimental_values:
|
||||
if !::util::opts::experimental_enabled() { return Err(()) }
|
||||
if !::util::prefs::get_pref("layout.${value}.enabled", false) {
|
||||
return Err(())
|
||||
}
|
||||
% endif
|
||||
Ok(computed_value::T::${to_rust_ident(value)})
|
||||
},
|
||||
|
@ -458,7 +460,9 @@ pub mod longhands {
|
|||
% for value in values[-1:]:
|
||||
"${value}" => {
|
||||
% if value in experimental_values:
|
||||
if !::util::opts::experimental_enabled() { return Err(()) }
|
||||
if !::util::prefs::get_pref("layout.${value}.enabled", false) {
|
||||
return Err(())
|
||||
}
|
||||
% endif
|
||||
Ok(computed_value::T::${to_rust_ident(value)})
|
||||
}
|
||||
|
@ -5720,7 +5724,7 @@ impl PropertyDeclaration {
|
|||
% if property.derived_from is None:
|
||||
"${property.name}" => {
|
||||
% if property.experimental:
|
||||
if !::util::opts::experimental_enabled() {
|
||||
if !::util::prefs::get_pref("${property.experimental}", false) {
|
||||
return PropertyDeclarationParseResult::ExperimentalProperty
|
||||
}
|
||||
% endif
|
||||
|
@ -5739,7 +5743,7 @@ impl PropertyDeclaration {
|
|||
% for shorthand in SHORTHANDS:
|
||||
"${shorthand.name}" => {
|
||||
% if shorthand.experimental:
|
||||
if !::util::opts::experimental_enabled() {
|
||||
if !::util::prefs::get_pref("${shorthand.experimental}", false) {
|
||||
return PropertyDeclarationParseResult::ExperimentalProperty
|
||||
}
|
||||
% endif
|
||||
|
|
|
@ -429,7 +429,7 @@ impl<'a, 'b> AtRuleParser for NestedRuleParser<'a, 'b> {
|
|||
Ok(AtRuleType::WithBlock(AtRulePrelude::FontFace))
|
||||
},
|
||||
"viewport" => {
|
||||
if ::util::opts::experimental_enabled() {
|
||||
if ::util::prefs::get_pref("layout.viewport.enabled", false) {
|
||||
Ok(AtRuleType::WithBlock(AtRulePrelude::Viewport))
|
||||
} else {
|
||||
Err(())
|
||||
|
|
|
@ -60,6 +60,7 @@ pub mod logical_geometry;
|
|||
pub mod mem;
|
||||
pub mod opts;
|
||||
pub mod persistent_list;
|
||||
pub mod prefs;
|
||||
pub mod range;
|
||||
pub mod resource_files;
|
||||
pub mod str;
|
||||
|
|
|
@ -10,6 +10,7 @@ use geometry::ScreenPx;
|
|||
use euclid::size::{Size2D, TypedSize2D};
|
||||
use getopts::Options;
|
||||
use num_cpus;
|
||||
use prefs;
|
||||
use std::cmp;
|
||||
use std::default::Default;
|
||||
use std::env;
|
||||
|
@ -17,7 +18,6 @@ use std::fs::{File, PathExt};
|
|||
use std::io::{self, Read, Write};
|
||||
use std::path::Path;
|
||||
use std::process;
|
||||
use std::sync::atomic::{AtomicBool, Ordering, ATOMIC_BOOL_INIT};
|
||||
use url::{self, Url};
|
||||
|
||||
/// Global flags for Servo, currently set on the command line.
|
||||
|
@ -50,9 +50,6 @@ pub struct Opts {
|
|||
/// and cause it to produce output on that interval (`-m`).
|
||||
pub mem_profiler_period: Option<f64>,
|
||||
|
||||
/// Enable experimental web features (`-e`).
|
||||
pub enable_experimental: bool,
|
||||
|
||||
/// The number of threads to use for layout (`-y`). Defaults to 1, which results in a recursive
|
||||
/// sequential algorithm.
|
||||
pub layout_threads: usize,
|
||||
|
@ -384,7 +381,6 @@ pub fn default_opts() -> Opts {
|
|||
device_pixels_per_px: None,
|
||||
time_profiler_period: None,
|
||||
mem_profiler_period: None,
|
||||
enable_experimental: false,
|
||||
layout_threads: 1,
|
||||
nonincremental_layout: false,
|
||||
nossl: false,
|
||||
|
@ -434,7 +430,6 @@ pub fn from_cmdline_args(args: &[String]) {
|
|||
opts.optopt("o", "output", "Output file", "output.png");
|
||||
opts.optopt("s", "size", "Size of tiles", "512");
|
||||
opts.optopt("", "device-pixel-ratio", "Device pixels per px", "");
|
||||
opts.optflag("e", "experimental", "Enable experimental web features");
|
||||
opts.optopt("t", "threads", "Number of paint threads", "1");
|
||||
opts.optflagopt("p", "profile", "Profiler flag and output interval", "10");
|
||||
opts.optflagopt("m", "memory-profile", "Memory profiler flag and output interval", "10");
|
||||
|
@ -461,6 +456,8 @@ pub fn from_cmdline_args(args: &[String]) {
|
|||
opts.optflag("h", "help", "Print this message");
|
||||
opts.optopt("", "resources-path", "Path to find static resources", "/home/servo/resources");
|
||||
opts.optflag("", "sniff-mime-types" , "Enable MIME sniffing");
|
||||
opts.optmulti("", "pref",
|
||||
"A preference to set to enable", "dom.mozbrowser.enabled");
|
||||
|
||||
let opt_match = match opts.parse(args) {
|
||||
Ok(m) => m,
|
||||
|
@ -589,7 +586,6 @@ pub fn from_cmdline_args(args: &[String]) {
|
|||
device_pixels_per_px: device_pixels_per_px,
|
||||
time_profiler_period: time_profiler_period,
|
||||
mem_profiler_period: mem_profiler_period,
|
||||
enable_experimental: opt_match.opt_present("e"),
|
||||
layout_threads: layout_threads,
|
||||
nonincremental_layout: nonincremental_layout,
|
||||
nossl: nossl,
|
||||
|
@ -630,19 +626,12 @@ pub fn from_cmdline_args(args: &[String]) {
|
|||
};
|
||||
|
||||
set_defaults(opts);
|
||||
}
|
||||
|
||||
static EXPERIMENTAL_ENABLED: AtomicBool = ATOMIC_BOOL_INIT;
|
||||
|
||||
/// Turn on experimental features globally. Normally this is done
|
||||
/// during initialization by `set` or `from_cmdline_args`, but
|
||||
/// tests that require experimental features will also set it.
|
||||
pub fn set_experimental_enabled(new_value: bool) {
|
||||
EXPERIMENTAL_ENABLED.store(new_value, Ordering::SeqCst);
|
||||
}
|
||||
|
||||
pub fn experimental_enabled() -> bool {
|
||||
EXPERIMENTAL_ENABLED.load(Ordering::SeqCst)
|
||||
// This must happen after setting the default options, since the prefs rely on
|
||||
// on the resource path.
|
||||
for pref in opt_match.opt_strs("pref").iter() {
|
||||
prefs::set_pref(pref, true);
|
||||
}
|
||||
}
|
||||
|
||||
// Make Opts available globally. This saves having to clone and pass
|
||||
|
@ -653,7 +642,7 @@ const INVALID_OPTIONS: *mut Opts = 0x01 as *mut Opts;
|
|||
|
||||
lazy_static! {
|
||||
static ref OPTIONS: Opts = {
|
||||
let opts = unsafe {
|
||||
unsafe {
|
||||
let initial = if !DEFAULT_OPTIONS.is_null() {
|
||||
let opts = Box::from_raw(DEFAULT_OPTIONS);
|
||||
*opts
|
||||
|
@ -662,9 +651,7 @@ lazy_static! {
|
|||
};
|
||||
DEFAULT_OPTIONS = INVALID_OPTIONS;
|
||||
initial
|
||||
};
|
||||
set_experimental_enabled(opts.enable_experimental);
|
||||
opts
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
/* 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 resource_files::resources_dir_path;
|
||||
use rustc_serialize::json::Json;
|
||||
use std::collections::HashMap;
|
||||
use std::fs::File;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
lazy_static! {
|
||||
static ref PREFS: Arc<Mutex<HashMap<String, bool>>> = {
|
||||
let prefs = read_prefs().unwrap_or(HashMap::new());
|
||||
Arc::new(Mutex::new(prefs))
|
||||
};
|
||||
}
|
||||
|
||||
fn read_prefs() -> Result<HashMap<String, bool>, ()> {
|
||||
let mut path = resources_dir_path();
|
||||
path.push("prefs.json");
|
||||
|
||||
let mut file = try!(File::open(path).or_else(|e| {
|
||||
println!("Error opening preferences: {:?}.", e);
|
||||
Err(())
|
||||
}));
|
||||
let json = try!(Json::from_reader(&mut file).or_else(|e| {
|
||||
println!("Ignoring invalid JSON in preferences: {:?}.", e);
|
||||
Err(())
|
||||
}));
|
||||
|
||||
let mut prefs = HashMap::new();
|
||||
if let Some(obj) = json.as_object() {
|
||||
for (name, value) in obj.iter() {
|
||||
if let Some(bool_value) = value.as_boolean() {
|
||||
prefs.insert(name.clone(), bool_value);
|
||||
} else {
|
||||
println!("Ignoring non-boolean preference value for {:?}", name);
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(prefs)
|
||||
}
|
||||
|
||||
pub fn get_pref(name: &str, default: bool) -> bool {
|
||||
*PREFS.lock().unwrap().get(name).unwrap_or(&default)
|
||||
}
|
||||
|
||||
pub fn set_pref(name: &str, value: bool) {
|
||||
let _ = PREFS.lock().unwrap().insert(name.to_owned(), value);
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"dom.mouseevent.which.enabled": false,
|
||||
"dom.mozbrowser.enabled": false,
|
||||
"layout.columns.enabled": false,
|
||||
"layout.column-width.enabled": false,
|
||||
"layout.column-count.enabled": false,
|
||||
"layout.column-gap.enabled": false,
|
||||
"layout.flex.enabled": false,
|
||||
"layout.flex-direction.enabled": false,
|
||||
"layout.text-orientation.enabled": false,
|
||||
"layout.viewport.enabled": false,
|
||||
"layout.writing-mode.enabled": false
|
||||
}
|
|
@ -140,7 +140,7 @@ struct Reftest {
|
|||
servo_args: Vec<String>,
|
||||
render_mode: RenderMode,
|
||||
is_flaky: bool,
|
||||
experimental: bool,
|
||||
prefs: Vec<String>,
|
||||
fragment_identifier: Option<String>,
|
||||
resolution: Option<String>,
|
||||
}
|
||||
|
@ -198,7 +198,7 @@ fn parse_lists(file: &Path, servo_args: &[String], render_mode: RenderMode, id_o
|
|||
|
||||
let conditions_list = test_line.conditions.split(',');
|
||||
let mut flakiness = RenderMode::empty();
|
||||
let mut experimental = false;
|
||||
let mut prefs = vec![];
|
||||
let mut fragment_identifier = None;
|
||||
let mut resolution = None;
|
||||
for condition in conditions_list {
|
||||
|
@ -207,8 +207,12 @@ fn parse_lists(file: &Path, servo_args: &[String], render_mode: RenderMode, id_o
|
|||
"flaky_gpu" => flakiness.insert(GPU_RENDERING),
|
||||
"flaky_linux" => flakiness.insert(LINUX_TARGET),
|
||||
"flaky_macos" => flakiness.insert(MACOS_TARGET),
|
||||
"experimental" => experimental = true,
|
||||
_ => (),
|
||||
_ => ()
|
||||
}
|
||||
if condition.starts_with("prefs:\"") {
|
||||
if let Some(joined) = condition.split("\"").nth(1) {
|
||||
prefs.extend(joined.split(",").map(str::to_owned));
|
||||
}
|
||||
}
|
||||
if condition.starts_with("fragment=") {
|
||||
fragment_identifier = Some(condition["fragment=".len()..].to_string());
|
||||
|
@ -226,7 +230,7 @@ fn parse_lists(file: &Path, servo_args: &[String], render_mode: RenderMode, id_o
|
|||
render_mode: render_mode,
|
||||
servo_args: servo_args.to_vec(),
|
||||
is_flaky: render_mode.intersects(flakiness),
|
||||
experimental: experimental,
|
||||
prefs: prefs,
|
||||
fragment_identifier: fragment_identifier,
|
||||
resolution: resolution,
|
||||
};
|
||||
|
@ -275,8 +279,9 @@ fn capture(reftest: &Reftest, side: usize) -> (u32, u32, Vec<u8>) {
|
|||
if reftest.render_mode.contains(GPU_RENDERING) {
|
||||
command.arg("-g");
|
||||
}
|
||||
if reftest.experimental {
|
||||
command.arg("--experimental");
|
||||
for pref in &reftest.prefs {
|
||||
command.arg("--pref");
|
||||
command.arg(pref);
|
||||
}
|
||||
if let Some(ref resolution) = reftest.resolution {
|
||||
command.arg("--resolution");
|
||||
|
|
|
@ -25,7 +25,7 @@ fn test_viewport_rule<F>(css: &str,
|
|||
callback: F)
|
||||
where F: Fn(&Vec<ViewportDescriptorDeclaration>, &str)
|
||||
{
|
||||
::util::opts::set_experimental_enabled(true);
|
||||
::util::prefs::set_pref("layout.viewport.enabled", true);
|
||||
|
||||
let stylesheet = stylesheet!(css, Author);
|
||||
let mut rule_count = 0;
|
||||
|
@ -172,7 +172,7 @@ fn cascading_within_viewport_rule() {
|
|||
|
||||
#[test]
|
||||
fn multiple_stylesheets_cascading() {
|
||||
::util::opts::set_experimental_enabled(true);
|
||||
::util::prefs::set_pref("layout.viewport.enabled", true);
|
||||
let device = Device::new(MediaType::Screen, Size2D::typed(800., 600.));
|
||||
|
||||
let stylesheets = vec![
|
||||
|
|
Загрузка…
Ссылка в новой задаче