@@ -63,12 +63,19 @@ BraveNewTabUI::BraveNewTabUI(content::WebUI* web_ui, const std::string& name)
63
63
BraveNewTabUI::~BraveNewTabUI () {
64
64
}
65
65
66
- void BraveNewTabUI::CustomizeNewTabWebUIProperties () {
66
+ void BraveNewTabUI::CustomizeNewTabWebUIProperties (content::RenderFrameHost* render_frame_host ) {
67
67
Profile* profile = Profile::FromWebUI (web_ui ());
68
68
PrefService* prefs = profile->GetPrefs ();
69
- auto * web_contents = web_ui ()->GetWebContents ();
70
- if (web_contents) {
71
- auto * render_view_host = web_contents->GetRenderViewHost ();
69
+ content::RenderViewHost* render_view_host = nullptr ;
70
+ if (render_frame_host) {
71
+ render_view_host = render_frame_host->GetRenderViewHost ();
72
+ } else {
73
+ auto * web_contents = web_ui ()->GetWebContents ();
74
+ if (web_contents) {
75
+ render_view_host = web_contents->GetRenderViewHost ();
76
+ }
77
+ }
78
+ if (render_view_host) {
72
79
if (render_view_host) {
73
80
render_view_host->SetWebUIProperty (
74
81
" adsBlockedStat" ,
@@ -95,13 +102,13 @@ void BraveNewTabUI::CustomizeNewTabWebUIProperties() {
95
102
96
103
void BraveNewTabUI::RenderFrameCreated (content::RenderFrameHost* render_frame_host) {
97
104
if (0 != (web_ui ()->GetBindings () & content::BINDINGS_POLICY_WEB_UI)) {
98
- CustomizeNewTabWebUIProperties ();
105
+ CustomizeNewTabWebUIProperties (render_frame_host );
99
106
}
100
107
}
101
108
102
109
void BraveNewTabUI::OnPreferenceChanged () {
103
110
if (0 != (web_ui ()->GetBindings () & content::BINDINGS_POLICY_WEB_UI)) {
104
- CustomizeNewTabWebUIProperties ();
111
+ CustomizeNewTabWebUIProperties (nullptr );
105
112
web_ui ()->CallJavascriptFunctionUnsafe (" brave_new_tab.statsUpdated" );
106
113
}
107
114
}
0 commit comments