Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(408)

Side by Side Diff: components/printing/renderer/print_web_view_helper.cc

Issue 2389493002: Revert of Require WebLocalFrame to be created with a non-null client (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "components/printing/renderer/print_web_view_helper.h" 5 #include "components/printing/renderer/print_web_view_helper.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 520
521 blink::WebSize page_size(page_layout.margin_left + page_layout.margin_right + 521 blink::WebSize page_size(page_layout.margin_left + page_layout.margin_right +
522 page_layout.content_width, 522 page_layout.content_width,
523 page_layout.margin_top + page_layout.margin_bottom + 523 page_layout.margin_top + page_layout.margin_bottom +
524 page_layout.content_height); 524 page_layout.content_height);
525 525
526 blink::WebView* web_view = 526 blink::WebView* web_view =
527 blink::WebView::create(nullptr, blink::WebPageVisibilityStateVisible); 527 blink::WebView::create(nullptr, blink::WebPageVisibilityStateVisible);
528 web_view->settings()->setJavaScriptEnabled(true); 528 web_view->settings()->setJavaScriptEnabled(true);
529 529
530 blink::WebFrameClient frame_client; 530 blink::WebLocalFrame* frame =
531 blink::WebLocalFrame* frame = blink::WebLocalFrame::create( 531 blink::WebLocalFrame::create(blink::WebTreeScopeType::Document, NULL);
532 blink::WebTreeScopeType::Document, &frame_client);
533 web_view->setMainFrame(frame); 532 web_view->setMainFrame(frame);
534 blink::WebFrameWidget::create(nullptr, web_view, frame); 533 blink::WebFrameWidget* widget =
534 blink::WebFrameWidget::create(nullptr, web_view, frame);
535 535
536 base::StringValue html(ResourceBundle::GetSharedInstance().GetLocalizedString( 536 base::StringValue html(ResourceBundle::GetSharedInstance().GetLocalizedString(
537 IDR_PRINT_PREVIEW_PAGE)); 537 IDR_PRINT_PREVIEW_PAGE));
538 // Load page with script to avoid async operations. 538 // Load page with script to avoid async operations.
539 ExecuteScript(frame, kPageLoadScriptFormat, html); 539 ExecuteScript(frame, kPageLoadScriptFormat, html);
540 540
541 std::unique_ptr<base::DictionaryValue> options(new base::DictionaryValue()); 541 std::unique_ptr<base::DictionaryValue> options(new base::DictionaryValue());
542 options.reset(new base::DictionaryValue()); 542 options.reset(new base::DictionaryValue());
543 options->SetDouble(kSettingHeaderFooterDate, base::Time::Now().ToJsTime()); 543 options->SetDouble(kSettingHeaderFooterDate, base::Time::Now().ToJsTime());
544 options->SetDouble("width", page_size.width); 544 options->SetDouble("width", page_size.width);
545 options->SetDouble("height", page_size.height); 545 options->SetDouble("height", page_size.height);
546 options->SetDouble("topMargin", page_layout.margin_top); 546 options->SetDouble("topMargin", page_layout.margin_top);
547 options->SetDouble("bottomMargin", page_layout.margin_bottom); 547 options->SetDouble("bottomMargin", page_layout.margin_bottom);
548 options->SetString("pageNumber", 548 options->SetString("pageNumber",
549 base::StringPrintf("%d/%d", page_number, total_pages)); 549 base::StringPrintf("%d/%d", page_number, total_pages));
550 550
551 options->SetString("url", params.url); 551 options->SetString("url", params.url);
552 base::string16 title = source_frame.document().title(); 552 base::string16 title = source_frame.document().title();
553 options->SetString("title", title.empty() ? params.title : title); 553 options->SetString("title", title.empty() ? params.title : title);
554 554
555 ExecuteScript(frame, kPageSetupScriptFormat, *options); 555 ExecuteScript(frame, kPageSetupScriptFormat, *options);
556 556
557 blink::WebPrintParams webkit_params(page_size); 557 blink::WebPrintParams webkit_params(page_size);
558 webkit_params.printerDPI = GetDPI(&params); 558 webkit_params.printerDPI = GetDPI(&params);
559 559
560 frame->printBegin(webkit_params); 560 frame->printBegin(webkit_params);
561 frame->printPage(0, canvas); 561 frame->printPage(0, canvas);
562 frame->printEnd(); 562 frame->printEnd();
563 563
564 widget->close();
564 web_view->close(); 565 web_view->close();
566 frame->close();
565 } 567 }
566 #endif // defined(ENABLE_PRINT_PREVIEW) 568 #endif // defined(ENABLE_PRINT_PREVIEW)
567 569
568 // static - Not anonymous so that platform implementations can use it. 570 // static - Not anonymous so that platform implementations can use it.
569 float PrintWebViewHelper::RenderPageContent(blink::WebFrame* frame, 571 float PrintWebViewHelper::RenderPageContent(blink::WebFrame* frame,
570 int page_number, 572 int page_number,
571 const gfx::Rect& canvas_area, 573 const gfx::Rect& canvas_area,
572 const gfx::Rect& content_area, 574 const gfx::Rect& content_area,
573 double scale_factor, 575 double scale_factor,
574 blink::WebCanvas* canvas) { 576 blink::WebCanvas* canvas) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 } 613 }
612 614
613 private: 615 private:
614 // blink::WebViewClient: 616 // blink::WebViewClient:
615 void didStopLoading() override; 617 void didStopLoading() override;
616 // TODO(ojan): Remove this override and have this class use a non-null 618 // TODO(ojan): Remove this override and have this class use a non-null
617 // layerTreeView. 619 // layerTreeView.
618 bool allowsBrokenNullLayerTreeView() const override; 620 bool allowsBrokenNullLayerTreeView() const override;
619 621
620 // blink::WebFrameClient: 622 // blink::WebFrameClient:
621 blink::WebLocalFrame* createChildFrame( 623 blink::WebFrame* createChildFrame(
622 blink::WebLocalFrame* parent, 624 blink::WebLocalFrame* parent,
623 blink::WebTreeScopeType scope, 625 blink::WebTreeScopeType scope,
624 const blink::WebString& name, 626 const blink::WebString& name,
625 const blink::WebString& unique_name, 627 const blink::WebString& unique_name,
626 blink::WebSandboxFlags sandbox_flags, 628 blink::WebSandboxFlags sandbox_flags,
627 const blink::WebFrameOwnerProperties& frame_owner_properties) override; 629 const blink::WebFrameOwnerProperties& frame_owner_properties) override;
630 void frameDetached(blink::WebLocalFrame* frame, DetachType type) override;
628 631
629 void CallOnReady(); 632 void CallOnReady();
630 void ResizeForPrinting(); 633 void ResizeForPrinting();
631 void RestoreSize(); 634 void RestoreSize();
632 void CopySelection(const WebPreferences& preferences); 635 void CopySelection(const WebPreferences& preferences);
633 636
634 FrameReference frame_; 637 FrameReference frame_;
635 blink::WebNode node_to_print_; 638 blink::WebNode node_to_print_;
636 bool owns_web_view_; 639 bool owns_web_view_;
637 blink::WebPrintParams web_print_params_; 640 blink::WebPrintParams web_print_params_;
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 768
766 void PrepareFrameAndViewForPrint::didStopLoading() { 769 void PrepareFrameAndViewForPrint::didStopLoading() {
767 DCHECK(!on_ready_.is_null()); 770 DCHECK(!on_ready_.is_null());
768 // Don't call callback here, because it can delete |this| and WebView that is 771 // Don't call callback here, because it can delete |this| and WebView that is
769 // called didStopLoading. 772 // called didStopLoading.
770 base::ThreadTaskRunnerHandle::Get()->PostTask( 773 base::ThreadTaskRunnerHandle::Get()->PostTask(
771 FROM_HERE, base::Bind(&PrepareFrameAndViewForPrint::CallOnReady, 774 FROM_HERE, base::Bind(&PrepareFrameAndViewForPrint::CallOnReady,
772 weak_ptr_factory_.GetWeakPtr())); 775 weak_ptr_factory_.GetWeakPtr()));
773 } 776 }
774 777
775 blink::WebLocalFrame* PrepareFrameAndViewForPrint::createChildFrame( 778 blink::WebFrame* PrepareFrameAndViewForPrint::createChildFrame(
776 blink::WebLocalFrame* parent, 779 blink::WebLocalFrame* parent,
777 blink::WebTreeScopeType scope, 780 blink::WebTreeScopeType scope,
778 const blink::WebString& name, 781 const blink::WebString& name,
779 const blink::WebString& unique_name, 782 const blink::WebString& unique_name,
780 blink::WebSandboxFlags sandbox_flags, 783 blink::WebSandboxFlags sandbox_flags,
781 const blink::WebFrameOwnerProperties& frame_owner_properties) { 784 const blink::WebFrameOwnerProperties& frame_owner_properties) {
782 blink::WebLocalFrame* frame = blink::WebLocalFrame::create(scope, this); 785 blink::WebFrame* frame = blink::WebLocalFrame::create(scope, this);
783 parent->appendChild(frame); 786 parent->appendChild(frame);
784 return frame; 787 return frame;
785 } 788 }
786 789
790 void PrepareFrameAndViewForPrint::frameDetached(blink::WebLocalFrame* frame,
791 DetachType type) {
792 DCHECK(type == DetachType::Remove);
793 if (frame->parent())
794 frame->parent()->removeChild(frame);
795 frame->close();
796 }
797
787 void PrepareFrameAndViewForPrint::CallOnReady() { 798 void PrepareFrameAndViewForPrint::CallOnReady() {
788 return on_ready_.Run(); // Can delete |this|. 799 return on_ready_.Run(); // Can delete |this|.
789 } 800 }
790 801
791 void PrepareFrameAndViewForPrint::RestoreSize() { 802 void PrepareFrameAndViewForPrint::RestoreSize() {
792 if (frame()) { 803 if (frame()) {
793 blink::WebView* web_view = frame_.GetFrame()->view(); 804 blink::WebView* web_view = frame_.GetFrame()->view();
794 web_view->resize(prev_view_size_); 805 web_view->resize(prev_view_size_);
795 if (blink::WebFrame* web_frame = web_view->mainFrame()) 806 if (blink::WebFrame* web_frame = web_view->mainFrame())
796 web_frame->setScrollOffset(prev_scroll_offset_); 807 web_frame->setScrollOffset(prev_scroll_offset_);
(...skipping 1453 matching lines...) Expand 10 before | Expand all | Expand 10 after
2250 blink::WebConsoleMessage::LevelWarning, message)); 2261 blink::WebConsoleMessage::LevelWarning, message));
2251 return false; 2262 return false;
2252 } 2263 }
2253 2264
2254 void PrintWebViewHelper::ScriptingThrottler::Reset() { 2265 void PrintWebViewHelper::ScriptingThrottler::Reset() {
2255 // Reset counter on successful print. 2266 // Reset counter on successful print.
2256 count_ = 0; 2267 count_ = 0;
2257 } 2268 }
2258 2269
2259 } // namespace printing 2270 } // namespace printing
OLDNEW
« no previous file with comments | « components/plugins/renderer/webview_plugin.cc ('k') | content/renderer/media/android/media_info_loader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698