Update files for Chrome 54 API changes

This commit is contained in:
Cheng Zhao 2016-11-30 16:30:03 +09:00 committed by Birunthan Mohanathas
parent bdc334d797
commit 497f5a1199
52 changed files with 275 additions and 298 deletions

View file

@ -7,7 +7,9 @@
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/threading/thread_restrictions.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/threading/worker_pool.h"
#include "base/timer/timer.h"
#include "chrome/browser/chrome_notification_types.h"
@ -196,12 +198,13 @@ bool PrintJob::FlushJob(base::TimeDelta timeout) {
// Make sure the object outlive this message loop.
scoped_refptr<PrintJob> handle(this);
base::MessageLoop::current()->PostDelayedTask(FROM_HERE,
base::Bind(&PrintJob::Quit, quit_factory_.GetWeakPtr()), timeout);
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, base::Bind(&PrintJob::Quit, quit_factory_.GetWeakPtr()),
timeout);
base::MessageLoop::ScopedNestableTaskAllower allow(
base::MessageLoop::current());
base::MessageLoop::current()->Run();
base::RunLoop().Run();
return true;
}
@ -362,7 +365,7 @@ void PrintJob::OnNotifyPrintJobEvent(const JobEventDetails& event_details) {
}
case JobEventDetails::DOC_DONE: {
// This will call Stop() and broadcast a JOB_DONE message.
base::MessageLoop::current()->PostTask(
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::Bind(&PrintJob::OnDocumentDone, this));
break;
}

View file

