Skip to content

Commit

Permalink
Revert "Add support for OOPIF printing in renderer"
Browse files Browse the repository at this point in the history
This reverts commit ef052a2.

Reason for revert: this (with the previous CL 648979) brpoke builds for devices that do not have CUPS.

Original change's description:
> Add support for OOPIF printing in renderer
> 
> These mainly include painting placeholders for cross process subframes,
> sending messages to browser to inform printing such subframes,
> serialization and deserialization of printed content, and compositing
> these contents into the final result.
> 
> The high level design doc is at goo.gl/CF1RUy, and browser side change
> is at https:/crrev.com/c/822155.
> 
> BUG=455764
> 
> Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel;master.tryserver.chromium.android:android_optional_gpu_tests_rel
> Change-Id: I15066f46da41d416356cad7392efb669b5f9f024
> Reviewed-on: https://chromium-review.googlesource.com/838512
> Reviewed-by: Khushal <khushalsagar@chromium.org>
> Reviewed-by: Lei Zhang <thestig@chromium.org>
> Reviewed-by: Daniel Cheng <dcheng@chromium.org>
> Reviewed-by: Alex Moshchuk <alexmos@chromium.org>
> Reviewed-by: vmpstr <vmpstr@chromium.org>
> Commit-Queue: Wei Li <weili@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#537243}

TBR=dcheng@chromium.org,thestig@chromium.org,weili@chromium.org,vmpstr@chromium.org,alexmos@chromium.org,khushalsagar@chromium.org

