2013-07-03 20:42:47 +04:00
|
|
|
/* 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 http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2014-11-05 04:12:32 +03:00
|
|
|
//! The high-level interface from script to constellation. Using this abstract interface helps
|
|
|
|
//! reduce coupling between these two components.
|
2013-07-03 20:42:47 +04:00
|
|
|
|
2015-06-19 05:50:22 +03:00
|
|
|
use euclid::scale_factor::ScaleFactor;
|
2015-12-11 20:22:47 +03:00
|
|
|
use euclid::size::TypedSize2D;
|
2014-12-05 14:16:11 +03:00
|
|
|
use hyper::header::Headers;
|
2015-01-04 22:39:47 +03:00
|
|
|
use hyper::method::Method;
|
2015-11-20 01:29:48 +03:00
|
|
|
use ipc_channel::ipc::{self, IpcReceiver, IpcSender, IpcSharedMemory};
|
2014-09-02 23:14:37 +04:00
|
|
|
use layers::geometry::DevicePixel;
|
2015-11-20 01:29:48 +03:00
|
|
|
use serde::{Deserialize, Serialize};
|
2015-10-06 10:08:32 +03:00
|
|
|
use std::cell::Cell;
|
|
|
|
use std::fmt;
|
2015-11-20 01:29:48 +03:00
|
|
|
use std::sync::mpsc::channel;
|
2014-04-05 02:52:50 +04:00
|
|
|
use url::Url;
|
2015-08-20 16:43:56 +03:00
|
|
|
use util::geometry::{PagePx, ViewportPx};
|
|
|
|
use util::mem::HeapSizeOf;
|
2015-09-24 00:02:56 +03:00
|
|
|
use webdriver_msg::{LoadStatus, WebDriverScriptCommand};
|
2013-07-03 20:42:47 +04:00
|
|
|
|
2015-11-20 01:29:48 +03:00
|
|
|
#[derive(Deserialize, Serialize)]
|
|
|
|
pub struct ConstellationChan<T: Deserialize + Serialize>(pub IpcSender<T>);
|
2013-11-07 03:02:18 +04:00
|
|
|
|
2015-11-20 01:29:48 +03:00
|
|
|
impl<T: Deserialize + Serialize> ConstellationChan<T> {
|
|
|
|
pub fn new() -> (IpcReceiver<T>, ConstellationChan<T>) {
|
|
|
|
let (chan, port) = ipc::channel().unwrap();
|
2014-01-13 07:16:21 +04:00
|
|
|
(port, ConstellationChan(chan))
|
2013-07-03 20:42:47 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-20 01:29:48 +03:00
|
|
|
impl<T: Serialize + Deserialize> Clone for ConstellationChan<T> {
|
2015-11-19 02:09:20 +03:00
|
|
|
fn clone(&self) -> ConstellationChan<T> {
|
|
|
|
ConstellationChan(self.0.clone())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-18 16:43:24 +03:00
|
|
|
#[derive(PartialEq, Eq, Copy, Clone, Debug, Deserialize, Serialize)]
|
2013-09-11 23:22:59 +04:00
|
|
|
pub enum IFrameSandboxState {
|
|
|
|
IFrameSandboxed,
|
|
|
|
IFrameUnsandboxed
|
|
|
|
}
|
|
|
|
|
2014-02-14 03:08:07 +04:00
|
|
|
// We pass this info to various tasks, so it lives in a separate, cloneable struct.
|
2015-07-18 16:43:24 +03:00
|
|
|
#[derive(Clone, Copy, Deserialize, Serialize)]
|
2014-02-14 03:08:07 +04:00
|
|
|
pub struct Failure {
|
2014-04-28 02:52:39 +04:00
|
|
|
pub pipeline_id: PipelineId,
|
2015-03-17 02:54:50 +03:00
|
|
|
pub parent_info: Option<(PipelineId, SubpageId)>,
|
2014-02-14 03:08:07 +04:00
|
|
|
}
|
|
|
|
|
2015-08-04 06:24:41 +03:00
|
|
|
#[derive(Copy, Clone, Deserialize, Serialize, HeapSizeOf)]
|
2014-06-21 17:06:26 +04:00
|
|
|
pub struct WindowSizeData {
|
|
|
|
/// The size of the initial layout viewport, before parsing an
|
|
|
|
/// http://www.w3.org/TR/css-device-adapt/#initial-viewport
|
|
|
|
pub initial_viewport: TypedSize2D<ViewportPx, f32>,
|
|
|
|
|
|
|
|
/// The "viewing area" in page px. See `PagePx` documentation for details.
|
|
|
|
pub visible_viewport: TypedSize2D<PagePx, f32>,
|
|
|
|
|
|
|
|
/// The resolution of the window in dppx, not including any "pinch zoom" factor.
|
|
|
|
pub device_pixel_ratio: ScaleFactor<ViewportPx, DevicePixel, f32>,
|
|
|
|
}
|
|
|
|
|
2015-11-17 08:32:50 +03:00
|
|
|
#[derive(PartialEq, Eq, Copy, Clone, Debug, Deserialize, Serialize)]
|
2014-11-13 20:57:33 +03:00
|
|
|
pub enum KeyState {
|
|
|
|
Pressed,
|
|
|
|
Released,
|
|
|
|
Repeated,
|
|
|
|
}
|
|
|
|
|
2015-02-02 11:30:50 +03:00
|
|
|
//N.B. Based on the glutin key enum
|
2015-08-13 22:16:14 +03:00
|
|
|
#[derive(Debug, PartialEq, Eq, Copy, Clone, Deserialize, Serialize, HeapSizeOf)]
|
2014-11-13 20:57:33 +03:00
|
|
|
pub enum Key {
|
2014-12-18 04:45:49 +03:00
|
|
|
Space,
|
|
|
|
Apostrophe,
|
|
|
|
Comma,
|
|
|
|
Minus,
|
|
|
|
Period,
|
|
|
|
Slash,
|
|
|
|
Num0,
|
|
|
|
Num1,
|
|
|
|
Num2,
|
|
|
|
Num3,
|
|
|
|
Num4,
|
|
|
|
Num5,
|
|
|
|
Num6,
|
|
|
|
Num7,
|
|
|
|
Num8,
|
|
|
|
Num9,
|
|
|
|
Semicolon,
|
|
|
|
Equal,
|
|
|
|
A,
|
|
|
|
B,
|
|
|
|
C,
|
|
|
|
D,
|
|
|
|
E,
|
|
|
|
F,
|
|
|
|
G,
|
|
|
|
H,
|
|
|
|
I,
|
|
|
|
J,
|
|
|
|
K,
|
|
|
|
L,
|
|
|
|
M,
|
|
|
|
N,
|
|
|
|
O,
|
|
|
|
P,
|
|
|
|
Q,
|
|
|
|
R,
|
|
|
|
S,
|
|
|
|
T,
|
|
|
|
U,
|
|
|
|
V,
|
|
|
|
W,
|
|
|
|
X,
|
|
|
|
Y,
|
|
|
|
Z,
|
|
|
|
LeftBracket,
|
|
|
|
Backslash,
|
|
|
|
RightBracket,
|
|
|
|
GraveAccent,
|
|
|
|
World1,
|
|
|
|
World2,
|
2014-11-13 20:57:33 +03:00
|
|
|
|
2014-12-18 04:45:49 +03:00
|
|
|
Escape,
|
|
|
|
Enter,
|
|
|
|
Tab,
|
|
|
|
Backspace,
|
|
|
|
Insert,
|
|
|
|
Delete,
|
|
|
|
Right,
|
|
|
|
Left,
|
|
|
|
Down,
|
|
|
|
Up,
|
|
|
|
PageUp,
|
|
|
|
PageDown,
|
|
|
|
Home,
|
|
|
|
End,
|
|
|
|
CapsLock,
|
|
|
|
ScrollLock,
|
|
|
|
NumLock,
|
|
|
|
PrintScreen,
|
|
|
|
Pause,
|
|
|
|
F1,
|
|
|
|
F2,
|
|
|
|
F3,
|
|
|
|
F4,
|
|
|
|
F5,
|
|
|
|
F6,
|
|
|
|
F7,
|
|
|
|
F8,
|
|
|
|
F9,
|
|
|
|
F10,
|
|
|
|
F11,
|
|
|
|
F12,
|
|
|
|
F13,
|
|
|
|
F14,
|
|
|
|
F15,
|
|
|
|
F16,
|
|
|
|
F17,
|
|
|
|
F18,
|
|
|
|
F19,
|
|
|
|
F20,
|
|
|
|
F21,
|
|
|
|
F22,
|
|
|
|
F23,
|
|
|
|
F24,
|
|
|
|
F25,
|
|
|
|
Kp0,
|
|
|
|
Kp1,
|
|
|
|
Kp2,
|
|
|
|
Kp3,
|
|
|
|
Kp4,
|
|
|
|
Kp5,
|
|
|
|
Kp6,
|
|
|
|
Kp7,
|
|
|
|
Kp8,
|
|
|
|
Kp9,
|
|
|
|
KpDecimal,
|
|
|
|
KpDivide,
|
|
|
|
KpMultiply,
|
|
|
|
KpSubtract,
|
|
|
|
KpAdd,
|
|
|
|
KpEnter,
|
|
|
|
KpEqual,
|
|
|
|
LeftShift,
|
|
|
|
LeftControl,
|
|
|
|
LeftAlt,
|
|
|
|
LeftSuper,
|
|
|
|
RightShift,
|
|
|
|
RightControl,
|
|
|
|
RightAlt,
|
|
|
|
RightSuper,
|
|
|
|
Menu,
|
2014-11-13 20:57:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bitflags! {
|
2015-07-14 17:46:07 +03:00
|
|
|
#[derive(Deserialize, Serialize)]
|
2014-11-13 20:57:33 +03:00
|
|
|
flags KeyModifiers: u8 {
|
2015-06-29 20:44:03 +03:00
|
|
|
const NONE = 0x00,
|
2014-11-13 20:57:33 +03:00
|
|
|
const SHIFT = 0x01,
|
|
|
|
const CONTROL = 0x02,
|
|
|
|
const ALT = 0x04,
|
|
|
|
const SUPER = 0x08,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-06 10:08:32 +03:00
|
|
|
/// Specifies the information required to load a URL in an iframe.
|
|
|
|
#[derive(Deserialize, Serialize)]
|
|
|
|
pub struct IframeLoadInfo {
|
|
|
|
/// Url to load
|
2015-12-17 17:15:44 +03:00
|
|
|
pub url: Option<Url>,
|
2015-10-06 10:08:32 +03:00
|
|
|
/// Pipeline ID of the parent of this iframe
|
|
|
|
pub containing_pipeline_id: PipelineId,
|
|
|
|
/// The new subpage ID for this load
|
|
|
|
pub new_subpage_id: SubpageId,
|
|
|
|
/// The old subpage ID for this iframe, if a page was previously loaded.
|
|
|
|
pub old_subpage_id: Option<SubpageId>,
|
|
|
|
/// The new pipeline ID that the iframe has generated.
|
|
|
|
pub new_pipeline_id: PipelineId,
|
|
|
|
/// Sandbox type of this iframe
|
|
|
|
pub sandbox: IFrameSandboxState,
|
|
|
|
}
|
|
|
|
|
2015-12-04 00:24:22 +03:00
|
|
|
#[derive(Deserialize, HeapSizeOf, Serialize)]
|
|
|
|
pub enum MouseEventType {
|
|
|
|
Click,
|
|
|
|
MouseDown,
|
|
|
|
MouseUp,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// The mouse button involved in the event.
|
|
|
|
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
|
|
|
|
pub enum MouseButton {
|
|
|
|
/// The left mouse button.
|
|
|
|
Left,
|
|
|
|
/// The middle mouse button.
|
|
|
|
Middle,
|
|
|
|
/// The right mouse button.
|
|
|
|
Right,
|
|
|
|
}
|
|
|
|
|
2015-09-24 03:46:29 +03:00
|
|
|
#[derive(Clone, Eq, PartialEq, Deserialize, Serialize, Debug)]
|
2015-05-06 08:50:13 +03:00
|
|
|
pub enum AnimationState {
|
|
|
|
AnimationsPresent,
|
|
|
|
AnimationCallbacksPresent,
|
|
|
|
NoAnimationsPresent,
|
|
|
|
NoAnimationCallbacksPresent,
|
|
|
|
}
|
|
|
|
|
2015-12-17 13:49:16 +03:00
|
|
|
/// Used to determine if a script has any pending asynchronous activity.
|
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Deserialize, Serialize)]
|
|
|
|
pub enum DocumentState {
|
|
|
|
/// The document has been loaded and is idle.
|
|
|
|
Idle,
|
|
|
|
/// The document is either loading or waiting on an event.
|
|
|
|
Pending,
|
|
|
|
}
|
|
|
|
|
2015-03-26 05:00:54 +03:00
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/API/Using_the_Browser_API#Events
|
2015-07-18 16:43:24 +03:00
|
|
|
#[derive(Deserialize, Serialize)]
|
2015-03-26 05:00:54 +03:00
|
|
|
pub enum MozBrowserEvent {
|
2015-10-07 22:59:24 +03:00
|
|
|
/// Sent when the scroll position within a browser `<iframe>` changes.
|
2015-03-26 05:00:54 +03:00
|
|
|
AsyncScroll,
|
2015-10-07 22:59:24 +03:00
|
|
|
/// Sent when window.close() is called within a browser `<iframe>`.
|
2015-03-26 05:00:54 +03:00
|
|
|
Close,
|
2015-10-07 22:59:24 +03:00
|
|
|
/// Sent when a browser `<iframe>` tries to open a context menu. This allows
|
|
|
|
/// handling `<menuitem>` element available within the browser `<iframe>`'s content.
|
2015-03-26 05:00:54 +03:00
|
|
|
ContextMenu,
|
2015-10-07 22:59:24 +03:00
|
|
|
/// Sent when an error occurred while trying to load content within a browser `<iframe>`.
|
2015-03-26 05:00:54 +03:00
|
|
|
Error,
|
2015-10-07 22:59:24 +03:00
|
|
|
/// Sent when the favicon of a browser `<iframe>` changes.
|
2015-11-14 17:24:03 +03:00
|
|
|
IconChange(String, String, String),
|
2015-10-07 22:59:24 +03:00
|
|
|
/// Sent when the browser `<iframe>` has finished loading all its assets.
|
2015-03-26 05:00:54 +03:00
|
|
|
LoadEnd,
|
2015-10-07 22:59:24 +03:00
|
|
|
/// Sent when the browser `<iframe>` starts to load a new page.
|
2015-03-26 05:00:54 +03:00
|
|
|
LoadStart,
|
2015-10-07 22:59:24 +03:00
|
|
|
/// Sent when a browser `<iframe>`'s location changes.
|
2015-03-26 05:00:54 +03:00
|
|
|
LocationChange(String),
|
2015-10-07 22:59:24 +03:00
|
|
|
/// Sent when window.open() is called within a browser `<iframe>`.
|
2015-03-26 05:00:54 +03:00
|
|
|
OpenWindow,
|
2015-10-07 22:59:24 +03:00
|
|
|
/// Sent when the SSL state changes within a browser `<iframe>`.
|
2015-03-26 05:00:54 +03:00
|
|
|
SecurityChange,
|
2015-10-07 22:59:24 +03:00
|
|
|
/// Sent when alert(), confirm(), or prompt() is called within a browser `<iframe>`.
|
2015-12-20 23:58:32 +03:00
|
|
|
ShowModalPrompt(String, String, String, String), // TODO(simartin): Handle unblock()
|
2015-10-07 22:59:24 +03:00
|
|
|
/// Sent when the document.title changes within a browser `<iframe>`.
|
2015-03-26 05:00:54 +03:00
|
|
|
TitleChange(String),
|
|
|
|
/// Sent when an HTTP authentification is requested.
|
|
|
|
UsernameAndPasswordRequired,
|
|
|
|
/// Sent when a link to a search engine is found.
|
|
|
|
OpenSearch,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl MozBrowserEvent {
|
|
|
|
pub fn name(&self) -> &'static str {
|
|
|
|
match *self {
|
|
|
|
MozBrowserEvent::AsyncScroll => "mozbrowserasyncscroll",
|
|
|
|
MozBrowserEvent::Close => "mozbrowserclose",
|
|
|
|
MozBrowserEvent::ContextMenu => "mozbrowsercontextmenu",
|
|
|
|
MozBrowserEvent::Error => "mozbrowsererror",
|
2015-11-14 17:24:03 +03:00
|
|
|
MozBrowserEvent::IconChange(_, _, _) => "mozbrowsericonchange",
|
2015-03-26 05:00:54 +03:00
|
|
|
MozBrowserEvent::LoadEnd => "mozbrowserloadend",
|
|
|
|
MozBrowserEvent::LoadStart => "mozbrowserloadstart",
|
|
|
|
MozBrowserEvent::LocationChange(_) => "mozbrowserlocationchange",
|
|
|
|
MozBrowserEvent::OpenWindow => "mozbrowseropenwindow",
|
|
|
|
MozBrowserEvent::SecurityChange => "mozbrowsersecuritychange",
|
2015-12-20 23:58:32 +03:00
|
|
|
MozBrowserEvent::ShowModalPrompt(_, _, _, _) => "mozbrowsershowmodalprompt",
|
2015-03-26 05:00:54 +03:00
|
|
|
MozBrowserEvent::TitleChange(_) => "mozbrowsertitlechange",
|
|
|
|
MozBrowserEvent::UsernameAndPasswordRequired => "mozbrowserusernameandpasswordrequired",
|
|
|
|
MozBrowserEvent::OpenSearch => "mozbrowseropensearch"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-18 16:43:24 +03:00
|
|
|
#[derive(Deserialize, Serialize)]
|
2015-05-14 13:02:27 +03:00
|
|
|
pub enum WebDriverCommandMsg {
|
2015-07-18 16:43:24 +03:00
|
|
|
LoadUrl(PipelineId, LoadData, IpcSender<LoadStatus>),
|
2015-07-20 00:03:36 +03:00
|
|
|
Refresh(PipelineId, IpcSender<LoadStatus>),
|
2015-05-14 13:02:27 +03:00
|
|
|
ScriptCommand(PipelineId, WebDriverScriptCommand),
|
2015-11-17 08:32:50 +03:00
|
|
|
SendKeys(PipelineId, Vec<(Key, KeyModifiers, KeyState)>),
|
2015-10-13 00:06:31 +03:00
|
|
|
TakeScreenshot(PipelineId, IpcSender<Option<Image>>),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize, Eq, PartialEq, Serialize, HeapSizeOf)]
|
|
|
|
pub enum PixelFormat {
|
|
|
|
K8, // Luminance channel only
|
|
|
|
KA8, // Luminance + alpha
|
|
|
|
RGB8, // RGB, 8 bits per channel
|
|
|
|
RGBA8, // RGB + alpha, 8 bits per channel
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize, Serialize, HeapSizeOf)]
|
|
|
|
pub struct Image {
|
|
|
|
pub width: u32,
|
|
|
|
pub height: u32,
|
|
|
|
pub format: PixelFormat,
|
|
|
|
#[ignore_heap_size_of = "Defined in ipc-channel"]
|
|
|
|
pub bytes: IpcSharedMemory,
|
2015-05-14 13:02:27 +03:00
|
|
|
}
|
2015-03-26 05:00:54 +03:00
|
|
|
|
2014-10-10 02:00:34 +04:00
|
|
|
/// Similar to net::resource_task::LoadData
|
2015-01-04 22:39:47 +03:00
|
|
|
/// can be passed to LoadUrl to load a page with GET/POST
|
2014-10-10 02:00:34 +04:00
|
|
|
/// parameters or headers
|
2015-07-18 16:43:24 +03:00
|
|
|
#[derive(Clone, Deserialize, Serialize)]
|
2014-10-10 02:00:34 +04:00
|
|
|
pub struct LoadData {
|
|
|
|
pub url: Url,
|
|
|
|
pub method: Method,
|
2014-12-05 14:16:11 +03:00
|
|
|
pub headers: Headers,
|
2014-10-10 02:00:34 +04:00
|
|
|
pub data: Option<Vec<u8>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl LoadData {
|
|
|
|
pub fn new(url: Url) -> LoadData {
|
|
|
|
LoadData {
|
|
|
|
url: url,
|
2015-01-04 22:39:47 +03:00
|
|
|
method: Method::Get,
|
2014-12-05 14:16:11 +03:00
|
|
|
headers: Headers::new(),
|
2014-10-10 02:00:34 +04:00
|
|
|
data: None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-18 16:43:24 +03:00
|
|
|
#[derive(Clone, PartialEq, Eq, Copy, Hash, Debug, Deserialize, Serialize)]
|
2013-07-03 20:42:47 +04:00
|
|
|
pub enum NavigationDirection {
|
|
|
|
Forward,
|
|
|
|
Back,
|
|
|
|
}
|
2013-07-30 08:21:19 +04:00
|
|
|
|
2015-07-18 16:43:24 +03:00
|
|
|
#[derive(Clone, PartialEq, Eq, Copy, Hash, Debug, Deserialize, Serialize)]
|
2015-03-28 22:58:02 +03:00
|
|
|
pub struct FrameId(pub u32);
|
2015-03-17 02:54:50 +03:00
|
|
|
|
2015-10-06 10:08:32 +03:00
|
|
|
/// Each pipeline ID needs to be unique. However, it also needs to be possible to
|
|
|
|
/// generate the pipeline ID from an iframe element (this simplifies a lot of other
|
|
|
|
/// code that makes use of pipeline IDs).
|
|
|
|
///
|
|
|
|
/// To achieve this, each pipeline index belongs to a particular namespace. There is
|
|
|
|
/// a namespace for the constellation thread, and also one for every script thread.
|
|
|
|
/// This allows pipeline IDs to be generated by any of those threads without conflicting
|
|
|
|
/// with pipeline IDs created by other script threads or the constellation. The
|
|
|
|
/// constellation is the only code that is responsible for creating new *namespaces*.
|
|
|
|
/// This ensures that namespaces are always unique, even when using multi-process mode.
|
|
|
|
///
|
|
|
|
/// It may help conceptually to think of the namespace ID as an identifier for the
|
|
|
|
/// thread that created this pipeline ID - however this is really an implementation
|
|
|
|
/// detail so shouldn't be relied upon in code logic. It's best to think of the
|
|
|
|
/// pipeline ID as a simple unique identifier that doesn't convey any more information.
|
|
|
|
#[derive(Clone, Copy)]
|
|
|
|
pub struct PipelineNamespace {
|
|
|
|
id: PipelineNamespaceId,
|
|
|
|
next_index: PipelineIndex,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl PipelineNamespace {
|
|
|
|
pub fn install(namespace_id: PipelineNamespaceId) {
|
|
|
|
PIPELINE_NAMESPACE.with(|tls| {
|
|
|
|
assert!(tls.get().is_none());
|
|
|
|
tls.set(Some(PipelineNamespace {
|
|
|
|
id: namespace_id,
|
|
|
|
next_index: PipelineIndex(0),
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
fn next(&mut self) -> PipelineId {
|
|
|
|
let pipeline_id = PipelineId {
|
|
|
|
namespace_id: self.id,
|
|
|
|
index: self.next_index,
|
|
|
|
};
|
|
|
|
|
|
|
|
let PipelineIndex(current_index) = self.next_index;
|
|
|
|
self.next_index = PipelineIndex(current_index + 1);
|
|
|
|
|
|
|
|
pipeline_id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
thread_local!(pub static PIPELINE_NAMESPACE: Cell<Option<PipelineNamespace>> = Cell::new(None));
|
|
|
|
|
2015-08-04 06:24:41 +03:00
|
|
|
#[derive(Clone, PartialEq, Eq, Copy, Hash, Debug, Deserialize, Serialize, HeapSizeOf)]
|
2015-10-06 10:08:32 +03:00
|
|
|
pub struct PipelineNamespaceId(pub u32);
|
|
|
|
|
|
|
|
#[derive(Clone, PartialEq, Eq, Copy, Hash, Debug, Deserialize, Serialize, HeapSizeOf)]
|
2015-10-08 03:36:35 +03:00
|
|
|
pub struct PipelineIndex(pub u32);
|
2015-10-06 10:08:32 +03:00
|
|
|
|
|
|
|
#[derive(Clone, PartialEq, Eq, Copy, Hash, Debug, Deserialize, Serialize, HeapSizeOf)]
|
|
|
|
pub struct PipelineId {
|
2015-10-08 03:36:35 +03:00
|
|
|
pub namespace_id: PipelineNamespaceId,
|
|
|
|
pub index: PipelineIndex
|
2015-10-06 10:08:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
impl PipelineId {
|
|
|
|
pub fn new() -> PipelineId {
|
|
|
|
PIPELINE_NAMESPACE.with(|tls| {
|
|
|
|
let mut namespace = tls.get().expect("No namespace set for this thread!");
|
|
|
|
let new_pipeline_id = namespace.next();
|
|
|
|
tls.set(Some(namespace));
|
|
|
|
new_pipeline_id
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(gw): This should be removed. It's only required because of the code
|
|
|
|
// that uses it in the devtools lib.rs file (which itself is a TODO). Once
|
|
|
|
// that is fixed, this should be removed. It also relies on the first
|
|
|
|
// call to PipelineId::new() returning (0,0), which is checked with an
|
|
|
|
// assert in handle_init_load().
|
|
|
|
pub fn fake_root_pipeline_id() -> PipelineId {
|
|
|
|
PipelineId {
|
|
|
|
namespace_id: PipelineNamespaceId(0),
|
|
|
|
index: PipelineIndex(0),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for PipelineId {
|
|
|
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
let PipelineNamespaceId(namespace_id) = self.namespace_id;
|
|
|
|
let PipelineIndex(index) = self.index;
|
|
|
|
write!(fmt, "({},{})", namespace_id, index)
|
|
|
|
}
|
|
|
|
}
|
2014-01-13 07:16:21 +04:00
|
|
|
|
2015-08-04 06:24:41 +03:00
|
|
|
#[derive(Clone, PartialEq, Eq, Copy, Hash, Debug, Deserialize, Serialize, HeapSizeOf)]
|
2015-03-28 22:58:02 +03:00
|
|
|
pub struct SubpageId(pub u32);
|