Skip to content

Fixed page crash (Aw, Snap!) issue when we reload any page multiple times #321

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

Open
wants to merge 1 commit into
base: chromium
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ class ActionUrlHandlerAndroid;
namespace {

bool IsRenderFrameHostSupported(content::RenderFrameHost* rfh) {
if (!rfh) {
return false;
}

if (rfh->GetLifecycleState() ==
content::RenderFrameHost::LifecycleState::kPendingCommit) {
return true;
Expand All @@ -46,13 +50,21 @@ bool IsRenderFrameHostSupported(content::RenderFrameHost* rfh) {
ContentActionUrlDriver::ContentActionUrlDriver(
content::RenderFrameHost* render_frame_host)
: render_frame_host_(render_frame_host) {
if (!render_frame_host_) {
LOG(ERROR) << "AMIT ContentActionUrlDriver: render_frame_host is null!";
return;
}
static unsigned next_free_id = 0;
id_ = next_free_id++;
handler_processing_remaining_ = 0;
action_block_draw_remaining_ = 0;
requested_for_header_ = false;

LOG(INFO) << "AMIT ContentActionUrlDriver constructor before get interface";
if (!render_frame_host_->GetRemoteAssociatedInterfaces()) {
LOG(ERROR) << "AMIT ContentActionUrlDriver: RemoteAssociatedInterfaces is null!";
return;
}

render_frame_host_->GetRemoteAssociatedInterfaces()->GetInterface(
&action_url_agent_);
LOG(INFO) << "AMIT action_url_agent_ is bound: " << action_url_agent_.is_bound();
Expand All @@ -64,12 +76,23 @@ ContentActionUrlDriver::~ContentActionUrlDriver() = default;
void ContentActionUrlDriver::BindPendingReceiver(
mojo::PendingAssociatedReceiver<action_url::mojom::ActionUrlDriver>
pending_receiver) {
if (!render_frame_host_) {
LOG(ERROR) << "AMIT BindPendingReceiver: render_frame_host_ is null!";
return;
}

if (IsRenderFrameHostSupported(render_frame_host_)) {
action_url_receiver_.Bind(std::move(pending_receiver));
}
}

void ContentActionUrlDriver::DidNavigate() {
if (!render_frame_host_) {
LOG(ERROR) << "AMIT DidNavigate: render_frame_host_ is null!";
action_url_receiver_.reset();
return;
}

if (!IsRenderFrameHostSupported(render_frame_host_)) {
action_url_receiver_.reset();
}
Expand All @@ -83,6 +106,11 @@ int ContentActionUrlDriver::GetId() const {
void ContentActionUrlDriver::AllAnchorsParsed(
const std::vector<action_url::AnchorData>& anchors_data) {

if (!render_frame_host_) {
LOG(ERROR) << "AMIT AllAnchorsParsed: render_frame_host_ is null!";
return;
}

Profile* profile = Profile::FromBrowserContext(render_frame_host_->GetBrowserContext());
if (!profile->GetPrefs()->GetBoolean(action_url::prefs::kBlinksEnabled)) {
LOG(INFO) << "AMIT Blinks are disabled";
Expand Down Expand Up @@ -165,6 +193,11 @@ void ContentActionUrlDriver::ActionUrlFetched(action_url::AnchorData anchor,
void ContentActionUrlDriver::ProcessActionUrl(GURL action_url,
action_url::AnchorData anchor,
std::string tag) {
if (!render_frame_host_) {
LOG(ERROR) << "AMIT ProcessActionUrl: render_frame_host_ is null!";
return;
}

std::unique_ptr<network::ResourceRequest> request =
std::make_unique<network::ResourceRequest>();
request->url = action_url;
Expand Down Expand Up @@ -228,6 +261,12 @@ void ContentActionUrlDriver::OnDownloadedJson(
const mojo::AssociatedRemote<action_url::mojom::ActionUrlAgent>&
ContentActionUrlDriver::GetActionUrlAgent() {
LOG(INFO) << "AMIT GetActionUrlAgent";

if (!render_frame_host_) {
LOG(ERROR) << "AMIT GetActionUrlAgent: render_frame_host_ is null!";
return action_url_agent_unbound_;
}

CHECK_NE(render_frame_host_->GetLifecycleState(),
content::RenderFrameHost::LifecycleState::kPendingCommit);
LOG(INFO) << "AMIT GetActionUrlAgent 2";
Expand Down
57 changes: 56 additions & 1 deletion src/components/action_url/content/renderer/action_url_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ mojom::ActionUrlDriver& ActionUrlAgent::GetActionUrlDriver() {
// return *deferring_password_manager_driver_;
// }
LOG(INFO) << "AMIT GetActionUrlDriver";
if (!render_frame()) {
LOG(ERROR) << "AMIT GetActionUrlDriver: render_frame() is null!";
// Return a static unbound driver to prevent crash
static mojo::AssociatedRemote<mojom::ActionUrlDriver> unbound_driver_;
return *unbound_driver_;
}

// Lazily bind this interface.
if (!action_url_driver_) {
LOG(INFO) << "AMIT GetActionUrlDriver 1";
Expand All @@ -70,12 +77,23 @@ void ActionUrlAgent::Reset() {
action_block_counter_ = 1;
renderer_anchor_cache_.clear();
buffer_for_anchors_.clear();
GetActionUrlDriver().Reset();

if (render_frame()) {
GetActionUrlDriver().Reset();
} else {
LOG(ERROR) << "AMIT Reset: render_frame() is null!";
}
}

// mojom::ActionUrlAgent:
void ActionUrlAgent::SetUpHeader() {
LOG(INFO) << "Unfurling :: " << __func__;

if (!render_frame()) {
LOG(ERROR) << "AMIT SetUpHeader: render_frame() is null!";
return;
}

render_frame()->GetWebFrame()->GetDocument().SetUpActionUrlHeader();
}

Expand Down Expand Up @@ -107,6 +125,12 @@ void ActionUrlAgent::ReplaceUrL(const std::string& json,
void ActionUrlAgent::SetUpScriptBlock() {
LOG(INFO)<< "AMIT Setting up action url script block in action url agent";
LOG(INFO) << "Unfurling :: " << __func__;

if (!render_frame()) {
LOG(ERROR) << "AMIT SetUpScriptBlock: render_frame() is null!";
return;
}

render_frame()->GetWebFrame()->GetDocument().SetUpActionUrlScriptBlock();
}

Expand All @@ -127,6 +151,12 @@ void ActionUrlAgent::DidCommitProvisionalLoad(ui::PageTransition transition) {

void ActionUrlAgent::DidCreateDocumentElement() {
Reset();

if (!render_frame()) {
LOG(ERROR) << "AMIT DidCreateDocumentElement: render_frame() is null!";
return;
}

render_frame()->GetWebFrame()->GetDocument().ResetScriptState();
}

Expand All @@ -135,6 +165,12 @@ void ActionUrlAgent::DidDispatchDOMContentLoadedEvent() {
// Parse the content and find all anchor elements
LOG(INFO) << "Unfurling :: " << __func__;
is_dom_content_loaded_ = true;

if (!render_frame()) {
LOG(ERROR) << "AMIT DidDispatchDOMContentLoadedEvent: render_frame() is null!";
return;
}

render_frame()->GetWebFrame()->GetDocument().ResetScriptState();
FindAnchorElementsOnPage(false);
}
Expand All @@ -158,10 +194,23 @@ void ActionUrlAgent::WaitTillDynamicChangeTimer(base::OneShotTimer& timer) {

// Top-level wrapper call to trigger DOM traversal to find anchor element.
void ActionUrlAgent::FindAnchorElementsOnPage(bool is_dynamic) {
if (!render_frame()) {
LOG(ERROR) << "AMIT FindAnchorElementsOnPage: render_frame() is null!";
return;
}

const blink::WebDocument doc = render_frame()->GetWebFrame()->GetDocument();
if (doc.IsNull() || doc.Body().IsNull()) {
return;
}

// Enabling only for x.com pages
GURL page_url = GURL(doc.Url());
if (!page_url.is_valid() || page_url.host() != "x.com") {
LOG(INFO) << "AMIT Skipping non-x.com page";
return;
}

WebVector<WebAnchorElement> anchor_elements;
if (is_dynamic) {
buffer_mu_.Acquire();
Expand Down Expand Up @@ -405,6 +454,12 @@ void ActionUrlAgent::OnJsonParsed(WebAnchorElement anchor,
void ActionUrlAgent::ActionBlockDrawCompleted() {
LOG(INFO) << "Unfurling :: " << __func__;
LOG(INFO) << "AMIT Action block draw completed";

if (!render_frame()) {
LOG(ERROR) << "AMIT ActionBlockDrawCompleted: render_frame() is null!";
return;
}

GetActionUrlDriver().OnBlockDrawCompleted();
}

Expand Down