OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/renderer/printing/print_web_view_helper.h" | 5 #include "chrome/renderer/printing/print_web_view_helper.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
15 #include "base/process/process_handle.h" | 15 #include "base/process/process_handle.h" |
16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
19 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
20 #include "chrome/common/print_messages.h" | 20 #include "chrome/common/print_messages.h" |
21 #include "chrome/common/render_messages.h" | 21 #include "chrome/common/render_messages.h" |
22 #include "chrome/grit/browser_resources.h" | 22 #include "chrome/grit/browser_resources.h" |
23 #include "chrome/renderer/prerender/prerender_helper.h" | 23 #include "chrome/renderer/prerender/prerender_helper.h" |
24 #include "content/public/common/web_preferences.h" | 24 #include "content/public/common/web_preferences.h" |
25 #include "content/public/renderer/render_frame.h" | 25 #include "content/public/renderer/render_frame.h" |
26 #include "content/public/renderer/render_thread.h" | 26 #include "content/public/renderer/render_thread.h" |
27 #include "content/public/renderer/render_view.h" | 27 #include "content/public/renderer/render_view.h" |
28 #include "net/base/escape.h" | 28 #include "net/base/escape.h" |
29 #include "printing/metafile.h" | |
30 #include "printing/pdf_metafile_skia.h" | 29 #include "printing/pdf_metafile_skia.h" |
31 #include "printing/units.h" | 30 #include "printing/units.h" |
32 #include "skia/ext/vector_platform_device_skia.h" | 31 #include "skia/ext/vector_platform_device_skia.h" |
33 #include "third_party/WebKit/public/platform/WebSize.h" | 32 #include "third_party/WebKit/public/platform/WebSize.h" |
34 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 33 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
35 #include "third_party/WebKit/public/web/WebConsoleMessage.h" | 34 #include "third_party/WebKit/public/web/WebConsoleMessage.h" |
36 #include "third_party/WebKit/public/web/WebDocument.h" | 35 #include "third_party/WebKit/public/web/WebDocument.h" |
37 #include "third_party/WebKit/public/web/WebElement.h" | 36 #include "third_party/WebKit/public/web/WebElement.h" |
38 #include "third_party/WebKit/public/web/WebFrameClient.h" | 37 #include "third_party/WebKit/public/web/WebFrameClient.h" |
39 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 38 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
(...skipping 1547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1587 print_pages_params_->pages.empty()); | 1586 print_pages_params_->pages.empty()); |
1588 prep_frame_view_->CopySelectionIfNeeded( | 1587 prep_frame_view_->CopySelectionIfNeeded( |
1589 render_view()->GetWebkitPreferences(), | 1588 render_view()->GetWebkitPreferences(), |
1590 base::Bind(&PrintWebViewHelper::OnFramePreparedForPrintPages, | 1589 base::Bind(&PrintWebViewHelper::OnFramePreparedForPrintPages, |
1591 base::Unretained(this))); | 1590 base::Unretained(this))); |
1592 return true; | 1591 return true; |
1593 } | 1592 } |
1594 | 1593 |
1595 #if defined(OS_POSIX) | 1594 #if defined(OS_POSIX) |
1596 bool PrintWebViewHelper::CopyMetafileDataToSharedMem( | 1595 bool PrintWebViewHelper::CopyMetafileDataToSharedMem( |
1597 Metafile* metafile, | 1596 PdfMetafileSkia* metafile, |
1598 base::SharedMemoryHandle* shared_mem_handle) { | 1597 base::SharedMemoryHandle* shared_mem_handle) { |
1599 uint32 buf_size = metafile->GetDataSize(); | 1598 uint32 buf_size = metafile->GetDataSize(); |
1600 scoped_ptr<base::SharedMemory> shared_buf( | 1599 scoped_ptr<base::SharedMemory> shared_buf( |
1601 content::RenderThread::Get()->HostAllocateSharedMemoryBuffer( | 1600 content::RenderThread::Get()->HostAllocateSharedMemoryBuffer( |
1602 buf_size).release()); | 1601 buf_size).release()); |
1603 | 1602 |
1604 if (shared_buf) { | 1603 if (shared_buf) { |
1605 if (shared_buf->Map(buf_size)) { | 1604 if (shared_buf->Map(buf_size)) { |
1606 metafile->GetData(shared_buf->memory(), buf_size); | 1605 metafile->GetData(shared_buf->memory(), buf_size); |
1607 return shared_buf->GiveToProcess(base::GetCurrentProcessHandle(), | 1606 return shared_buf->GiveToProcess(base::GetCurrentProcessHandle(), |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1700 Send(new PrintHostMsg_CheckForCancel(routing_id(), | 1699 Send(new PrintHostMsg_CheckForCancel(routing_id(), |
1701 print_params.preview_ui_id, | 1700 print_params.preview_ui_id, |
1702 print_params.preview_request_id, | 1701 print_params.preview_request_id, |
1703 &cancel)); | 1702 &cancel)); |
1704 if (cancel) | 1703 if (cancel) |
1705 notify_browser_of_print_failure_ = false; | 1704 notify_browser_of_print_failure_ = false; |
1706 return cancel; | 1705 return cancel; |
1707 } | 1706 } |
1708 | 1707 |
1709 bool PrintWebViewHelper::PreviewPageRendered(int page_number, | 1708 bool PrintWebViewHelper::PreviewPageRendered(int page_number, |
1710 Metafile* metafile) { | 1709 PdfMetafileSkia* metafile) { |
1711 DCHECK_GE(page_number, FIRST_PAGE_INDEX); | 1710 DCHECK_GE(page_number, FIRST_PAGE_INDEX); |
1712 | 1711 |
1713 // For non-modifiable files, |metafile| should be NULL, so do not bother | 1712 // For non-modifiable files, |metafile| should be NULL, so do not bother |
1714 // sending a message. If we don't generate draft metafiles, |metafile| is | 1713 // sending a message. If we don't generate draft metafiles, |metafile| is |
1715 // NULL. | 1714 // NULL. |
1716 if (!print_preview_context_.IsModifiable() || | 1715 if (!print_preview_context_.IsModifiable() || |
1717 !print_preview_context_.generate_draft_pages()) { | 1716 !print_preview_context_.generate_draft_pages()) { |
1718 DCHECK(!metafile); | 1717 DCHECK(!metafile); |
1719 return true; | 1718 return true; |
1720 } | 1719 } |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2033 blink::WebConsoleMessage::LevelWarning, message)); | 2032 blink::WebConsoleMessage::LevelWarning, message)); |
2034 return false; | 2033 return false; |
2035 } | 2034 } |
2036 | 2035 |
2037 void PrintWebViewHelper::ScriptingThrottler::Reset() { | 2036 void PrintWebViewHelper::ScriptingThrottler::Reset() { |
2038 // Reset counter on successful print. | 2037 // Reset counter on successful print. |
2039 count_ = 0; | 2038 count_ = 0; |
2040 } | 2039 } |
2041 | 2040 |
2042 } // namespace printing | 2041 } // namespace printing |
OLD | NEW |