Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Beta backports (#4462)
Browse files Browse the repository at this point in the history
* Support HTML5-routed dapps (#4173)

* Fix compilation on latest nightly

* Updating precompiled
  • Loading branch information
tomusdrw authored and arkpar committed Feb 7, 2017
1 parent 8764563 commit 449e857
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 14 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dapps/src/apps/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub const RPC_PATH: &'static str = "rpc";
pub const API_PATH: &'static str = "api";
pub const UTILS_PATH: &'static str = "parity-utils";
pub const WEB_PATH: &'static str = "web";
pub const URL_REFERER: &'static str = "__referer=";

pub fn utils() -> Box<Endpoint> {
Box::new(PageEndpoint::with_prefix(parity_ui::App::default(), UTILS_PATH.to_owned()))
Expand Down
24 changes: 20 additions & 4 deletions dapps/src/router/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ pub struct Router<A: Authorization + 'static> {
impl<A: Authorization + 'static> server::Handler<HttpStream> for Router<A> {

fn on_request(&mut self, req: server::Request<HttpStream>) -> Next {

// Choose proper handler depending on path / domain
let url = handlers::extract_url(&req);
let endpoint = extract_endpoint(&url);
Expand Down Expand Up @@ -92,8 +91,7 @@ impl<A: Authorization + 'static> server::Handler<HttpStream> for Router<A> {
self.handler = match (endpoint.0, endpoint.1, referer) {
// Handle invalid web requests that we can recover from
(ref path, SpecialEndpoint::None, Some((ref referer, ref referer_url)))
if is_get_request
&& referer.app_id == apps::WEB_PATH
if referer.app_id == apps::WEB_PATH
&& self.endpoints.contains_key(apps::WEB_PATH)
&& !is_web_endpoint(path)
=>
Expand Down Expand Up @@ -225,10 +223,28 @@ fn extract_referer_endpoint(req: &server::Request<HttpStream>) -> Option<(Endpoi
let url = referer.and_then(|referer| Url::parse(&referer.0).ok());
url.and_then(|url| {
let option = Some(url);
extract_endpoint(&option).0.map(|endpoint| (endpoint, option.expect("Just wrapped; qed")))
extract_url_referer_endpoint(&option).or_else(|| {
extract_endpoint(&option).0.map(|endpoint| (endpoint, option.expect("Just wrapped; qed")))
})
})
}

fn extract_url_referer_endpoint(url: &Option<Url>) -> Option<(EndpointPath, Url)> {
let query = url.as_ref().and_then(|url| url.query.as_ref());
match (url, query) {
(&Some(ref url), Some(ref query)) if query.starts_with(apps::URL_REFERER) => {
let referer_url = format!("http://{}:{}/{}", url.host, url.port, &query[apps::URL_REFERER.len()..]);
debug!(target: "dapps", "Recovering referer from query parameter: {}", referer_url);

let referer_url = Url::parse(&referer_url).ok();
extract_endpoint(&referer_url).0.map(|endpoint| {
(endpoint, referer_url.expect("Endpoint returned only when url `is_some`").clone())
})
},
_ => None,
}
}

fn extract_endpoint(url: &Option<Url>) -> (Option<EndpointPath>, SpecialEndpoint) {
fn special_endpoint(url: &Url) -> SpecialEndpoint {
if url.path.len() <= 1 {
Expand Down
15 changes: 11 additions & 4 deletions dapps/src/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ impl<F: Fetch> Endpoint for Web<F> {

struct WebInstaller {
embeddable_on: Embeddable,
referer: String,
}

impl ContentValidator for WebInstaller {
Expand All @@ -84,7 +85,12 @@ impl ContentValidator for WebInstaller {
self.embeddable_on.clone(),
);
if is_html {
handler.set_initial_content(&format!(r#"<script src="/{}/inject.js"></script>"#, apps::UTILS_PATH));
handler.set_initial_content(&format!(
r#"<script src="/{}/inject.js"></script><script>history.replaceState({{}}, "", "/?{}{}")</script>"#,
apps::UTILS_PATH,
apps::URL_REFERER,
&self.referer,
));
}
Ok(ValidatorResponse::Streaming(handler))
}
Expand All @@ -108,7 +114,7 @@ struct WebHandler<F: Fetch> {
}

impl<F: Fetch> WebHandler<F> {
fn extract_target_url(&self, url: Option<Url>) -> Result<String, State<F>> {
fn extract_target_url(&self, url: Option<Url>) -> Result<(String, String), State<F>> {
let (path, query) = match url {
Some(url) => (url.path, url.query),
None => {
Expand Down Expand Up @@ -157,7 +163,7 @@ impl<F: Fetch> WebHandler<F> {
None => "".into(),
};

Ok(format!("{}://{}{}", protocol, path[idx + 2..].join("/"), query))
Ok((format!("{}://{}{}", protocol, path[idx + 2..].join("/"), query), path[0..].join("/")))
}
}

Expand All @@ -166,7 +172,7 @@ impl<F: Fetch> server::Handler<net::HttpStream> for WebHandler<F> {
let url = extract_url(&request);

// First extract the URL (reject invalid URLs)
let target_url = match self.extract_target_url(url) {
let (target_url, referer) = match self.extract_target_url(url) {
Ok(url) => url,
Err(error) => {
self.state = error;
Expand All @@ -180,6 +186,7 @@ impl<F: Fetch> server::Handler<net::HttpStream> for WebHandler<F> {
self.control.clone(),
WebInstaller {
embeddable_on: self.embeddable_on.clone(),
referer: referer,
},
self.embeddable_on.clone(),
self.remote.clone(),
Expand Down
2 changes: 1 addition & 1 deletion dapps/ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ rustc_version = "0.1"

[dependencies]
parity-ui-dev = { path = "../../js", optional = true }
parity-ui-precompiled = { git = "https://github.com/ethcore/js-precompiled.git", optional = true }
parity-ui-precompiled = { git = "https://github.com/ethcore/js-precompiled.git", branch = "beta", optional = true }

[features]
no-precompiled-js = ["parity-ui-dev"]
Expand Down
4 changes: 2 additions & 2 deletions ethcore/src/trace/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

//! Trace database.
use std::ops::Deref;
use std::collections::HashMap;
use std::collections::{HashMap, VecDeque};
use std::sync::Arc;
use bloomchain::{Number, Config as BloomConfig};
use bloomchain::group::{BloomGroupDatabase, BloomGroupChain, GroupPosition, BloomGroup};
Expand Down Expand Up @@ -305,7 +305,7 @@ impl<T> TraceDatabase for TraceDB<T> where T: DatabaseExtras {
}

fn trace(&self, block_number: BlockNumber, tx_position: usize, trace_position: Vec<usize>) -> Option<LocalizedTrace> {
let trace_position_deq = trace_position.into_iter().collect();
let trace_position_deq = trace_position.into_iter().collect::<VecDeque<usize>>();
self.extras.block_hash(block_number)
.and_then(|block_hash| self.transactions_traces(&block_hash)
.and_then(|traces| traces.into_iter().nth(tx_position))
Expand Down

0 comments on commit 449e857

Please sign in to comment.