diff options
author | Anthony Ramine <n.oxyde@gmail.com> | 2016-05-27 13:40:39 +0200 |
---|---|---|
committer | Anthony Ramine <n.oxyde@gmail.com> | 2016-05-27 16:16:02 +0200 |
commit | 056bdc5514473af665067e3a228b77965973bbbc (patch) | |
tree | 6ad198da15f1090eb34b161c93d02fb75564352f | |
parent | 8003687debc55c646f40d55ad0dd6a3b80ad50d8 (diff) | |
download | servo-056bdc5514473af665067e3a228b77965973bbbc.tar.gz servo-056bdc5514473af665067e3a228b77965973bbbc.zip |
Implement window.openURLInDefaultBrowser() (fixes #11292)
-rw-r--r-- | components/script/Cargo.toml | 1 | ||||
-rw-r--r-- | components/script/dom/webidls/BrowserElement.webidl | 8 | ||||
-rw-r--r-- | components/script/dom/webidls/Window.webidl | 2 | ||||
-rw-r--r-- | components/script/dom/window.rs | 14 | ||||
-rw-r--r-- | components/script/lib.rs | 1 | ||||
-rw-r--r-- | components/servo/Cargo.lock | 6 | ||||
-rw-r--r-- | ports/cef/Cargo.lock | 6 | ||||
-rw-r--r-- | ports/gonk/Cargo.lock | 6 |
8 files changed, 39 insertions, 5 deletions
diff --git a/components/script/Cargo.toml b/components/script/Cargo.toml index ee0291429cc..c44f2448a48 100644 --- a/components/script/Cargo.toml +++ b/components/script/Cargo.toml @@ -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"} diff --git a/components/script/dom/webidls/BrowserElement.webidl b/components/script/dom/webidls/BrowserElement.webidl index 2767fa15071..9bb34b90a95 100644 --- a/components/script/dom/webidls/BrowserElement.webidl +++ b/components/script/dom/webidls/BrowserElement.webidl @@ -146,16 +146,16 @@ interface BrowserElementPrivileged { // unsigned long count, // unsigned long modifiers); - [Func="Window::global_is_mozbrowser", Throws] + [Throws] void goBack(); - [Func="Window::global_is_mozbrowser", Throws] + [Throws] void goForward(); - [Func="Window::global_is_mozbrowser", Throws] + [Throws] void reload(optional boolean hardReload = false); - [Func="Window::global_is_mozbrowser", Throws] + [Throws] void stop(); //[Throws, diff --git a/components/script/dom/webidls/Window.webidl b/components/script/dom/webidls/Window.webidl index c75def477da..b263d53bb7b 100644 --- a/components/script/dom/webidls/Window.webidl +++ b/components/script/dom/webidls/Window.webidl @@ -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 diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index 38c2588749c..dbcd9063aca 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -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 { diff --git a/components/script/lib.rs b/components/script/lib.rs index e647003e860..af6d3b2a9c0 100644 --- a/components/script/lib.rs +++ b/components/script/lib.rs @@ -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; diff --git a/components/servo/Cargo.lock b/components/servo/Cargo.lock index 238d0fb03f6..1545361c85c 100644 --- a/components/servo/Cargo.lock +++ b/components/servo/Cargo.lock @@ -1566,6 +1566,11 @@ dependencies = [ ] [[package]] +name = "open" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] name = "openssl" version = "0.7.13" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1877,6 +1882,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", diff --git a/ports/cef/Cargo.lock b/ports/cef/Cargo.lock index 582374fe857..0b2dbf04d56 100644 --- a/ports/cef/Cargo.lock +++ b/ports/cef/Cargo.lock @@ -1444,6 +1444,11 @@ dependencies = [ ] [[package]] +name = "open" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] name = "openssl" version = "0.7.13" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1735,6 +1740,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", diff --git a/ports/gonk/Cargo.lock b/ports/gonk/Cargo.lock index 4978035175c..bd4ce1ff6ad 100644 --- a/ports/gonk/Cargo.lock +++ b/ports/gonk/Cargo.lock @@ -1432,6 +1432,11 @@ dependencies = [ ] [[package]] +name = "open" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] name = "openssl" version = "0.7.13" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1723,6 +1728,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", |