summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/printing/print_view_manager.cc3
-rw-r--r--chrome/renderer/chrome_ppb_pdf_impl.cc21
-rw-r--r--chrome/renderer/print_web_view_helper.cc28
-rw-r--r--chrome/renderer/print_web_view_helper.h2
-rw-r--r--ppapi/c/private/ppb_pdf.h3
5 files changed, 43 insertions, 14 deletions
diff --git a/chrome/browser/printing/print_view_manager.cc b/chrome/browser/printing/print_view_manager.cc
index 2b22ad8..4d083a0 100644
--- a/chrome/browser/printing/print_view_manager.cc
+++ b/chrome/browser/printing/print_view_manager.cc
@@ -124,7 +124,8 @@ bool PrintViewManager::PrintPreviewNow() {
void PrintViewManager::PrintPreviewDone() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- DCHECK_NE(NOT_PREVIEWING, print_preview_state_);
+ // DCHECK_NE(NOT_PREVIEWING, print_preview_state_);
+ // TODO(thestig) Fix this. http://crbug.com/105640
if (print_preview_state_ == SCRIPTED_PREVIEW) {
ScriptedPrintPreviewClosureMap& map =
diff --git a/chrome/renderer/chrome_ppb_pdf_impl.cc b/chrome/renderer/chrome_ppb_pdf_impl.cc
index ba7e127..5a4592c 100644
--- a/chrome/renderer/chrome_ppb_pdf_impl.cc
+++ b/chrome/renderer/chrome_ppb_pdf_impl.cc
@@ -8,6 +8,7 @@
#include "base/utf_string_conversions.h"
#include "build/build_config.h"
#include "chrome/common/render_messages.h"
+#include "chrome/renderer/print_web_view_helper.h"
#include "content/public/common/child_process_sandbox_support_linux.h"
#include "content/public/common/content_client.h"
#include "content/public/renderer/render_thread.h"
@@ -23,6 +24,7 @@
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
#include "third_party/skia/include/core/SkBitmap.h"
@@ -37,6 +39,7 @@
using ppapi::PpapiGlobals;
using webkit::ppapi::HostGlobals;
using webkit::ppapi::PluginInstance;
+using WebKit::WebElement;
using WebKit::WebView;
using content::RenderThread;
@@ -340,6 +343,21 @@ void SaveAs(PP_Instance instance_id) {
instance->delegate()->SaveURLAs(instance->plugin_url());
}
+void Print(PP_Instance instance_id) {
+ PluginInstance* instance = HostGlobals::Get()->GetInstance(instance_id);
+ if (!instance)
+ return;
+
+ WebElement element = instance->container()->element();
+ WebView* view = element.document().frame()->view();
+ content::RenderView* render_view = content::RenderView::FromWebView(view);
+
+ PrintWebViewHelper* print_view_helper = PrintWebViewHelper::Get(render_view);
+ if (print_view_helper) {
+ print_view_helper->PrintNode(element);
+ }
+}
+
const PPB_PDF ppb_pdf = {
&GetLocalizedString,
&GetResourceImage,
@@ -352,7 +370,8 @@ const PPB_PDF ppb_pdf = {
&HistogramPDFPageCount,
&UserMetricsRecordAction,
&HasUnsupportedFeature,
- &SaveAs
+ &SaveAs,
+ &Print
};
// static
diff --git a/chrome/renderer/print_web_view_helper.cc b/chrome/renderer/print_web_view_helper.cc
index ab87046..66e6d73 100644
--- a/chrome/renderer/print_web_view_helper.cc
+++ b/chrome/renderer/print_web_view_helper.cc
@@ -966,7 +966,20 @@ void PrintWebViewHelper::OnPrintingDone(bool success) {
void PrintWebViewHelper::OnPrintNodeUnderContextMenu() {
const WebNode& context_menu_node = render_view()->GetContextMenuNode();
- if (context_menu_node.isNull()) {
+ PrintNode(context_menu_node);
+}
+
+void PrintWebViewHelper::OnInitiatePrintPreview() {
+ DCHECK(is_preview_enabled_);
+ WebFrame* frame;
+ if (GetPrintFrame(&frame)) {
+ print_preview_context_.InitWithFrame(frame);
+ RequestPrintPreview();
+ }
+}
+
+void PrintWebViewHelper::PrintNode(const WebNode& node) {
+ if (node.isNull()) {
NOTREACHED();
return;
}
@@ -974,23 +987,14 @@ void PrintWebViewHelper::OnPrintNodeUnderContextMenu() {
// Make a copy of the node, in case RenderView::OnContextMenuClosed resets
// its |context_menu_node_|.
if (is_preview_enabled_) {
- print_preview_context_.InitWithNode(context_menu_node);
+ print_preview_context_.InitWithNode(node);
RequestPrintPreview();
} else {
- WebNode duplicate_node(context_menu_node);
+ WebNode duplicate_node(node);
Print(duplicate_node.document().frame(), duplicate_node);
}
}
-void PrintWebViewHelper::OnInitiatePrintPreview() {
- DCHECK(is_preview_enabled_);
- WebFrame* frame;
- if (GetPrintFrame(&frame)) {
- print_preview_context_.InitWithFrame(frame);
- RequestPrintPreview();
- }
-}
-
void PrintWebViewHelper::Print(WebKit::WebFrame* frame,
const WebKit::WebNode& node) {
// If still not finished with earlier print request simply ignore.
diff --git a/chrome/renderer/print_web_view_helper.h b/chrome/renderer/print_web_view_helper.h
index 984a52c..5c6941d 100644
--- a/chrome/renderer/print_web_view_helper.h
+++ b/chrome/renderer/print_web_view_helper.h
@@ -90,6 +90,8 @@ class PrintWebViewHelper
explicit PrintWebViewHelper(content::RenderView* render_view);
virtual ~PrintWebViewHelper();
+ void PrintNode(const WebKit::WebNode& node);
+
protected:
// WebKit::WebViewClient override:
virtual void didStopLoading();
diff --git a/ppapi/c/private/ppb_pdf.h b/ppapi/c/private/ppb_pdf.h
index 85b1f1f..3646edd 100644
--- a/ppapi/c/private/ppb_pdf.h
+++ b/ppapi/c/private/ppb_pdf.h
@@ -158,6 +158,9 @@ struct PPB_PDF {
// Invoke SaveAs... dialog, similar to the right-click or wrench menu.
void (*SaveAs)(PP_Instance instance);
+
+ // Invoke Print dialog for plugin.
+ void (*Print)(PP_Instance instance);
};
#endif // PPAPI_C_PRIVATE_PPB_PDF_H_