Commit 5add4705 authored by Tommy Li's avatar Tommy Li Committed by Commit Bot

[pdf] Speculatively fix PDFIFrameNavigationThrottle crash on Android

This is a speculative fix. But I think it has few / no side effects.

Not 100% sure what's causing this crash, but I have two theories:
 1. Perhaps navigation_handle()->GetWebContents() can return nullptr
    now. On Android only maybe?
 2. I think posting to the UI thread is wrong in any case, we should be
    posting to the current sequence, as otherwise dereferencing the
    weak pointer is invalid. (It's not sequence-safe).

Bug: 1058303
Change-Id: I75fcb86d58602d26e7b8d6991fd933b70881bd99
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2090300
Commit-Queue: Tommy Li <tommycli@chromium.org>
Reviewed-by: default avatarŁukasz Anforowicz <lukasza@chromium.org>
Cr-Commit-Position: refs/heads/master@{#747441}
parent 5cb16e20
......@@ -8,13 +8,10 @@
#include "base/feature_list.h"
#include "base/memory/weak_ptr.h"
#include "base/no_destructor.h"
#include "base/task/post_task.h"
#include "base/threading/sequenced_task_runner_handle.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/pdf_util.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/download_utils.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/render_frame_host.h"
......@@ -169,11 +166,14 @@ void PDFIFrameNavigationThrottle::LoadPlaceholderHTML() {
// an antipattern. Use a helper object scoped to the WebContents lifetime to
// scope the navigation task to the WebContents lifetime.
content::WebContents* web_contents = navigation_handle()->GetWebContents();
if (!web_contents)
return;
PdfWebContentsLifetimeHelper::CreateForWebContents(web_contents);
PdfWebContentsLifetimeHelper* helper =
PdfWebContentsLifetimeHelper::FromWebContents(web_contents);
base::PostTask(
FROM_HERE, {content::BrowserThread::UI},
base::SequencedTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::BindOnce(&PdfWebContentsLifetimeHelper::NavigateIFrameToPlaceholder,
helper->GetWeakPtr(), std::move(params)));
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment