1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

#[cfg(any(feature = "v2_12", feature = "dox"))]
use ConsoleMessage;
#[cfg(any(feature = "v2_8", feature = "dox"))]
use ContextMenu;
use DOMDocument;
#[cfg(any(feature = "v2_2", feature = "dox"))]
use Frame;
use URIRequest;
use URIResponse;
#[cfg(any(feature = "v2_10", feature = "dox"))]
use WebEditor;
#[cfg(any(feature = "v2_8", feature = "dox"))]
use WebHitTestResult;
use glib::GString;
use glib::object::Cast;
use glib::object::IsA;
use glib::signal::SignalHandlerId;
use glib::signal::connect_raw;
use glib::translate::*;
use glib_sys;
use std::boxed::Box as Box_;
use std::fmt;
use std::mem::transmute;
use webkit2_webextension_sys;

glib_wrapper! {
    pub struct WebPage(Object<webkit2_webextension_sys::WebKitWebPage, webkit2_webextension_sys::WebKitWebPageClass, WebPageClass>);

    match fn {
        get_type => || webkit2_webextension_sys::webkit_web_page_get_type(),
    }
}

pub const NONE_WEB_PAGE: Option<&WebPage> = None;

pub trait WebPageExt: 'static {
    fn get_dom_document(&self) -> Option<DOMDocument>;

    #[cfg(any(feature = "v2_10", feature = "dox"))]
    fn get_editor(&self) -> Option<WebEditor>;

    fn get_id(&self) -> u64;

    #[cfg(any(feature = "v2_2", feature = "dox"))]
    fn get_main_frame(&self) -> Option<Frame>;

    fn get_uri(&self) -> Option<GString>;

    #[cfg(any(feature = "v2_12", feature = "dox"))]
    fn connect_console_message_sent<F: Fn(&Self, &ConsoleMessage) + 'static>(&self, f: F) -> SignalHandlerId;

    #[cfg(any(feature = "v2_8", feature = "dox"))]
    fn connect_context_menu<F: Fn(&Self, &ContextMenu, &WebHitTestResult) -> bool + 'static>(&self, f: F) -> SignalHandlerId;

    fn connect_document_loaded<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

    //#[cfg(any(feature = "v2_16", feature = "dox"))]
    //fn connect_form_controls_associated<Unsupported or ignored types>(&self, f: F) -> SignalHandlerId;

    fn connect_send_request<F: Fn(&Self, &URIRequest, Option<&URIResponse>) -> bool + 'static>(&self, f: F) -> SignalHandlerId;

    //#[cfg(any(feature = "v2_20", feature = "dox"))]
    //fn connect_will_submit_form<Unsupported or ignored types>(&self, f: F) -> SignalHandlerId;

    fn connect_property_uri_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
}

impl<O: IsA<WebPage>> WebPageExt for O {
    fn get_dom_document(&self) -> Option<DOMDocument> {
        unsafe {
            from_glib_none(webkit2_webextension_sys::webkit_web_page_get_dom_document(self.as_ref().to_glib_none().0))
        }
    }

    #[cfg(any(feature = "v2_10", feature = "dox"))]
    fn get_editor(&self) -> Option<WebEditor> {
        unsafe {
            from_glib_none(webkit2_webextension_sys::webkit_web_page_get_editor(self.as_ref().to_glib_none().0))
        }
    }

    fn get_id(&self) -> u64 {
        unsafe {
            webkit2_webextension_sys::webkit_web_page_get_id(self.as_ref().to_glib_none().0)
        }
    }

    #[cfg(any(feature = "v2_2", feature = "dox"))]
    fn get_main_frame(&self) -> Option<Frame> {
        unsafe {
            from_glib_none(webkit2_webextension_sys::webkit_web_page_get_main_frame(self.as_ref().to_glib_none().0))
        }
    }

    fn get_uri(&self) -> Option<GString> {
        unsafe {
            from_glib_none(webkit2_webextension_sys::webkit_web_page_get_uri(self.as_ref().to_glib_none().0))
        }
    }

