Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(638)

Side by Side Diff: components/pdf/renderer/pepper_pdf_host.cc

Issue 2174963002: Fix a crash in pdf::PepperPDFHost::OnHostMsgHasUnsupportedFeature(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: niiiiiiiits! Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/pdf/renderer/pepper_pdf_host.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/pdf/renderer/pepper_pdf_host.h" 5 #include "components/pdf/renderer/pepper_pdf_host.h"
6 6
7 #include "base/memory/ptr_util.h"
7 #include "components/pdf/common/pdf_messages.h" 8 #include "components/pdf/common/pdf_messages.h"
8 #include "components/pdf/renderer/pdf_accessibility_tree.h" 9 #include "components/pdf/renderer/pdf_accessibility_tree.h"
9 #include "content/public/common/referrer.h" 10 #include "content/public/common/referrer.h"
10 #include "content/public/renderer/pepper_plugin_instance.h" 11 #include "content/public/renderer/pepper_plugin_instance.h"
11 #include "content/public/renderer/render_frame.h" 12 #include "content/public/renderer/render_frame.h"
12 #include "content/public/renderer/render_thread.h" 13 #include "content/public/renderer/render_thread.h"
13 #include "content/public/renderer/render_view.h" 14 #include "content/public/renderer/render_view.h"
14 #include "content/public/renderer/renderer_ppapi_host.h" 15 #include "content/public/renderer/renderer_ppapi_host.h"
15 #include "ppapi/host/dispatch_host_message.h" 16 #include "ppapi/host/dispatch_host_message.h"
16 #include "ppapi/host/host_message_context.h" 17 #include "ppapi/host/host_message_context.h"
17 #include "ppapi/host/ppapi_host.h" 18 #include "ppapi/host/ppapi_host.h"
18 #include "ppapi/proxy/host_dispatcher.h" 19 #include "ppapi/proxy/host_dispatcher.h"
19 #include "ppapi/proxy/ppapi_messages.h" 20 #include "ppapi/proxy/ppapi_messages.h"
20 #include "ppapi/proxy/ppb_image_data_proxy.h" 21 #include "ppapi/proxy/ppb_image_data_proxy.h"
21 #include "ppapi/shared_impl/ppb_image_data_shared.h" 22 #include "ppapi/shared_impl/ppb_image_data_shared.h"
22 #include "ppapi/shared_impl/scoped_pp_resource.h" 23 #include "ppapi/shared_impl/scoped_pp_resource.h"
23 #include "ppapi/thunk/enter.h" 24 #include "ppapi/thunk/enter.h"
24 #include "ppapi/thunk/ppb_image_data_api.h" 25 #include "ppapi/thunk/ppb_image_data_api.h"
25 #include "third_party/WebKit/public/web/WebDocument.h" 26 #include "third_party/WebKit/public/web/WebDocument.h"
26 #include "third_party/WebKit/public/web/WebLocalFrame.h" 27 #include "third_party/WebKit/public/web/WebLocalFrame.h"
27 #include "third_party/WebKit/public/web/WebPluginContainer.h" 28 #include "third_party/WebKit/public/web/WebPluginContainer.h"
28 #include "third_party/WebKit/public/web/WebView.h" 29 #include "third_party/WebKit/public/web/WebView.h"
29 30
30 namespace pdf { 31 namespace pdf {
31 32
32 namespace { 33 namespace {
34
33 // --single-process model may fail in CHECK(!g_print_client) if there exist 35 // --single-process model may fail in CHECK(!g_print_client) if there exist
34 // more than two RenderThreads, so here we use TLS for g_print_client. 36 // more than two RenderThreads, so here we use TLS for g_print_client.
35 // See http://crbug.com/457580. 37 // See http://crbug.com/457580.
36 base::LazyInstance<base::ThreadLocalPointer<PepperPDFHost::PrintClient>>::Leaky 38 base::LazyInstance<base::ThreadLocalPointer<PepperPDFHost::PrintClient>>::Leaky
37 g_print_client_tls = LAZY_INSTANCE_INITIALIZER; 39 g_print_client_tls = LAZY_INSTANCE_INITIALIZER;
38 40
39 } // namespace 41 } // namespace
40 42
41 PepperPDFHost::PepperPDFHost(content::RendererPpapiHost* host, 43 PepperPDFHost::PepperPDFHost(content::RendererPpapiHost* host,
42 PP_Instance instance, 44 PP_Instance instance,
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 OnHostMsgSetAccessibilityDocInfo) 91 OnHostMsgSetAccessibilityDocInfo)
90 PPAPI_DISPATCH_HOST_RESOURCE_CALL( 92 PPAPI_DISPATCH_HOST_RESOURCE_CALL(
91 PpapiHostMsg_PDF_SetAccessibilityPageInfo, 93 PpapiHostMsg_PDF_SetAccessibilityPageInfo,
92 OnHostMsgSetAccessibilityPageInfo) 94 OnHostMsgSetAccessibilityPageInfo)
93 PPAPI_END_MESSAGE_MAP() 95 PPAPI_END_MESSAGE_MAP()
94 return PP_ERROR_FAILED; 96 return PP_ERROR_FAILED;
95 } 97 }
96 98
97 int32_t PepperPDFHost::OnHostMsgDidStartLoading( 99 int32_t PepperPDFHost::OnHostMsgDidStartLoading(
98 ppapi::host::HostMessageContext* context) { 100 ppapi::host::HostMessageContext* context) {
99 content::PepperPluginInstance* instance = 101 content::RenderView* render_view = GetRenderView();
100 host_->GetPluginInstance(pp_instance()); 102 if (!render_view)
101 if (!instance)
102 return PP_ERROR_FAILED; 103 return PP_ERROR_FAILED;
103 instance->GetRenderView()->DidStartLoading(); 104
105 render_view->DidStartLoading();
104 return PP_OK; 106 return PP_OK;
105 } 107 }
106 108
107 int32_t PepperPDFHost::OnHostMsgDidStopLoading( 109 int32_t PepperPDFHost::OnHostMsgDidStopLoading(
108 ppapi::host::HostMessageContext* context) { 110 ppapi::host::HostMessageContext* context) {
109 content::PepperPluginInstance* instance = 111 content::RenderView* render_view = GetRenderView();
110 host_->GetPluginInstance(pp_instance()); 112 if (!render_view)
111 if (!instance)
112 return PP_ERROR_FAILED; 113 return PP_ERROR_FAILED;
113 instance->GetRenderView()->DidStopLoading(); 114
115 render_view->DidStopLoading();
114 return PP_OK; 116 return PP_OK;
115 } 117 }
116 118
117 int32_t PepperPDFHost::OnHostMsgSetContentRestriction( 119 int32_t PepperPDFHost::OnHostMsgSetContentRestriction(
118 ppapi::host::HostMessageContext* context, 120 ppapi::host::HostMessageContext* context,
119 int restrictions) { 121 int restrictions) {
120 content::PepperPluginInstance* instance = 122 content::RenderView* render_view = GetRenderView();
121 host_->GetPluginInstance(pp_instance()); 123 if (!render_view)
122 if (!instance)
123 return PP_ERROR_FAILED; 124 return PP_ERROR_FAILED;
124 instance->GetRenderView()->Send(new PDFHostMsg_PDFUpdateContentRestrictions( 125
125 instance->GetRenderView()->GetRoutingID(), restrictions)); 126 render_view->Send(new PDFHostMsg_PDFUpdateContentRestrictions(
127 render_view->GetRoutingID(), restrictions));
126 return PP_OK; 128 return PP_OK;
127 } 129 }
128 130
129 int32_t PepperPDFHost::OnHostMsgUserMetricsRecordAction( 131 int32_t PepperPDFHost::OnHostMsgUserMetricsRecordAction(
130 ppapi::host::HostMessageContext* context, 132 ppapi::host::HostMessageContext* context,
131 const std::string& action) { 133 const std::string& action) {
132 if (action.empty()) 134 if (action.empty())
133 return PP_ERROR_FAILED; 135 return PP_ERROR_FAILED;
134 content::RenderThread::Get()->RecordComputedAction(action); 136 content::RenderThread::Get()->RecordComputedAction(action);
135 return PP_OK; 137 return PP_OK;
136 } 138 }
137 139
138 int32_t PepperPDFHost::OnHostMsgHasUnsupportedFeature( 140 int32_t PepperPDFHost::OnHostMsgHasUnsupportedFeature(
139 ppapi::host::HostMessageContext* context) { 141 ppapi::host::HostMessageContext* context) {
140 content::PepperPluginInstance* instance = 142 content::RenderView* render_view = GetRenderView();
141 host_->GetPluginInstance(pp_instance()); 143 if (!render_view)
142 if (!instance)
143 return PP_ERROR_FAILED; 144 return PP_ERROR_FAILED;
144 145
145 // TODO(thestig): Turn CHECKs into the proper if statement after figuring out
146 // what's wrong for https://crbug.com/627814
147 CHECK(instance->GetContainer());
148 CHECK(instance->GetContainer()->document().frame());
149 CHECK(instance->GetContainer()->document().frame()->view());
150 blink::WebView* view =
151 instance->GetContainer()->document().frame()->view();
152 content::RenderView* render_view = content::RenderView::FromWebView(view);
153 render_view->Send( 146 render_view->Send(
154 new PDFHostMsg_PDFHasUnsupportedFeature(render_view->GetRoutingID())); 147 new PDFHostMsg_PDFHasUnsupportedFeature(render_view->GetRoutingID()));
155 return PP_OK; 148 return PP_OK;
156 } 149 }
157 150
158 int32_t PepperPDFHost::OnHostMsgPrint( 151 int32_t PepperPDFHost::OnHostMsgPrint(
159 ppapi::host::HostMessageContext* context) { 152 ppapi::host::HostMessageContext* context) {
160 return InvokePrintingForInstance(pp_instance()) ? PP_OK : PP_ERROR_FAILED; 153 return InvokePrintingForInstance(pp_instance()) ? PP_OK : PP_ERROR_FAILED;
161 } 154 }
162 155
163 int32_t PepperPDFHost::OnHostMsgSaveAs( 156 int32_t PepperPDFHost::OnHostMsgSaveAs(
164 ppapi::host::HostMessageContext* context) { 157 ppapi::host::HostMessageContext* context) {
165 content::PepperPluginInstance* instance = 158 content::PepperPluginInstance* instance =
166 host_->GetPluginInstance(pp_instance()); 159 host_->GetPluginInstance(pp_instance());
167 if (!instance) 160 if (!instance)
168 return PP_ERROR_FAILED; 161 return PP_ERROR_FAILED;
162
163 content::RenderView* render_view = instance->GetRenderView();
164 if (!render_view)
165 return PP_ERROR_FAILED;
166
169 GURL url = instance->GetPluginURL(); 167 GURL url = instance->GetPluginURL();
170 content::RenderView* render_view = instance->GetRenderView();
171 content::Referrer referrer; 168 content::Referrer referrer;
172 referrer.url = url; 169 referrer.url = url;
173 referrer.policy = blink::WebReferrerPolicyDefault; 170 referrer.policy = blink::WebReferrerPolicyDefault;
174 referrer = content::Referrer::SanitizeForRequest(url, referrer); 171 referrer = content::Referrer::SanitizeForRequest(url, referrer);
175 render_view->Send( 172 render_view->Send(
176 new PDFHostMsg_PDFSaveURLAs(render_view->GetRoutingID(), url, referrer)); 173 new PDFHostMsg_PDFSaveURLAs(render_view->GetRoutingID(), url, referrer));
177 return PP_OK; 174 return PP_OK;
178 } 175 }
179 176
180 int32_t PepperPDFHost::OnHostMsgSetSelectedText( 177 int32_t PepperPDFHost::OnHostMsgSetSelectedText(
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 if (!host_->GetPluginInstance(pp_instance())) 224 if (!host_->GetPluginInstance(pp_instance()))
228 return PP_ERROR_FAILED; 225 return PP_ERROR_FAILED;
229 CreatePdfAccessibilityTreeIfNeeded(); 226 CreatePdfAccessibilityTreeIfNeeded();
230 pdf_accessibility_tree_->SetAccessibilityPageInfo( 227 pdf_accessibility_tree_->SetAccessibilityPageInfo(
231 page_info, text_run_info, chars); 228 page_info, text_run_info, chars);
232 return PP_OK; 229 return PP_OK;
233 } 230 }
234 231
235 void PepperPDFHost::CreatePdfAccessibilityTreeIfNeeded() { 232 void PepperPDFHost::CreatePdfAccessibilityTreeIfNeeded() {
236 if (!pdf_accessibility_tree_) { 233 if (!pdf_accessibility_tree_) {
237 pdf_accessibility_tree_.reset(new PdfAccessibilityTree( 234 pdf_accessibility_tree_ =
238 host_, pp_instance())); 235 base::MakeUnique<PdfAccessibilityTree>(host_, pp_instance());
239 } 236 }
240 } 237 }
241 238
239 content::RenderView* PepperPDFHost::GetRenderView() {
240 content::PepperPluginInstance* instance =
241 host_->GetPluginInstance(pp_instance());
242 return instance ? instance->GetRenderView() : nullptr;
243 }
244
242 } // namespace pdf 245 } // namespace pdf
OLDNEW
« no previous file with comments | « components/pdf/renderer/pepper_pdf_host.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698