@@ -8,7 +8,7 @@ function get_associated_webview(self::ID)
88 unsafe_pointer_to_objref (Ptr {Webview} (w))
99end
1010
11- function create_app_delegate (w :: Webview )
11+ function create_app_delegate ()
1212 cls = @ccall objc_allocateClassPair (a " NSResponder" cls :: ID , " WebviewAppDelegate" :: Cstring , 0 :: Int ):: ID
1313 @ccall class_addProtocol (
1414 cls:: ID ,
@@ -19,34 +19,56 @@ function create_app_delegate(w::Webview)
1919 a " applicationShouldTerminateAfterLastWindowClosed:" sel :: SEL ,
2020 @cfunction (
2121 (self, _2, _3) -> begin
22- w = get_associated_webview (self)
23- terminate (w)
22+ _terminate ()
2423 false
2524 end ,
2625 Bool, (ID, SEL, ID)
2726 ):: Ptr{Cvoid} ,
2827 " c@:@" :: Cstring
2928 ):: Bool
30- if w. parent_window ≡ C_NULL
31- @ccall class_addMethod (
32- cls:: ID ,
33- a " applicationDidFinishLaunching:" sel :: SEL ,
34- @cfunction (
35- (self, _, notification) -> begin
36- app = @msg_send ID notification a " object" sel
37- w = get_associated_webview (self)
38- on_application_did_finish_launching (w, self, app)
39- end ,
40- Cvoid, (ID, SEL, ID)
41- ):: Ptr{Cvoid} ,
42- " v@:@" :: Cstring
43- ):: Bool
44- end
4529 @ccall objc_registerClassPair (cls:: ID ):: Ptr{Cvoid}
4630 @msg_send ID cls a " new" sel
4731end
4832
49- function create_webkit_ui_delegate ()
33+ function get_window_delegate_class ()
34+ cls = @ccall objc_getClass (" WebviewWindowDelegate" :: Cstring ):: ID
35+ cls == C_NULL || return cls
36+ cls = @ccall objc_allocateClassPair (a " NSResponder" cls :: ID , " WebviewWindowDelegate" :: Cstring , 0 :: Int ):: ID
37+ @ccall class_addProtocol (
38+ cls:: ID ,
39+ (@ccall objc_getProtocol (" NSWindowDelegate" :: Cstring ):: ID ):: ID
40+ ):: Bool
41+ @ccall class_addMethod (
42+ cls:: ID ,
43+ a " windowWillClose:" sel :: SEL ,
44+ @cfunction (
45+ (self, _2, _3) -> begin
46+ w = get_associated_webview (self)
47+ window = window_handle (w)
48+ Webviews. on_window_close (window)
49+ end ,
50+ Cvoid, (ID, SEL, ID)
51+ ):: Ptr{Cvoid} ,
52+ " v@:@" :: Cstring
53+ ):: Bool
54+ @ccall objc_registerClassPair (cls:: ID ):: Cvoid
55+ cls
56+ end
57+ function create_window_delegate (w:: Webview )
58+ cls = get_window_delegate_class ()
59+ instance = @msg_send ID cls a " new" sel
60+ @ccall objc_setAssociatedObject (
61+ instance:: ID ,
62+ ASSOCIATED_KEY:: Cstring ,
63+ pointer_from_objref (w):: ID ,
64+ 0 :: UInt # OBJC_ASSOCIATION_ASSIGN
65+ ):: ID
66+ instance
67+ end
68+
69+ function get_webkit_ui_delegate_class ()
70+ cls = @ccall objc_getClass (" WebkitUIDelegate" :: Cstring ):: ID
71+ cls == C_NULL || return cls
5072 cls = @ccall objc_allocateClassPair (a " NSObject" cls :: ID , " WebkitUIDelegate" :: Cstring , 0 :: Int ):: ID
5173 @ccall class_addProtocol (
5274 cls:: ID ,
@@ -83,10 +105,16 @@ function create_webkit_ui_delegate()
83105 " v@:@@@@" :: Cstring
84106 ):: Bool
85107 @ccall objc_registerClassPair (cls:: ID ):: Cvoid
108+ cls
109+ end
110+ function create_webkit_ui_delegate ()
111+ cls = get_webkit_ui_delegate_class ()
86112 @msg_send ID cls a " new" sel
87113end
88114
89- function create_script_message_handler (w:: Webview )
115+ function get_script_message_handler_class ()
116+ cls = @ccall objc_getClass (" WebkitScriptMessageHandler" :: Cstring ):: ID
117+ cls == C_NULL || return cls
90118 cls = @ccall objc_allocateClassPair (a " NSResponder" cls :: ID , " WebkitScriptMessageHandler" :: Cstring , 0 :: Int ):: ID
91119 @ccall class_addProtocol (
92120 cls:: ID ,
@@ -110,6 +138,10 @@ function create_script_message_handler(w::Webview)
110138 " v@:@@" :: Cstring
111139 ):: Bool
112140 @ccall objc_registerClassPair (cls:: ID ):: Cvoid
141+ cls
142+ end
143+ function create_script_message_handler (w:: Webview )
144+ cls = get_script_message_handler_class ()
113145 instance = @msg_send ID cls a " new" sel
114146 @ccall objc_setAssociatedObject (
115147 instance:: ID ,
@@ -129,7 +161,7 @@ function is_app_bundled()
129161 bundled = @msg_send Bool bundle_path a " hasSuffix:" sel a " .app" str
130162end
131163
132- function on_application_did_finish_launching (w:: Webview , _self :: ID , app:: ID )
164+ function on_application_did_finish_launching (w:: Webview , app:: ID )
133165 if w. parent_window ≡ C_NULL
134166 @msg_send Cvoid app a " stop:" sel C_NULL
135167 end
@@ -152,6 +184,7 @@ function on_application_did_finish_launching(w::Webview, _self::ID, app::ID)
152184 else
153185 w. parent_window
154186 end
187+ create_window_delegate (w)
155188
156189 # Webview
157190 config = w. config = @msg_send ID a " WKWebViewConfiguration" cls a " new" sel
0 commit comments