    #[cfg(any(feature = "v2_12", feature = "dox"))]
    fn connect_console_message_sent<F: Fn(&Self, &ConsoleMessage) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn console_message_sent_trampoline<P, F: Fn(&P, &ConsoleMessage) + 'static>(this: *mut webkit2_webextension_sys::WebKitWebPage, console_message: *mut webkit2_webextension_sys::WebKitConsoleMessage, f: glib_sys::gpointer)
            where P: IsA<WebPage>
        {
            let f: &F = &*(f as *const F);
            f(&WebPage::from_glib_borrow(this).unsafe_cast(), &from_glib_borrow(console_message))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(self.as_ptr() as *mut _, b"console-message-sent\0".as_ptr() as *const _,
                Some(transmute(console_message_sent_trampoline::<Self, F> as usize)), Box_::into_raw(f))
        }
    }

    #[cfg(any(feature = "v2_8", feature = "dox"))]
    fn connect_context_menu<F: Fn(&Self, &ContextMenu, &WebHitTestResult) -> bool + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn context_menu_trampoline<P, F: Fn(&P, &ContextMenu, &WebHitTestResult) -> bool + 'static>(this: *mut webkit2_webextension_sys::WebKitWebPage, context_menu: *mut webkit2_webextension_sys::WebKitContextMenu, hit_test_result: *mut webkit2_webextension_sys::WebKitWebHitTestResult, f: glib_sys::gpointer) -> glib_sys::gboolean
            where P: IsA<WebPage>
        {
            let f: &F = &*(f as *const F);
            f(&WebPage::from_glib_borrow(this).unsafe_cast(), &from_glib_borrow(context_menu), &from_glib_borrow(hit_test_result)).to_glib()
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(self.as_ptr() as *mut _, b"context-menu\0".as_ptr() as *const _,
                Some(transmute(context_menu_trampoline::<Self, F> as usize)), Box_::into_raw(f))
        }
    }

    fn connect_document_loaded<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn document_loaded_trampoline<P, F: Fn(&P) + 'static>(this: *mut webkit2_webextension_sys::WebKitWebPage, f: glib_sys::gpointer)
            where P: IsA<WebPage>
        {
            let f: &F = &*(f as *const F);
            f(&WebPage::from_glib_borrow(this).unsafe_cast())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(self.as_ptr() as *mut _, b"document-loaded\0".as_ptr() as *const _,
                Some(transmute(document_loaded_trampoline::<Self, F> as usize)), Box_::into_raw(f))
        }
    }

    //#[cfg(any(feature = "v2_16", feature = "dox"))]
    //fn connect_form_controls_associated<Unsupported or ignored types>(&self, f: F) -> SignalHandlerId {
    //    Empty ctype elements: *.PtrArray TypeId { ns_id: 1, id: 12 }
    //}

    fn connect_send_request<F: Fn(&Self, &URIRequest, Option<&URIResponse>) -> bool + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn send_request_trampoline<P, F: Fn(&P, &URIRequest, Option<&URIResponse>) -> bool + 'static>(this: *mut webkit2_webextension_sys::WebKitWebPage, request: *mut webkit2_webextension_sys::WebKitURIRequest, redirected_response: *mut webkit2_webextension_sys::WebKitURIResponse, f: glib_sys::gpointer) -> glib_sys::gboolean
            where P: IsA<WebPage>
        {
            let f: &F = &*(f as *const F);
            f(&WebPage::from_glib_borrow(this).unsafe_cast(), &from_glib_borrow(request), Option::<URIResponse>::from_glib_borrow(redirected_response).as_ref()).to_glib()
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(self.as_ptr() as *mut _, b"send-request\0".as_ptr() as *const _,
                Some(transmute(send_request_trampoline::<Self, F> as usize)), Box_::into_raw(f))
        }
    }

    //#[cfg(any(feature = "v2_20", feature = "dox"))]
    //fn connect_will_submit_form<Unsupported or ignored types>(&self, f: F) -> SignalHandlerId {
    //    Ignored step: WebKit2WebExtension.FormSubmissionStep
    //    Empty ctype text_field_names: *.PtrArray TypeId { ns_id: 0, id: 28 }
    //    Empty ctype text_field_values: *.PtrArray TypeId { ns_id: 0, id: 28 }
    //}

    fn connect_property_uri_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_uri_trampoline<P, F: Fn(&P) + 'static>(this: *mut webkit2_webextension_sys::WebKitWebPage, _param_spec: glib_sys::gpointer, f: glib_sys::gpointer)
            where P: IsA<WebPage>
        {
            let f: &F = &*(f as *const F);
            f(&WebPage::from_glib_borrow(this).unsafe_cast())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(self.as_ptr() as *mut _, b"notify::uri\0".as_ptr() as *const _,
                Some(transmute(notify_uri_trampoline::<Self, F> as usize)), Box_::into_raw(f))
        }
    }
}

impl fmt::Display for WebPage {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "WebPage")
    }
}