2018-06-04 10:19:50 +02:00
|
|
|
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
|
2016-04-07 12:10:26 +02:00
|
|
|
// This file is part of Parity.
|
|
|
|
|
|
|
|
// Parity is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// Parity is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2017-01-06 16:05:58 +01:00
|
|
|
use std::path::PathBuf;
|
2016-12-27 11:15:02 +01:00
|
|
|
use std::sync::Arc;
|
2017-05-24 12:24:07 +02:00
|
|
|
|
2016-05-13 18:40:20 +02:00
|
|
|
use endpoint::{Endpoints, Endpoint};
|
2017-10-05 12:35:01 +02:00
|
|
|
use futures_cpupool::CpuPool;
|
|
|
|
use page;
|
2016-05-12 14:45:09 +02:00
|
|
|
use proxypac::ProxyPac;
|
2016-12-22 18:26:39 +01:00
|
|
|
use web::Web;
|
|
|
|
use fetch::Fetch;
|
2017-07-11 13:45:23 +02:00
|
|
|
use {WebProxyTokens, ParentFrameSettings};
|
2016-04-07 12:10:26 +02:00
|
|
|
|
2017-05-24 12:24:07 +02:00
|
|
|
mod app;
|
2016-08-30 14:04:52 +02:00
|
|
|
mod cache;
|
2017-05-24 12:24:07 +02:00
|
|
|
mod ui;
|
2017-08-09 19:06:40 +02:00
|
|
|
pub mod fs;
|
2016-08-18 12:19:09 +02:00
|
|
|
pub mod fetcher;
|
|
|
|
pub mod manifest;
|
2016-06-03 11:51:11 +02:00
|
|
|
|
2017-05-24 12:24:07 +02:00
|
|
|
pub use self::app::App;
|
2016-05-21 15:27:55 +02:00
|
|
|
|
2017-05-24 12:24:07 +02:00
|
|
|
pub const HOME_PAGE: &'static str = "home";
|
2016-12-22 18:26:39 +01:00
|
|
|
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";
|
2017-01-16 10:49:27 +01:00
|
|
|
pub const URL_REFERER: &'static str = "__referer=";
|
2016-05-13 18:40:20 +02:00
|
|
|
|
2017-10-05 12:35:01 +02:00
|
|
|
pub fn utils(pool: CpuPool) -> Box<Endpoint> {
|
2018-04-10 16:14:15 +02:00
|
|
|
Box::new(page::builtin::Dapp::new(pool, ::parity_ui::App::default()))
|
2016-05-13 18:40:20 +02:00
|
|
|
}
|
|
|
|
|
2017-10-05 12:35:01 +02:00
|
|
|
pub fn ui(pool: CpuPool) -> Box<Endpoint> {
|
2018-04-10 16:14:15 +02:00
|
|
|
Box::new(page::builtin::Dapp::with_fallback_to_index(pool, ::parity_ui::App::default()))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn ui_deprecation(pool: CpuPool) -> Box<Endpoint> {
|
|
|
|
Box::new(page::builtin::Dapp::with_fallback_to_index(pool, ::parity_ui_deprecation::App::default()))
|
2017-05-24 12:24:07 +02:00
|
|
|
}
|
|
|
|
|
2017-07-11 13:45:23 +02:00
|
|
|
pub fn ui_redirection(embeddable: Option<ParentFrameSettings>) -> Box<Endpoint> {
|
|
|
|
Box::new(ui::Redirection::new(embeddable))
|
2017-05-24 12:24:07 +02:00
|
|
|
}
|
|
|
|
|
2016-12-27 11:15:02 +01:00
|
|
|
pub fn all_endpoints<F: Fetch>(
|
2017-01-06 16:05:58 +01:00
|
|
|
dapps_path: PathBuf,
|
|
|
|
extra_dapps: Vec<PathBuf>,
|
2017-07-11 13:45:23 +02:00
|
|
|
dapps_domain: &str,
|
|
|
|
embeddable: Option<ParentFrameSettings>,
|
2016-12-27 11:15:02 +01:00
|
|
|
web_proxy_tokens: Arc<WebProxyTokens>,
|
|
|
|
fetch: F,
|
2017-10-05 12:35:01 +02:00
|
|
|
pool: CpuPool,
|
2017-08-09 19:06:40 +02:00
|
|
|
) -> (Vec<String>, Endpoints) {
|
2016-06-03 11:51:11 +02:00
|
|
|
// fetch fs dapps at first to avoid overwriting builtins
|
2017-10-05 12:35:01 +02:00
|
|
|
let mut pages = fs::local_endpoints(dapps_path.clone(), embeddable.clone(), pool.clone());
|
2017-08-09 19:06:40 +02:00
|
|
|
let local_endpoints: Vec<String> = pages.keys().cloned().collect();
|
2017-01-06 16:05:58 +01:00
|
|
|
for path in extra_dapps {
|
2017-10-05 12:35:01 +02:00
|
|
|
if let Some((id, endpoint)) = fs::local_endpoint(path.clone(), embeddable.clone(), pool.clone()) {
|
2017-01-06 16:05:58 +01:00
|
|
|
pages.insert(id, endpoint);
|
|
|
|
} else {
|
|
|
|
warn!(target: "dapps", "Ignoring invalid dapp at {}", path.display());
|
|
|
|
}
|
|
|
|
}
|
2016-10-19 11:02:21 +02:00
|
|
|
|
2016-10-17 11:56:42 +02:00
|
|
|
// NOTE [ToDr] Dapps will be currently embeded on 8180
|
2018-04-03 12:43:34 +02:00
|
|
|
pages.insert(
|
|
|
|
"ui".into(),
|
2018-04-10 16:14:15 +02:00
|
|
|
Box::new(page::builtin::Dapp::new_safe_to_embed(pool.clone(), ::parity_ui::App::default(), embeddable.clone()))
|
2018-04-03 12:43:34 +02:00
|
|
|
);
|
2017-09-05 11:21:18 +02:00
|
|
|
// old version
|
2018-04-03 12:43:34 +02:00
|
|
|
pages.insert(
|
|
|
|
"v1".into(),
|
|
|
|
Box::new({
|
2018-04-10 16:14:15 +02:00
|
|
|
let mut page = page::builtin::Dapp::new_safe_to_embed(pool.clone(), ::parity_ui::old::App::default(), embeddable.clone());
|
2018-04-03 12:43:34 +02:00
|
|
|
// allow JS eval on old Wallet
|
|
|
|
page.allow_js_eval();
|
|
|
|
page
|
|
|
|
})
|
|
|
|
);
|
|
|
|
pages.insert(
|
|
|
|
"proxy".into(),
|
|
|
|
ProxyPac::boxed(embeddable.clone(), dapps_domain.to_owned())
|
|
|
|
);
|
|
|
|
pages.insert(
|
|
|
|
WEB_PATH.into(),
|
|
|
|
Web::boxed(embeddable.clone(), web_proxy_tokens.clone(), fetch.clone(), pool.clone())
|
|
|
|
);
|
2016-06-03 11:51:11 +02:00
|
|
|
|
2017-08-09 19:06:40 +02:00
|
|
|
(local_endpoints, pages)
|
2016-04-07 12:10:26 +02:00
|
|
|
}
|