@ -9,6 +9,7 @@
#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/message_loop/message_loop.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/values.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
@ -278,7 +279,7 @@ void PrintJobWorker::OnNewPage() {
scoped_refptr<PrintedPage> page = document_->GetPage(page_number_.ToInt());
if (!page.get()) {
// We need to wait for the page to be available.
base::MessageLoop::current()->PostDelayedTask(
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE,
base::Bind(&PrintJobWorker::OnNewPage, weak_factory_.GetWeakPtr()),
base::TimeDelta::FromMilliseconds(500));

View file

@ -8,6 +8,7 @@
#include "base/bind.h"
#include "base/memory/ref_counted_memory.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/timer/timer.h"
#include "components/prefs/pref_service.h"
@ -424,7 +425,7 @@ bool PrintViewManagerBase::RunInnerMessageLoop() {
{
base::MessageLoop::ScopedNestableTaskAllower allow(
base::MessageLoop::current());
base::MessageLoop::current()->Run();
base::RunLoop().Run();
}
bool success = true;

View file

@ -32,7 +32,7 @@ PepperBrokerMessageFilter::~PepperBrokerMessageFilter() {}
scoped_refptr<base::TaskRunner>
PepperBrokerMessageFilter::OverrideTaskRunnerForMessage(
const IPC::Message& message) {
return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI);
return BrowserThread::GetTaskRunnerForThread(BrowserThread::UI);
}
int32_t PepperBrokerMessageFilter::OnResourceMessageReceived(

View file

@ -110,16 +110,16 @@ PepperFlashClipboardMessageFilter::OverrideTaskRunnerForMessage(
// restrictions of various platform APIs. In general, the clipboard is not
// thread-safe, so all clipboard calls should be serviced from the UI thread.
if (msg.type() == PpapiHostMsg_FlashClipboard_WriteData::ID)
return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI);
return BrowserThread::GetTaskRunnerForThread(BrowserThread::UI);
// Windows needs clipboard reads to be serviced from the IO thread because
// these are sync IPCs which can result in deadlocks with plugins if serviced
// from the UI thread. Note that Windows clipboard calls ARE thread-safe so it
// is ok for reads and writes to be serviced from different threads.
#if !defined(OS_WIN)
return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI);
return BrowserThread::GetTaskRunnerForThread(BrowserThread::UI);
#else
return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
return BrowserThread::GetTaskRunnerForThread(BrowserThread::IO);
#endif
}

View file

@ -54,7 +54,7 @@ PepperIsolatedFileSystemMessageFilter::OverrideTaskRunnerForMessage(
const IPC::Message& msg) {
// In order to reach ExtensionSystem, we need to get ProfileManager first.
// ProfileManager lives in UI thread, so we need to do this in UI thread.
return content::BrowserThread::GetMessageLoopProxyForThread(
return content::BrowserThread::GetTaskRunnerForThread(
content::BrowserThread::UI);
}

View file

@ -24,6 +24,7 @@
#include "net/base/escape.h"
#include "printing/pdf_metafile_skia.h"
#include "printing/units.h"
#include "third_party/WebKit/public/platform/WebDoubleSize.h"
#include "third_party/WebKit/public/platform/WebSize.h"
#include "third_party/WebKit/public/platform/WebURLRequest.h"
#include "third_party/WebKit/public/web/WebConsoleMessage.h"
@ -69,15 +70,15 @@ bool PrintMsg_Print_Params_IsValid(const PrintMsg_Print_Params& params) {
}
PrintMsg_Print_Params GetCssPrintParams(
blink::WebFrame* frame,
blink::WebLocalFrame* frame,
int page_index,
const PrintMsg_Print_Params& page_params) {
PrintMsg_Print_Params page_css_params = page_params;
int dpi = GetDPI(&page_params);
blink::WebSize page_size_in_pixels(
ConvertUnit(page_params.page_size.width(), dpi, kPixelsPerInch),
ConvertUnit(page_params.page_size.height(), dpi, kPixelsPerInch));
blink::WebDoubleSize page_size_in_pixels(
ConvertUnitDouble(page_params.page_size.width(), dpi, kPixelsPerInch),
ConvertUnitDouble(page_params.page_size.height(), dpi, kPixelsPerInch));
int margin_top_in_pixels =
ConvertUnit(page_params.margin_top, dpi, kPixelsPerInch);
int margin_right_in_pixels = ConvertUnit(
@ -92,8 +93,6 @@ PrintMsg_Print_Params GetCssPrintParams(
page_params.margin_left,
dpi, kPixelsPerInch);
blink::WebSize original_page_size_in_pixels = page_size_in_pixels;
if (frame) {
frame->pageSizeAndMarginsInPixels(page_index,
page_size_in_pixels,
@ -103,9 +102,9 @@ PrintMsg_Print_Params GetCssPrintParams(
margin_left_in_pixels);
}
int new_content_width = page_size_in_pixels.width -
double new_content_width = page_size_in_pixels.width() -
margin_left_in_pixels - margin_right_in_pixels;
int new_content_height = page_size_in_pixels.height -
double new_content_height = page_size_in_pixels.height() -
margin_top_in_pixels - margin_bottom_in_pixels;
// Invalid page size and/or margins. We just use the default setting.
@ -115,20 +114,12 @@ PrintMsg_Print_Params GetCssPrintParams(
return page_css_params;
}
page_css_params.content_size = gfx::Size(
ConvertUnit(new_content_width, kPixelsPerInch, dpi),
ConvertUnit(new_content_height, kPixelsPerInch, dpi));
if (original_page_size_in_pixels != page_size_in_pixels) {
page_css_params.page_size = gfx::Size(
ConvertUnit(page_size_in_pixels.width, kPixelsPerInch, dpi),
ConvertUnit(page_size_in_pixels.height, kPixelsPerInch, dpi));
} else {
// Printing frame doesn't have any page size css. Pixels to dpi conversion
// causes rounding off errors. Therefore use the default page size values
// directly.
page_css_params.page_size = page_params.page_size;
}
page_css_params.page_size =
gfx::Size(ConvertUnit(page_size_in_pixels.width(), kPixelsPerInch, dpi),
ConvertUnit(page_size_in_pixels.height(), kPixelsPerInch, dpi));
page_css_params.content_size =
gfx::Size(ConvertUnit(new_content_width, kPixelsPerInch, dpi),
ConvertUnit(new_content_height, kPixelsPerInch, dpi));
page_css_params.margin_top =
ConvertUnit(margin_top_in_pixels, kPixelsPerInch, dpi);
@ -274,7 +265,7 @@ MarginType GetMarginsForPdf(blink::WebFrame* frame,
}
PrintMsg_Print_Params CalculatePrintParamsForCss(
blink::WebFrame* frame,
blink::WebLocalFrame* frame,
int page_index,
const PrintMsg_Print_Params& page_params,
bool ignore_css_margins,
@ -429,7 +420,6 @@ class PrepareFrameAndViewForPrint : public blink::WebViewClient,
const blink::WebString& unique_name,
blink::WebSandboxFlags sandbox_flags,
const blink::WebFrameOwnerProperties& frame_owner_properties) override;
void frameDetached(blink::WebFrame* frame, DetachType type) override;
private:
void CallOnReady();
@ -567,10 +557,9 @@ void PrepareFrameAndViewForPrint::didStopLoading() {
DCHECK(!on_ready_.is_null());
// Don't call callback here, because it can delete |this| and WebView that is
// called didStopLoading.
base::MessageLoop::current()->PostTask(
FROM_HERE,
base::Bind(&PrepareFrameAndViewForPrint::CallOnReady,
weak_ptr_factory_.GetWeakPtr()));
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::Bind(&PrepareFrameAndViewForPrint::CallOnReady,
weak_ptr_factory_.GetWeakPtr()));
}
blink::WebFrame* PrepareFrameAndViewForPrint::createChildFrame(
@ -585,14 +574,6 @@ blink::WebFrame* PrepareFrameAndViewForPrint::createChildFrame(
return frame;
}
void PrepareFrameAndViewForPrint::frameDetached(blink::WebFrame* frame,
DetachType type) {
DCHECK(type == DetachType::Remove);
if (frame->parent())
frame->parent()->removeChild(frame);
frame->close();
}
void PrepareFrameAndViewForPrint::CallOnReady() {
return on_ready_.Run(); // Can delete |this|.
}
@ -640,6 +621,7 @@ PrintWebViewHelper::PrintWebViewHelper(content::RenderView* render_view)
print_node_in_progress_(false),
is_loading_(false),
is_scripted_preview_delayed_(false),
ipc_nesting_level_(0),
weak_ptr_factory_(this) {
}
@ -653,6 +635,15 @@ void PrintWebViewHelper::PrintPage(blink::WebLocalFrame* frame,
}
bool PrintWebViewHelper::OnMessageReceived(const IPC::Message& message) {
// The class is not designed to handle recursive messages. This is not
// expected during regular flow. However, during rendering of content for
// printing, lower level code may run nested message loop. E.g. PDF may has
// script to show message box http://crbug.com/502562. In that moment browser
// may receive updated printer capabilities and decide to restart print
// preview generation. When this happened message handling function may
// choose to ignore message or safely crash process.
++ipc_nesting_level_;
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(PrintWebViewHelper, message)
IPC_MESSAGE_HANDLER(PrintMsg_PrintPages, OnPrintPages)
@ -660,6 +651,8 @@ bool PrintWebViewHelper::OnMessageReceived(const IPC::Message& message) {
IPC_MESSAGE_HANDLER(PrintMsg_PrintPreview, OnPrintPreview)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
--ipc_nesting_level_;
return handled;
}
@ -667,28 +660,14 @@ void PrintWebViewHelper::OnDestruct() {
delete this;
}
bool PrintWebViewHelper::GetPrintFrame(blink::WebLocalFrame** frame) {
DCHECK(frame);
blink::WebView* webView = render_view()->GetWebView();
DCHECK(webView);
if (!webView)
return false;
// If the user has selected text in the currently focused frame we print
// only that frame (this makes print selection work for multiple frames).
blink::WebLocalFrame* focusedFrame =
webView->focusedFrame()->toWebLocalFrame();
*frame = focusedFrame->hasSelection()
? focusedFrame
: webView->mainFrame()->toWebLocalFrame();
return true;
}
#if !defined(DISABLE_BASIC_PRINTING)
void PrintWebViewHelper::OnPrintPages(bool silent, bool print_background) {
blink::WebLocalFrame* frame;
if (GetPrintFrame(&frame))
Print(frame, blink::WebNode(), silent, print_background);
if (ipc_nesting_level_> 1)
return;
blink::WebLocalFrame* frame =
render_view()->GetMainRenderFrame()->GetWebFrame();
Print(frame, blink::WebNode(), silent, print_background);
}
#endif // !DISABLE_BASIC_PRINTING
@ -725,22 +704,25 @@ void PrintWebViewHelper::OnPrintingDone(bool success) {
}
void PrintWebViewHelper::OnPrintPreview(const base::DictionaryValue& settings) {
blink::WebLocalFrame* frame;
if (GetPrintFrame(&frame)) {
print_preview_context_.InitWithFrame(frame);
if (!print_preview_context_.source_frame()) {
DidFinishPrinting(FAIL_PREVIEW);
return;
}
if (ipc_nesting_level_ > 1)
return;
if (!UpdatePrintSettings(print_preview_context_.source_frame(),
print_preview_context_.source_node(), settings)) {
DidFinishPrinting(FAIL_PREVIEW);
return;
}
is_print_ready_metafile_sent_ = false;
PrepareFrameForPreviewDocument();
blink::WebLocalFrame* frame =
render_view()->GetMainRenderFrame()->GetWebFrame();
print_preview_context_.InitWithFrame(frame);
if (!print_preview_context_.source_frame()) {
DidFinishPrinting(FAIL_PREVIEW);
return;
}
if (!UpdatePrintSettings(print_preview_context_.source_frame(),
print_preview_context_.source_node(), settings)) {
DidFinishPrinting(FAIL_PREVIEW);
return;
}
is_print_ready_metafile_sent_ = false;
PrepareFrameForPreviewDocument();
}
void PrintWebViewHelper::PrepareFrameForPreviewDocument() {
@ -972,7 +954,7 @@ void PrintWebViewHelper::FinishFramePrinting() {
}
#if defined(OS_MACOSX)
bool PrintWebViewHelper::PrintPagesNative(blink::WebFrame* frame,
bool PrintWebViewHelper::PrintPagesNative(blink::WebLocalFrame* frame,
int page_count) {
const PrintMsg_PrintPages_Params& params = *print_pages_params_;
const PrintMsg_Print_Params& print_params = params.params;
@ -999,7 +981,7 @@ bool PrintWebViewHelper::PrintPagesNative(blink::WebFrame* frame,
// static - Not anonymous so that platform implementations can use it.
void PrintWebViewHelper::ComputePageLayoutInPointsForCss(
blink::WebFrame* frame,
blink::WebLocalFrame* frame,
int page_index,
const PrintMsg_Print_Params& page_params,
bool ignore_css_margins,
@ -1120,7 +1102,7 @@ bool PrintWebViewHelper::UpdatePrintSettings(
}
bool PrintWebViewHelper::GetPrintSettingsFromUser(blink::WebFrame* frame,
bool PrintWebViewHelper::GetPrintSettingsFromUser(blink::WebLocalFrame* frame,
const blink::WebNode& node,
int expected_pages_count) {
PrintHostMsg_ScriptedPrint_Params params;

View file

@ -163,7 +163,7 @@ class PrintWebViewHelper
// Get final print settings from the user.
// Return false if the user cancels or on error.
bool GetPrintSettingsFromUser(blink::WebFrame* frame,
bool GetPrintSettingsFromUser(blink::WebLocalFrame* frame,
const blink::WebNode& node,
int expected_pages_count);
@ -171,23 +171,23 @@ class PrintWebViewHelper
void OnFramePreparedForPrintPages();
void PrintPages();
bool PrintPagesNative(blink::WebFrame* frame, int page_count);
bool PrintPagesNative(blink::WebLocalFrame* frame, int page_count);
void FinishFramePrinting();
// Prints the page listed in |params|.
#if defined(OS_LINUX) || defined(OS_ANDROID)
void PrintPageInternal(const PrintMsg_PrintPage_Params& params,
blink::WebFrame* frame,
blink::WebLocalFrame* frame,
PdfMetafileSkia* metafile);
#elif defined(OS_WIN)
void PrintPageInternal(const PrintMsg_PrintPage_Params& params,
blink::WebFrame* frame,
blink::WebLocalFrame* frame,
PdfMetafileSkia* metafile,
gfx::Size* page_size_in_dpi,
gfx::Rect* content_area_in_dpi);
#else
void PrintPageInternal(const PrintMsg_PrintPage_Params& params,
blink::WebFrame* frame);
blink::WebLocalFrame* frame);
#endif
// Render the frame for printing.
@ -198,7 +198,7 @@ class PrintWebViewHelper
#if defined(OS_MACOSX)
void RenderPage(const PrintMsg_Print_Params& params,
int page_number,
blink::WebFrame* frame,
blink::WebLocalFrame* frame,
bool is_preview,
PdfMetafileSkia* metafile,
gfx::Size* page_size,
@ -223,15 +223,13 @@ class PrintWebViewHelper
// Helper method to get page layout in points and fit to page if needed.
static void ComputePageLayoutInPointsForCss(
blink::WebFrame* frame,
blink::WebLocalFrame* frame,
int page_index,
const PrintMsg_Print_Params& default_params,
bool ignore_css_margins,
double* scale_factor,
PageSizeMargins* page_layout_in_points);
bool GetPrintFrame(blink::WebLocalFrame** frame);
// Script Initiated Printing ------------------------------------------------
// Notifies the browser a print preview page has been rendered.
@ -373,6 +371,7 @@ class PrintWebViewHelper
bool print_node_in_progress_;
bool is_loading_;
bool is_scripted_preview_delayed_;
int ipc_nesting_level_;
PrintPreviewContext print_preview_context_;

View file

@ -22,7 +22,7 @@
namespace printing {
using blink::WebFrame;
using blink::WebLocalFrame;
bool PrintWebViewHelper::RenderPreviewPage(
int page_number,
@ -56,7 +56,7 @@ bool PrintWebViewHelper::RenderPreviewPage(
return PreviewPageRendered(page_number, draft_metafile.get());
}
bool PrintWebViewHelper::PrintPagesNative(blink::WebFrame* frame,
bool PrintWebViewHelper::PrintPagesNative(blink::WebLocalFrame* frame,
int page_count) {
PdfMetafileSkia metafile(PDF_SKIA_DOCUMENT_TYPE);
if (!metafile.Init())
@ -113,7 +113,7 @@ bool PrintWebViewHelper::PrintPagesNative(blink::WebFrame* frame,
void PrintWebViewHelper::PrintPageInternal(
const PrintMsg_PrintPage_Params& params,
WebFrame* frame,
WebLocalFrame* frame,
PdfMetafileSkia* metafile) {
PageSizeMargins page_layout_in_points;
double scale_factor = 1.0f;

View file

@ -18,11 +18,11 @@
namespace printing {
using blink::WebFrame;
using blink::WebLocalFrame;
void PrintWebViewHelper::PrintPageInternal(
const PrintMsg_PrintPage_Params& params,
WebFrame* frame) {
WebLocalFrame* frame) {
PdfMetafileSkia metafile(PDF_SKIA_DOCUMENT_TYPE);
CHECK(metafile.Init());
@ -89,7 +89,7 @@ bool PrintWebViewHelper::RenderPreviewPage(
void PrintWebViewHelper::RenderPage(const PrintMsg_Print_Params& params,
int page_number,
WebFrame* frame,
WebLocalFrame* frame,
bool is_preview,
PdfMetafileSkia* metafile,
gfx::Size* page_size,

View file

@ -20,7 +20,7 @@
namespace printing {
using blink::WebFrame;
using blink::WebLocalFrame;
bool PrintWebViewHelper::RenderPreviewPage(
int page_number,
@ -55,7 +55,7 @@ bool PrintWebViewHelper::RenderPreviewPage(
return PreviewPageRendered(page_number, draft_metafile.get());
}
bool PrintWebViewHelper::PrintPagesNative(blink::WebFrame* frame,
bool PrintWebViewHelper::PrintPagesNative(blink::WebLocalFrame* frame,
int page_count) {
PdfMetafileSkia metafile(PDF_SKIA_DOCUMENT_TYPE);
if (!metafile.Init())
@ -122,7 +122,7 @@ bool PrintWebViewHelper::PrintPagesNative(blink::WebFrame* frame,
void PrintWebViewHelper::PrintPageInternal(
const PrintMsg_PrintPage_Params& params,
WebFrame* frame,
WebLocalFrame* frame,
PdfMetafileSkia* metafile,
gfx::Size* page_size_in_dpi,
gfx::Rect* content_area_in_dpi) {