Procházet zdrojové kódy

- better handling of external resources when not found
- issues with "NotScripts" extension fixed
- typos fixed in help page
- file:/// URI matching removed

Gildas lormeau před 15 roky
rodič
revize
cbe97bbc25

+ 5 - 5
WebContent/core/manifest.json

@@ -4,15 +4,15 @@
 		"16": "resources/icon_16.png",
 		"48": "resources/icon_48.png",
 		"128": "resources/icon_128.png" },
-	"version": "0.2.18",
+	"version": "0.2.19",
 	"description": "Page processor used by SingleFile",
 	"background_page" : "pages/background.html",
-	"content_scripts": [{
-		  "matches": ["http://*/*", "https://*/*", "ftp://*/*", "file:///*"],
-		  "js": ["scripts/content/wininfo.js"],
+	"content_scripts": [ {
+		  "matches": [ "http://*/*", "https://*/*", "ftp://*/*" ],
+		  "js": [ "scripts/content/wininfo.js" ],
 		  "run_at" : "document_end",
 		  "all_frames" : true
-	 }],
+	 } ],
 	"permissions": [ "tabs", "http://*/*", "https://*/*", "unlimitedStorage" ],
 	"minimum_chrome_version" : "7"
 }

+ 3 - 7
WebContent/core/scripts/common/docprocessor.js

@@ -85,7 +85,6 @@
 					return "@import \"" + formatURL(result[1], host) + "\";";
 			return value;
 		});
