diff options
author | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-24 23:22:28 +0000 |
---|---|---|
committer | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-24 23:22:28 +0000 |
commit | 116d0963cadfbf55ef2ec3d13781987c4d80517a (patch) | |
tree | a7e5b7ceabdad7e6386a87b7f813a79dc57f94a0 /chrome/renderer | |
parent | 0ccc7e3af6db2fc2ce09ebcd780dace294adeb61 (diff) | |
download | chromium_src-116d0963cadfbf55ef2ec3d13781987c4d80517a.zip chromium_src-116d0963cadfbf55ef2ec3d13781987c4d80517a.tar.gz chromium_src-116d0963cadfbf55ef2ec3d13781987c4d80517a.tar.bz2 |
Print preview: Use an ID instead of memory pointer string in WebUI.
BUG=144051
Review URL: https://chromiumcodereview.appspot.com/10870003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@153342 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
-rw-r--r-- | chrome/renderer/chrome_mock_render_thread.cc | 87 | ||||
-rw-r--r-- | chrome/renderer/chrome_mock_render_thread.h | 19 | ||||
-rw-r--r-- | chrome/renderer/print_web_view_helper.cc | 14 | ||||
-rw-r--r-- | chrome/renderer/print_web_view_helper_browsertest.cc | 4 |
4 files changed, 65 insertions, 59 deletions
diff --git a/chrome/renderer/chrome_mock_render_thread.cc b/chrome/renderer/chrome_mock_render_thread.cc index b946dd6..dd72285 100644 --- a/chrome/renderer/chrome_mock_render_thread.cc +++ b/chrome/renderer/chrome_mock_render_thread.cc @@ -4,20 +4,23 @@ #include "chrome/renderer/chrome_mock_render_thread.h" -#include <fcntl.h> +#include <vector> -#include "base/file_util.h" -#include "base/process_util.h" +#include "base/values.h" #include "chrome/common/extensions/extension_messages.h" #include "chrome/common/print_messages.h" -#include "chrome/common/render_messages.h" -#include "chrome/common/url_constants.h" -#include "ipc/ipc_message_utils.h" +#include "chrome/renderer/mock_printer.h" #include "ipc/ipc_sync_message.h" #include "printing/print_job_constants.h" #include "printing/page_range.h" #include "testing/gtest/include/gtest/gtest.h" +#if defined(OS_CHROMEOS) +#include <fcntl.h> + +#include "base/file_util.h" +#endif + ChromeMockRenderThread::ChromeMockRenderThread() : printer_(new MockPrinter), print_dialog_user_response_(true), @@ -64,9 +67,11 @@ bool ChromeMockRenderThread::OnMessageReceived(const IPC::Message& msg) { } void ChromeMockRenderThread::OnMsgOpenChannelToExtension( - int routing_id, const std::string& source_extension_id, + int routing_id, + const std::string& source_extension_id, const std::string& target_extension_id, - const std::string& channel_name, int* port_id) { + const std::string& channel_name, + int* port_id) { *port_id = 0; } @@ -93,14 +98,13 @@ void ChromeMockRenderThread::OnTempFileForPrintingWritten(int render_view_id, void ChromeMockRenderThread::OnGetDefaultPrintSettings( PrintMsg_Print_Params* params) { - if (printer_.get()) - printer_->GetDefaultPrintSettings(params); + printer_->GetDefaultPrintSettings(params); } void ChromeMockRenderThread::OnScriptedPrint( const PrintHostMsg_ScriptedPrint_Params& params, PrintMsg_PrintPages_Params* settings) { - if (print_dialog_user_response_ && printer_.get()) { + if (print_dialog_user_response_) { printer_->ScriptedPrint(params.cookie, params.expected_pages_count, params.has_selection, @@ -110,14 +114,12 @@ void ChromeMockRenderThread::OnScriptedPrint( void ChromeMockRenderThread::OnDidGetPrintedPagesCount( int cookie, int number_pages) { - if (printer_.get()) - printer_->SetPrintedPagesCount(cookie, number_pages); + printer_->SetPrintedPagesCount(cookie, number_pages); } void ChromeMockRenderThread::OnDidPrintPage( const PrintHostMsg_DidPrintPage_Params& params) { - if (printer_.get()) - printer_->PrintPage(params); + printer_->PrintPage(params); } void ChromeMockRenderThread::OnDidGetPreviewPageCount( @@ -127,14 +129,13 @@ void ChromeMockRenderThread::OnDidGetPreviewPageCount( void ChromeMockRenderThread::OnDidPreviewPage( const PrintHostMsg_DidPreviewPage_Params& params) { - DCHECK(params.page_number >= printing::FIRST_PAGE_INDEX); + DCHECK_GE(params.page_number, printing::FIRST_PAGE_INDEX); print_preview_pages_remaining_--; } -void ChromeMockRenderThread::OnCheckForCancel( - const std::string& preview_ui_addr, - int preview_request_id, - bool* cancel) { +void ChromeMockRenderThread::OnCheckForCancel(int32 preview_ui_id, + int preview_request_id, + bool* cancel) { *cancel = (print_preview_pages_remaining_ == print_preview_cancel_page_number_); } @@ -155,36 +156,38 @@ void ChromeMockRenderThread::OnUpdatePrintSettings( !job_settings.GetString(printing::kSettingDeviceName, &dummy_string) || !job_settings.GetInteger(printing::kSettingDuplexMode, NULL) || !job_settings.GetInteger(printing::kSettingCopies, NULL) || - !job_settings.GetString(printing::kPreviewUIAddr, &dummy_string) || + !job_settings.GetInteger(printing::kPreviewUIID, NULL) || !job_settings.GetInteger(printing::kPreviewRequestID, NULL) || !job_settings.GetInteger(printing::kSettingMarginsType, &margins_type)) { return; } // Just return the default settings. - if (printer_.get()) { - const ListValue* page_range_array; - printing::PageRanges new_ranges; - if (job_settings.GetList(printing::kSettingPageRange, &page_range_array)) { - for (size_t index = 0; index < page_range_array->GetSize(); ++index) { - const base::DictionaryValue* dict; - if (!page_range_array->GetDictionary(index, &dict)) - continue; - printing::PageRange range; - if (!dict->GetInteger(printing::kSettingPageRangeFrom, &range.from) || - !dict->GetInteger(printing::kSettingPageRangeTo, &range.to)) { - continue; - } - // Page numbers are 1-based in the dictionary. - // Page numbers are 0-based for the printing context. - range.from--; - range.to--; - new_ranges.push_back(range); + const ListValue* page_range_array; + printing::PageRanges new_ranges; + if (job_settings.GetList(printing::kSettingPageRange, &page_range_array)) { + for (size_t index = 0; index < page_range_array->GetSize(); ++index) { + const base::DictionaryValue* dict; + if (!page_range_array->GetDictionary(index, &dict)) + continue; + printing::PageRange range; + if (!dict->GetInteger(printing::kSettingPageRangeFrom, &range.from) || + !dict->GetInteger(printing::kSettingPageRangeTo, &range.to)) { + continue; } + // Page numbers are 1-based in the dictionary. + // Page numbers are 0-based for the printing context. + range.from--; + range.to--; + new_ranges.push_back(range); } - std::vector<int> pages(printing::PageRange::GetPages(new_ranges)); - printer_->UpdateSettings(document_cookie, params, pages, margins_type); } + std::vector<int> pages(printing::PageRange::GetPages(new_ranges)); + printer_->UpdateSettings(document_cookie, params, pages, margins_type); +} + +MockPrinter* ChromeMockRenderThread::printer() { + return printer_.get(); } void ChromeMockRenderThread::set_print_dialog_user_response(bool response) { @@ -195,6 +198,6 @@ void ChromeMockRenderThread::set_print_preview_cancel_page_number(int page) { print_preview_cancel_page_number_ = page; } -int ChromeMockRenderThread::print_preview_pages_remaining() { +int ChromeMockRenderThread::print_preview_pages_remaining() const { return print_preview_pages_remaining_; } diff --git a/chrome/renderer/chrome_mock_render_thread.h b/chrome/renderer/chrome_mock_render_thread.h index f0bef66..5db8826 100644 --- a/chrome/renderer/chrome_mock_render_thread.h +++ b/chrome/renderer/chrome_mock_render_thread.h @@ -8,16 +8,16 @@ #include <string> #include "base/compiler_specific.h" -#include "chrome/common/extensions/extension_set.h" -#include "chrome/renderer/mock_printer.h" #include "content/public/test/mock_render_thread.h" namespace base { class DictionaryValue; } +class MockPrinter; struct PrintHostMsg_DidGetPreviewPageCount_Params; struct PrintHostMsg_DidPreviewPage_Params; +struct PrintHostMsg_DidPrintPage_Params; struct PrintHostMsg_ScriptedPrint_Params; struct PrintMsg_PrintPages_Params; struct PrintMsg_Print_Params; @@ -33,7 +33,7 @@ class ChromeMockRenderThread : public content::MockRenderThread { // The following functions are called by the test itself. // Returns the pseudo-printer instance. - MockPrinter* printer() const { return printer_.get(); } + MockPrinter* printer(); // Call with |response| set to true if the user wants to print. // False if the user decides to cancel. @@ -43,7 +43,7 @@ class ChromeMockRenderThread : public content::MockRenderThread { void set_print_preview_cancel_page_number(int page); // Get the number of pages to generate for print preview. - int print_preview_pages_remaining(); + int print_preview_pages_remaining() const; private: // Overrides base class implementation to add custom handling for @@ -51,10 +51,11 @@ class ChromeMockRenderThread : public content::MockRenderThread { virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; // The callee expects to be returned a valid channel_id. - void OnMsgOpenChannelToExtension( - int routing_id, const std::string& extension_id, - const std::string& source_extension_id, - const std::string& target_extension_id, int* port_id); + void OnMsgOpenChannelToExtension(int routing_id, + const std::string& extension_id, + const std::string& source_extension_id, + const std::string& target_extension_id, + int* port_id); #if defined(OS_CHROMEOS) void OnAllocateTempFileForPrinting(base::FileDescriptor* renderer_fd, @@ -74,7 +75,7 @@ class ChromeMockRenderThread : public content::MockRenderThread { void OnDidGetPreviewPageCount( const PrintHostMsg_DidGetPreviewPageCount_Params& params); void OnDidPreviewPage(const PrintHostMsg_DidPreviewPage_Params& params); - void OnCheckForCancel(const std::string& preview_ui_addr, + void OnCheckForCancel(int32 preview_ui_id, int preview_request_id, bool* cancel); diff --git a/chrome/renderer/print_web_view_helper.cc b/chrome/renderer/print_web_view_helper.cc index acbc450..0e03cc0 100644 --- a/chrome/renderer/print_web_view_helper.cc +++ b/chrome/renderer/print_web_view_helper.cc @@ -1437,8 +1437,8 @@ bool PrintWebViewHelper::UpdatePrintSettings( if (!print_for_preview_) { // Validate expected print preview settings. - if (!job_settings->GetString(printing::kPreviewUIAddr, - &(settings.params.preview_ui_addr)) || + if (!job_settings->GetInteger(printing::kPreviewUIID, + &(settings.params.preview_ui_id)) || !job_settings->GetInteger(printing::kPreviewRequestID, &(settings.params.preview_request_id)) || !job_settings->GetBoolean(printing::kIsFirstRequest, @@ -1608,12 +1608,12 @@ void PrintWebViewHelper::RequestPrintPreview(PrintPreviewRequestType type) { } bool PrintWebViewHelper::CheckForCancel() { + const PrintMsg_Print_Params& print_params = print_pages_params_->params; bool cancel = false; - Send(new PrintHostMsg_CheckForCancel( - routing_id(), - print_pages_params_->params.preview_ui_addr, - print_pages_params_->params.preview_request_id, - &cancel)); + Send(new PrintHostMsg_CheckForCancel(routing_id(), + print_params.preview_ui_id, + print_params.preview_request_id, + &cancel)); if (cancel) notify_browser_of_print_failure_ = false; return cancel; diff --git a/chrome/renderer/print_web_view_helper_browsertest.cc b/chrome/renderer/print_web_view_helper_browsertest.cc index b06418f..c494634 100644 --- a/chrome/renderer/print_web_view_helper_browsertest.cc +++ b/chrome/renderer/print_web_view_helper_browsertest.cc @@ -2,8 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/command_line.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/print_messages.h" +#include "chrome/renderer/mock_printer.h" #include "chrome/renderer/print_web_view_helper.h" #include "chrome/test/base/chrome_render_view_test.h" #include "content/public/renderer/render_view.h" @@ -70,7 +72,7 @@ void CreatePrintSettingsDictionary(DictionaryValue* dict) { dict->SetInteger(printing::kSettingDuplexMode, printing::SIMPLEX); dict->SetInteger(printing::kSettingCopies, 1); dict->SetString(printing::kSettingDeviceName, "dummy"); - dict->SetString(printing::kPreviewUIAddr, "0xb33fbeef"); + dict->SetInteger(printing::kPreviewUIID, 4); dict->SetInteger(printing::kPreviewRequestID, 12345); dict->SetBoolean(printing::kIsFirstRequest, true); dict->SetInteger(printing::kSettingMarginsType, printing::DEFAULT_MARGINS); |