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

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

Issue 1141283002: Replicate whether a frame is in a document or shadow tree. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix typo Created 5 years, 7 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
« no previous file with comments | « components/plugins/renderer/webview_plugin.cc ('k') | content/browser/DEPS » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <string> 7 #include <string>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 canvas->scale(1 / webkit_scale_factor, 1 / webkit_scale_factor); 486 canvas->scale(1 / webkit_scale_factor, 1 / webkit_scale_factor);
487 487
488 blink::WebSize page_size(page_layout.margin_left + page_layout.margin_right + 488 blink::WebSize page_size(page_layout.margin_left + page_layout.margin_right +
489 page_layout.content_width, 489 page_layout.content_width,
490 page_layout.margin_top + page_layout.margin_bottom + 490 page_layout.margin_top + page_layout.margin_bottom +
491 page_layout.content_height); 491 page_layout.content_height);
492 492
493 blink::WebView* web_view = blink::WebView::create(NULL); 493 blink::WebView* web_view = blink::WebView::create(NULL);
494 web_view->settings()->setJavaScriptEnabled(true); 494 web_view->settings()->setJavaScriptEnabled(true);
495 495
496 blink::WebLocalFrame* frame = blink::WebLocalFrame::create(NULL); 496 blink::WebLocalFrame* frame =
497 blink::WebLocalFrame::create(blink::WebTreeScopeType::Document, NULL);
497 web_view->setMainFrame(frame); 498 web_view->setMainFrame(frame);
498 499
499 base::StringValue html(ResourceBundle::GetSharedInstance().GetLocalizedString( 500 base::StringValue html(ResourceBundle::GetSharedInstance().GetLocalizedString(
500 IDR_PRINT_PREVIEW_PAGE)); 501 IDR_PRINT_PREVIEW_PAGE));
501 // Load page with script to avoid async operations. 502 // Load page with script to avoid async operations.
502 ExecuteScript(frame, kPageLoadScriptFormat, html); 503 ExecuteScript(frame, kPageLoadScriptFormat, html);
503 504
504 scoped_ptr<base::DictionaryValue> options(new base::DictionaryValue()); 505 scoped_ptr<base::DictionaryValue> options(new base::DictionaryValue());
505 options.reset(new base::DictionaryValue()); 506 options.reset(new base::DictionaryValue());
506 options->SetDouble(kSettingHeaderFooterDate, base::Time::Now().ToJsTime()); 507 options->SetDouble(kSettingHeaderFooterDate, base::Time::Now().ToJsTime());
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 // TODO(ojan): Remove this override and have this class use a non-null 580 // TODO(ojan): Remove this override and have this class use a non-null
580 // layerTreeView. 581 // layerTreeView.
581 // blink::WebViewClient override: 582 // blink::WebViewClient override:
582 virtual bool allowsBrokenNullLayerTreeView() const; 583 virtual bool allowsBrokenNullLayerTreeView() const;
583 584
584 protected: 585 protected:
585 // blink::WebViewClient override: 586 // blink::WebViewClient override:
586 virtual void didStopLoading(); 587 virtual void didStopLoading();
587 588
588 // blink::WebFrameClient override: 589 // blink::WebFrameClient override:
589 virtual blink::WebFrame* createChildFrame( 590 virtual blink::WebFrame* createChildFrame(
Lei Zhang 2015/05/22 01:59:40 random comment: should these be override?
dcheng 2015/05/22 02:01:00 We generally avoid marking Blink overrides with 'o
590 blink::WebLocalFrame* parent, 591 blink::WebLocalFrame* parent,
592 blink::WebTreeScopeType scope,
591 const blink::WebString& name, 593 const blink::WebString& name,
592 blink::WebSandboxFlags sandboxFlags); 594 blink::WebSandboxFlags sandboxFlags);
593 virtual void frameDetached(blink::WebFrame* frame); 595 virtual void frameDetached(blink::WebFrame* frame);
594 596
595 private: 597 private:
596 void CallOnReady(); 598 void CallOnReady();
597 void ResizeForPrinting(); 599 void ResizeForPrinting();
598 void RestoreSize(); 600 void RestoreSize();
599 void CopySelection(const WebPreferences& preferences); 601 void CopySelection(const WebPreferences& preferences);
600 602
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 // Create a new WebView with the same settings as the current display one. 702 // Create a new WebView with the same settings as the current display one.
701 // Except that we disable javascript (don't want any active content running 703 // Except that we disable javascript (don't want any active content running
702 // on the page). 704 // on the page).
703 WebPreferences prefs = preferences; 705 WebPreferences prefs = preferences;
704 prefs.javascript_enabled = false; 706 prefs.javascript_enabled = false;
705 prefs.java_enabled = false; 707 prefs.java_enabled = false;
706 708
707 blink::WebView* web_view = blink::WebView::create(this); 709 blink::WebView* web_view = blink::WebView::create(this);
708 owns_web_view_ = true; 710 owns_web_view_ = true;
709 content::RenderView::ApplyWebPreferences(prefs, web_view); 711 content::RenderView::ApplyWebPreferences(prefs, web_view);
710 web_view->setMainFrame(blink::WebLocalFrame::create(this)); 712 web_view->setMainFrame(
713 blink::WebLocalFrame::create(blink::WebTreeScopeType::Document, this));
711 frame_.Reset(web_view->mainFrame()->toWebLocalFrame()); 714 frame_.Reset(web_view->mainFrame()->toWebLocalFrame());
712 node_to_print_.reset(); 715 node_to_print_.reset();
713 716
714 // When loading is done this will call didStopLoading() and that will do the 717 // When loading is done this will call didStopLoading() and that will do the
715 // actual printing. 718 // actual printing.
716 frame()->loadRequest(blink::WebURLRequest(GURL(url_str))); 719 frame()->loadRequest(blink::WebURLRequest(GURL(url_str)));
717 } 720 }
718 721
719 bool PrepareFrameAndViewForPrint::allowsBrokenNullLayerTreeView() const { 722 bool PrepareFrameAndViewForPrint::allowsBrokenNullLayerTreeView() const {
720 return true; 723 return true;
721 } 724 }
722 725
723 void PrepareFrameAndViewForPrint::didStopLoading() { 726 void PrepareFrameAndViewForPrint::didStopLoading() {
724 DCHECK(!on_ready_.is_null()); 727 DCHECK(!on_ready_.is_null());
725 // Don't call callback here, because it can delete |this| and WebView that is 728 // Don't call callback here, because it can delete |this| and WebView that is
726 // called didStopLoading. 729 // called didStopLoading.
727 base::MessageLoop::current()->PostTask( 730 base::MessageLoop::current()->PostTask(
728 FROM_HERE, base::Bind(&PrepareFrameAndViewForPrint::CallOnReady, 731 FROM_HERE, base::Bind(&PrepareFrameAndViewForPrint::CallOnReady,
729 weak_ptr_factory_.GetWeakPtr())); 732 weak_ptr_factory_.GetWeakPtr()));
730 } 733 }
731 734
732 blink::WebFrame* PrepareFrameAndViewForPrint::createChildFrame( 735 blink::WebFrame* PrepareFrameAndViewForPrint::createChildFrame(
733 blink::WebLocalFrame* parent, 736 blink::WebLocalFrame* parent,
737 blink::WebTreeScopeType scope,
734 const blink::WebString& name, 738 const blink::WebString& name,
735 blink::WebSandboxFlags sandboxFlags) { 739 blink::WebSandboxFlags sandboxFlags) {
736 blink::WebFrame* frame = blink::WebLocalFrame::create(this); 740 blink::WebFrame* frame = blink::WebLocalFrame::create(scope, this);
737 parent->appendChild(frame); 741 parent->appendChild(frame);
738 return frame; 742 return frame;
739 } 743 }
740 744
741 void PrepareFrameAndViewForPrint::frameDetached(blink::WebFrame* frame) { 745 void PrepareFrameAndViewForPrint::frameDetached(blink::WebFrame* frame) {
742 if (frame->parent()) 746 if (frame->parent())
743 frame->parent()->removeChild(frame); 747 frame->parent()->removeChild(frame);
744 frame->close(); 748 frame->close();
745 } 749 }
746 750
(...skipping 1317 matching lines...) Expand 10 before | Expand all | Expand 10 after
2064 blink::WebConsoleMessage::LevelWarning, message)); 2068 blink::WebConsoleMessage::LevelWarning, message));
2065 return false; 2069 return false;
2066 } 2070 }
2067 2071
2068 void PrintWebViewHelper::ScriptingThrottler::Reset() { 2072 void PrintWebViewHelper::ScriptingThrottler::Reset() {
2069 // Reset counter on successful print. 2073 // Reset counter on successful print.
2070 count_ = 0; 2074 count_ = 0;
2071 } 2075 }
2072 2076
2073 } // namespace printing 2077 } // namespace printing
OLDNEW
« no previous file with comments | « components/plugins/renderer/webview_plugin.cc ('k') | content/browser/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698