Implement window.openURLInDefaultBrowser() (fixes #11292)

This commit is contained in:
Anthony Ramine 2016-05-27 13:40:39 +02:00
parent 8003687deb
commit 056bdc5514
8 changed files with 39 additions and 5 deletions

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 {