Index: chrome/browser/ui/webui/print_preview/print_preview_handler.cc |
diff --git a/chrome/browser/ui/webui/print_preview/print_preview_handler.cc b/chrome/browser/ui/webui/print_preview/print_preview_handler.cc |
index 237bba967a6013be8075d1ae87087d520386b79e..eb42f2507ed7b6fe6f67cc762389ad6269fd8f1e 100644 |
--- a/chrome/browser/ui/webui/print_preview/print_preview_handler.cc |
+++ b/chrome/browser/ui/webui/print_preview/print_preview_handler.cc |
@@ -30,6 +30,7 @@ |
#include "base/values.h" |
#include "chrome/browser/app_mode/app_mode_utils.h" |
#include "chrome/browser/browser_process.h" |
+#include "chrome/browser/dom_distiller/tab_utils.h" |
#include "chrome/browser/platform_util.h" |
#include "chrome/browser/printing/print_dialog_cloud.h" |
#include "chrome/browser/printing/print_error_dialog.h" |
@@ -57,6 +58,7 @@ |
#include "components/cloud_devices/common/cloud_device_description.h" |
#include "components/cloud_devices/common/cloud_devices_urls.h" |
#include "components/cloud_devices/common/printer_description.h" |
+#include "components/dom_distiller/core/url_utils.h" |
#include "components/printing/common/print_messages.h" |
#include "components/signin/core/browser/gaia_cookie_manager_service.h" |
#include "components/signin/core/browser/profile_oauth2_token_service.h" |
@@ -165,6 +167,8 @@ const char kHidePrintWithSystemDialogLink[] = "hidePrintWithSystemDialogLink"; |
#endif |
// Name of a dictionary field holding the state of selection for document. |
const char kDocumentHasSelection[] = "documentHasSelection"; |
+// Dictionary field indicating whether to simplify the page. |
+const char kPrintFriendlyEnabled[] = "printFriendlyEnabled"; |
// Id of the predefined PDF printer. |
const char kLocalPdfPrinterId[] = "Save as PDF"; |
@@ -823,8 +827,24 @@ void PrintPreviewHandler::HandleGetPreview(const base::ListValue* args) { |
} |
VLOG(1) << "Print preview request start"; |
- RenderViewHost* rvh = initiator->GetRenderViewHost(); |
- rvh->Send(new PrintMsg_PrintPreview(rvh->GetRoutingID(), *settings)); |
+ |
+ bool print_friendly = false; |
+ if (!settings->GetBoolean(printing::kSettingPrintFriendlyEnabled, |
+ &print_friendly)) { |
+ NOTREACHED(); |
+ } |
+ |
+ if (print_friendly) { |
+ if (!hidden_print_preview_) |
+ MaybeStartDistillation(initiator); |
nyquist
2015/05/13 07:56:38
Could this be simplified by using the new DistillA
arjunpatel
2015/05/27 00:16:45
Yes, depending on whether or not we keep the synch
|
+ |
+ hidden_print_preview_.reset( |
+ new HiddenPrintPreview(initiator, print_preview_ui())); |
+ hidden_print_preview_->SetSettings(settings.Pass()); |
+ } else { |
+ RenderViewHost* rvh = initiator->GetRenderViewHost(); |
+ rvh->Send(new PrintMsg_PrintPreview(rvh->GetRoutingID(), *settings)); |
+ } |
} |
void PrintPreviewHandler::HandlePrint(const base::ListValue* args) { |
@@ -1237,6 +1257,15 @@ void PrintPreviewHandler::SendInitialSettings( |
initial_settings.SetBoolean(kHidePrintWithSystemDialogLink, is_ash); |
#endif |
+ WebContents* initiator = GetInitiator(); |
+ bool can_simplify = false; |
+ if (initiator) { |
+ can_simplify = cmdline->HasSwitch(switches::kEnableDomDistiller) && |
nyquist
2015/05/13 07:56:38
Should this also check to see if we assume that th
arjunpatel
2015/05/27 17:10:11
The latest version of the CL does this, showing th
|
+ dom_distiller::url_utils::IsUrlDistillable( |
+ initiator->GetLastCommittedURL()); |
+ } |
+ initial_settings.SetBoolean(kPrintFriendlyEnabled, can_simplify); |
+ |
if (print_preview_ui()->source_is_modifiable()) |
GetNumberFormatAndMeasurementSystem(&initial_settings); |
web_ui()->CallJavascriptFunction("setInitialSettings", initial_settings); |