servo/ports/servoshell/desktop/protocols/servo.rs
webbeef 1b48bd18aa
Basic tab strip for the minibrowser (#33100)
This implements a simple tab system for servoshell:
- The egui part uses the built-in SelectableLabels components and
  display the full tab title on hover.
- WebView structs now hold all the state for each WebView. When we
  need "global" state, we return the focused WebView state, eg.
  for the load status since it's still global in the UI.
- New keyboard shortcut: [Cmd-or-Ctrl]+[W] to close the current tab.
- New keyboard shortcut: [Cmd-or-Ctrl]+[T] to create a new tab.
- The new tab content is loaded from the 'servo:newtab' url using a
  couple of custom protocol handlers.

Signed-off-by: webbeef <me@webbeef.org>
2024-08-27 20:17:33 +00:00

43 lines
1.3 KiB
Rust

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
//! Loads resources using a mapping from well-known shortcuts to resource: urls.
//! Recognized shorcuts:
//! - servo:newtab
use std::future::Future;
use std::pin::Pin;
use net::fetch::methods::{DoneChannel, FetchContext};
use net::protocols::ProtocolHandler;
use net_traits::request::Request;
use net_traits::response::Response;
use crate::desktop::protocols::resource::ResourceProtocolHander;
#[derive(Default)]
pub struct ServoProtocolHander {}
impl ProtocolHandler for ServoProtocolHander {
fn load(
&self,
request: &mut Request,
done_chan: &mut DoneChannel,
context: &FetchContext,
) -> Pin<Box<dyn Future<Output = Response> + Send>> {
let url = request.current_url();
match url.path() {
"newtab" => ResourceProtocolHander::response_for_path(
request,
done_chan,
context,
"/newtab.html",
),
_ => Box::pin(std::future::ready(Response::network_internal_error(
"Invalid shortcut",
))),
}
}
}