Change-Id: I58a03469bf216957f190e23a3795de472ca58402
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 455764, 813246
Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel;master.tryserver.chromium.android:android_optional_gpu_tests_rel
Reviewed-on: https://chromium-review.googlesource.com/924486
Reviewed-by: Alexander Alekseev <alemate@chromium.org>
Commit-Queue: Alexander Alekseev <alemate@chromium.org>
Cr-Commit-Position: refs/heads/master@{#537484}
  • Loading branch information
Alexander Alekseev authored and Commit Bot committed Feb 17, 2018
1 parent 8bfb0b0 commit 39d52aa
Show file tree
Hide file tree
Showing 24 changed files with 41 additions and 289 deletions.
23 changes: 9 additions & 14 deletions cc/paint/skia_paint_canvas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,15 @@ void SkiaPaintCanvas::drawTextBlob(scoped_refptr<PaintTextBlob> blob,
}

void SkiaPaintCanvas::drawPicture(sk_sp<const PaintRecord> record) {
drawPicture(record, PlaybackParams::CustomDataRasterCallback());
auto did_draw_op_cb =
context_flushes_.enable
? base::BindRepeating(&SkiaPaintCanvas::FlushAfterDrawIfNeeded,
base::Unretained(this))
: PlaybackParams::DidDrawOpCallback();
PlaybackParams params(image_provider_, canvas_->getTotalMatrix(),
PlaybackParams::CustomDataRasterCallback(),
did_draw_op_cb);
record->Playback(canvas_, params);
}

bool SkiaPaintCanvas::isClipEmpty() const {
Expand Down Expand Up @@ -377,19 +385,6 @@ void SkiaPaintCanvas::Annotate(AnnotationType type,
}
}

void SkiaPaintCanvas::drawPicture(
sk_sp<const PaintRecord> record,
PlaybackParams::CustomDataRasterCallback custom_raster_callback) {
auto did_draw_op_cb =
context_flushes_.enable
? base::BindRepeating(&SkiaPaintCanvas::FlushAfterDrawIfNeeded,
base::Unretained(this))
: PlaybackParams::DidDrawOpCallback();
PlaybackParams params(image_provider_, canvas_->getTotalMatrix(),
custom_raster_callback, did_draw_op_cb);
record->Playback(canvas_, params);
}

void SkiaPaintCanvas::FlushAfterDrawIfNeeded() {
if (!context_flushes_.enable)
return;
Expand Down
6 changes: 0 additions & 6 deletions cc/paint/skia_paint_canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,6 @@ class CC_PAINT_EXPORT SkiaPaintCanvas final : public PaintCanvas {
using PaintCanvas::drawImage;
using PaintCanvas::drawPicture;

// Same as the above drawPicture() except using the given custom data
// raster callback.
void drawPicture(
sk_sp<const PaintRecord> record,
PlaybackParams::CustomDataRasterCallback custom_raster_callback);

private:
// We always need skia shaders since the ops will be played on an SkCanvas.
static const bool kCreateSkiaShaders;
Expand Down
3 changes: 2 additions & 1 deletion chrome/browser/chromeos/arc/print/arc_print_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ std::unique_ptr<printing::PdfMetafileSkia> ReadFileOnBlockingTaskRunner(

file.Close();

auto metafile = std::make_unique<printing::PdfMetafileSkia>();
auto metafile = std::make_unique<printing::PdfMetafileSkia>(
printing::SkiaDocumentType::PDF);
if (!metafile->InitFromData(buf.data(), buf.size())) {
LOG(ERROR) << "Failed to initialize PDF metafile";
return nullptr;
Expand Down
7 changes: 5 additions & 2 deletions chrome/browser/printing/print_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,15 @@ IN_PROC_BROWSER_TEST_F(PrintBrowserTest, PrintSubframeContent) {
WaitUntilMessagesReceived();
}

// TODO(weili): Enabled the following tests when the render side change is
// completed.

// Printing frame content with a cross-site iframe which also has a cross-site
// iframe. The site reference chain is a.com --> b.com --> c.com.
// This test passes when both cross-site frames are printed and their
// responses which are checked in
// TestPrintFrameContentMsgFilter::CheckMessage().
IN_PROC_BROWSER_TEST_F(PrintBrowserTest, PrintSubframeChain) {
IN_PROC_BROWSER_TEST_F(PrintBrowserTest, DISABLED_PrintSubframeChain) {
ASSERT_TRUE(embedded_test_server()->Started());
GURL url(embedded_test_server()->GetURL(
"/printing/content_with_iframe_chain.html"));
Expand Down Expand Up @@ -279,7 +282,7 @@ IN_PROC_BROWSER_TEST_F(PrintBrowserTest, PrintSubframeChain) {
// This test passes when both cross-site frames are printed and send back
// responses which are checked in
// TestPrintFrameContentMsgFilter::CheckMessage().
IN_PROC_BROWSER_TEST_F(PrintBrowserTest, PrintSubframeABA) {
IN_PROC_BROWSER_TEST_F(PrintBrowserTest, DISABLED_PrintSubframeABA) {
ASSERT_TRUE(embedded_test_server()->Started());
GURL url(embedded_test_server()->GetURL(
"a.com", "/printing/content_with_iframe_loop.html"));
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/printing/print_view_manager_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ void PrintViewManagerBase::PrintDocument(
}
#else
std::unique_ptr<PdfMetafileSkia> metafile =
std::make_unique<PdfMetafileSkia>();
std::make_unique<PdfMetafileSkia>(SkiaDocumentType::PDF);
CHECK(metafile->InitFromData(print_data->front(), print_data->size()));

// Update the rendered document. It will send notifications to the listener.
Expand Down
5 changes: 4 additions & 1 deletion components/printing/browser/print_composite_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ uint64_t GenerateFrameGuid(int process_id, int frame_id) {
namespace printing {

PrintCompositeClient::PrintCompositeClient(content::WebContents* web_contents)
: content::WebContentsObserver(web_contents), for_preview_(false) {}
: for_preview_(false) {
DCHECK(web_contents);
}

PrintCompositeClient::~PrintCompositeClient() {}

Expand Down Expand Up @@ -89,6 +91,7 @@ void PrintCompositeClient::DoCompositePageToPdf(
const ContentToProxyIdMap& subframe_content_info,
mojom::PdfCompositor::CompositePageToPdfCallback callback) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);

auto& compositor = GetCompositeRequest(document_cookie);

DCHECK(data_size);
Expand Down
15 changes: 5 additions & 10 deletions components/printing/renderer/print_render_frame_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1221,8 +1221,7 @@ bool PrintRenderFrameHelper::CreatePreviewDocument() {
const std::vector<int>& pages = print_pages_params_->pages;

if (!print_preview_context_.CreatePreviewDocument(
std::move(prep_frame_view_), pages, print_params.printed_doc_type,
print_params.document_cookie)) {
std::move(prep_frame_view_), pages, print_params.printed_doc_type)) {
return false;
}

Expand Down Expand Up @@ -1432,7 +1431,7 @@ void PrintRenderFrameHelper::OnPrintFrameContent(
if (!weak_this)
return;

PdfMetafileSkia metafile(SkiaDocumentType::MSKP, params.document_cookie);
PdfMetafileSkia metafile(SkiaDocumentType::MSKP);
gfx::Rect area(params.printable_area.width(), params.printable_area.height());
// Since GetVectorCanvasForNewPage() starts a new recording, it will return
// a valid canvas.
Expand Down Expand Up @@ -1470,7 +1469,6 @@ void PrintRenderFrameHelper::OnPrintFrameContent(
DLOG(ERROR) << "CopyMetafileDataToSharedMem failed";
return;
}

Send(new PrintHostMsg_DidPrintFrameContent(
routing_id(), params.document_cookie, printed_frame_params));

Expand Down Expand Up @@ -1670,8 +1668,7 @@ bool PrintRenderFrameHelper::PrintPagesNative(blink::WebLocalFrame* frame,
if (printed_pages.empty())
return false;

PdfMetafileSkia metafile(print_params.printed_doc_type,
print_params.document_cookie);
PdfMetafileSkia metafile(print_params.printed_doc_type);
CHECK(metafile.Init());

PrintHostMsg_DidPrintDocument_Params page_params;
Expand Down Expand Up @@ -2031,7 +2028,6 @@ bool PrintRenderFrameHelper::CopyMetafileDataToReadOnlySharedMem(
&params->metafile_data_handle, nullptr, nullptr);
DCHECK_EQ(MOJO_RESULT_OK, result);
params->data_size = metafile.GetDataSize();
params->subframe_content_info = metafile.GetSubframeContentInfo();
return true;
}

Expand Down Expand Up @@ -2199,8 +2195,7 @@ void PrintRenderFrameHelper::PrintPreviewContext::OnPrintPreview() {
bool PrintRenderFrameHelper::PrintPreviewContext::CreatePreviewDocument(
std::unique_ptr<PrepareFrameAndViewForPrint> prepared_frame,
const std::vector<int>& pages,
SkiaDocumentType doc_type,
int document_cookie) {
SkiaDocumentType doc_type) {
DCHECK_EQ(INITIALIZED, state_);
state_ = RENDERING;

Expand All @@ -2215,7 +2210,7 @@ bool PrintRenderFrameHelper::PrintPreviewContext::CreatePreviewDocument(
return false;
}

metafile_ = std::make_unique<PdfMetafileSkia>(doc_type, document_cookie);
metafile_ = std::make_unique<PdfMetafileSkia>(doc_type);
CHECK(metafile_->Init());

current_page_index_ = 0;
Expand Down
3 changes: 1 addition & 2 deletions components/printing/renderer/print_render_frame_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,7 @@ class PrintRenderFrameHelper
bool CreatePreviewDocument(
std::unique_ptr<PrepareFrameAndViewForPrint> prepared_frame,
const std::vector<int>& pages,
SkiaDocumentType doc_type,
int document_cookie);
SkiaDocumentType doc_type);

// Called after a page gets rendered. |page_time| is how long the
// rendering took.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ bool PrintRenderFrameHelper::PrintPagesNative(blink::WebLocalFrame* frame,
if (printed_pages.empty())
return false;

PdfMetafileSkia metafile(print_params.printed_doc_type,
print_params.document_cookie);
PdfMetafileSkia metafile(print_params.printed_doc_type);
CHECK(metafile.Init());

for (int page_number : printed_pages) {
Expand Down
7 changes: 4 additions & 3 deletions components/printing/service/pdf_compositor_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ mojom::PdfCompositor::Status PdfCompositorImpl::CompositeToPdf(
}

std::vector<SkDocumentPage> pages(page_count);
SkDeserialProcs procs = DeserializationProcs(&subframes);
// TODO(weili): Change the default functions to actual implementation.
SkDeserialProcs procs;
if (!SkMultiPictureDocumentRead(&stream, pages.data(), page_count, &procs)) {
DLOG(ERROR) << "CompositeToPdf: Page reading failed.";
return mojom::PdfCompositor::Status::CONTENT_FORMAT_ERROR;
Expand Down Expand Up @@ -210,7 +211,6 @@ sk_sp<SkPicture> PdfCompositorImpl::CompositeSubframe(uint64_t frame_guid) {
// The content of this frame should be available.
auto iter = frame_info_map_.find(frame_guid);
DCHECK(iter != frame_info_map_.end());

std::unique_ptr<FrameInfo>& frame_info = iter->second;
frame_info->composited = true;

Expand All @@ -221,7 +221,8 @@ sk_sp<SkPicture> PdfCompositorImpl::CompositeSubframe(uint64_t frame_guid) {
// Composite the entire frame.
SkMemoryStream stream(iter->second->serialized_content->memory(),
iter->second->serialized_content->mapped_size());
SkDeserialProcs procs = DeserializationProcs(&subframes);
// TODO(weili): Change the default functions to actual implementation.
SkDeserialProcs procs;
iter->second->content = SkPicture::MakeFromStream(&stream, &procs);
return iter->second->content;
}
Expand Down
2 changes: 1 addition & 1 deletion components/printing/test/mock_printer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ void MockPrinter::PrintPage(
#if defined(OS_MACOSX)
printing::PdfMetafileCg metafile;
#else
printing::PdfMetafileSkia metafile;
printing::PdfMetafileSkia metafile(printing::SkiaDocumentType::PDF);
#endif
metafile.InitFromData(metafile_data.memory(), content.data_size);
printing::Image image(metafile);
Expand Down
29 changes: 0 additions & 29 deletions content/renderer/render_frame_proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#include "content/renderer/render_widget.h"
#include "content/renderer/resource_timing_info_conversions.h"
#include "ipc/ipc_message_macros.h"
#include "printing/features/features.h"
#include "third_party/WebKit/public/common/feature_policy/feature_policy.h"
#include "third_party/WebKit/public/common/frame/frame_policy.h"
#include "third_party/WebKit/public/platform/URLConversion.h"
Expand All @@ -51,13 +50,6 @@
#include "content/renderer/mus/renderer_window_tree_client.h"
#endif

#if BUILDFLAG(ENABLE_PRINTING)
// nogncheck because dependency on //printing is conditional upon
// enable_basic_printing or enable_print_preview flags.
#include "printing/metafile_skia_wrapper.h" // nogncheck
#include "printing/pdf_metafile_skia.h" // nogncheck
#endif

namespace content {

namespace {
Expand Down Expand Up @@ -804,25 +796,4 @@ SkBitmap* RenderFrameProxy::GetSadPageBitmap() {
return GetContentClient()->renderer()->GetSadWebViewBitmap();
}

uint32_t RenderFrameProxy::Print(const blink::WebRect& rect,
blink::WebCanvas* canvas) {
#if BUILDFLAG(ENABLE_PRINTING)
printing::PdfMetafileSkia* metafile =
printing::MetafileSkiaWrapper::GetMetafileFromCanvas(canvas);
DCHECK(metafile);

// Create a place holder content for the remote frame so it can be replaced
// with actual content later.
uint32_t content_id =
metafile->CreateContentForRemoteFrame(rect, routing_id_);

// Inform browser to print the remote subframe.
Send(new FrameHostMsg_PrintCrossProcessSubframe(
routing_id_, rect, metafile->GetDocumentCookie()));
return content_id;
#else
return 0;
#endif
}

} // namespace content
2 changes: 0 additions & 2 deletions content/renderer/render_frame_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include "ipc/ipc_listener.h"
#include "ipc/ipc_sender.h"
#include "third_party/WebKit/public/common/feature_policy/feature_policy.h"
#include "third_party/WebKit/public/platform/WebCanvas.h"
#include "third_party/WebKit/public/platform/WebFocusType.h"
#include "third_party/WebKit/public/platform/WebInsecureRequestPolicy.h"
#include "third_party/WebKit/public/web/WebRemoteFrame.h"
Expand Down Expand Up @@ -194,7 +193,6 @@ class CONTENT_EXPORT RenderFrameProxy : public IPC::Listener,
blink::WebLocalFrame* source) override;
void FrameFocused() override;
base::UnguessableToken GetDevToolsFrameToken() override;
uint32_t Print(const blink::WebRect& rect, blink::WebCanvas* canvas) override;

// IPC handlers
void OnDidStartLoading();
Expand Down
58 changes: 0 additions & 58 deletions printing/common/pdf_metafile_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
#include "printing/common/pdf_metafile_utils.h"

#include "base/time/time.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkPicture.h"
#include "third_party/skia/include/core/SkPictureRecorder.h"
#include "third_party/skia/include/core/SkTime.h"

namespace {
Expand All @@ -27,15 +24,6 @@ SkTime::DateTime TimeToSkTime(base::Time time) {
return skdate;
}

sk_sp<SkPicture> GetEmptyPicture() {
SkPictureRecorder rec;
SkCanvas* canvas = rec.beginRecording(100, 100);
// Add some ops whose net effects equal to a noop.
canvas->save();
canvas->restore();
return rec.finishRecordingAsPicture();
}

} // namespace

namespace printing {
Expand All @@ -54,50 +42,4 @@ sk_sp<SkDocument> MakePdfDocument(const std::string& creator,
return SkDocument::MakePDF(stream, metadata);
}

sk_sp<SkData> SerializeOopPicture(SkPicture* pic, void* ctx) {
const ContentToProxyIdMap* context =
reinterpret_cast<const ContentToProxyIdMap*>(ctx);
uint32_t pic_id = pic->uniqueID();
auto iter = context->find(pic_id);
if (iter == context->end())
return nullptr;

return SkData::MakeWithCopy(&pic_id, sizeof(pic_id));
}

sk_sp<SkPicture> DeserializeOopPicture(const void* data,
size_t length,
void* ctx) {
uint32_t pic_id;
if (length < sizeof(pic_id)) {
NOTREACHED(); // Should not happen if the content is as written.
return GetEmptyPicture();
}
memcpy(&pic_id, data, sizeof(pic_id));

auto* context = reinterpret_cast<DeserializationContext*>(ctx);
auto iter = context->find(pic_id);
if (iter == context->end()) {
// When we don't have the out-of-process picture available, we return
// an empty picture. Returning a nullptr will cause the deserialization
// crash.
return GetEmptyPicture();
}
return iter->second;
}

SkSerialProcs SerializationProcs(SerializationContext* ctx) {
SkSerialProcs procs;
procs.fPictureProc = SerializeOopPicture;
procs.fPictureCtx = ctx;
return procs;
}

SkDeserialProcs DeserializationProcs(DeserializationContext* ctx) {
SkDeserialProcs procs;
procs.fPictureProc = DeserializeOopPicture;
procs.fPictureCtx = ctx;
return procs;
}

} // namespace printing
Loading

0 comments on commit 39d52aa

Please sign in to comment.