servo: Merge #11465 - Implement window.openURLInDefaultBrowser() (fixes #11292) (from nox:open); r=jdm

Source-Repo: https://github.com/servo/servo
Source-Revision: 3052e4f478e660a60c01dcd2368607429d423e10
This commit is contained in:
Anthony Ramine 2016-05-27 12:03:56 -05:00
parent 3ad4bfdffa
commit 6c7df3f453
9 changed files with 40 additions and 14 deletions

View File

@ -43,6 +43,7 @@ msg = {path = "../msg"}
net_traits = {path = "../net_traits"}
num-traits = "0.1.32"
offscreen_gl_context = "0.1.2"
open = "1.1.1"
phf = "0.7.13"
phf_macros = "0.7.13"
plugins = {path = "../plugins"}

View File

@ -2390,6 +2390,7 @@ Root::from_ref(&*raw)""" % {'copyUnforgeable': unforgeable, 'createObject': crea
create = CreateBindingJSObject(self.descriptor)
return CGGeneric("""\
%(createObject)s
(*raw).init_reflector(obj.ptr);
let _ac = JSAutoCompartment::new(cx, obj.ptr);
let mut proto = RootedObject::new(cx, ptr::null_mut());
@ -2397,7 +2398,6 @@ GetProtoObject(cx, obj.handle(), proto.handle_mut());
JS_SetPrototype(cx, obj.handle(), proto.handle());
%(copyUnforgeable)s
(*raw).init_reflector(obj.ptr);
Root::from_ref(&*raw)\
""" % {'copyUnforgeable': unforgeable, 'createObject': create})

View File

@ -146,24 +146,16 @@ interface BrowserElementPrivileged {
// unsigned long count,
// unsigned long modifiers);
[Throws,
Pref="dom.mozbrowser.enabled",
CheckAnyPermissions="browser"]
[Throws]
void goBack();
[Throws,
Pref="dom.mozbrowser.enabled",
CheckAnyPermissions="browser"]
[Throws]
void goForward();
[Throws,
Pref="dom.mozbrowser.enabled",
CheckAnyPermissions="browser"]
[Throws]
void reload(optional boolean hardReload = false);
[Throws,
Pref="dom.mozbrowser.enabled",
CheckAnyPermissions="browser"]
[Throws]
void stop();
//[Throws,

View File

@ -159,6 +159,8 @@ partial interface Window {
void debug(DOMString arg);
void gc();
void trap();
[Func="Window::global_is_mozbrowser", Throws]
void openURLInDefaultBrowser(DOMString href);
};
// WebDriver extensions

View File

@ -13,7 +13,7 @@ use dom::bindings::codegen::Bindings::EventHandlerBinding::OnErrorEventHandlerNo
use dom::bindings::codegen::Bindings::FunctionBinding::Function;
use dom::bindings::codegen::Bindings::WindowBinding::{ScrollBehavior, ScrollToOptions};
use dom::bindings::codegen::Bindings::WindowBinding::{self, FrameRequestCallback, WindowMethods};
use dom::bindings::error::{Error, Fallible, report_pending_exception};
use dom::bindings::error::{Error, ErrorResult, Fallible, report_pending_exception};
use dom::bindings::global::{GlobalRef, global_root_from_object};
use dom::bindings::inheritance::Castable;
use dom::bindings::js::{JS, MutNullableHeap, Root};
@ -52,6 +52,7 @@ use net_traits::image_cache_thread::{ImageCacheChan, ImageCacheThread};
use net_traits::storage_thread::StorageType;
use net_traits::{ResourceThreads, CustomResponseSender};
use num_traits::ToPrimitive;
use open;
use profile_traits::mem;
use profile_traits::time::{ProfilerCategory, TimerMetadata, TimerMetadataFrameType};
use profile_traits::time::{ProfilerChan, TimerMetadataReflowType, profile};
@ -839,6 +840,17 @@ impl WindowMethods for Window {
fn SetStatus(&self, status: DOMString) {
*self.status.borrow_mut() = status
}
// check-tidy: no specs after this line
fn OpenURLInDefaultBrowser(&self, href: DOMString) -> ErrorResult {
let url = try!(Url::parse(&href).map_err(|e| {
Error::Type(format!("Couldn't parse URL: {}", e))
}));
match open::that(url.as_str()) {
Ok(_) => Ok(()),
Err(e) => Err(Error::Type(format!("Couldn't open URL: {}", e))),
}
}
}
pub trait ScriptHelpers {

View File

@ -59,6 +59,7 @@ extern crate msg;
extern crate net_traits;
extern crate num_traits;
extern crate offscreen_gl_context;
extern crate open;
extern crate phf;
#[macro_use]
extern crate profile_traits;

View File

@ -1566,6 +1566,11 @@ dependencies = [
"x11 2.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "open"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "openssl"
version = "0.7.13"
@ -1878,6 +1883,7 @@ dependencies = [
"net_traits 0.0.1",
"num-traits 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
"offscreen_gl_context 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"open 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"phf 0.7.14 (registry+https://github.com/rust-lang/crates.io-index)",
"phf_macros 0.7.14 (registry+https://github.com/rust-lang/crates.io-index)",
"plugins 0.0.1",

View File

@ -1444,6 +1444,11 @@ dependencies = [
"x11 2.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "open"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "openssl"
version = "0.7.13"
@ -1736,6 +1741,7 @@ dependencies = [
"net_traits 0.0.1",
"num-traits 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
"offscreen_gl_context 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"open 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"phf 0.7.14 (registry+https://github.com/rust-lang/crates.io-index)",
"phf_macros 0.7.14 (registry+https://github.com/rust-lang/crates.io-index)",
"plugins 0.0.1",

View File

@ -1432,6 +1432,11 @@ dependencies = [
"x11 2.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "open"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "openssl"
version = "0.7.13"
@ -1724,6 +1729,7 @@ dependencies = [
"net_traits 0.0.1",
"num-traits 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
"offscreen_gl_context 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"open 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"phf 0.7.14 (registry+https://github.com/rust-lang/crates.io-index)",
"phf_macros 0.7.14 (registry+https://github.com/rust-lang/crates.io-index)",
"plugins 0.0.1",