titanium_common/
lib.rs

1/*
2 * Copyright (c) 2016-2017 Boucher, Antoni <bouanto@zoho.com>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy of
5 * this software and associated documentation files (the "Software"), to deal in
6 * the Software without restriction, including without limitation the rights to
7 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8 * the Software, and to permit persons to whom the Software is furnished to do so,
9 * subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in all
12 * copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 */
21
22//! Message used to communicate between the UI and the web processes.
23
24#![warn(
25    missing_docs,
26    trivial_casts,
27    trivial_numeric_casts,
28    unused_extern_crates,
29    unused_import_braces,
30    unused_qualifications,
31    unused_results,
32)]
33
34#[macro_use]
35extern crate serde_derive;
36
37// TODO: put in the home directory.
38/// The path to the unix domain socket.
39pub const PATH: &str = "/tmp/titanium";
40
41#[doc(hidden)]
42pub type ExtensionId = u64;
43#[doc(hidden)]
44pub type PageId = u64;
45
46/// Action that should be executed from the UI process.
47#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
48pub enum Action {
49    /// Show the file input.
50    FileInput,
51    /// Go in insert mode.
52    GoInInsertMode,
53    /// No action.
54    NoAction,
55}
56
57/// Message with the associated window/page id.
58#[derive(Debug, Deserialize, Serialize)]
59pub struct Message(pub PageId, pub InnerMessage);
60
61/// Message representing actions to to in the web page.
62// Switch to SimpleMsg to avoid these empty ().
63#[derive(Clone, Debug, Deserialize, Serialize)]
64pub enum InnerMessage {
65    /// Response to ActivateHint.
66    ActivateAction(Action),
67    /// Activate the selected hint according to the specified follow mode.
68    ActivateHint(String),
69    /// Click on the link in the selection.
70    ActivateSelection(),
71    /// Response to EnterHintKey.
72    ClickHintElement(),
73    /// Regex lookup next page link to click
74    ClickNextPage(),
75    /// Regex lookup prev page link to click
76    ClickPrevPage(),
77    /// Response to GetCredentials.
78    Credentials(String, String),
79    /// Add a key to the current hint text.
80    EnterHintKey(char),
81    /// Response to FocusInput.
82    EnterInsertMode(),
83    /// Focus the first text input.
84    FocusInput(),
85    /// Ask for the credentials from the login form.
86    GetCredentials(),
87    /// Ask for the scroll percentage of the web page.
88    GetScrollPercentage(),
89    /// Send the page ID to the application to connect the web extension with the right window.
90    /// Answer to GetId.
91    Id(ExtensionId, PageId),
92    /// Insert some text in the currently focused text field.
93    InsertText(String),
94    /// Hide the hints.
95    HideHints(),
96    /// Write the username and password in the login form.
97    LoadUsernamePass(String, String),
98    /// Open the given URL.
99    /// This is used when starting a new titanium process to tell the existing process to open a
100    /// new window.
101    Open(Vec<String>),
102    /// Reset the scroll element to None.
103    ResetScrollElement(),
104    /// Scroll to the bottom of the web page
105    ScrollBottom(),
106    /// Scroll vertically by the specified amount of pixels.
107    ScrollBy(i64),
108    /// Scroll horizontally by the specified amount of pixels.
109    ScrollByX(i64),
110    /// Response of GetScrollPercentage.
111    ScrollPercentage(Percentage),
112    /// Scroll to the top of the web page.
113    ScrollTop(),
114    /// Set the selected file on a file input.
115    SelectFile(String),
116    /// Show the hints over the elements.
117    ShowHints(String),
118    /// Submit the login form.
119    SubmitLoginForm(),
120}
121
122/// Either all the page is shown (hence, no percentage) or a value between 0 and 100.
123#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
124pub enum Percentage {
125    /// No percentage, since all the page is shown.
126    All,
127    /// A scroll percentage between 0 and 100.
128    Percent(i64),
129}