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

Unified Diff: chrome/renderer/printing/print_web_view_helper.cc

Issue 791133006: Delegates for the printing component (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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/printing/print_web_view_helper.cc
diff --git a/chrome/renderer/printing/print_web_view_helper.cc b/chrome/renderer/printing/print_web_view_helper.cc
index d50f076af6e752024875635ad9e468bee841069b..4c440e31632266f811cd9a5505afeb9557295469 100644
--- a/chrome/renderer/printing/print_web_view_helper.cc
+++ b/chrome/renderer/printing/print_web_view_helper.cc
@@ -7,7 +7,6 @@
#include <string>
#include "base/auto_reset.h"
-#include "base/command_line.h"
#include "base/json/json_writer.h"
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
@@ -16,11 +15,8 @@
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
-#include "chrome/common/chrome_switches.h"
#include "chrome/common/print_messages.h"
-#include "chrome/common/render_messages.h"
-#include "chrome/grit/browser_resources.h"
-#include "chrome/renderer/prerender/prerender_helper.h"
+#include "chrome/renderer/printing/print_web_view_helper_delegate.h"
#include "content/public/common/web_preferences.h"
#include "content/public/renderer/render_frame.h"
#include "content/public/renderer/render_thread.h"
@@ -44,12 +40,6 @@
#include "third_party/WebKit/public/web/WebSettings.h"
#include "third_party/WebKit/public/web/WebView.h"
#include "third_party/WebKit/public/web/WebViewClient.h"
-#include "ui/base/resource/resource_bundle.h"
-
-#if defined(ENABLE_EXTENSIONS)
-#include "chrome/common/extensions/extension_constants.h"
-#include "extensions/common/constants.h"
-#endif // defined(ENABLE_EXTENSIONS)
using content::WebPreferences;
@@ -410,24 +400,6 @@ PrintMsg_Print_Params CalculatePrintParamsForCss(
return result_params;
}
-// Return the PDF object element if |frame| is the out of process PDF extension.
-blink::WebElement GetPdfElement(blink::WebLocalFrame* frame) {
-#if defined(ENABLE_EXTENSIONS)
- GURL url = frame->document().url();
- if (url.SchemeIs(extensions::kExtensionScheme) &&
Vitaly Buka (NO REVIEWS) 2015/01/05 19:57:03 Is this because of extensions? Seems components ar
dgn 2015/01/05 22:45:47 That was about the extensionId but apparently it's
- url.host() == extension_misc::kPdfExtensionId) {
- // <object> with id="plugin" is created in
- // chrome/browser/resources/pdf/pdf.js.
- auto plugin_element = frame->document().getElementById("plugin");
- if (!plugin_element.isNull()) {
- return plugin_element;
- }
- NOTREACHED();
- }
-#endif // defined(ENABLE_EXTENSIONS)
- return blink::WebElement();
-}
-
} // namespace
FrameReference::FrameReference(blink::WebLocalFrame* frame) {
@@ -490,10 +462,8 @@ void PrintWebViewHelper::PrintHeaderAndFooter(
blink::WebLocalFrame* frame = blink::WebLocalFrame::create(NULL);
web_view->setMainFrame(frame);
- base::StringValue html(ResourceBundle::GetSharedInstance().GetLocalizedString(
- IDR_PRINT_PREVIEW_PAGE));
// Load page with script to avoid async operations.
Vitaly Buka (NO REVIEWS) 2015/01/05 19:57:03 this resource has nothing chrome specific so it sh
dgn 2015/01/05 22:45:47 Acknowledged.
- ExecuteScript(frame, kPageLoadScriptFormat, html);
+ ExecuteScript(frame, kPageLoadScriptFormat, delegate_->GetPrintPreviewHtml());
scoped_ptr<base::DictionaryValue> options(new base::DictionaryValue());
options.reset(new base::DictionaryValue());
@@ -790,7 +760,9 @@ void PrepareFrameAndViewForPrint::FinishPrinting() {
on_ready_.Reset();
}
-PrintWebViewHelper::PrintWebViewHelper(content::RenderView* render_view)
+PrintWebViewHelper::PrintWebViewHelper(
+ content::RenderView* render_view,
+ scoped_ptr<PrintWebViewHelperDelegate> delegate)
: content::RenderViewObserver(render_view),
content::RenderViewObserverTracker<PrintWebViewHelper>(render_view),
reset_prep_frame_view_(false),
@@ -799,12 +771,12 @@ PrintWebViewHelper::PrintWebViewHelper(content::RenderView* render_view)
is_scripted_printing_blocked_(false),
notify_browser_of_print_failure_(true),
print_for_preview_(false),
+ delegate_(delegate.Pass()),
print_node_in_progress_(false),
is_loading_(false),
is_scripted_preview_delayed_(false),
weak_ptr_factory_(this) {
- if (CommandLine::ForCurrentProcess()->HasSwitch(
Vitaly Buka (NO REVIEWS) 2015/01/05 19:57:03 this switch could go to components not sure yet if
dgn 2015/01/05 22:45:47 Replaced with a constructor argument
- switches::kDisablePrintPreview)) {
+ if (delegate_->PrintPreviewDisabled()) {
DisablePreview();
}
}
@@ -844,10 +816,11 @@ void PrintWebViewHelper::PrintPage(blink::WebLocalFrame* frame,
bool user_initiated) {
DCHECK(frame);
- // Allow Prerendering to cancel this print request if necessary.
- if (prerender::PrerenderHelper::IsPrerendering(
- render_view()->GetMainRenderFrame())) {
- Send(new ChromeViewHostMsg_CancelPrerenderForPrinting(routing_id()));
+ // In Chrome, allows prerendering to cancel this print request if necessary.
+ IPC::Message* cancel_message = delegate_->GetScriptedPrintCancelMessage(
+ render_view(), routing_id());
+ if (cancel_message) {
+ Send(cancel_message);
return;
}
@@ -906,10 +879,10 @@ void PrintWebViewHelper::OnPrintForPrintPreview(
// the element with ID "pdf-viewer" if it isn't an iframe.
blink::WebLocalFrame* plugin_frame = pdf_element.document().frame();
blink::WebElement plugin_element = pdf_element;
- if (switches::OutOfProcessPdfEnabled() &&
+ if (delegate_->OutOfProcessPdfEnabled() &&
pdf_element.hasHTMLTagName("iframe")) {
plugin_frame = blink::WebLocalFrame::fromFrameOwnerElement(pdf_element);
- plugin_element = GetPdfElement(plugin_frame);
+ plugin_element = delegate_->GetPdfElement(plugin_frame);
if (plugin_element.isNull()) {
NOTREACHED();
return;
@@ -969,7 +942,7 @@ void PrintWebViewHelper::OnPrintPages() {
return;
// If we are printing a PDF extension frame, find the plugin node and print
// that instead.
- auto plugin = GetPdfElement(frame);
+ auto plugin = delegate_->GetPdfElement(frame);
Print(frame, plugin, false);
}
@@ -1224,7 +1197,7 @@ void PrintWebViewHelper::OnInitiatePrintPreview(bool selection_only) {
DCHECK(frame);
// If we are printing a PDF extension frame, find the plugin node and print
// that instead.
- auto plugin = GetPdfElement(frame);
+ auto plugin = delegate_->GetPdfElement(frame);
if (!plugin.isNull()) {
PrintNode(plugin);
return;

Powered by Google App Engine
This is Rietveld 408576698