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

Unified Diff: chrome/renderer/pepper/chrome_pdf_print_delegate.cc

Issue 477263003: pdf: Create a separate component for using the pdf pepper plugin. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: chrome/renderer/pepper/chrome_pdf_print_delegate.cc
diff --git a/chrome/renderer/pepper/chrome_pdf_print_delegate.cc b/chrome/renderer/pepper/chrome_pdf_print_delegate.cc
new file mode 100644
index 0000000000000000000000000000000000000000..59e692bd0bbe1bc86ad6e7c78384652ce11f70d1
--- /dev/null
+++ b/chrome/renderer/pepper/chrome_pdf_print_delegate.cc
@@ -0,0 +1,50 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/renderer/pepper/chrome_pdf_print_delegate.h"
+
+#include "chrome/renderer/printing/print_web_view_helper.h"
+#include "content/public/renderer/pepper_plugin_instance.h"
+#include "content/public/renderer/render_view.h"
+#include "third_party/WebKit/public/web/WebDocument.h"
+#include "third_party/WebKit/public/web/WebElement.h"
+#include "third_party/WebKit/public/web/WebLocalFrame.h"
+#include "third_party/WebKit/public/web/WebPluginContainer.h"
+
+namespace {
+
+blink::WebElement GetWebElement(PP_Instance instance_id) {
+ content::PepperPluginInstance* instance =
+ content::PepperPluginInstance::Get(instance_id);
+ if (!instance)
+ return blink::WebElement();
+ return instance->GetContainer()->element();
+}
+
+printing::PrintWebViewHelper* GetPrintWebViewHelper(
+ const blink::WebElement& element) {
+ if (element.isNull())
+ return NULL;
+ blink::WebView* view = element.document().frame()->view();
+ content::RenderView* render_view = content::RenderView::FromWebView(view);
+ return printing::PrintWebViewHelper::Get(render_view);
+}
+
+} // namespace
+
+ChromePDFPrintDelegate::ChromePDFPrintDelegate() {}
+ChromePDFPrintDelegate::~ChromePDFPrintDelegate() {}
+
+bool ChromePDFPrintDelegate::IsPrintingEnabled(PP_Instance instance_id) {
+ blink::WebElement element = GetWebElement(instance_id);
+ printing::PrintWebViewHelper* helper = GetPrintWebViewHelper(element);
+ return helper && helper->IsPrintingEnabled();
+}
+
+void ChromePDFPrintDelegate::Print(PP_Instance instance_id) {
+ blink::WebElement element = GetWebElement(instance_id);
+ printing::PrintWebViewHelper* helper = GetPrintWebViewHelper(element);
+ if (helper)
+ helper->PrintNode(element);
+}

Powered by Google App Engine
This is Rietveld 408576698