PrintWebViewHelper is attached to RenderFrame
This commit is contained in:
parent
234e1bb811
commit
81784827ff
4 changed files with 39 additions and 43 deletions
|
@ -257,6 +257,7 @@ void AtomRendererClient::RenderFrameCreated(
|
||||||
new PepperHelper(render_frame);
|
new PepperHelper(render_frame);
|
||||||
new AtomRenderFrameObserver(render_frame, this);
|
new AtomRenderFrameObserver(render_frame, this);
|
||||||
new ContentSettingsObserver(render_frame);
|
new ContentSettingsObserver(render_frame);
|
||||||
|
new printing::PrintWebViewHelper(render_frame);
|
||||||
|
|
||||||
// Allow file scheme to handle service worker by default.
|
// Allow file scheme to handle service worker by default.
|
||||||
// FIXME(zcbenz): Can this be moved elsewhere?
|
// FIXME(zcbenz): Can this be moved elsewhere?
|
||||||
|
@ -271,7 +272,6 @@ void AtomRendererClient::RenderFrameCreated(
|
||||||
}
|
}
|
||||||
|
|
||||||
void AtomRendererClient::RenderViewCreated(content::RenderView* render_view) {
|
void AtomRendererClient::RenderViewCreated(content::RenderView* render_view) {
|
||||||
new printing::PrintWebViewHelper(render_view);
|
|
||||||
new AtomRenderViewObserver(render_view, this);
|
new AtomRenderViewObserver(render_view, this);
|
||||||
|
|
||||||
blink::WebFrameWidget* web_frame_widget = render_view->GetWebFrameWidget();
|
blink::WebFrameWidget* web_frame_widget = render_view->GetWebFrameWidget();
|
||||||
|
|
|
@ -123,11 +123,11 @@ AtomSandboxedRendererClient::~AtomSandboxedRendererClient() {
|
||||||
void AtomSandboxedRendererClient::RenderFrameCreated(
|
void AtomSandboxedRendererClient::RenderFrameCreated(
|
||||||
content::RenderFrame* render_frame) {
|
content::RenderFrame* render_frame) {
|
||||||
new AtomSandboxedRenderFrameObserver(render_frame, this);
|
new AtomSandboxedRenderFrameObserver(render_frame, this);
|
||||||
|
new printing::PrintWebViewHelper(render_frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AtomSandboxedRendererClient::RenderViewCreated(
|
void AtomSandboxedRendererClient::RenderViewCreated(
|
||||||
content::RenderView* render_view) {
|
content::RenderView* render_view) {
|
||||||
new printing::PrintWebViewHelper(render_view);
|
|
||||||
new AtomSandboxedRenderViewObserver(render_view, this);
|
new AtomSandboxedRenderViewObserver(render_view, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include "chrome/renderer/printing/print_web_view_helper.h"
|
#include "chrome/renderer/printing/print_web_view_helper.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "base/auto_reset.h"
|
#include "base/auto_reset.h"
|
||||||
|
@ -334,7 +335,7 @@ blink::WebLocalFrame* FrameReference::GetFrame() {
|
||||||
if (view_ == NULL || frame_ == NULL)
|
if (view_ == NULL || frame_ == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
for (blink::WebFrame* frame = view_->mainFrame(); frame != NULL;
|
for (blink::WebFrame* frame = view_->mainFrame(); frame != NULL;
|
||||||
frame = frame->traverseNext(false)) {
|
frame = frame->traverseNext()) {
|
||||||
if (frame == frame_)
|
if (frame == frame_)
|
||||||
return frame_;
|
return frame_;
|
||||||
}
|
}
|
||||||
|
@ -353,19 +354,8 @@ float PrintWebViewHelper::RenderPageContent(blink::WebFrame* frame,
|
||||||
double scale_factor,
|
double scale_factor,
|
||||||
blink::WebCanvas* canvas) {
|
blink::WebCanvas* canvas) {
|
||||||
SkAutoCanvasRestore auto_restore(canvas, true);
|
SkAutoCanvasRestore auto_restore(canvas, true);
|
||||||
if (content_area != canvas_area) {
|
|
||||||
canvas->translate((content_area.x() - canvas_area.x()) / scale_factor,
|
canvas->translate((content_area.x() - canvas_area.x()) / scale_factor,
|
||||||
(content_area.y() - canvas_area.y()) / scale_factor);
|
(content_area.y() - canvas_area.y()) / scale_factor);
|
||||||
SkRect clip_rect(
|
|
||||||
SkRect::MakeXYWH(content_area.origin().x() / scale_factor,
|
|
||||||
content_area.origin().y() / scale_factor,
|
|
||||||
content_area.size().width() / scale_factor,
|
|
||||||
content_area.size().height() / scale_factor));
|
|
||||||
SkIRect clip_int_rect;
|
|
||||||
clip_rect.roundOut(&clip_int_rect);
|
|
||||||
SkRegion clip_region(clip_int_rect);
|
|
||||||
canvas->setClipRegion(clip_region);
|
|
||||||
}
|
|
||||||
return frame->printPage(page_number, canvas);
|
return frame->printPage(page_number, canvas);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -413,7 +403,7 @@ class PrepareFrameAndViewForPrint : public blink::WebViewClient,
|
||||||
bool allowsBrokenNullLayerTreeView() const override;
|
bool allowsBrokenNullLayerTreeView() const override;
|
||||||
|
|
||||||
// blink::WebFrameClient:
|
// blink::WebFrameClient:
|
||||||
blink::WebFrame* createChildFrame(
|
blink::WebLocalFrame* createChildFrame(
|
||||||
blink::WebLocalFrame* parent,
|
blink::WebLocalFrame* parent,
|
||||||
blink::WebTreeScopeType scope,
|
blink::WebTreeScopeType scope,
|
||||||
const blink::WebString& name,
|
const blink::WebString& name,
|
||||||
|
@ -491,10 +481,16 @@ void PrepareFrameAndViewForPrint::ResizeForPrinting() {
|
||||||
|
|
||||||
if (!frame())
|
if (!frame())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// Backup size and offset if it's a local frame.
|
||||||
blink::WebView* web_view = frame_.view();
|
blink::WebView* web_view = frame_.view();
|
||||||
// Backup size and offset.
|
// Backup size and offset.
|
||||||
if (blink::WebFrame* web_frame = web_view->mainFrame())
|
if (blink::WebFrame* web_frame = web_view->mainFrame())
|
||||||
prev_scroll_offset_ = web_frame->scrollOffset();
|
prev_scroll_offset_ = web_frame->scrollOffset();
|
||||||
|
if (blink::WebFrame* web_frame = web_view->mainFrame()) {
|
||||||
|
if (web_frame->isWebLocalFrame())
|
||||||
|
prev_scroll_offset_ = web_frame->scrollOffset();
|
||||||
|
}
|
||||||
prev_view_size_ = web_view->size();
|
prev_view_size_ = web_view->size();
|
||||||
|
|
||||||
web_view->resize(print_layout_size);
|
web_view->resize(print_layout_size);
|
||||||
|
@ -562,14 +558,14 @@ void PrepareFrameAndViewForPrint::didStopLoading() {
|
||||||
weak_ptr_factory_.GetWeakPtr()));
|
weak_ptr_factory_.GetWeakPtr()));
|
||||||
}
|
}
|
||||||
|
|
||||||
blink::WebFrame* PrepareFrameAndViewForPrint::createChildFrame(
|
blink::WebLocalFrame* PrepareFrameAndViewForPrint::createChildFrame(
|
||||||
blink::WebLocalFrame* parent,
|
blink::WebLocalFrame* parent,
|
||||||
blink::WebTreeScopeType scope,
|
blink::WebTreeScopeType scope,
|
||||||
const blink::WebString& name,
|
const blink::WebString& name,
|
||||||
const blink::WebString& unique_name,
|
const blink::WebString& unique_name,
|
||||||
blink::WebSandboxFlags sandbox_flags,
|
blink::WebSandboxFlags sandbox_flags,
|
||||||
const blink::WebFrameOwnerProperties& frame_owner_properties) {
|
const blink::WebFrameOwnerProperties& frame_owner_properties) {
|
||||||
blink::WebFrame* frame = blink::WebLocalFrame::create(scope, this);
|
blink::WebLocalFrame* frame = blink::WebLocalFrame::create(scope, this);
|
||||||
parent->appendChild(frame);
|
parent->appendChild(frame);
|
||||||
return frame;
|
return frame;
|
||||||
}
|
}
|
||||||
|
@ -579,10 +575,13 @@ void PrepareFrameAndViewForPrint::CallOnReady() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrepareFrameAndViewForPrint::RestoreSize() {
|
void PrepareFrameAndViewForPrint::RestoreSize() {
|
||||||
if (frame()) {
|
if (!frame())
|
||||||
|
return;
|
||||||
|
|
||||||
blink::WebView* web_view = frame_.GetFrame()->view();
|
blink::WebView* web_view = frame_.GetFrame()->view();
|
||||||
web_view->resize(prev_view_size_);
|
web_view->resize(prev_view_size_);
|
||||||
if (blink::WebFrame* web_frame = web_view->mainFrame())
|
if (blink::WebFrame* web_frame = web_view->mainFrame()) {
|
||||||
|
if (web_frame->isWebLocalFrame())
|
||||||
web_frame->setScrollOffset(prev_scroll_offset_);
|
web_frame->setScrollOffset(prev_scroll_offset_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -609,9 +608,9 @@ void PrepareFrameAndViewForPrint::FinishPrinting() {
|
||||||
on_ready_.Reset();
|
on_ready_.Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
PrintWebViewHelper::PrintWebViewHelper(content::RenderView* render_view)
|
PrintWebViewHelper::PrintWebViewHelper(content::RenderFrame* render_frame)
|
||||||
: content::RenderViewObserver(render_view),
|
: content::RenderFrameObserver(render_frame),
|
||||||
content::RenderViewObserverTracker<PrintWebViewHelper>(render_view),
|
content::RenderFrameObserverTracker<PrintWebViewHelper>(render_frame),
|
||||||
reset_prep_frame_view_(false),
|
reset_prep_frame_view_(false),
|
||||||
is_print_ready_metafile_sent_(false),
|
is_print_ready_metafile_sent_(false),
|
||||||
ignore_css_margins_(false),
|
ignore_css_margins_(false),
|
||||||
|
@ -628,10 +627,8 @@ PrintWebViewHelper::PrintWebViewHelper(content::RenderView* render_view)
|
||||||
PrintWebViewHelper::~PrintWebViewHelper() {}
|
PrintWebViewHelper::~PrintWebViewHelper() {}
|
||||||
|
|
||||||
// Prints |frame| which called window.print().
|
// Prints |frame| which called window.print().
|
||||||
void PrintWebViewHelper::PrintPage(blink::WebLocalFrame* frame,
|
void PrintWebViewHelper::ScriptedPrint(bool user_initiated) {
|
||||||
bool user_initiated) {
|
Print(render_frame()->GetWebFrame(), blink::WebNode());
|
||||||
DCHECK(frame);
|
|
||||||
Print(frame, blink::WebNode());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PrintWebViewHelper::OnMessageReceived(const IPC::Message& message) {
|
bool PrintWebViewHelper::OnMessageReceived(const IPC::Message& message) {
|
||||||
|
@ -665,8 +662,7 @@ void PrintWebViewHelper::OnPrintPages(bool silent, bool print_background) {
|
||||||
if (ipc_nesting_level_> 1)
|
if (ipc_nesting_level_> 1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
blink::WebLocalFrame* frame =
|
blink::WebLocalFrame* frame = render_frame()->GetWebFrame();
|
||||||
render_view()->GetMainRenderFrame()->GetWebFrame();
|
|
||||||
Print(frame, blink::WebNode(), silent, print_background);
|
Print(frame, blink::WebNode(), silent, print_background);
|
||||||
}
|
}
|
||||||
#endif // !DISABLE_BASIC_PRINTING
|
#endif // !DISABLE_BASIC_PRINTING
|
||||||
|
@ -707,8 +703,7 @@ void PrintWebViewHelper::OnPrintPreview(const base::DictionaryValue& settings) {
|
||||||
if (ipc_nesting_level_ > 1)
|
if (ipc_nesting_level_ > 1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
blink::WebLocalFrame* frame =
|
blink::WebLocalFrame* frame = render_frame()->GetWebFrame();
|
||||||
render_view()->GetMainRenderFrame()->GetWebFrame();
|
|
||||||
|
|
||||||
print_preview_context_.InitWithFrame(frame);
|
print_preview_context_.InitWithFrame(frame);
|
||||||
if (!print_preview_context_.source_frame()) {
|
if (!print_preview_context_.source_frame()) {
|
||||||
|
@ -745,7 +740,7 @@ void PrintWebViewHelper::PrepareFrameForPreviewDocument() {
|
||||||
print_params, print_preview_context_.source_frame(),
|
print_params, print_preview_context_.source_frame(),
|
||||||
print_preview_context_.source_node(), ignore_css_margins_));
|
print_preview_context_.source_node(), ignore_css_margins_));
|
||||||
prep_frame_view_->CopySelectionIfNeeded(
|
prep_frame_view_->CopySelectionIfNeeded(
|
||||||
render_view()->GetWebkitPreferences(),
|
render_frame()->GetWebkitPreferences(),
|
||||||
base::Bind(&PrintWebViewHelper::OnFramePreparedForPreviewDocument,
|
base::Bind(&PrintWebViewHelper::OnFramePreparedForPreviewDocument,
|
||||||
base::Unretained(this)));
|
base::Unretained(this)));
|
||||||
}
|
}
|
||||||
|
@ -1142,7 +1137,7 @@ bool PrintWebViewHelper::RenderPagesForPrint(blink::WebLocalFrame* frame,
|
||||||
DCHECK(!print_pages_params_->params.selection_only ||
|
DCHECK(!print_pages_params_->params.selection_only ||
|
||||||
print_pages_params_->pages.empty());
|
print_pages_params_->pages.empty());
|
||||||
prep_frame_view_->CopySelectionIfNeeded(
|
prep_frame_view_->CopySelectionIfNeeded(
|
||||||
render_view()->GetWebkitPreferences(),
|
render_frame()->GetWebkitPreferences(),
|
||||||
base::Bind(&PrintWebViewHelper::OnFramePreparedForPrintPages,
|
base::Bind(&PrintWebViewHelper::OnFramePreparedForPrintPages,
|
||||||
base::Unretained(this)));
|
base::Unretained(this)));
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -13,10 +13,11 @@
|
||||||
#include "base/memory/shared_memory.h"
|
#include "base/memory/shared_memory.h"
|
||||||
#include "base/memory/weak_ptr.h"
|
#include "base/memory/weak_ptr.h"
|
||||||
#include "base/time/time.h"
|
#include "base/time/time.h"
|
||||||
#include "content/public/renderer/render_view_observer.h"
|
#include "content/public/renderer/render_frame_observer.h"
|
||||||
#include "content/public/renderer/render_view_observer_tracker.h"
|
#include "content/public/renderer/render_frame_observer_tracker.h"
|
||||||
#include "printing/pdf_metafile_skia.h"
|
#include "printing/pdf_metafile_skia.h"
|
||||||
#include "third_party/WebKit/public/platform/WebCanvas.h"
|
#include "third_party/WebKit/public/platform/WebCanvas.h"
|
||||||
|
#include "third_party/WebKit/public/web/WebLocalFrame.h"
|
||||||
#include "third_party/WebKit/public/web/WebNode.h"
|
#include "third_party/WebKit/public/web/WebNode.h"
|
||||||
#include "third_party/WebKit/public/web/WebPrintParams.h"
|
#include "third_party/WebKit/public/web/WebPrintParams.h"
|
||||||
#include "ui/gfx/geometry/size.h"
|
#include "ui/gfx/geometry/size.h"
|
||||||
|
@ -63,10 +64,10 @@ class FrameReference {
|
||||||
// We plan on making print asynchronous and that will require copying the DOM
|
// We plan on making print asynchronous and that will require copying the DOM
|
||||||
// of the document and creating a new WebView with the contents.
|
// of the document and creating a new WebView with the contents.
|
||||||
class PrintWebViewHelper
|
class PrintWebViewHelper
|
||||||
: public content::RenderViewObserver,
|
: public content::RenderFrameObserver,
|
||||||
public content::RenderViewObserverTracker<PrintWebViewHelper> {
|
public content::RenderFrameObserverTracker<PrintWebViewHelper> {
|
||||||
public:
|
public:
|
||||||
explicit PrintWebViewHelper(content::RenderView* render_view);
|
explicit PrintWebViewHelper(content::RenderFrame* render_frame);
|
||||||
virtual ~PrintWebViewHelper();
|
virtual ~PrintWebViewHelper();
|
||||||
|
|
||||||
void PrintNode(const blink::WebNode& node);
|
void PrintNode(const blink::WebNode& node);
|
||||||
|
@ -91,10 +92,10 @@ class PrintWebViewHelper
|
||||||
PREVIEW_ERROR_LAST_ENUM // Always last.
|
PREVIEW_ERROR_LAST_ENUM // Always last.
|
||||||
};
|
};
|
||||||
|
|
||||||
// RenderViewObserver implementation.
|
// RenderFrameObserver implementation.
|
||||||
bool OnMessageReceived(const IPC::Message& message) override;
|
bool OnMessageReceived(const IPC::Message& message) override;
|
||||||
void PrintPage(blink::WebLocalFrame* frame, bool user_initiated) override;
|
|
||||||
void OnDestruct() override;
|
void OnDestruct() override;
|
||||||
|
void ScriptedPrint(bool user_initiated) override;
|
||||||
|
|
||||||
// Message handlers ---------------------------------------------------------
|
// Message handlers ---------------------------------------------------------
|
||||||
#if !defined(DISABLE_BASIC_PRINTING)
|
#if !defined(DISABLE_BASIC_PRINTING)
|
||||||
|
|
Loading…
Reference in a new issue