webbrowser-0.5.2/.gitignore010064400007650000024000000000221340575033100141010ustar0000000000000000target Cargo.lock webbrowser-0.5.2/.travis.yml010064400007650000024000000012431340621364700142350ustar0000000000000000language: rust cache: cargo env: RUST_BACKTRACE=1 script: - cargo update - cargo test --all --locked --verbose - cargo doc --verbose - rustup component add clippy rustfmt - cargo clippy --all-targets -- -D warnings - cargo fmt --all -- --check matrix: fast_finish: true allow_failures: - rust: nightly include: - rust: stable os: linux - rust: beta os: linux - rust: nightly os: linux - rust: stable os: osx branches: only: - master deploy: provider: pages local-dir: target/doc skip-cleanup: true github-token: $GITHUB_TOKEN on: branch: master os: linux condition: $TRAVIS_RUST_VERSION = stable webbrowser-0.5.2/Cargo.toml.orig010064400007650000024000000011011352746640300150100ustar0000000000000000[package] name = "webbrowser" description = "Open URLs in web browsers available on a platform" version = "0.5.2" authors = ["Amod Malviya @amodm"] documentation = "http://code.rootnet.in/webbrowser-rs/webbrowser" homepage = "https://github.com/amodm/webbrowser-rs" repository = "https://github.com/amodm/webbrowser-rs" readme = "README.md" keywords = ["webbrowser", "browser"] license = "MIT OR Apache-2.0" edition = "2015" [target.'cfg(windows)'.dependencies] winapi = { version = "0.3.6", features = ["combaseapi", "objbase", "shellapi", "winerror"] } widestring = "0.4.0" webbrowser-0.5.2/Cargo.toml0000644000000021630000000000000112600ustar00# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g. crates.io) dependencies # # If you believe there's an error in this file please file an # issue against the rust-lang/cargo repository. If you're # editing this file be aware that the upstream Cargo.toml # will likely look very different (and much more reasonable) [package] edition = "2015" name = "webbrowser" version = "0.5.2" authors = ["Amod Malviya @amodm"] description = "Open URLs in web browsers available on a platform" homepage = "https://github.com/amodm/webbrowser-rs" documentation = "http://code.rootnet.in/webbrowser-rs/webbrowser" readme = "README.md" keywords = ["webbrowser", "browser"] license = "MIT OR Apache-2.0" repository = "https://github.com/amodm/webbrowser-rs" [target."cfg(windows)".dependencies.widestring] version = "0.4.0" [target."cfg(windows)".dependencies.winapi] version = "0.3.6" features = ["combaseapi", "objbase", "shellapi", "winerror"] webbrowser-0.5.2/CHANGELOG.md010064400007650000024000000061001352746705400137410ustar0000000000000000# Changelog The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## [Unreleased] ## [0.5.2] - 2019-08-22 ### Fixed - Fix a COM leak bug on Windows [PR #15](https://github.com/amodm/webbrowser-rs/pull/15) ## [0.5.1] - 2019-04-01 ### Fixed - Fix the behaviour that open() was blocking on Linux and BSD family. [Issue #13](https://github.com/amodm/webbrowser-rs/issues/13) - Fix tests on macos ## [0.5.0] - 2019-03-31 ### Added - Add BSD family to supported platforms. [PR #12](https://github.com/amodm/webbrowser-rs/pull/12) ## [0.4.0] - 2018-12-18 ### Changed - Use `ShellExecuteW` on Windows as the earlier approach of using cmd.exe was breaking on special characters. [PR #11](https://github.com/amodm/webbrowser-rs/pull/11) ### Fixed - Fixed Apache Licensing format ## [0.3.1] - 2018-06-22 ### Fixed - Fix broken examples header. [PR #7](https://github.com/amodm/webbrowser-rs/pull/7) - Fix undeclared reference to `env` that breaks Linux. [PR #8](https://github.com/amodm/webbrowser-rs/pull/8) ## [0.3.0] - 2018-06-18 ### Changed - Change the OS test to use conditional complication and raise a compile error if the target OS is unsupported. [PR #6](https://github.com/amodm/webbrowser-rs/pull/6) - Implement useful trait from StdLib for Browser such as `Display`, `Default` and `FromStr`. [PR #6](https://github.com/amodm/webbrowser-rs/pull/6) ### Fixed - Fix the command in `open_on_windows` to use `cmd.exe` instead of `start`. [PR #5](https://github.com/amodm/webbrowser-rs/pull/5) ## [0.2.2] - 2017-01-23 ### Fixed - Honour the right syntax for `$BROWSER`. Closes [#3](https://github.com/amodm/webbrowser-rs/issues/3) - Include `gvfs-open` and `gnome-open` for [#2](https://github.com/amodm/webbrowser-rs/issues/2) ## [0.2.1] - 2017-01-22 ### Changed - Honour `$BROWSER` env var on Linux, before choosing to fallback to `xdg-open`. [Issue #2](https://github.com/amodm/webbrowser-rs/issues/2) ## [0.1.3] - 2016-01-11 ### Added - Add Apache license [Issue #1](https://github.com/amodm/webbrowser-rs/issues/1) ## [0.1.2] - 2015-12-09 ### Added - Initial release. [Unreleased]: https://github.com/amodm/webbrowser-rs/compare/v0.5.2...HEAD [0.5.2]: https://github.com/amodm/webbrowser-rs/compare/v0.5.1...v0.5.2 [0.5.1]: https://github.com/amodm/webbrowser-rs/compare/v0.5.0...v0.5.1 [0.5.0]: https://github.com/amodm/webbrowser-rs/compare/v0.4.0...v0.5.0 [0.4.0]: https://github.com/amodm/webbrowser-rs/compare/v0.3.1...v0.4.0 [0.3.1]: https://github.com/amodm/webbrowser-rs/compare/v0.3.0...v0.3.1 [0.3.0]: https://github.com/amodm/webbrowser-rs/compare/v0.2.2...v0.3.0 [0.2.2]: https://github.com/amodm/webbrowser-rs/compare/v0.2.1...v0.2.2 [0.2.1]: https://github.com/amodm/webbrowser-rs/compare/v0.1.3...v0.2.1 [0.1.3]: https://github.com/amodm/webbrowser-rs/compare/v0.1.2...v0.1.3 webbrowser-0.5.2/LICENSE-APACHE010064400007650000024000000241611340575033100140470ustar0000000000000000Copyright (c) 2015 Amod Malviya Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ------------------------------------------------------------------------ Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS webbrowser-0.5.2/LICENSE-MIT010064400007650000024000000020671340575033100135600ustar0000000000000000The MIT License (MIT) Copyright (c) 2015 Amod Malviya Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. webbrowser-0.5.2/README.md010064400007650000024000000034731345034726100134110ustar0000000000000000# webbrowser [![Build Status](https://travis-ci.com/amodm/webbrowser-rs.svg?branch=master)](https://travis-ci.com/amodm/webbrowser-rs) [![Current Crates.io Version](https://img.shields.io/crates/v/webbrowser.svg)](https://crates.io/crates/webbrowser) [![Crates.io Downloads](https://img.shields.io/crates/d/webbrowser.svg)](https://crates.io/crates/webbrowser) [![License](https://img.shields.io/crates/l/webbrowser.svg)](LICENSE-MIT) Rust library to open URLs in the web browsers available on a platform Inspired by the [webbrowser](https://docs.python.org/2/library/webbrowser.html) python library ## Documentation - [API Reference](http://code.rootnet.in/webbrowser-rs/webbrowser/) - [Release Notes](CHANGELOG.md) ## Examples ```rust use webbrowser; if webbrowser::open("http://github.com").is_ok() { // ... } ``` Currently state of platform support is: * macos => default, as well as browsers listed under [Browser](enum.Browser.html) * windows => default browser only * linux/*bsd => default browser only (uses $BROWSER env var, failing back to xdg-open, gvfs-open, gnome-open, whichever works first) * android => not supported right now * ios => not supported right now Important note: * This library requires availability of browsers and a graphical environment during runtime * `cargo test` will actually open the browser locally ## License Licensed under either of * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) at your option. ### Contribution Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. webbrowser-0.5.2/src/lib.rs010064400007650000024000000253461352746635300140510ustar0000000000000000//! Open URLs in the web browsers available on a platform. //! //! Inspired by the [webbrowser](https://docs.python.org/2/library/webbrowser.html) python library. //! //! Currently state of platform support is: //! //! * macos => default, as well as browsers listed under [Browser](enum.Browser.html) //! * windows => default browser only //! * linux or *bsd => default browser only (uses $BROWSER env var, failing back to xdg-open, gvfs-open and //! gnome-open, in that order) //! * android => not supported right now //! * ios => not supported right now //! //! Important note: //! //! * This library requires availability of browsers and a graphical environment during runtime //! * `cargo test` will actually open the browser locally. //! //! # Examples //! //! ```no_run //! use webbrowser; //! //! if webbrowser::open("http://github.com").is_ok() { //! // ... //! } //! ``` #[cfg(windows)] extern crate widestring; #[cfg(windows)] extern crate winapi; use std::default::Default; use std::io::{Error, ErrorKind, Result}; use std::process::{ExitStatus, Output}; use std::str::FromStr; use std::{error, fmt}; #[cfg(windows)] use std::os::windows::process::ExitStatusExt; #[cfg(windows)] use std::ptr; #[cfg(unix)] use std::os::unix::process::ExitStatusExt; #[cfg(not(windows))] use std::process::Command; #[cfg(windows)] use widestring::U16CString; #[derive(Debug, Eq, PartialEq, Copy, Clone, Hash)] /// Browser types available pub enum Browser { ///Operating system's default browser Default, ///Mozilla Firefox Firefox, ///Microsoft's Internet Explorer InternetExplorer, ///Google Chrome Chrome, ///Opera Opera, ///Mac OS Safari Safari, } ///The Error type for parsing a string into a Browser. #[derive(Debug, Eq, PartialEq, Copy, Clone, Hash)] pub struct ParseBrowserError; impl fmt::Display for ParseBrowserError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.write_str("Invalid browser given") } } impl error::Error for ParseBrowserError { fn description(&self) -> &str { "invalid browser" } } impl Default for Browser { fn default() -> Self { Browser::Default } } impl fmt::Display for Browser { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { Browser::Default => f.write_str("Default"), Browser::Firefox => f.write_str("Firefox"), Browser::InternetExplorer => f.write_str("Internet Explorer"), Browser::Chrome => f.write_str("Chrome"), Browser::Opera => f.write_str("Opera"), Browser::Safari => f.write_str("Safari"), } } } impl FromStr for Browser { type Err = ParseBrowserError; fn from_str(s: &str) -> ::std::result::Result { match s { "firefox" => Ok(Browser::Firefox), "default" => Ok(Browser::Default), "ie" | "internet explorer" | "internetexplorer" => Ok(Browser::InternetExplorer), "chrome" => Ok(Browser::Chrome), "opera" => Ok(Browser::Opera), "safari" => Ok(Browser::Safari), _ => Err(ParseBrowserError), } } } /// Opens the URL on the default browser of this platform /// /// Returns Ok(..) so long as the browser invocation was successful. An Err(..) is returned only if /// there was an error in running the command, or if the browser was not found. /// /// Equivalent to: /// ```no_run /// # use webbrowser::{Browser, open_browser}; /// # let url = "http://example.com"; /// open_browser(Browser::Default, url); /// ``` /// /// # Examples /// ```no_run /// use webbrowser; /// /// if webbrowser::open("http://github.com").is_ok() { /// // ... /// } /// ``` pub fn open(url: &str) -> Result { open_browser(Browser::Default, url) } /// Opens the specified URL on the specific browser (if available) requested. Return semantics are /// the same as for [open](fn.open.html). /// /// # Examples /// ```no_run /// use webbrowser::{open_browser, Browser}; /// /// if open_browser(Browser::Firefox, "http://github.com").is_ok() { /// // ... /// } /// ``` pub fn open_browser(browser: Browser, url: &str) -> Result { open_browser_internal(browser, url).and_then(|status| { if let Some(code) = status.code() { if code == 0 { Ok(Output { status: ExitStatus::from_raw(0), stdout: vec![], stderr: vec![], }) } else { Err(Error::new( ErrorKind::Other, format!("return code {}", code), )) } } else { Err(Error::new(ErrorKind::Other, "interrupted by signal")) } }) } /// Deal with opening of browsers on Windows, using [`ShellExecuteW`]( /// https://docs.microsoft.com/en-us/windows/desktop/api/shellapi/nf-shellapi-shellexecutew) /// fucntion. #[cfg(target_os = "windows")] #[inline] fn open_browser_internal(browser: Browser, url: &str) -> Result { use winapi::shared::winerror::SUCCEEDED; use winapi::um::combaseapi::{CoInitializeEx, CoUninitialize}; use winapi::um::objbase::{COINIT_APARTMENTTHREADED, COINIT_DISABLE_OLE1DDE}; use winapi::um::shellapi::ShellExecuteW; use winapi::um::winuser::SW_SHOWNORMAL; match browser { Browser::Default => { static OPEN: &[u16] = &['o' as u16, 'p' as u16, 'e' as u16, 'n' as u16, 0x0000]; let url = U16CString::from_str(url).map_err(|e| Error::new(ErrorKind::InvalidInput, e))?; let code = unsafe { let coinitializeex_result = CoInitializeEx( ptr::null_mut(), COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE, ); let code = ShellExecuteW( ptr::null_mut(), OPEN.as_ptr(), url.as_ptr(), ptr::null(), ptr::null(), SW_SHOWNORMAL, ) as usize as i32; if SUCCEEDED(coinitializeex_result) { CoUninitialize(); } code }; if code > 32 { Ok(ExitStatus::from_raw(0)) } else { Err(Error::last_os_error()) } } _ => Err(Error::new( ErrorKind::NotFound, "Only the default browser is supported on this platform right now", )), } } /// Deal with opening of browsers on Mac OS X, using `open` command #[cfg(target_os = "macos")] #[inline] fn open_browser_internal(browser: Browser, url: &str) -> Result { let mut cmd = Command::new("open"); match browser { Browser::Default => cmd.arg(url).status(), _ => { let app: Option<&str> = match browser { Browser::Firefox => Some("Firefox"), Browser::Chrome => Some("Google Chrome"), Browser::Opera => Some("Opera"), Browser::Safari => Some("Safari"), _ => None, }; match app { Some(name) => cmd.arg("-a").arg(name).arg(url).status(), None => Err(Error::new( ErrorKind::NotFound, format!("Unsupported browser {:?}", browser), )), } } } } /// Deal with opening of browsers on Linux and *BSD - currently supports only the default browser /// /// The mechanism of opening the default browser is as follows: /// 1. Attempt to use $BROWSER env var if available /// 2. Attempt to open the url via xdg-open, gvfs-open, gnome-open, respectively, whichever works /// first #[cfg(any( target_os = "linux", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd" ))] #[inline] fn open_browser_internal(browser: Browser, url: &str) -> Result { match browser { Browser::Default => open_on_unix_using_browser_env(url) .or_else(|_| -> Result { Command::new("xdg-open").arg(url).status() }) .or_else(|_| -> Result { Command::new("gvfs-open").arg(url).status() }) .or_else(|_| -> Result { Command::new("gnome-open").arg(url).status() }), _ => Err(Error::new( ErrorKind::NotFound, "Only the default browser is supported on this platform right now", )), } } #[cfg(any( target_os = "linux", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd" ))] fn open_on_unix_using_browser_env(url: &str) -> Result { let browsers = ::std::env::var("BROWSER") .map_err(|_| -> Error { Error::new(ErrorKind::NotFound, "BROWSER env not set") })?; for browser in browsers.split(':') { // $BROWSER can contain ':' delimited options, each representing a potential browser command line if !browser.is_empty() { // each browser command can have %s to represent URL, while %c needs to be replaced // with ':' and %% with '%' let cmdline = browser .replace("%s", url) .replace("%c", ":") .replace("%%", "%"); let cmdarr: Vec<&str> = cmdline.split_whitespace().collect(); let mut cmd = Command::new(&cmdarr[0]); if cmdarr.len() > 1 { cmd.args(&cmdarr[1..cmdarr.len()]); } if !browser.contains("%s") { // append the url as an argument only if it was not already set via %s cmd.arg(url); } if let Ok(status) = cmd.status() { return Ok(status); } } } Err(Error::new( ErrorKind::NotFound, "No valid command in $BROWSER", )) } #[cfg(not(any( target_os = "windows", target_os = "macos", target_os = "linux", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd" )))] compile_error!("Only Windows, Mac OS, Linux and *BSD are currently supported"); #[test] fn test_open_default() { assert!(open("http://github.com").is_ok()); assert!(open("http://github.com?dummy_query1=0&dummy_query2=nonascii").is_ok()); } #[test] #[ignore] fn test_open_firefox() { assert!(open_browser(Browser::Firefox, "http://github.com").is_ok()); } #[test] #[ignore] fn test_open_chrome() { assert!(open_browser(Browser::Chrome, "http://github.com").is_ok()); } #[test] #[ignore] #[cfg(target_os = "windows")] fn test_open_internet_explorer() { assert!(open_browser(Browser::InternetExplorer, "http://github.com").is_ok()); } #[test] #[ignore] fn test_open_safari() { assert!(open_browser(Browser::Safari, "http://github.com").is_ok()); } webbrowser-0.5.2/.cargo_vcs_info.json0000644000000001120000000000000132520ustar00{ "git": { "sha1": "13b3bec7489b93c5bbee53b064c40472f53a42fd" } }