OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/renderer/pepper/ppb_pdf_impl.h" | 5 #include "chrome/renderer/pepper/ppb_pdf_impl.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/safe_numerics.h" | 9 #include "base/safe_numerics.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
12 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
13 #include "chrome/common/render_messages.h" | 13 #include "chrome/common/render_messages.h" |
14 #include "chrome/renderer/printing/print_web_view_helper.h" | 14 #include "chrome/renderer/printing/print_web_view_helper.h" |
15 #include "content/public/common/child_process_sandbox_support_linux.h" | 15 #include "content/public/common/child_process_sandbox_support_linux.h" |
16 #include "content/public/common/referrer.h" | 16 #include "content/public/common/referrer.h" |
17 #include "content/public/renderer/render_thread.h" | 17 #include "content/public/renderer/render_thread.h" |
18 #include "content/public/renderer/render_view.h" | 18 #include "content/public/renderer/render_view.h" |
19 #include "grit/webkit_resources.h" | 19 #include "grit/webkit_resources.h" |
20 #include "grit/webkit_strings.h" | 20 #include "grit/webkit_strings.h" |
21 #include "ppapi/c/pp_resource.h" | 21 #include "ppapi/c/pp_resource.h" |
22 #include "ppapi/c/private/ppb_pdf.h" | 22 #include "ppapi/c/private/ppb_pdf.h" |
| 23 #include "ppapi/c/trusted/ppb_browser_font_trusted.h" |
23 #include "ppapi/shared_impl/ppapi_globals.h" | 24 #include "ppapi/shared_impl/ppapi_globals.h" |
24 #include "ppapi/shared_impl/resource.h" | 25 #include "ppapi/shared_impl/resource.h" |
25 #include "ppapi/shared_impl/resource_tracker.h" | 26 #include "ppapi/shared_impl/resource_tracker.h" |
26 #include "ppapi/shared_impl/var.h" | 27 #include "ppapi/shared_impl/var.h" |
27 #include "third_party/skia/include/core/SkBitmap.h" | 28 #include "third_party/skia/include/core/SkBitmap.h" |
28 #include "third_party/WebKit/public/web/WebDocument.h" | 29 #include "third_party/WebKit/public/web/WebDocument.h" |
29 #include "third_party/WebKit/public/web/WebElement.h" | 30 #include "third_party/WebKit/public/web/WebElement.h" |
30 #include "third_party/WebKit/public/web/WebFrame.h" | 31 #include "third_party/WebKit/public/web/WebFrame.h" |
31 #include "third_party/WebKit/public/web/WebPluginContainer.h" | 32 #include "third_party/WebKit/public/web/WebPluginContainer.h" |
32 #include "third_party/WebKit/public/web/WebView.h" | 33 #include "third_party/WebKit/public/web/WebView.h" |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 { PP_RESOURCEIMAGE_PDF_PAGE_DROPSHADOW, IDR_PDF_PAGE_DROPSHADOW }, | 130 { PP_RESOURCEIMAGE_PDF_PAGE_DROPSHADOW, IDR_PDF_PAGE_DROPSHADOW }, |
130 { PP_RESOURCEIMAGE_PDF_PAN_SCROLL_ICON, IDR_PAN_SCROLL_ICON }, | 131 { PP_RESOURCEIMAGE_PDF_PAN_SCROLL_ICON, IDR_PAN_SCROLL_ICON }, |
131 }; | 132 }; |
132 | 133 |
133 #if defined(ENABLE_PRINTING) | 134 #if defined(ENABLE_PRINTING) |
134 | 135 |
135 WebKit::WebElement GetWebElement(PP_Instance instance_id) { | 136 WebKit::WebElement GetWebElement(PP_Instance instance_id) { |
136 PluginInstance* instance = PluginInstance::Get(instance_id); | 137 PluginInstance* instance = PluginInstance::Get(instance_id); |
137 if (!instance) | 138 if (!instance) |
138 return WebKit::WebElement(); | 139 return WebKit::WebElement(); |
139 return instance->container()->element(); | 140 return instance->GetContainer()->element(); |
140 } | 141 } |
141 | 142 |
142 printing::PrintWebViewHelper* GetPrintWebViewHelper( | 143 printing::PrintWebViewHelper* GetPrintWebViewHelper( |
143 const WebKit::WebElement& element) { | 144 const WebKit::WebElement& element) { |
144 if (element.isNull()) | 145 if (element.isNull()) |
145 return NULL; | 146 return NULL; |
146 WebKit::WebView* view = element.document().frame()->view(); | 147 WebKit::WebView* view = element.document().frame()->view(); |
147 content::RenderView* render_view = content::RenderView::FromWebView(view); | 148 content::RenderView* render_view = content::RenderView::FromWebView(view); |
148 return printing::PrintWebViewHelper::Get(render_view); | 149 return printing::PrintWebViewHelper::Get(render_view); |
149 } | 150 } |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 *results = NULL; | 283 *results = NULL; |
283 } | 284 } |
284 | 285 |
285 usearch_close(searcher); | 286 usearch_close(searcher); |
286 } | 287 } |
287 | 288 |
288 void DidStartLoading(PP_Instance instance_id) { | 289 void DidStartLoading(PP_Instance instance_id) { |
289 PluginInstance* instance = PluginInstance::Get(instance_id); | 290 PluginInstance* instance = PluginInstance::Get(instance_id); |
290 if (!instance) | 291 if (!instance) |
291 return; | 292 return; |
292 instance->render_view()->DidStartLoading(); | 293 instance->GetRenderView()->DidStartLoading(); |
293 } | 294 } |
294 | 295 |
295 void DidStopLoading(PP_Instance instance_id) { | 296 void DidStopLoading(PP_Instance instance_id) { |
296 PluginInstance* instance = PluginInstance::Get(instance_id); | 297 PluginInstance* instance = PluginInstance::Get(instance_id); |
297 if (!instance) | 298 if (!instance) |
298 return; | 299 return; |
299 instance->render_view()->DidStopLoading(); | 300 instance->GetRenderView()->DidStopLoading(); |
300 } | 301 } |
301 | 302 |
302 void SetContentRestriction(PP_Instance instance_id, int restrictions) { | 303 void SetContentRestriction(PP_Instance instance_id, int restrictions) { |
303 PluginInstance* instance = PluginInstance::Get(instance_id); | 304 PluginInstance* instance = PluginInstance::Get(instance_id); |
304 if (!instance) | 305 if (!instance) |
305 return; | 306 return; |
306 instance->render_view()->Send( | 307 instance->GetRenderView()->Send( |
307 new ChromeViewHostMsg_PDFUpdateContentRestrictions( | 308 new ChromeViewHostMsg_PDFUpdateContentRestrictions( |
308 instance->render_view()->GetRoutingID(), restrictions)); | 309 instance->GetRenderView()->GetRoutingID(), restrictions)); |
309 } | 310 } |
310 | 311 |
311 void HistogramPDFPageCount(PP_Instance /*instance*/, int count) { | 312 void HistogramPDFPageCount(PP_Instance instance, int count) { |
312 UMA_HISTOGRAM_COUNTS_10000("PDF.PageCount", count); | 313 UMA_HISTOGRAM_COUNTS_10000("PDF.PageCount", count); |
313 } | 314 } |
314 | 315 |
315 void UserMetricsRecordAction(PP_Instance /*instance*/, PP_Var action) { | 316 void UserMetricsRecordAction(PP_Instance instance, PP_Var action) { |
316 scoped_refptr<ppapi::StringVar> action_str( | 317 scoped_refptr<ppapi::StringVar> action_str( |
317 ppapi::StringVar::FromPPVar(action)); | 318 ppapi::StringVar::FromPPVar(action)); |
318 if (action_str.get()) | 319 if (action_str.get()) |
319 RenderThread::Get()->RecordUserMetrics(action_str->value()); | 320 RenderThread::Get()->RecordUserMetrics(action_str->value()); |
320 } | 321 } |
321 | 322 |
322 void HasUnsupportedFeature(PP_Instance instance_id) { | 323 void HasUnsupportedFeature(PP_Instance instance_id) { |
323 PluginInstance* instance = PluginInstance::Get(instance_id); | 324 PluginInstance* instance = PluginInstance::Get(instance_id); |
324 if (!instance) | 325 if (!instance) |
325 return; | 326 return; |
326 | 327 |
327 // Only want to show an info bar if the pdf is the whole tab. | 328 // Only want to show an info bar if the pdf is the whole tab. |
328 if (!instance->IsFullPagePlugin()) | 329 if (!instance->IsFullPagePlugin()) |
329 return; | 330 return; |
330 | 331 |
331 WebView* view = instance->container()->element().document().frame()->view(); | 332 WebView* view = instance->GetContainer()->element().document().frame()->view()
; |
332 content::RenderView* render_view = content::RenderView::FromWebView(view); | 333 content::RenderView* render_view = content::RenderView::FromWebView(view); |
333 render_view->Send(new ChromeViewHostMsg_PDFHasUnsupportedFeature( | 334 render_view->Send(new ChromeViewHostMsg_PDFHasUnsupportedFeature( |
334 render_view->GetRoutingID())); | 335 render_view->GetRoutingID())); |
335 } | 336 } |
336 | 337 |
337 void SaveAs(PP_Instance instance_id) { | 338 void SaveAs(PP_Instance instance_id) { |
338 PluginInstance* instance = PluginInstance::Get(instance_id); | 339 PluginInstance* instance = PluginInstance::Get(instance_id); |
339 if (!instance) | 340 if (!instance) |
340 return; | 341 return; |
341 GURL url = instance->plugin_url(); | 342 GURL url = instance->GetPluginURL(); |
342 | 343 |
343 content::RenderView* render_view = instance->render_view(); | 344 content::RenderView* render_view = instance->GetRenderView(); |
344 WebKit::WebFrame* frame = render_view->GetWebView()->mainFrame(); | 345 WebKit::WebFrame* frame = render_view->GetWebView()->mainFrame(); |
345 content::Referrer referrer(frame->document().url(), | 346 content::Referrer referrer(frame->document().url(), |
346 frame->document().referrerPolicy()); | 347 frame->document().referrerPolicy()); |
347 render_view->Send(new ChromeViewHostMsg_PDFSaveURLAs( | 348 render_view->Send(new ChromeViewHostMsg_PDFSaveURLAs( |
348 render_view->GetRoutingID(), url, referrer)); | 349 render_view->GetRoutingID(), url, referrer)); |
349 } | 350 } |
350 | 351 |
351 PP_Bool IsFeatureEnabled(PP_Instance instance, PP_PDFFeature feature) { | 352 PP_Bool IsFeatureEnabled(PP_Instance instance, PP_PDFFeature feature) { |
352 switch (feature) { | 353 switch (feature) { |
353 case PP_PDFFEATURE_HIDPI: | 354 case PP_PDFFEATURE_HIDPI: |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 | 418 |
418 // static | 419 // static |
419 void PPB_PDF_Impl::InvokePrintingForInstance(PP_Instance instance_id) { | 420 void PPB_PDF_Impl::InvokePrintingForInstance(PP_Instance instance_id) { |
420 #if defined(ENABLE_PRINTING) | 421 #if defined(ENABLE_PRINTING) |
421 WebKit::WebElement element = GetWebElement(instance_id); | 422 WebKit::WebElement element = GetWebElement(instance_id); |
422 printing::PrintWebViewHelper* helper = GetPrintWebViewHelper(element); | 423 printing::PrintWebViewHelper* helper = GetPrintWebViewHelper(element); |
423 if (helper) | 424 if (helper) |
424 helper->PrintNode(element); | 425 helper->PrintNode(element); |
425 #endif // ENABLE_PRINTING | 426 #endif // ENABLE_PRINTING |
426 } | 427 } |
OLD | NEW |