Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/print_web_view_helper.h" | 5 #include "chrome/renderer/print_web_view_helper.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/process_util.h" | 9 #include "base/process_util.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/common/render_messages.h" | 11 #include "chrome/common/render_messages.h" |
| 12 #include "chrome/common/render_messages_params.h" | 12 #include "chrome/common/render_messages_params.h" |
| 13 #include "chrome/renderer/render_view.h" | 13 #include "chrome/renderer/render_view.h" |
| 14 #include "grit/generated_resources.h" | 14 #include "grit/generated_resources.h" |
| 15 #include "printing/units.h" | 15 #include "printing/units.h" |
| 16 #include "third_party/WebKit/WebKit/chromium/public/WebConsoleMessage.h" | 16 #include "third_party/WebKit/WebKit/chromium/public/WebConsoleMessage.h" |
| 17 #include "third_party/WebKit/WebKit/chromium/public/WebDocument.h" | |
| 18 #include "third_party/WebKit/WebKit/chromium/public/WebElement.h" | |
| 17 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" | 19 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" |
| 20 #include "third_party/WebKit/WebKit/chromium/public/WebNode.h" | |
| 18 #include "third_party/WebKit/WebKit/chromium/public/WebRect.h" | 21 #include "third_party/WebKit/WebKit/chromium/public/WebRect.h" |
| 19 #include "third_party/WebKit/WebKit/chromium/public/WebScreenInfo.h" | 22 #include "third_party/WebKit/WebKit/chromium/public/WebScreenInfo.h" |
| 20 #include "third_party/WebKit/WebKit/chromium/public/WebSize.h" | 23 #include "third_party/WebKit/WebKit/chromium/public/WebSize.h" |
| 21 #include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h" | 24 #include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h" |
| 22 #include "third_party/WebKit/WebKit/chromium/public/WebView.h" | 25 #include "third_party/WebKit/WebKit/chromium/public/WebView.h" |
| 23 #include "webkit/glue/webkit_glue.h" | 26 #include "webkit/glue/webkit_glue.h" |
| 24 | 27 |
| 25 using printing::ConvertPixelsToPoint; | 28 using printing::ConvertPixelsToPoint; |
| 26 using printing::ConvertPixelsToPointDouble; | 29 using printing::ConvertPixelsToPointDouble; |
| 27 using printing::ConvertUnit; | 30 using printing::ConvertUnit; |
| 28 using printing::ConvertUnitDouble; | 31 using printing::ConvertUnitDouble; |
| 29 using WebKit::WebConsoleMessage; | 32 using WebKit::WebConsoleMessage; |
| 30 using WebKit::WebFrame; | 33 using WebKit::WebFrame; |
| 34 using WebKit::WebPoint; | |
|
viettrungluu
2011/01/13 01:04:40
To be consistent with the file, maybe you should a
| |
| 31 using WebKit::WebRect; | 35 using WebKit::WebRect; |
| 32 using WebKit::WebSize; | 36 using WebKit::WebSize; |
| 33 using WebKit::WebScreenInfo; | 37 using WebKit::WebScreenInfo; |
| 34 using WebKit::WebString; | 38 using WebKit::WebString; |
| 35 using WebKit::WebURLRequest; | 39 using WebKit::WebURLRequest; |
| 36 using WebKit::WebView; | 40 using WebKit::WebView; |
| 37 | 41 |
| 38 PrepareFrameAndViewForPrint::PrepareFrameAndViewForPrint( | 42 PrepareFrameAndViewForPrint::PrepareFrameAndViewForPrint( |
| 39 const ViewMsg_Print_Params& print_params, | 43 const ViewMsg_Print_Params& print_params, |
| 40 WebFrame* frame, | 44 WebFrame* frame, |
| 45 WebKit::WebNode* node, | |
| 41 WebView* web_view) | 46 WebView* web_view) |
| 42 : frame_(frame), web_view_(web_view), expected_pages_count_(0), | 47 : frame_(frame), web_view_(web_view), expected_pages_count_(0), |
| 43 use_browser_overlays_(true) { | 48 use_browser_overlays_(true) { |
| 44 int dpi = static_cast<int>(print_params.dpi); | 49 int dpi = static_cast<int>(print_params.dpi); |
| 45 #if defined(OS_MACOSX) | 50 #if defined(OS_MACOSX) |
| 46 // On the Mac, the printable area is in points, don't do any scaling based | 51 // On the Mac, the printable area is in points, don't do any scaling based |
| 47 // on dpi. | 52 // on dpi. |
| 48 dpi = printing::kPointsPerInch; | 53 dpi = printing::kPointsPerInch; |
| 49 #endif // defined(OS_MACOSX) | 54 #endif // defined(OS_MACOSX) |
| 50 print_canvas_size_.set_width( | 55 print_canvas_size_.set_width( |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 62 // This is important for sites that try to fill the page. | 67 // This is important for sites that try to fill the page. |
| 63 gfx::Size print_layout_size(print_canvas_size_); | 68 gfx::Size print_layout_size(print_canvas_size_); |
| 64 print_layout_size.set_height(static_cast<int>( | 69 print_layout_size.set_height(static_cast<int>( |
| 65 static_cast<double>(print_layout_size.height()) * 1.25)); | 70 static_cast<double>(print_layout_size.height()) * 1.25)); |
| 66 | 71 |
| 67 prev_view_size_ = web_view->size(); | 72 prev_view_size_ = web_view->size(); |
| 68 | 73 |
| 69 web_view->resize(print_layout_size); | 74 web_view->resize(print_layout_size); |
| 70 | 75 |
| 71 expected_pages_count_ = frame->printBegin( | 76 expected_pages_count_ = frame->printBegin( |
| 72 print_canvas_size_, static_cast<int>(print_params.dpi), | 77 print_canvas_size_, |
| 78 node, | |
| 79 static_cast<int>(print_params.dpi), | |
| 73 &use_browser_overlays_); | 80 &use_browser_overlays_); |
| 74 } | 81 } |
| 75 | 82 |
| 76 PrepareFrameAndViewForPrint::~PrepareFrameAndViewForPrint() { | 83 PrepareFrameAndViewForPrint::~PrepareFrameAndViewForPrint() { |
| 77 frame_->printEnd(); | 84 frame_->printEnd(); |
| 78 web_view_->resize(prev_view_size_); | 85 web_view_->resize(prev_view_size_); |
| 79 } | 86 } |
| 80 | 87 |
| 81 | 88 |
| 82 PrintWebViewHelper::PrintWebViewHelper(RenderView* render_view) | 89 PrintWebViewHelper::PrintWebViewHelper(RenderView* render_view) |
| 83 : render_view_(render_view), | 90 : render_view_(render_view), |
| 84 print_web_view_(NULL), | 91 print_web_view_(NULL), |
| 85 user_cancelled_scripted_print_count_(0), | 92 user_cancelled_scripted_print_count_(0), |
| 86 is_preview_(false) {} | 93 is_preview_(false) {} |
| 87 | 94 |
| 88 PrintWebViewHelper::~PrintWebViewHelper() {} | 95 PrintWebViewHelper::~PrintWebViewHelper() {} |
| 89 | 96 |
| 90 void PrintWebViewHelper::Print(WebFrame* frame, | 97 void PrintWebViewHelper::Print(WebFrame* frame, |
| 91 bool script_initiated, | 98 bool script_initiated, |
| 92 bool is_preview) { | 99 bool is_preview) { |
| 100 Print(frame, NULL, script_initiated, is_preview); | |
| 101 } | |
| 102 | |
| 103 void PrintWebViewHelper::Print(WebKit::WebNode* node, | |
| 104 bool script_initiated, | |
| 105 bool is_preview) { | |
| 106 Print(node->document().frame(), node, script_initiated, is_preview); | |
| 107 } | |
| 108 | |
| 109 void PrintWebViewHelper::Print(WebKit::WebFrame* frame, | |
| 110 WebKit::WebNode* node, | |
| 111 bool script_initiated, | |
| 112 bool is_preview) { | |
| 93 const int kMinSecondsToIgnoreJavascriptInitiatedPrint = 2; | 113 const int kMinSecondsToIgnoreJavascriptInitiatedPrint = 2; |
| 94 const int kMaxSecondsToIgnoreJavascriptInitiatedPrint = 2 * 60; // 2 Minutes. | 114 const int kMaxSecondsToIgnoreJavascriptInitiatedPrint = 2 * 60; // 2 Minutes. |
| 95 | 115 |
| 96 // If still not finished with earlier print request simply ignore. | 116 // If still not finished with earlier print request simply ignore. |
| 97 if (IsPrinting()) | 117 if (IsPrinting()) |
| 98 return; | 118 return; |
| 99 | 119 |
| 100 // Check if there is script repeatedly trying to print and ignore it if too | 120 // Check if there is script repeatedly trying to print and ignore it if too |
| 101 // frequent. We use exponential wait time so for a page that calls print() in | 121 // frequent. We use exponential wait time so for a page that calls print() in |
| 102 // a loop the user will need to cancel the print dialog after 2 seconds, 4 | 122 // a loop the user will need to cancel the print dialog after 2 seconds, 4 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 115 WebConsoleMessage::LevelWarning, | 135 WebConsoleMessage::LevelWarning, |
| 116 message)); | 136 message)); |
| 117 return; | 137 return; |
| 118 } | 138 } |
| 119 } | 139 } |
| 120 | 140 |
| 121 bool print_cancelled = false; | 141 bool print_cancelled = false; |
| 122 is_preview_ = is_preview; | 142 is_preview_ = is_preview; |
| 123 | 143 |
| 124 // Initialize print settings. | 144 // Initialize print settings. |
| 125 if (!InitPrintSettings(frame)) | 145 if (!InitPrintSettings(frame, node)) |
| 126 return; // Failed to init print page settings. | 146 return; // Failed to init print page settings. |
| 127 | 147 |
| 128 int expected_pages_count = 0; | 148 int expected_pages_count = 0; |
| 129 bool use_browser_overlays = true; | 149 bool use_browser_overlays = true; |
| 130 | 150 |
| 131 // Prepare once to calculate the estimated page count. This must be in | 151 // Prepare once to calculate the estimated page count. This must be in |
| 132 // a scope for itself (see comments on PrepareFrameAndViewForPrint). | 152 // a scope for itself (see comments on PrepareFrameAndViewForPrint). |
| 133 { | 153 { |
| 134 PrepareFrameAndViewForPrint prep_frame_view( | 154 PrepareFrameAndViewForPrint prep_frame_view( |
| 135 (*print_pages_params_).params, frame, frame->view()); | 155 (*print_pages_params_).params, frame, node, frame->view()); |
| 136 expected_pages_count = prep_frame_view.GetExpectedPageCount(); | 156 expected_pages_count = prep_frame_view.GetExpectedPageCount(); |
| 137 if (expected_pages_count) | 157 if (expected_pages_count) |
| 138 use_browser_overlays = prep_frame_view.ShouldUseBrowserOverlays(); | 158 use_browser_overlays = prep_frame_view.ShouldUseBrowserOverlays(); |
| 139 } | 159 } |
| 140 | 160 |
| 141 // Some full screen plugins can say they don't want to print. | 161 // Some full screen plugins can say they don't want to print. |
| 142 if (expected_pages_count) { | 162 if (expected_pages_count) { |
| 143 if (!is_preview_) { | 163 if (!is_preview_) { |
| 144 // Ask the browser to show UI to retrieve the final print settings. | 164 // Ask the browser to show UI to retrieve the final print settings. |
| 145 if (!GetPrintSettingsFromUser(frame, expected_pages_count, | 165 if (!GetPrintSettingsFromUser(frame, expected_pages_count, |
| 146 use_browser_overlays)) { | 166 use_browser_overlays)) { |
| 147 print_cancelled = true; | 167 print_cancelled = true; |
| 148 } | 168 } |
| 149 } | 169 } |
| 150 | 170 |
| 151 // Render Pages for printing. | 171 // Render Pages for printing. |
| 152 if (!print_cancelled) { | 172 if (!print_cancelled) { |
| 153 if (is_preview_) | 173 if (is_preview_) |
| 154 RenderPagesForPreview(frame); | 174 RenderPagesForPreview(frame); |
| 155 else | 175 else |
| 156 RenderPagesForPrint(frame); | 176 RenderPagesForPrint(frame, node); |
| 157 | 177 |
| 158 // Reset cancel counter on first successful print. | 178 // Reset cancel counter on first successful print. |
| 159 user_cancelled_scripted_print_count_ = 0; | 179 user_cancelled_scripted_print_count_ = 0; |
| 160 return; // All went well. | 180 return; // All went well. |
| 161 } else { | 181 } else { |
| 162 if (script_initiated) { | 182 if (script_initiated) { |
| 163 ++user_cancelled_scripted_print_count_; | 183 ++user_cancelled_scripted_print_count_; |
| 164 last_cancelled_script_print_ = base::Time::Now(); | 184 last_cancelled_script_print_ = base::Time::Now(); |
| 165 } | 185 } |
| 166 } | 186 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 215 | 235 |
| 216 // When loading is done this will call DidStopLoading that will do the | 236 // When loading is done this will call DidStopLoading that will do the |
| 217 // actual printing. | 237 // actual printing. |
| 218 print_web_view_->mainFrame()->loadRequest(WebURLRequest(url)); | 238 print_web_view_->mainFrame()->loadRequest(WebURLRequest(url)); |
| 219 | 239 |
| 220 return true; | 240 return true; |
| 221 } | 241 } |
| 222 | 242 |
| 223 #if defined(OS_MACOSX) || defined(OS_WIN) | 243 #if defined(OS_MACOSX) || defined(OS_WIN) |
| 224 void PrintWebViewHelper::PrintPages(const ViewMsg_PrintPages_Params& params, | 244 void PrintWebViewHelper::PrintPages(const ViewMsg_PrintPages_Params& params, |
| 225 WebFrame* frame) { | 245 WebFrame* frame, |
| 246 WebKit::WebNode* node) { | |
| 226 ViewMsg_Print_Params printParams = params.params; | 247 ViewMsg_Print_Params printParams = params.params; |
| 227 UpdatePrintableSizeInPrintParameters(frame, &printParams); | 248 UpdatePrintableSizeInPrintParameters(frame, node, &printParams); |
| 228 | 249 |
| 229 PrepareFrameAndViewForPrint prep_frame_view(printParams, | 250 PrepareFrameAndViewForPrint prep_frame_view(printParams, |
| 230 frame, | 251 frame, |
| 252 node, | |
| 231 frame->view()); | 253 frame->view()); |
| 232 int page_count = prep_frame_view.GetExpectedPageCount(); | 254 int page_count = prep_frame_view.GetExpectedPageCount(); |
| 233 | 255 |
| 234 Send(new ViewHostMsg_DidGetPrintedPagesCount(routing_id(), | 256 Send(new ViewHostMsg_DidGetPrintedPagesCount(routing_id(), |
| 235 printParams.document_cookie, | 257 printParams.document_cookie, |
| 236 page_count)); | 258 page_count)); |
| 237 if (!page_count) | 259 if (!page_count) |
| 238 return; | 260 return; |
| 239 | 261 |
| 240 const gfx::Size& canvas_size = prep_frame_view.GetPrintCanvasSize(); | 262 const gfx::Size& canvas_size = prep_frame_view.GetPrintCanvasSize(); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 259 bool PrintWebViewHelper::Send(IPC::Message* msg) { | 281 bool PrintWebViewHelper::Send(IPC::Message* msg) { |
| 260 return render_view_->Send(msg); | 282 return render_view_->Send(msg); |
| 261 } | 283 } |
| 262 | 284 |
| 263 int32 PrintWebViewHelper::routing_id() { | 285 int32 PrintWebViewHelper::routing_id() { |
| 264 return render_view_->routing_id(); | 286 return render_view_->routing_id(); |
| 265 } | 287 } |
| 266 | 288 |
| 267 void PrintWebViewHelper::didStopLoading() { | 289 void PrintWebViewHelper::didStopLoading() { |
| 268 DCHECK(print_pages_params_.get() != NULL); | 290 DCHECK(print_pages_params_.get() != NULL); |
| 269 PrintPages(*print_pages_params_.get(), print_web_view_->mainFrame()); | 291 PrintPages(*print_pages_params_.get(), print_web_view_->mainFrame(), NULL); |
| 270 } | 292 } |
| 271 | 293 |
| 272 void PrintWebViewHelper::GetPageSizeAndMarginsInPoints( | 294 void PrintWebViewHelper::GetPageSizeAndMarginsInPoints( |
| 273 WebFrame* frame, | 295 WebFrame* frame, |
| 274 int page_index, | 296 int page_index, |
| 275 const ViewMsg_Print_Params& default_params, | 297 const ViewMsg_Print_Params& default_params, |
| 276 double* content_width_in_points, | 298 double* content_width_in_points, |
| 277 double* content_height_in_points, | 299 double* content_height_in_points, |
| 278 double* margin_top_in_points, | 300 double* margin_top_in_points, |
| 279 double* margin_right_in_points, | 301 double* margin_right_in_points, |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 344 ConvertPixelsToPointDouble(margin_right_in_pixels); | 366 ConvertPixelsToPointDouble(margin_right_in_pixels); |
| 345 if (margin_bottom_in_points) | 367 if (margin_bottom_in_points) |
| 346 *margin_bottom_in_points = | 368 *margin_bottom_in_points = |
| 347 ConvertPixelsToPointDouble(margin_bottom_in_pixels); | 369 ConvertPixelsToPointDouble(margin_bottom_in_pixels); |
| 348 if (margin_left_in_points) | 370 if (margin_left_in_points) |
| 349 *margin_left_in_points = | 371 *margin_left_in_points = |
| 350 ConvertPixelsToPointDouble(margin_left_in_pixels); | 372 ConvertPixelsToPointDouble(margin_left_in_pixels); |
| 351 } | 373 } |
| 352 | 374 |
| 353 void PrintWebViewHelper::UpdatePrintableSizeInPrintParameters( | 375 void PrintWebViewHelper::UpdatePrintableSizeInPrintParameters( |
| 354 WebFrame* frame, ViewMsg_Print_Params* params) { | 376 WebFrame* frame, |
| 377 WebKit::WebNode* node, | |
| 378 ViewMsg_Print_Params* params) { | |
| 355 double content_width_in_points; | 379 double content_width_in_points; |
| 356 double content_height_in_points; | 380 double content_height_in_points; |
| 357 double margin_top_in_points; | 381 double margin_top_in_points; |
| 358 double margin_right_in_points; | 382 double margin_right_in_points; |
| 359 double margin_bottom_in_points; | 383 double margin_bottom_in_points; |
| 360 double margin_left_in_points; | 384 double margin_left_in_points; |
| 361 PrepareFrameAndViewForPrint prepare(*params, frame, frame->view()); | 385 PrepareFrameAndViewForPrint prepare(*params, frame, node, frame->view()); |
| 362 PrintWebViewHelper::GetPageSizeAndMarginsInPoints(frame, 0, *params, | 386 PrintWebViewHelper::GetPageSizeAndMarginsInPoints(frame, 0, *params, |
| 363 &content_width_in_points, &content_height_in_points, | 387 &content_width_in_points, &content_height_in_points, |
| 364 &margin_top_in_points, &margin_right_in_points, | 388 &margin_top_in_points, &margin_right_in_points, |
| 365 &margin_bottom_in_points, &margin_left_in_points); | 389 &margin_bottom_in_points, &margin_left_in_points); |
| 366 | 390 |
| 367 #if defined(OS_MACOSX) | 391 #if defined(OS_MACOSX) |
| 368 params->page_size = gfx::Size( | 392 params->page_size = gfx::Size( |
| 369 static_cast<int>(content_width_in_points + | 393 static_cast<int>(content_width_in_points + |
| 370 margin_left_in_points + margin_right_in_points), | 394 margin_left_in_points + margin_right_in_points), |
| 371 static_cast<int>(content_height_in_points + | 395 static_cast<int>(content_height_in_points + |
| 372 margin_top_in_points + margin_bottom_in_points)); | 396 margin_top_in_points + margin_bottom_in_points)); |
| 373 | 397 |
| 374 params->printable_size = gfx::Size(static_cast<int>(content_width_in_points), | 398 params->printable_size = gfx::Size(static_cast<int>(content_width_in_points), |
| 375 static_cast<int>(content_height_in_points)); | 399 static_cast<int>(content_height_in_points)); |
| 376 #else | 400 #else |
| 377 params->printable_size = gfx::Size( | 401 params->printable_size = gfx::Size( |
| 378 static_cast<int>(ConvertUnitDouble( | 402 static_cast<int>(ConvertUnitDouble( |
| 379 content_width_in_points, printing::kPointsPerInch, params->dpi)), | 403 content_width_in_points, printing::kPointsPerInch, params->dpi)), |
| 380 static_cast<int>(ConvertUnitDouble( | 404 static_cast<int>(ConvertUnitDouble( |
| 381 content_height_in_points, printing::kPointsPerInch, params->dpi))); | 405 content_height_in_points, printing::kPointsPerInch, params->dpi))); |
| 382 #endif | 406 #endif |
| 383 params->margin_top = static_cast<int>(margin_top_in_points); | 407 params->margin_top = static_cast<int>(margin_top_in_points); |
| 384 params->margin_left = static_cast<int>(margin_left_in_points); | 408 params->margin_left = static_cast<int>(margin_left_in_points); |
| 385 } | 409 } |
| 386 | 410 |
| 387 bool PrintWebViewHelper::InitPrintSettings(WebFrame* frame) { | 411 bool PrintWebViewHelper::InitPrintSettings(WebFrame* frame, |
| 412 WebKit::WebNode* node) { | |
| 388 ViewMsg_PrintPages_Params settings; | 413 ViewMsg_PrintPages_Params settings; |
| 389 if (GetDefaultPrintSettings(frame, &settings.params)) { | 414 if (GetDefaultPrintSettings(frame, node, &settings.params)) { |
| 390 print_pages_params_.reset(new ViewMsg_PrintPages_Params(settings)); | 415 print_pages_params_.reset(new ViewMsg_PrintPages_Params(settings)); |
| 391 print_pages_params_->pages.clear(); | 416 print_pages_params_->pages.clear(); |
| 392 return true; | 417 return true; |
| 393 } | 418 } |
| 394 return false; | 419 return false; |
| 395 } | 420 } |
| 396 | 421 |
| 397 bool PrintWebViewHelper::GetDefaultPrintSettings( | 422 bool PrintWebViewHelper::GetDefaultPrintSettings( |
| 398 WebFrame* frame, ViewMsg_Print_Params* params) { | 423 WebFrame* frame, |
| 424 WebKit::WebNode* node, | |
| 425 ViewMsg_Print_Params* params) { | |
| 399 IPC::SyncMessage* msg = | 426 IPC::SyncMessage* msg = |
| 400 new ViewHostMsg_GetDefaultPrintSettings(routing_id(), params); | 427 new ViewHostMsg_GetDefaultPrintSettings(routing_id(), params); |
| 401 if (!Send(msg)) { | 428 if (!Send(msg)) { |
| 402 NOTREACHED(); | 429 NOTREACHED(); |
| 403 return false; | 430 return false; |
| 404 } | 431 } |
| 405 // Check if the printer returned any settings, if the settings is empty, we | 432 // Check if the printer returned any settings, if the settings is empty, we |
| 406 // can safely assume there are no printer drivers configured. So we safely | 433 // can safely assume there are no printer drivers configured. So we safely |
| 407 // terminate. | 434 // terminate. |
| 408 if (params->IsEmpty()) { | 435 if (params->IsEmpty()) { |
| 409 render_view_->runModalAlertDialog( | 436 render_view_->runModalAlertDialog( |
| 410 frame, | 437 frame, |
| 411 l10n_util::GetStringUTF16(IDS_DEFAULT_PRINTER_NOT_FOUND_WARNING)); | 438 l10n_util::GetStringUTF16(IDS_DEFAULT_PRINTER_NOT_FOUND_WARNING)); |
| 412 return false; | 439 return false; |
| 413 } | 440 } |
| 414 if (!(params->dpi && params->document_cookie)) { | 441 if (!(params->dpi && params->document_cookie)) { |
| 415 // Invalid print page settings. | 442 // Invalid print page settings. |
| 416 NOTREACHED(); | 443 NOTREACHED(); |
| 417 return false; | 444 return false; |
| 418 } | 445 } |
| 419 UpdatePrintableSizeInPrintParameters(frame, params); | 446 UpdatePrintableSizeInPrintParameters(frame, node, params); |
| 420 return true; | 447 return true; |
| 421 } | 448 } |
| 422 | 449 |
| 423 bool PrintWebViewHelper::GetPrintSettingsFromUser(WebFrame* frame, | 450 bool PrintWebViewHelper::GetPrintSettingsFromUser(WebFrame* frame, |
| 424 int expected_pages_count, | 451 int expected_pages_count, |
| 425 bool use_browser_overlays) { | 452 bool use_browser_overlays) { |
| 426 ViewHostMsg_ScriptedPrint_Params params; | 453 ViewHostMsg_ScriptedPrint_Params params; |
| 427 ViewMsg_PrintPages_Params print_settings; | 454 ViewMsg_PrintPages_Params print_settings; |
| 428 | 455 |
| 429 // The routing id is sent across as it is needed to look up the | 456 // The routing id is sent across as it is needed to look up the |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 445 msg->EnableMessagePumping(); | 472 msg->EnableMessagePumping(); |
| 446 if (Send(msg)) { | 473 if (Send(msg)) { |
| 447 print_pages_params_.reset(new ViewMsg_PrintPages_Params(print_settings)); | 474 print_pages_params_.reset(new ViewMsg_PrintPages_Params(print_settings)); |
| 448 } else { | 475 } else { |
| 449 // Send() failed. | 476 // Send() failed. |
| 450 NOTREACHED(); | 477 NOTREACHED(); |
| 451 return false; | 478 return false; |
| 452 } | 479 } |
| 453 return (print_settings.params.dpi && print_settings.params.document_cookie); | 480 return (print_settings.params.dpi && print_settings.params.document_cookie); |
| 454 } | 481 } |
| 455 | 482 |
|
viettrungluu
2011/01/13 01:04:40
Could you change that to |WebFrame* frame| while y
| |
| 456 void PrintWebViewHelper::RenderPagesForPrint(WebFrame *frame) { | 483 void PrintWebViewHelper::RenderPagesForPrint(WebFrame *frame, |
| 484 WebKit::WebNode* node) { | |
| 457 ViewMsg_PrintPages_Params print_settings = *print_pages_params_; | 485 ViewMsg_PrintPages_Params print_settings = *print_pages_params_; |
| 458 if (print_settings.params.selection_only) { | 486 if (print_settings.params.selection_only) { |
| 459 CopyAndPrint(frame); | 487 CopyAndPrint(frame); |
| 460 } else { | 488 } else { |
| 461 // TODO: Always copy before printing. | 489 // TODO: Always copy before printing. |
| 462 PrintPages(print_settings, frame); | 490 PrintPages(print_settings, frame, node); |
| 463 } | 491 } |
| 464 } | 492 } |
| 465 | 493 |
| 466 void PrintWebViewHelper::RenderPagesForPreview(WebFrame *frame) { | 494 void PrintWebViewHelper::RenderPagesForPreview(WebFrame *frame) { |
| 467 ViewMsg_PrintPages_Params print_settings = *print_pages_params_; | 495 ViewMsg_PrintPages_Params print_settings = *print_pages_params_; |
| 468 ViewHostMsg_DidPreviewDocument_Params print_params; | 496 ViewHostMsg_DidPreviewDocument_Params print_params; |
| 469 CreatePreviewDocument(print_settings, frame, &print_params); | 497 CreatePreviewDocument(print_settings, frame, &print_params); |
| 470 Send(new ViewHostMsg_PagesReadyForPreview(routing_id(), print_params)); | 498 Send(new ViewHostMsg_PagesReadyForPreview(routing_id(), print_params)); |
| 471 } | 499 } |
| 472 | 500 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 494 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), | 522 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), |
| 495 shared_mem_handle); | 523 shared_mem_handle); |
| 496 return true; | 524 return true; |
| 497 } | 525 } |
| 498 } | 526 } |
| 499 } | 527 } |
| 500 NOTREACHED(); | 528 NOTREACHED(); |
| 501 return false; | 529 return false; |
| 502 } | 530 } |
| 503 #endif | 531 #endif |
| OLD | NEW |