瀏覽代碼

Merge patch by John Feiler, fixing issue 365

Antialize 15 年之前
父節點
當前提交
9628665a90

+ 3 - 0
include/wkhtmltox/loadsettings.hh

@@ -75,6 +75,9 @@ struct DLL_PUBLIC LoadPage {
 	//! How many milliseconds should we wait for a Javascript redirect
 	int jsdelay;
 
+	//! What window.status value should we wait for
+	QString windowStatus;
+	
 	//! What zoom factor should we apply when printing
 	// TODO MOVE
 	float zoomFactor;

+ 1 - 0
src/lib/loadsettings.cc

@@ -129,6 +129,7 @@ LoadGlobal::LoadGlobal():
 
 LoadPage::LoadPage():
 	jsdelay(200),
+	windowStatus(""),
 	zoomFactor(1.0),
 	repeatCustomHeaders(false),
 	blockLocalFileAccess(false),

+ 3 - 0
src/lib/loadsettings.hh

@@ -78,6 +78,9 @@ struct DLL_PUBLIC LoadPage {
 	//! How many milliseconds should we wait for a Javascript redirect
 	int jsdelay;
 
+	//! What window.status value should we wait for
+	QString windowStatus;
+
 	//! What zoom factor should we apply when printing
 	// TODO MOVE
 	float zoomFactor;

+ 11 - 0
src/lib/multipageloader.cc

@@ -217,9 +217,20 @@ void ResourceObject::loadFinished(bool ok) {
 		webPage.mainFrame()->evaluateJavaScript(str);
 
 	if (signalPrint || settings.jsdelay == 0) loadDone();
+	else if (!settings.windowStatus.isEmpty()) waitWindowStatus();
 	else QTimer::singleShot(settings.jsdelay, this, SLOT(loadDone()));
 }
 
+void ResourceObject::waitWindowStatus() {
+	QString windowStatus = webPage.mainFrame()->evaluateJavaScript("window.status").toString();
+	warning(QString("window.status:" + windowStatus + " settings.windowStatus:" + settings.windowStatus));
+	if (windowStatus != settings.windowStatus) {
+		QTimer::singleShot(50, this, SLOT(waitWindowStatus()));
+	} else {
+		QTimer::singleShot(settings.jsdelay, this, SLOT(loadDone()));
+	}
+}
+
 void ResourceObject::printRequested(QWebFrame *) {
 	signalPrint=true;
 	loadDone();

+ 1 - 0
src/lib/multipageloader_p.hh

@@ -91,6 +91,7 @@ public slots:
 	void loadStarted();
 	void loadProgress(int progress);
 	void loadFinished(bool ok);
+	void waitWindowStatus();
 	void printRequested(QWebFrame * frame);
 	void loadDone();
 	void handleAuthenticationRequired(QNetworkReply *reply, QAuthenticator *authenticator);

+ 1 - 0
src/lib/reflect.cc

@@ -59,6 +59,7 @@ ReflectImpl<LoadPage>::ReflectImpl(LoadPage & c) {
 	WKHTMLTOPDF_REFLECT(username);
 	WKHTMLTOPDF_REFLECT(password);
 	WKHTMLTOPDF_REFLECT(jsdelay);
+	WKHTMLTOPDF_REFLECT(windowStatus);
 	WKHTMLTOPDF_REFLECT(zoomFactor);
 	WKHTMLTOPDF_REFLECT(customHeaders);
 	WKHTMLTOPDF_REFLECT(repeatCustomHeaders);

+ 1 - 0
src/shared/commonarguments.cc

@@ -208,6 +208,7 @@ void CommandLineParserBase::addPageLoadArgs(LoadPage & s) {
 	addarg("no-custom-header-propagation",0,"Do not add HTTP headers specified by --custom-header for each resource request.", new ConstSetter<bool>(s.repeatCustomHeaders, true));
 
 	addarg("javascript-delay",0,"Wait some milliseconds for javascript finish", new IntSetter(s.jsdelay,"msec"));
+	addarg("window-status",0,"Wait until window.status is equal to this string before rendering page", new QStrSetter(s.windowStatus, "windowStatus"));
 
 	addarg("zoom",0,"Use this zoom factor", new FloatSetter(s.zoomFactor,"float",1.0));
 	addarg("cookie",0,"Set an additional cookie (repeatable)", new MapSetter<>(s.cookies, "name", "value"));