Skip to content

Commit 2b9e5e6

Browse files
authored
Use OnWindowObjectReady instead of OnDOMReady. (#27)
Fixes issue with webpage accessing `window.godot` before it is bound.
1 parent 5227b64 commit 2b9e5e6

File tree

5 files changed

+15
-15
lines changed

5 files changed

+15
-15
lines changed

demo/app_example.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ signal test_signal
66
func _ready():
77
test_signal.connect(func(): print("test_signal"))
88

9-
func _on_dom_ready(_url):
9+
func _on_window_ready(_url):
1010
return {
1111
"bool": true,
1212
"int": 69,

src/app_example.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ using namespace godot;
88

99
void AppExample::_bind_methods() {}
1010

11-
Dictionary AppExample::_on_dom_ready(const godot::String &url)
11+
Dictionary AppExample::_on_window_ready(const godot::String &url)
1212
{
1313
auto obj = Dictionary();
1414
obj["url"] = url;

src/app_example.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace godot {
1111
protected:
1212
static void _bind_methods();
1313

14-
Dictionary _on_dom_ready(const String &url) override;
14+
Dictionary _on_window_ready(const String &url) override;
1515
};
1616

1717
}

src/godot/html_rect/html_rect.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ void HtmlRect::_bind_methods()
1515
ClassDB::bind_method(D_METHOD("set_index", "p_index"), &HtmlRect::set_index);
1616
ClassDB::add_property(get_class_static(), PropertyInfo(Variant::STRING, "index_path"), "set_index", "get_index");
1717

18-
GDVIRTUAL_BIND(_on_dom_ready, "url");
18+
GDVIRTUAL_BIND(_on_window_ready, "url");
1919
}
2020

2121
HtmlRect::HtmlRect()
@@ -86,18 +86,18 @@ godot::String HtmlRect::get_index() const
8686
return index_path;
8787
}
8888

89-
Dictionary HtmlRect::call_on_dom_ready(const String &url)
89+
Dictionary HtmlRect::call_on_window_ready(const String &url)
9090
{
9191
Dictionary obj;
92-
if(GDVIRTUAL_CALL(_on_dom_ready, url, obj))
92+
if(GDVIRTUAL_CALL(_on_window_ready, url, obj))
9393
{
9494
return obj;
9595
}
96-
return _on_dom_ready(url);
96+
return _on_window_ready(url);
9797
}
9898

99-
void HtmlRect::OnDOMReady(ultralight::View *caller, uint64_t frame_id, bool is_main_frame,
100-
const ultralight::String &url)
99+
void godot::HtmlRect::OnWindowObjectReady(ultralight::View *caller, uint64_t frame_id, bool is_main_frame,
100+
const ultralight::String &url)
101101
{
102102
// Acquire the JS execution context for the current page.
103103
auto scoped_context = caller->LockJSContext();
@@ -106,7 +106,7 @@ void HtmlRect::OnDOMReady(ultralight::View *caller, uint64_t frame_id, bool is_m
106106
JSContextRef context = (*scoped_context);
107107

108108
String godot_url = godot::String(url.utf8().data());
109-
Dictionary godot_obj_dict = call_on_dom_ready(godot_url);
109+
Dictionary godot_obj_dict = call_on_window_ready(godot_url);
110110

111111
StoreGlobalObject(context, godot_obj_dict);
112112
}

src/godot/html_rect/html_rect.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ namespace godot {
1818
protected:
1919
static void _bind_methods();
2020

21-
Dictionary call_on_dom_ready(const String &url);
22-
GDVIRTUAL1R(Dictionary, _on_dom_ready, String);
23-
virtual Dictionary _on_dom_ready(const String &url) { return Dictionary(); };
21+
Dictionary call_on_window_ready(const String &url);
22+
GDVIRTUAL1R(Dictionary, _on_window_ready, String);
23+
virtual Dictionary _on_window_ready(const String &url) { return Dictionary(); };
2424

2525
public:
2626
String index_path = "";
@@ -35,8 +35,8 @@ namespace godot {
3535
void set_index(const String p_index);
3636
String get_index() const;
3737

38-
void OnDOMReady(ultralight::View *caller, uint64_t frame_id, bool is_main_frame, const ultralight::String &url) override;
39-
};
38+
void OnWindowObjectReady(ultralight::View *caller, uint64_t frame_id, bool is_main_frame, const ultralight::String &url) override;
39+
};
4040
}
4141

4242
#endif

0 commit comments

Comments
 (0)