]> khamidou — GitHub mirrors - electron.git/commitdiff
Remove more unused printing code.
authorCheng Zhao <zcbenz@gmail.com>
Fri, 22 Aug 2014 02:27:08 +0000 (10:27 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Fri, 22 Aug 2014 02:27:08 +0000 (10:27 +0800)
chromium_src/chrome/browser/printing/printing_message_filter.cc
chromium_src/chrome/browser/printing/printing_message_filter.h
chromium_src/chrome/common/print_messages.h
chromium_src/chrome/renderer/printing/print_web_view_helper.cc
chromium_src/chrome/renderer/printing/print_web_view_helper.h

index f237159e6a273609fa2ddcadc71f6c975d959c3f..18068a1fa944082410bcc6c89a552f311a9f94d5 100644 (file)
@@ -22,19 +22,6 @@ using content::BrowserThread;
 
 namespace {
 
-#if defined(OS_CHROMEOS)
-typedef std::map<int, base::FilePath> SequenceToPathMap;
-
-struct PrintingSequencePathMap {
-  SequenceToPathMap map;
-  int sequence;
-};
-
-// No locking, only access on the FILE thread.
-static base::LazyInstance<PrintingSequencePathMap>
-    g_printing_file_descriptor_map = LAZY_INSTANCE_INITIALIZER;
-#endif
-
 void RenderParamsFromPrintSettings(const printing::PrintSettings& settings,
                                    PrintMsg_Print_Params* params) {
   params->page_size = settings.page_setup_device_units().physical_size();
@@ -76,21 +63,6 @@ PrintingMessageFilter::PrintingMessageFilter(int render_process_id)
 PrintingMessageFilter::~PrintingMessageFilter() {
 }
 
-void PrintingMessageFilter::OverrideThreadForMessage(
-    const IPC::Message& message, BrowserThread::ID* thread) {
-#if defined(OS_CHROMEOS)
-  if (message.type() == PrintHostMsg_AllocateTempFileForPrinting::ID ||
-      message.type() == PrintHostMsg_TempFileForPrintingWritten::ID) {
-    *thread = BrowserThread::FILE;
-  }
-#elif defined(OS_ANDROID)
-  if (message.type() == PrintHostMsg_AllocateTempFileForPrinting::ID ||
-      message.type() == PrintHostMsg_TempFileForPrintingWritten::ID) {
-    *thread = BrowserThread::UI;
-  }
-#endif
-}
-
 bool PrintingMessageFilter::OnMessageReceived(const IPC::Message& message,
                                               bool* message_was_ok) {
   bool handled = true;
@@ -98,12 +70,9 @@ bool PrintingMessageFilter::OnMessageReceived(const IPC::Message& message,
 #if defined(OS_WIN)
     IPC_MESSAGE_HANDLER(PrintHostMsg_DuplicateSection, OnDuplicateSection)
 #endif
-    IPC_MESSAGE_HANDLER(PrintHostMsg_IsPrintingEnabled, OnIsPrintingEnabled)
     IPC_MESSAGE_HANDLER_DELAY_REPLY(PrintHostMsg_GetDefaultPrintSettings,
                                     OnGetDefaultPrintSettings)
     IPC_MESSAGE_HANDLER_DELAY_REPLY(PrintHostMsg_ScriptedPrint, OnScriptedPrint)
-    IPC_MESSAGE_HANDLER_DELAY_REPLY(PrintHostMsg_UpdatePrintSettings,
-                                    OnUpdatePrintSettings)
     IPC_MESSAGE_UNHANDLED(handled = false)
   IPC_END_MESSAGE_MAP()
   return handled;
@@ -168,11 +137,6 @@ void PrintingMessageFilter::OnGetPrintSettingsFailed(
   callback.Run();
 }
 
-void PrintingMessageFilter::OnIsPrintingEnabled(bool* is_enabled) {
-  DCHECK_CURRENTLY_ON(BrowserThread::IO);
-  *is_enabled = true;
-}
-
 void PrintingMessageFilter::OnGetDefaultPrintSettings(IPC::Message* reply_msg) {
   DCHECK_CURRENTLY_ON(BrowserThread::IO);
   scoped_refptr<printing::PrinterQuery> printer_query;
@@ -251,11 +215,6 @@ void PrintingMessageFilter::OnScriptedPrintReply(
     scoped_refptr<printing::PrinterQuery> printer_query,
     IPC::Message* reply_msg) {
   PrintMsg_PrintPages_Params params;
-#if defined(OS_ANDROID)
-  // We need to save the routing ID here because Send method below deletes the
-  // |reply_msg| before we can get the routing ID for the Android code.
-  int routing_id = reply_msg->routing_id();
-#endif
   if (printer_query->last_status() != printing::PrintingContext::OK ||
       !printer_query->settings().dpi()) {
     params.Reset();
@@ -268,61 +227,8 @@ void PrintingMessageFilter::OnScriptedPrintReply(
   PrintHostMsg_ScriptedPrint::WriteReplyParams(reply_msg, params);
   Send(reply_msg);
   if (params.params.dpi && params.params.document_cookie) {
-#if defined(OS_ANDROID)
-    int file_descriptor;
-    const base::string16& device_name = printer_query->settings().device_name();
-    if (base::StringToInt(device_name, &file_descriptor)) {
-      BrowserThread::PostTask(
-          BrowserThread::UI, FROM_HERE,
-          base::Bind(&PrintingMessageFilter::UpdateFileDescriptor, this,
-                     routing_id, file_descriptor));
-    }
-#endif
     queue_->QueuePrinterQuery(printer_query.get());
   } else {
     printer_query->StopWorker();
   }
 }
-
-void PrintingMessageFilter::OnUpdatePrintSettings(
-    int document_cookie, const base::DictionaryValue& job_settings,
-    IPC::Message* reply_msg) {
-  scoped_refptr<printing::PrinterQuery> printer_query;
-  if (false) {
-    // Reply with NULL query.
-    OnUpdatePrintSettingsReply(printer_query, reply_msg);
-    return;
-  }
-  printer_query = queue_->PopPrinterQuery(document_cookie);
-  if (!printer_query)
-    printer_query = queue_->CreatePrinterQuery();
-  printer_query->SetSettings(
-      job_settings,
-      base::Bind(&PrintingMessageFilter::OnUpdatePrintSettingsReply, this,
-                 printer_query, reply_msg));
-}
-
-void PrintingMessageFilter::OnUpdatePrintSettingsReply(
-    scoped_refptr<printing::PrinterQuery> printer_query,
-    IPC::Message* reply_msg) {
-  PrintMsg_PrintPages_Params params;
-  if (!printer_query.get() ||
-      printer_query->last_status() != printing::PrintingContext::OK) {
-    params.Reset();
-  } else {
-    RenderParamsFromPrintSettings(printer_query->settings(), &params.params);
-    params.params.document_cookie = printer_query->cookie();
-    params.pages =
-        printing::PageRange::GetPages(printer_query->settings().ranges());
-  }
-  PrintHostMsg_UpdatePrintSettings::WriteReplyParams(reply_msg, params);
-  Send(reply_msg);
-  // If user hasn't cancelled.
-  if (printer_query.get()) {
-    if (printer_query->cookie() && printer_query->settings().dpi()) {
-      queue_->QueuePrinterQuery(printer_query.get());
-    } else {
-      printer_query->StopWorker();
-    }
-  }
-}
index 656e175835fa07a838ee1ec82988ca973e62704e..0f587d87e1aee77e35ac9c6e526b5c6266f06ec4 100644 (file)
@@ -38,9 +38,6 @@ class PrintingMessageFilter : public content::BrowserMessageFilter {
   explicit PrintingMessageFilter(int render_process_id);
 
   // content::BrowserMessageFilter methods.
-  virtual void OverrideThreadForMessage(
-      const IPC::Message& message,
-      content::BrowserThread::ID* thread) OVERRIDE;
   virtual bool OnMessageReceived(const IPC::Message& message,
                                  bool* message_was_ok) OVERRIDE;
 
@@ -75,9 +72,6 @@ class PrintingMessageFilter : public content::BrowserMessageFilter {
       const base::Closure& callback,
       scoped_refptr<printing::PrinterQuery> printer_query);
 
-  // Checks if printing is enabled.
-  void OnIsPrintingEnabled(bool* is_enabled);
-
   // Get the default print setting.
   void OnGetDefaultPrintSettings(IPC::Message* reply_msg);
   void OnGetDefaultPrintSettingsReply(
@@ -93,16 +87,6 @@ class PrintingMessageFilter : public content::BrowserMessageFilter {
       scoped_refptr<printing::PrinterQuery> printer_query,
       IPC::Message* reply_msg);
 
-  // Modify the current print settings based on |job_settings|. The task is
-  // handled by the print worker thread and the UI thread. The reply occurs on
-  // the IO thread.
-  void OnUpdatePrintSettings(int document_cookie,
-                             const base::DictionaryValue& job_settings,
-                             IPC::Message* reply_msg);
-  void OnUpdatePrintSettingsReply(
-      scoped_refptr<printing::PrinterQuery> printer_query,
-      IPC::Message* reply_msg);
-
   const int render_process_id_;
 
   scoped_refptr<printing::PrintQueriesQueue> queue_;
index 7a20414117338ade88d9cac129de15e875180374..b52103e38cb322bfbe8579c4a076ffc0dda78f9c 100644 (file)
@@ -185,10 +185,6 @@ IPC_STRUCT_END()
 
 // Messages sent from the browser to the renderer.
 
-// Tells the render frame to initiate printing or print preview for a particular
-// node, depending on which mode the render frame is in.
-IPC_MESSAGE_ROUTED0(PrintMsg_PrintNodeUnderContextMenu)
-
 // Tells the render view to switch the CSS to print media type, renders every
 // requested pages and switch back the CSS to display media type.
 IPC_MESSAGE_ROUTED0(PrintMsg_PrintPages)
@@ -207,10 +203,6 @@ IPC_SYNC_MESSAGE_ROUTED1_1(PrintHostMsg_DuplicateSection,
                            base::SharedMemoryHandle /* browser handle */)
 #endif
 
-// Check if printing is enabled.
-IPC_SYNC_MESSAGE_ROUTED0_1(PrintHostMsg_IsPrintingEnabled,
-                           bool /* is_enabled */)
-
 // Tells the browser that the renderer is done calculating the number of
 // rendered pages according to the specified settings.
 IPC_MESSAGE_ROUTED2(PrintHostMsg_DidGetPrintedPagesCount,
@@ -234,13 +226,6 @@ IPC_MESSAGE_ROUTED1(PrintHostMsg_DidPrintPage,
 IPC_SYNC_MESSAGE_ROUTED0_1(PrintHostMsg_GetDefaultPrintSettings,
                            PrintMsg_Print_Params /* default_settings */)
 
-// The renderer wants to update the current print settings with new
-// |job_settings|.
-IPC_SYNC_MESSAGE_ROUTED2_1(PrintHostMsg_UpdatePrintSettings,
-                           int /* document_cookie */,
-                           base::DictionaryValue /* job_settings */,
-                           PrintMsg_PrintPages_Params /* current_settings */)
-
 // It's the renderer that controls the printing process when it is generated
 // by javascript. This step is about showing UI to the user to select the
 // final print settings. The output parameter is the same as
@@ -250,28 +235,6 @@ IPC_SYNC_MESSAGE_ROUTED1_1(PrintHostMsg_ScriptedPrint,
                            PrintMsg_PrintPages_Params
                                /* settings chosen by the user*/)
 
-#if defined(OS_CHROMEOS) || defined(OS_ANDROID)
-// Asks the browser to create a temporary file for the renderer to fill
-// in resulting NativeMetafile in printing.
-IPC_SYNC_MESSAGE_CONTROL1_2(PrintHostMsg_AllocateTempFileForPrinting,
-                            int /* render_view_id */,
-                            base::FileDescriptor /* temp file fd */,
-                            int /* fd in browser*/) // Used only by Chrome OS.
-IPC_MESSAGE_CONTROL2(PrintHostMsg_TempFileForPrintingWritten,
-                     int /* render_view_id */,
-                     int /* fd in browser */) // Used only by Chrome OS.
-#endif
-
-// Notify the browser of the default page layout according to the currently
-// selected printer and page size.
-// |printable_area_in_points| Specifies the printable area in points.
-// |has_custom_page_size_style| is true when the printing frame has a custom
-// page size css otherwise false.
-IPC_MESSAGE_ROUTED3(PrintHostMsg_DidGetDefaultPageLayout,
-                    printing::PageSizeMargins /* page layout in points */,
-                    gfx::Rect /* printable area in points */,
-                    bool /* has custom page size style */)
-
 // This is sent when there are invalid printer settings.
 IPC_MESSAGE_ROUTED0(PrintHostMsg_ShowInvalidPrinterSettingsError)
 
index 160718d67d15b8744d0249d389f3271577774217..43c408a7787462586eb3106c4ad2d80777750bbc 100644 (file)
@@ -50,20 +50,6 @@ namespace {
 
 const double kMinDpi = 1.0;
 
-const char kPageLoadScriptFormat[] =
-    "document.open(); document.write(%s); document.close();";
-
-const char kPageSetupScriptFormat[] = "setup(%s);";
-
-void ExecuteScript(blink::WebFrame* frame,
-                   const char* script_format,
-                   const base::Value& parameters) {
-  std::string json;
-  base::JSONWriter::Write(&parameters, &json);
-  std::string script = base::StringPrintf(script_format, json.c_str());
-  frame->executeScript(blink::WebString(base::UTF8ToUTF16(script)));
-}
-
 int GetDPI(const PrintMsg_Print_Params* print_params) {
 #if defined(OS_MACOSX)
   // On the Mac, the printable area is in points, don't do any scaling based
@@ -367,60 +353,6 @@ blink::WebView* FrameReference::view() {
   return view_;
 }
 
-// static - Not anonymous so that platform implementations can use it.
-void PrintWebViewHelper::PrintHeaderAndFooter(
-    blink::WebCanvas* canvas,
-    int page_number,
-    int total_pages,
-    float webkit_scale_factor,
-    const PageSizeMargins& page_layout,
-    const base::DictionaryValue& header_footer_info,
-    const PrintMsg_Print_Params& params) {
-  skia::VectorPlatformDeviceSkia* device =
-      static_cast<skia::VectorPlatformDeviceSkia*>(canvas->getTopDevice());
-  device->setDrawingArea(SkPDFDevice::kMargin_DrawingArea);
-
-  SkAutoCanvasRestore auto_restore(canvas, true);
-  canvas->scale(1 / webkit_scale_factor, 1 / webkit_scale_factor);
-
-  blink::WebSize page_size(page_layout.margin_left + page_layout.margin_right +
-                            page_layout.content_width,
-                            page_layout.margin_top + page_layout.margin_bottom +
-                            page_layout.content_height);
-
-  blink::WebView* web_view = blink::WebView::create(NULL);
-  web_view->settings()->setJavaScriptEnabled(true);
-
-  blink::WebLocalFrame* frame = blink::WebLocalFrame::create(NULL);
-  web_view->setMainFrame(frame);
-
-  base::StringValue html("Print Preview");
-  // Load page with script to avoid async operations.
-  ExecuteScript(frame, kPageLoadScriptFormat, html);
-
-  scoped_ptr<base::DictionaryValue> options(header_footer_info.DeepCopy());
-  options->SetDouble("width", page_size.width);
-  options->SetDouble("height", page_size.height);
-  options->SetDouble("topMargin", page_layout.margin_top);
-  options->SetDouble("bottomMargin", page_layout.margin_bottom);
-  options->SetString("pageNumber",
-                     base::StringPrintf("%d/%d", page_number, total_pages));
-
-  ExecuteScript(frame, kPageSetupScriptFormat, *options);
-
-  blink::WebPrintParams webkit_params(page_size);
-  webkit_params.printerDPI = GetDPI(&params);
-
-  frame->printBegin(webkit_params);
-  frame->printPage(0, canvas);
-  frame->printEnd();
-
-  web_view->close();
-  frame->close();
-
-  device->setDrawingArea(SkPDFDevice::kContent_DrawingArea);
-}
-
 // static - Not anonymous so that platform implementations can use it.
 float PrintWebViewHelper::RenderPageContent(blink::WebFrame* frame,
                                             int page_number,
@@ -697,25 +629,15 @@ void PrepareFrameAndViewForPrint::FinishPrinting() {
 PrintWebViewHelper::PrintWebViewHelper(content::RenderView* render_view)
     : content::RenderViewObserver(render_view),
       content::RenderViewObserverTracker<PrintWebViewHelper>(render_view),
-      reset_prep_frame_view_(false),
       is_print_ready_metafile_sent_(false),
       ignore_css_margins_(false),
       notify_browser_of_print_failure_(true),
       print_node_in_progress_(false),
-      is_loading_(false),
       weak_ptr_factory_(this) {
 }
 
 PrintWebViewHelper::~PrintWebViewHelper() {}
 
-void PrintWebViewHelper::DidStartLoading() {
-  is_loading_ = true;
-}
-
-void PrintWebViewHelper::DidStopLoading() {
-  is_loading_ = false;
-}
-
 // Prints |frame| which called window.print().
 void PrintWebViewHelper::PrintPage(blink::WebLocalFrame* frame,
                                    bool user_initiated) {
@@ -796,12 +718,6 @@ void PrintWebViewHelper::OnPrintingDone(bool success) {
   DidFinishPrinting(success ? OK : FAIL_PRINT);
 }
 
-bool PrintWebViewHelper::IsPrintingEnabled() {
-  bool result = false;
-  Send(new PrintHostMsg_IsPrintingEnabled(routing_id(), &result));
-  return result;
-}
-
 void PrintWebViewHelper::PrintNode(const blink::WebNode& node) {
   if (node.isNull() || !node.document().frame()) {
     // This can occur when the context menu refers to an invalid WebNode.
index 82d70d9cff9a68beb72dc72f13b095e93b52e7cb..7509391597463b9e6e7cba441a53e91eb3178d26 100644 (file)
@@ -7,7 +7,6 @@
 
 #include <vector>
 
-#include "base/gtest_prod_util.h"
 #include "base/memory/scoped_ptr.h"
 #include "base/memory/shared_memory.h"
 #include "base/memory/weak_ptr.h"
@@ -67,23 +66,9 @@ class PrintWebViewHelper
   explicit PrintWebViewHelper(content::RenderView* render_view);
   virtual ~PrintWebViewHelper();
 
-  bool IsPrintingEnabled();
-
   void PrintNode(const blink::WebNode& node);
 
  private:
-  friend class PrintWebViewHelperTestBase;
-  FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperTest,
-                           BlockScriptInitiatedPrinting);
-  FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperTest,
-                           BlockScriptInitiatedPrintingFromPopup);
-  FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperTest, OnPrintPages);
-
-#if defined(OS_WIN) || defined(OS_MACOSX)
-  FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperTest, PrintLayoutTest);
-  FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperTest, PrintWithIframe);
-#endif  // defined(OS_WIN) || defined(OS_MACOSX)
-
   enum PrintingResult {
     OK,
     FAIL_PRINT_INIT,
@@ -94,12 +79,9 @@ class PrintWebViewHelper
   virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
   virtual void PrintPage(blink::WebLocalFrame* frame,
                          bool user_initiated) OVERRIDE;
-  virtual void DidStartLoading() OVERRIDE;
-  virtual void DidStopLoading() OVERRIDE;
 
   // Message handlers ---------------------------------------------------------
   void OnPrintPages();
-  void OnPrintForSystemDialog();
   void OnPrintingDone(bool success);
 
   // Get |page_size| and |content_area| information from
@@ -115,10 +97,6 @@ class PrintWebViewHelper
   // Returns true if the current destination printer is PRINT_TO_PDF.
   bool IsPrintToPdfRequested(const base::DictionaryValue& settings);
 
-  // Enable/Disable window.print calls.  If |blocked| is true window.print
-  // calls will silently fail.  Call with |blocked| set to false to reenable.
-  void SetScriptedPrintBlocked(bool blocked);
-
   // Main printing code -------------------------------------------------------
 
   void Print(blink::WebLocalFrame* frame, const blink::WebNode& node);
@@ -213,28 +191,14 @@ class PrintWebViewHelper
       double* scale_factor,
       PageSizeMargins* page_layout_in_points);
 
-  // Given the |device| and |canvas| to draw on, prints the appropriate headers
-  // and footers using strings from |header_footer_info| on to the canvas.
-  static void PrintHeaderAndFooter(
-      blink::WebCanvas* canvas,
-      int page_number,
-      int total_pages,
-      float webkit_scale_factor,
-      const PageSizeMargins& page_layout_in_points,
-      const base::DictionaryValue& header_footer_info,
-      const PrintMsg_Print_Params& params);
-
   bool GetPrintFrame(blink::WebLocalFrame** frame);
 
   // Script Initiated Printing ------------------------------------------------
 
   // WebView used only to print the selection.
   scoped_ptr<PrepareFrameAndViewForPrint> prep_frame_view_;
-  bool reset_prep_frame_view_;
 
   scoped_ptr<PrintMsg_PrintPages_Params> print_pages_params_;
-  bool is_preview_enabled_;
-  bool is_scripted_print_throttling_disabled_;
   bool is_print_ready_metafile_sent_;
   bool ignore_css_margins_;
 
@@ -242,14 +206,10 @@ class PrintWebViewHelper
   // the failure came from the browser in the first place.
   bool notify_browser_of_print_failure_;
 
-  // Strings generated by the browser process to be printed as headers and
-  // footers if requested by the user.
-  scoped_ptr<base::DictionaryValue> header_footer_info_;
-
   bool print_node_in_progress_;
-  bool is_loading_;
-  bool is_scripted_preview_delayed_;
+
   base::WeakPtrFactory<PrintWebViewHelper> weak_ptr_factory_;
+
   DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper);
 };