Commit d72a1999 authored by thestig's avatar thestig Committed by Commit bot

Fix a crash in pdf::PepperPDFHost::OnHostMsgHasUnsupportedFeature().

BUG=627814

Review-Url: https://codereview.chromium.org/2174963002
Cr-Commit-Position: refs/heads/master@{#407323}
parent a1b402e7
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "components/pdf/renderer/pepper_pdf_host.h" #include "components/pdf/renderer/pepper_pdf_host.h"
#include "base/memory/ptr_util.h"
#include "components/pdf/common/pdf_messages.h" #include "components/pdf/common/pdf_messages.h"
#include "components/pdf/renderer/pdf_accessibility_tree.h" #include "components/pdf/renderer/pdf_accessibility_tree.h"
#include "content/public/common/referrer.h" #include "content/public/common/referrer.h"
...@@ -30,6 +31,7 @@ ...@@ -30,6 +31,7 @@
namespace pdf { namespace pdf {
namespace { namespace {
// --single-process model may fail in CHECK(!g_print_client) if there exist // --single-process model may fail in CHECK(!g_print_client) if there exist
// more than two RenderThreads, so here we use TLS for g_print_client. // more than two RenderThreads, so here we use TLS for g_print_client.
// See http://crbug.com/457580. // See http://crbug.com/457580.
...@@ -96,33 +98,33 @@ int32_t PepperPDFHost::OnResourceMessageReceived( ...@@ -96,33 +98,33 @@ int32_t PepperPDFHost::OnResourceMessageReceived(
int32_t PepperPDFHost::OnHostMsgDidStartLoading( int32_t PepperPDFHost::OnHostMsgDidStartLoading(
ppapi::host::HostMessageContext* context) { ppapi::host::HostMessageContext* context) {
content::PepperPluginInstance* instance = content::RenderView* render_view = GetRenderView();
host_->GetPluginInstance(pp_instance()); if (!render_view)
if (!instance)
return PP_ERROR_FAILED; return PP_ERROR_FAILED;
instance->GetRenderView()->DidStartLoading();
render_view->DidStartLoading();
return PP_OK; return PP_OK;
} }
int32_t PepperPDFHost::OnHostMsgDidStopLoading( int32_t PepperPDFHost::OnHostMsgDidStopLoading(
ppapi::host::HostMessageContext* context) { ppapi::host::HostMessageContext* context) {
content::PepperPluginInstance* instance = content::RenderView* render_view = GetRenderView();
host_->GetPluginInstance(pp_instance()); if (!render_view)
if (!instance)
return PP_ERROR_FAILED; return PP_ERROR_FAILED;
instance->GetRenderView()->DidStopLoading();
render_view->DidStopLoading();
return PP_OK; return PP_OK;
} }
int32_t PepperPDFHost::OnHostMsgSetContentRestriction( int32_t PepperPDFHost::OnHostMsgSetContentRestriction(
ppapi::host::HostMessageContext* context, ppapi::host::HostMessageContext* context,
int restrictions) { int restrictions) {
content::PepperPluginInstance* instance = content::RenderView* render_view = GetRenderView();
host_->GetPluginInstance(pp_instance()); if (!render_view)
if (!instance)
return PP_ERROR_FAILED; return PP_ERROR_FAILED;
instance->GetRenderView()->Send(new PDFHostMsg_PDFUpdateContentRestrictions(
instance->GetRenderView()->GetRoutingID(), restrictions)); render_view->Send(new PDFHostMsg_PDFUpdateContentRestrictions(
render_view->GetRoutingID(), restrictions));
return PP_OK; return PP_OK;
} }
...@@ -137,19 +139,10 @@ int32_t PepperPDFHost::OnHostMsgUserMetricsRecordAction( ...@@ -137,19 +139,10 @@ int32_t PepperPDFHost::OnHostMsgUserMetricsRecordAction(
int32_t PepperPDFHost::OnHostMsgHasUnsupportedFeature( int32_t PepperPDFHost::OnHostMsgHasUnsupportedFeature(
ppapi::host::HostMessageContext* context) { ppapi::host::HostMessageContext* context) {
content::PepperPluginInstance* instance = content::RenderView* render_view = GetRenderView();
host_->GetPluginInstance(pp_instance()); if (!render_view)
if (!instance)
return PP_ERROR_FAILED; return PP_ERROR_FAILED;
// TODO(thestig): Turn CHECKs into the proper if statement after figuring out
// what's wrong for https://crbug.com/627814
CHECK(instance->GetContainer());
CHECK(instance->GetContainer()->document().frame());
CHECK(instance->GetContainer()->document().frame()->view());
blink::WebView* view =
instance->GetContainer()->document().frame()->view();
content::RenderView* render_view = content::RenderView::FromWebView(view);
render_view->Send( render_view->Send(
new PDFHostMsg_PDFHasUnsupportedFeature(render_view->GetRoutingID())); new PDFHostMsg_PDFHasUnsupportedFeature(render_view->GetRoutingID()));
return PP_OK; return PP_OK;
...@@ -166,8 +159,12 @@ int32_t PepperPDFHost::OnHostMsgSaveAs( ...@@ -166,8 +159,12 @@ int32_t PepperPDFHost::OnHostMsgSaveAs(
host_->GetPluginInstance(pp_instance()); host_->GetPluginInstance(pp_instance());
if (!instance) if (!instance)
return PP_ERROR_FAILED; return PP_ERROR_FAILED;
GURL url = instance->GetPluginURL();
content::RenderView* render_view = instance->GetRenderView(); content::RenderView* render_view = instance->GetRenderView();
if (!render_view)
return PP_ERROR_FAILED;
GURL url = instance->GetPluginURL();
content::Referrer referrer; content::Referrer referrer;
referrer.url = url; referrer.url = url;
referrer.policy = blink::WebReferrerPolicyDefault; referrer.policy = blink::WebReferrerPolicyDefault;
...@@ -234,9 +231,15 @@ int32_t PepperPDFHost::OnHostMsgSetAccessibilityPageInfo( ...@@ -234,9 +231,15 @@ int32_t PepperPDFHost::OnHostMsgSetAccessibilityPageInfo(
void PepperPDFHost::CreatePdfAccessibilityTreeIfNeeded() { void PepperPDFHost::CreatePdfAccessibilityTreeIfNeeded() {
if (!pdf_accessibility_tree_) { if (!pdf_accessibility_tree_) {
pdf_accessibility_tree_.reset(new PdfAccessibilityTree( pdf_accessibility_tree_ =
host_, pp_instance())); base::MakeUnique<PdfAccessibilityTree>(host_, pp_instance());
} }
} }
content::RenderView* PepperPDFHost::GetRenderView() {
content::PepperPluginInstance* instance =
host_->GetPluginInstance(pp_instance());
return instance ? instance->GetRenderView() : nullptr;
}
} // namespace pdf } // namespace pdf
...@@ -7,7 +7,9 @@ ...@@ -7,7 +7,9 @@
#include <stdint.h> #include <stdint.h>
#include <memory>
#include <string> #include <string>
#include <vector>
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/macros.h" #include "base/macros.h"
...@@ -24,18 +26,17 @@ class SkBitmap; ...@@ -24,18 +26,17 @@ class SkBitmap;
namespace content { namespace content {
class PepperPluginInstance; class PepperPluginInstance;
class RenderView;
class RendererPpapiHost; class RendererPpapiHost;
} }
namespace ppapi { namespace ppapi {
class HostResource; class HostResource;
}
namespace ppapi {
namespace host { namespace host {
struct HostMessageContext; struct HostMessageContext;
} } // namespace host
} } // namespace ppapi
namespace pdf { namespace pdf {
...@@ -71,6 +72,7 @@ class PepperPDFHost : public ppapi::host::ResourceHost { ...@@ -71,6 +72,7 @@ class PepperPDFHost : public ppapi::host::ResourceHost {
// PPB_PDF_Impl instance. // PPB_PDF_Impl instance.
static void SetPrintClient(PrintClient* print_client); static void SetPrintClient(PrintClient* print_client);
// ppapi::host::ResourceHost:
int32_t OnResourceMessageReceived( int32_t OnResourceMessageReceived(
const IPC::Message& msg, const IPC::Message& msg,
ppapi::host::HostMessageContext* context) override; ppapi::host::HostMessageContext* context) override;
...@@ -106,9 +108,11 @@ class PepperPDFHost : public ppapi::host::ResourceHost { ...@@ -106,9 +108,11 @@ class PepperPDFHost : public ppapi::host::ResourceHost {
void CreatePdfAccessibilityTreeIfNeeded(); void CreatePdfAccessibilityTreeIfNeeded();
content::RenderView* GetRenderView();
std::unique_ptr<PdfAccessibilityTree> pdf_accessibility_tree_; std::unique_ptr<PdfAccessibilityTree> pdf_accessibility_tree_;
content::RendererPpapiHost* host_; content::RendererPpapiHost* const host_;
DISALLOW_COPY_AND_ASSIGN(PepperPDFHost); DISALLOW_COPY_AND_ASSIGN(PepperPDFHost);
}; };
......
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