Index: chrome/browser/ui/webui/print_preview/print_preview_distiller.cc |
diff --git a/chrome/browser/ui/webui/print_preview/print_preview_distiller.cc b/chrome/browser/ui/webui/print_preview/print_preview_distiller.cc |
index 213078ceb85605bc3e15201f11a47283ef373f82..6dc6db85ded55449c6c8878d80e4c6678a2554e5 100644 |
--- a/chrome/browser/ui/webui/print_preview/print_preview_distiller.cc |
+++ b/chrome/browser/ui/webui/print_preview/print_preview_distiller.cc |
@@ -21,6 +21,7 @@ |
#include "chrome/common/prerender_messages.h" |
#include "components/dom_distiller/content/browser/distiller_javascript_utils.h" |
#include "components/printing/common/print_messages.h" |
+#include "content/public/browser/navigation_details.h" |
#include "content/public/browser/notification_service.h" |
#include "content/public/browser/render_frame_host.h" |
#include "content/public/browser/render_process_host.h" |
@@ -135,25 +136,10 @@ class PrintPreviewDistiller::WebContentsDelegateImpl |
render_frame_host->GetRoutingID(), true)); |
} |
- void DidFinishLoad(content::RenderFrameHost* render_frame_host, |
- const GURL& validated_url) override { |
- // Ask the page to trigger an anchor navigation once the distilled |
- // contents are added to the page. |
- dom_distiller::RunIsolatedJavaScript( |
- web_contents()->GetMainFrame(), |
- "navigate_on_initial_content_load = true;"); |
- } |
- |
- void DidNavigateMainFrame( |
- const content::LoadCommittedDetails& details, |
- const content::FrameNavigateParams& params) override { |
- // The second content loads signals that the distilled contents have |
- // been delivered to the page via inline JavaScript execution. |
- if (web_contents()->GetController().GetEntryCount() > 1) { |
- RenderViewHost* rvh = web_contents()->GetRenderViewHost(); |
- rvh->Send(new PrintMsg_InitiatePrintPreview(rvh->GetRoutingID(), false)); |
- rvh->Send(new PrintMsg_PrintPreview(rvh->GetRoutingID(), *settings_)); |
- } |
+ void DoPrintPreview() { |
+ RenderViewHost* rvh = web_contents()->GetRenderViewHost(); |
+ rvh->Send(new PrintMsg_InitiatePrintPreview(rvh->GetRoutingID(), false)); |
+ rvh->Send(new PrintMsg_PrintPreview(rvh->GetRoutingID(), *settings_)); |
} |
void DidGetRedirectForResourceRequest( |
@@ -169,6 +155,21 @@ class PrintPreviewDistiller::WebContentsDelegateImpl |
on_failed_callback_.Run(); |
} |
+ void DidNavigateMainFrame( |
+ const content::LoadCommittedDetails& details, |
+ const content::FrameNavigateParams& params) override { |
+ // Wait until we are done distilling the article and the target |
+ // WebContents is ready for printing. |
+ // The navigation to notify print preview that content is on the page will |
+ // be an in-page navigation. |
+ if (!details.is_in_page) |
+ return; |
+ // TODO(mvendra, wychen): resources (images, web fonts) are not necessarily |
+ // ready at this point - so deferring the call to |
+ // DoPrintPreview could be warranted |
+ DoPrintPreview(); |
+ } |
+ |
void Observe(int type, |
const content::NotificationSource& source, |
const content::NotificationDetails& details) override { |