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
use cocoa::base::id;

#[link(name = "WebKit", kind = "framework")]
extern "C" {
    pub static WKUserContentController: id;
}

pub trait WKUserContentController: Sized {
    /// # Safety
    /// All the FFI functions are unsafe.
    unsafe fn alloc(_: Self) -> id {
        msg_send![class!(WKUserContentController), alloc]
    }

    /// # Safety
    /// All the FFI functions are unsafe.
    unsafe fn init(self) -> id;

    /// # Safety
    /// All the FFI functions are unsafe.
    ///
    /// `message_handler` should be a `WKScriptMessageHandler` and `name` an `NSString`.
    ///
    /// `make_new_handler` is provided to create `WKScriptMessageHandler`s from closures, but it's
    /// also not safe.
    unsafe fn addScriptMessageHandler(self, message_handler: id, name: id) -> id;
}

impl WKUserContentController for id {
    unsafe fn init(self) -> id {
        msg_send![self, init]
    }

    unsafe fn addScriptMessageHandler(self, message_handler: id, name: id) -> id {
        msg_send![self, addScriptMessageHandler: message_handler name: name]
    }
}

#[link(name = "WebKit", kind = "framework")]
extern "C" {
    pub static WKWebViewConfiguration: id;
}

pub trait WKWebViewConfiguration: Sized {
    /// # Safety
    /// All the FFI functions are unsafe
    unsafe fn alloc(_: Self) -> id {
        msg_send![class!(WKWebViewConfiguration), alloc]
    }
    /// # Safety
    /// All the FFI functions are unsafe
    unsafe fn init(self) -> id;

    /// # Safety
    /// All the FFI functions are unsafe.
    /// `id` should point to a `WKUserContentController`
    unsafe fn setUserContentController(self, controller: id);
}

impl WKWebViewConfiguration for id {
    unsafe fn init(self) -> id {
        msg_send![self, init]
    }

    unsafe fn setUserContentController(self, controller: id) {
        msg_send![self, setUserContentController: controller]
    }
}