Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

execute js script only when render_frame_host is still alive (uplift to 1.18.x) #7173

Merged
merged 1 commit into from
Nov 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions browser/android/brave_cosmetic_resources_tab_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_isolated_world_ids.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/browser/global_routing_id.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/renderer/render_frame.h"

Expand Down Expand Up @@ -64,7 +65,7 @@ std::unique_ptr<base::ListValue> GetUrlCosmeticResourcesOnTaskRunner(
return result_list;
}

void GetUrlCosmeticResourcesOnUI(content::RenderFrameHost* render_frame_host,
void GetUrlCosmeticResourcesOnUI(content::GlobalFrameRoutingId frame_id,
std::unique_ptr<base::ListValue> resources) {
if (!resources) {
return;
Expand All @@ -78,7 +79,10 @@ void GetUrlCosmeticResourcesOnUI(content::RenderFrameHost* render_frame_host,
std::string to_inject;
resources_dict->GetString("injected_script", &to_inject);
if (to_inject.length() > 1) {
render_frame_host->ExecuteJavaScriptInIsolatedWorld(
auto* frame_host = content::RenderFrameHost::FromID(frame_id);
if (!frame_host)
return;
frame_host->ExecuteJavaScriptInIsolatedWorld(
base::UTF8ToUTF16(to_inject),
base::NullCallback(), ISOLATED_WORLD_ID_CHROME_INTERNAL);
}
Expand All @@ -104,7 +108,10 @@ void BraveCosmeticResourcesTabHelper::ProcessURL(
g_brave_browser_process->ad_block_service()->GetTaskRunner()->
PostTaskAndReplyWithResult(FROM_HERE,
base::BindOnce(&GetUrlCosmeticResourcesOnTaskRunner, url.spec()),
base::BindOnce(&GetUrlCosmeticResourcesOnUI, render_frame_host));
base::BindOnce(&GetUrlCosmeticResourcesOnUI,
content::GlobalFrameRoutingId(
render_frame_host->GetProcess()->GetID(),
render_frame_host->GetRoutingID())));
}

void BraveCosmeticResourcesTabHelper::DidFinishNavigation(
Expand Down