-
 	}
 
 	function getDataURI(data, defaultURL, woURL) {
@@ -142,7 +141,7 @@
 			if (!(href.indexOf("data:") == 0)) {
 				requestManager.send(fullHref, function(data) {
 					var i, newNode, commentNode;
-					if (data.status == 404) {
+					if (data.status >= 400) {
 						node.parentElement.removeChild(node);
 						return;
 					}
@@ -172,7 +171,7 @@
 			function sendRequest(imp) {
 				requestManager.send(url,
 						function(data) {
-							styleSheet.textContent = styleSheet.textContent.replace(imp, data.status != 404 && data.content ? resolveURLs(data.content,
+							styleSheet.textContent = styleSheet.textContent.replace(imp, data.status < 400 && data.content ? resolveURLs(data.content,
 									data.url) : "");
 						}, null, characterSet);
 				ret = false;
@@ -271,7 +270,7 @@
 			var src = node.getAttribute("src");
 			if (!(src.indexOf("data:") == 0))
 				requestManager.send(formatURL(src, baseURI), function(data) {
-					if (data.status != 404) {
+					if (data.status < 400) {
 						data.content = data.content.replace(/"([^"]*)<\/\s*script\s*>([^"]*)"/gi, '"$1<"+"/script>$2"');
 						data.content = data.content.replace(/'([^']*)<\/\s*script\s*>([^']*)'/gi, "'$1<'+'/script>$2'");
 						node.textContent = [ "\n", data.content, "\n" ].join("");
@@ -355,9 +354,7 @@
 
 		function RequestManager(onProgress) {
 			var that = this, currentCount = 0, requests = [];
-
 			this.requestCount = 0;
-
 			this.send = function(url, responseHandler, characterSet, mediaTypeParam) {
 				this.requestCount++;
 				requests.push({
@@ -367,7 +364,6 @@
 					mediaTypeParam : mediaTypeParam
 				});
 			};
-
 			this.doSend = function() {
 				requests.forEach(function(request) {
 					requestManager.send(request.url, function(response) {

+ 13 - 9
WebContent/core/scripts/content/content.js

@@ -283,21 +283,21 @@
 	}
 
 	function setContentRequest(message) {
-		var mutationEventId = 0, winId = wininfo.winId;
+		var mutationEventId = 0, winId = wininfo.winId, timeoutSetContent;
 
 		function resetWindowProperties(winPropertiesStr) {
-			var property, winProp, customEvent;
+			var property, winProp, customEvent, parse = JSON.parse || JSON.decode;
 			try {
-				winProp = eval("(" + winPropertiesStr + ")");
-				customEvent = document.createEvent("CustomEvent");
+				winProp = parse(winPropertiesStr);
 				for (property in window)
 					if (!winProp[property])
-						window[property] = null;
-				customEvent.initCustomEvent("WindowPropertiesCleaned", true, true);
-				document.dispatchEvent(customEvent);
+						window[property] = null;							
 			} catch (e) {
 				console.log(e);
 			}
+			customEvent = document.createEvent("CustomEvent");
+			customEvent.initCustomEvent("WindowPropertiesCleaned", true, true);
+			document.dispatchEvent(customEvent);
 		}
 
 		function onDOMSubtreeModified(event) {
@@ -342,6 +342,10 @@
 				doc.addEventListener("DOMSubtreeModified", onDOMSubtreeModified, true);
 			}
 
+			if (timeoutSetContent) {
+				clearTimeout(timeoutSetContent);
+				timeoutSetContent = null;
+			}				
 			doc.removeEventListener('WindowPropertiesCleaned', onWindowPropertiesCleaned, true);
 			if (config.processInBackground || singlefile.processSelection || (!config.processInBackground && !config.removeScripts))
 				if (location.pathname.indexOf(".txt") + 4 != location.pathname.length) {
@@ -384,9 +388,9 @@
 							.getDocContent(doc, docElement));
 			}
 		}
-
 		if (config.displayProcessedPage) {
-			window.location.href = "javascript:(" + resetWindowProperties.toString() + ")('" + JSON.stringify(message.winProperties) + "')";
+			window.location.href = "javascript:(" + resetWindowProperties.toString() + ")('" + JSON.stringify(message.winProperties) + "'); void 0;";			
+			timeoutSetContent = setTimeout(onWindowPropertiesCleaned, 3000);			
 			doc.addEventListener('WindowPropertiesCleaned', onWindowPropertiesCleaned, true);
 		} else
 			setContentResponse();

+ 15 - 3
WebContent/core/scripts/content/wininfo.js

@@ -24,7 +24,7 @@ var wininfo = {};
 
 	var EXT_ID = "wininfo";
 
-	var contentRequestCallbacks, executeSetFramesWinIdString = executeSetFramesWinId.toString(), processLength, processIndex, timeoutProcess;
+	var contentRequestCallbacks, executeSetFramesWinIdString = executeSetFramesWinId.toString(), processLength, processIndex, timeoutProcess, timeoutInit;
 
 	function addListener(onMessage) {
 		function windowMessageListener(event) {
@@ -120,7 +120,6 @@ var wininfo = {};
 					}
 				})(i);
 		}
-
 		execute(extensionId, document.querySelectorAll(selector), index, winId, window);
 	}
 
@@ -147,7 +146,16 @@ var wininfo = {};
 	function initRequest(message) {
 		wininfo.winId = message.winId;
 		wininfo.index = message.index;
-		location.href = "javascript:(" + executeSetFramesWinIdString + ")('" + EXT_ID + "','iframe, frame'," + wininfo.index + ",'" + wininfo.winId + "')";
+		timeoutInit = setTimeout(function() {
+			initResponse({
+				initResponse : true,
+				frames : [],
+				winId : message.winId,
+				index : message.index
+			});
+		}, 3000);
+		location.href = "javascript:(" + executeSetFramesWinIdString + ")('" + EXT_ID + "','iframe, frame'," + wininfo.index + ",'" + wininfo.winId
+				+ "'); void 0;";
 	}
 
 	function initResponse(message) {
@@ -164,6 +172,10 @@ var wininfo = {};
 			});
 		}
 
+		if (timeoutInit) {
+			clearTimeout(timeoutInit);
+			timeoutInit = null;
+		}
 		if (window == top) {
 			message.frames = message.frames instanceof Array ? message.frames : JSON.parse(message.frames);
 			if (message.winId != "0")

+ 1 - 1
WebContent/ui/manifest.json

@@ -4,7 +4,7 @@
 		"16": "resources/icon_16.png",
 		"48": "resources/icon_48.png",
 		"128": "resources/icon_128.png" },
-	"version": "0.2.18",
+	"version": "0.2.19",
 	"description": "SingleFile helps you to archive a complete page into a single HTML file",
 	"background_page" : "pages/background.html",
 	"options_page": "pages/options.html",

+ 4 - 0
WebContent/ui/pages/help.css

@@ -108,4 +108,8 @@ li {
 
 .availability {
 	font-size: 11pt;
+}
+
+code {
+	font-size: 1.1em;
 }

+ 27 - 24
WebContent/ui/pages/help.html

@@ -35,35 +35,35 @@ folder</a> - <a href="#notes">Technical notes</a> - <a href="#knownIssues">Known
 	</div>
 	<li><a id="options">Options description</a>
 
-	<p>You can customize the way SingleFile process the page through the options page. Right-click on SingleFile icon <img src="../resources/icon_48.png" id="icon"> in the
+	<p>You can customize the way SingleFile process a document through the options page. Right-click on SingleFile icon <img src="../resources/icon_48.png" id="icon"> in the
 	Chrome toolbar and select "Options" in the context menu to open the options page.</p>
 	<div class="screenshot"></div>
 	<p>Details :</p>
 	<ul>
 		<li><span class="option">remove frames</span>
 		<p>Remove all frames on the page</p>
-		<p>You can enable this option if the file size is too large when disabled or to remove some ads.</p>
-		<p class="notice">It is recommended to <u>disable</u> this option</p>
+		<p>You can enable this option if the file size is too large when disabled or to remove some ads. You should enable this option to view saved pages on IE8.</p>
+		<p class="notice">It is recommended to <u>disable</u> this option unless you want to open saved pages in IE8.</p>
 		</li>
 
 		<li><span class="option">remove scripts</span>
 		<p>Remove all javascript scripts</p>
-		<p>Most of the time, you don't need javascript into the saved page. If your want to save the page dynamic behavior, you may need to disable this option. Nevertheless, the
-		dynamic behavior may not work or document can be altered when opening the saved file.<br>
-		It is recommended to enable <span class="option">process raw document</span> if you disable this option.</p>
+		<p>Most of the time, you don't need javascript into the saved page. If you want to save the dynamic behavior of the document, you may need to disable this option.
+		Nevertheless it may not work or document can be altered when opening the saved file.<br>
+		It is strongly recommended to enable <span class="option">process raw document</span> if you disable this option.</p>
 		<p class="notice">It is recommended to <u>enable</u> this option</p>
 		</li>
 
 		<li><span class="option">remove objects</span>
 		<p>Remove all objects</p>
-		<p>Remove all non embeddable elements : flash, java applet ...</p>
+		<p>Remove all non embeddable elements : flash objects, java applets ...</p>
 		<p class="notice">It is recommended to <u>enable</u> this option if you want to read the saved page offline</p>
 		</li>
 
 		<li><span class="option">remove hidden elements</span>
 		<p>Remove all hidden elements</p>
-		<p>Remove all the HTML unvisible elements on the page (with <code>visibility = "hidden"</code>&nbsp;or&nbsp;<code>display = "none"</code>&nbsp;or&nbsp;<code>opacity =
-		0</code> CSS property values). This option may alter the document but can considerably reduce the saved file size.</p>
+		<p>Remove all document hidden elements (<code>visibility = "hidden"</code>&nbsp;or&nbsp;<code>display = "none"</code>&nbsp;or&nbsp;<code>opacity = "0"</code> CSS property
+		values). This option may alter the document but can considerably reduce the saved file size.</p>
 		<p class="notice">It is recommended to <u>disable</u> this option unless the saved file size is too large</p>
 		</li>
 
@@ -77,27 +77,28 @@ folder</a> - <a href="#notes">Technical notes</a> - <a href="#knownIssues">Known
 		<li><span class="option">scrapbook the page</span>
 		<p>Send the archived page to <a href="https://chrome.google.com/webstore/detail/ihkkeoeinpbomhnpkmmkpggkaefincbn">Scrapbook for SingleFile</a></p>
 		<p>This option allows to use SingleFile action icon as a shortcut to send the viewed page to <a
-			href="https://chrome.google.com/webstore/detail/ihkkeoeinpbomhnpkmmkpggkaefincbn">Scrapbook for SingleFile</a> extension if installed.</p>
+			href="https://chrome.google.com/webstore/detail/ihkkeoeinpbomhnpkmmkpggkaefincbn">Scrapbook for SingleFile</a> extension.</p>
 		<p class="notice">It is recommended to <u>disable</u> this option unless you want to use SingleFile icon to scrapbook pages</p>
 		</li>
 
 		<li><span class="option">process in background</span>
 		<p>Process the page in background</p>
-		<p>Processing in background means it won't be blocking (*). If you disable this option, a shadow will prevent you to use the page during the SingleFile processing. Even
-		though processing may be faster.</p>
+		<p>Processing in background means it won't be blocking (*). If you disable this option, a shadow will prevent you to use the page during the SingleFile processing but
+		processing will be faster.</p>
 		<p class="notice">It is recommended to <u>disable</u> this option unless <span class="option">display processed page</span> option is disabled</p>
 		</li>
 
 		<li><span class="option">save processed page (*)</span>
 		<p>Save the page on filesystem</p>
-		<p>When enabled this option allows to save automatically archives on filesystem. See <a href="#folder">Saved archives folder</a> for more details.</p>
+		<p>If you enable this option, documents will be automatically saved on filesystem. See <a href="#folder">Saved archives folder</a> for more details.</p>
 		<p class="notice">It is recommended to <u>disable</u> this option unless you want files to be automatically saved</p>
 		</li>
 
 		<li><span class="option">display processed page (*)</span>
 		<p>Display the processed page in the tab</p>
-		<p>This option must be enabled if you want to use Chrome "Save as" dialog box to save the processed page. To improve processing speed, you should disable <span class="option">process
-		in background</span> when this option is enabled.</p>
+		<p>This option must be enabled if you want to use Chrome "Save as" dialog box to save the processed page.<br>
+		You should enable <span class="option">process in background</span> when this option is disabled so the processing won't be blocking. Conversely, you should disable <span
+			class="option">process in background</span> when this option is enabled so the processing will be faster.</p>
 		<p class="notice">It is recommended to <u>enable</u> this option</p>
 		</li>
 
@@ -109,8 +110,8 @@ folder</a> - <a href="#notes">Technical notes</a> - <a href="#knownIssues">Known
 
 		<li><span class="option">process raw document</span>
 		<p>Process the raw downloaded document</p>
-		<p>This option allows SingleFile to process the downloaded document instead of the displayed document. The main difference is that JavaScript scripts won't be parsed and
-		executed. Frames won't be embedded too.</p>
+		<p>This option allows SingleFile to process the downloaded document instead of the displayed document. The main difference is that scripts won't be parsed and executed.
+		Frames won't be embedded too.</p>
 		<p class="notice">It is recommended to <u>disable</u> this option unless <span class="option">remove scripts</span> is disabled</p>
 		</li>
 
@@ -121,9 +122,9 @@ folder</a> - <a href="#notes">Technical notes</a> - <a href="#knownIssues">Known
 	</li>
 
 	<li><a id="folder">Saved archives folder (*)</a>
-	<p>When <span class="option">save processed page</span> is enabled, pages will be automatically saved but Chrome will not allow to choose the root folder where archives are
-	stored. Neither it will allow to make links pointing to saved files folder. So you have to find "manually" the this folder.</p>
-	<p>Files are saved in "FileSystem" folder located into Chrome user data folder:</p>
+	<p>When <span class="option">save processed page</span> is enabled, pages will be automatically saved on filesystem. However, Chrome will not allow to choose the root folder
+	where archives are stored. Neither it will allow SingleFile to make links pointing to saved files folder. So you have to find "manually" this folder.</p>
+	<p>Files are saved in the extension subfolder of "FileSystem" folder located into Chrome user data folder:</p>
 	<ul style="text-align: left">
 		<li>Windows default path: <br>
 		<span class="option">%LOCALAPPDATA%\Google\Chrome\User&nbsp;Data\Default\FileSystem\chrome-extension_jemlklgaibiijojffihnhieihhagocma_0\Persistent\</span></li>
@@ -132,7 +133,9 @@ folder</a> - <a href="#notes">Technical notes</a> - <a href="#knownIssues">Known
 		<li>Mac OS X default path: <br>
 		<span class="option">~/Library/Application&nbsp;Support/Google/Chrome/Default/FileSystem/chrome-extension_jemlklgaibiijojffihnhieihhagocma_0/Persistent/</span></li>
 	</ul>
-	<p>You can create symbolic links to help you to access easily to this folder and use sync services like dropbox. Here are the way of doing it on <a
+	<p>You can create shortcuts to access to this folder easily.
+	<p>
+	<p>You can also create symbolic links in order to use sync services like dropbox. Here are the way of doing it on <a
 		href="http://technet.microsoft.com/en-us/library/cc753194(WS.10).aspx">windows (mklink /d)</a> and <a href="http://www.unixtutorial.org/commands/ln/">linux or Mac OS X (ln
 	-s)</a>.</p>
 	<p>You can also change Chrome user data folder with <a href="http://www.chromium.org/user-experience/user-data-directory">--user-data-dir switch</a>.
@@ -141,9 +144,9 @@ folder</a> - <a href="#notes">Technical notes</a> - <a href="#knownIssues">Known
 	<li><a id="notes">Technical notes</a>
 	<ul>
 		<li>all images are converted into <a href="http://en.wikipedia.org/wiki/Base64">base64</a></li>
-		<li>frame document contents and automatically saved pages are encoded with <a href="http://en.wikipedia.org/wiki/Utf_8">utf-8 charset</a></li>
+		<li>frame document contents and automatically saved pages (*) are encoded with <a href="http://en.wikipedia.org/wiki/Utf_8">utf-8 charset</a></li>
 		<li>encoded contents are injected in the document using <a href="http://en.wikipedia.org/wiki/Data_URI_scheme">data URI scheme</a></li>
-		<li>data URI scheme is supported by the following web browsers: Chrome, Firefox, Opera, Safari, Konqueror and Internet Explorer 8 (limited support : data URIs must be
+		<li>data URI scheme is supported by the following web browsers: Chrome, Firefox, Opera, Safari, Konqueror and Internet Explorer 8 (limited support: data URIs must be
 		smaller than 32 KB, embedded frames are not supported)</li>
 		<li>SVG images are supported (SVG document is converted into utf-8 but is not processed)</li>
 	</ul>
@@ -151,7 +154,7 @@ folder</a> - <a href="#notes">Technical notes</a> - <a href="#knownIssues">Known
 
 	<li><a id="knownIssues">Known issues</a>
 	<ul>
-		<li>SVG images without src attribute or with empty src attribute are not embedded</li>		
+		<li>SVG images without src attribute or with empty src attribute are not embedded</li>
 	</ul>
 	</li>
 

+ 2 - 2
WebContent/ui/scripts/bg/background.js

@@ -20,7 +20,7 @@
 
 (function() {
 
-	var dev = true;
+	var dev = false;
 
 	var extensionDetected = [];
 
@@ -47,7 +47,7 @@
 	}
 
 	function process(tabId, url, processSelection) {
-		var SINGLE_FILE_CORE_EXT_ID = dev ? "jnonclilicbambcohnkjlpicicmmkceh" : "jemlklgaibiijojffihnhieihhagocma";
+		var SINGLE_FILE_CORE_EXT_ID = dev ? "oabofdibacblkhpogjinmdbcekfkikjc" : "jemlklgaibiijojffihnhieihhagocma";
 		detectExtension(SINGLE_FILE_CORE_EXT_ID, function(detected) {
 			if (detected) {
 				if (processable(url)) {