Jelajahi Sumber

removed deprecated API usage

Gildas lormeau 13 tahun lalu
induk
melakukan
00c58636bd

+ 6 - 6
WebContent/core/scripts/bg/background.js

@@ -64,7 +64,7 @@
 	function setContentResponse(tabId, pageId, docData, content) {
 		var pageData = tabs[tabId][pageId];
 		processingPagesCount--;
-		chrome.extension.sendRequest(pageData.senderId, {
+		chrome.extension.sendMessage(pageData.senderId, {
 			processEnd : true,
 			tabId : tabId,
 			pageId : pageId,
@@ -88,7 +88,7 @@
 			pageData.processableDocs = pageData.initializedDocs;
 			pageData.initProcess();
 			processingPagesCount++;
-			chrome.extension.sendRequest(pageData.senderId, {
+			chrome.extension.sendMessage(pageData.senderId, {
 				processStart : true,
 				tabId : pageData.tabId,
 				pageId : pageData.pageId,
@@ -136,7 +136,7 @@
 				progressMax += tabData.progressMax;
 			}
 		});
-		chrome.extension.sendRequest(pageData.senderId, {
+		chrome.extension.sendMessage(pageData.senderId, {
 			processProgress : true,
 			tabId : pageData.tabId,
 			pageId : pageData.pageId,
@@ -247,8 +247,8 @@
 		}
 	}
 
-	function onRequestExternal(request, sender, sendResponse) {
-		// console.log("onRequestExternal", request);
+	function onMessageExternal(request, sender, sendResponse) {
+		// console.log("onMessageExternal", request);
 		var property, config = JSON.parse(JSON.stringify(DEFAULT_CONFIG));
 		if (request.config)
 			for (property in request.config)
@@ -267,6 +267,6 @@
 	}
 
 	chrome.extension.onConnect.addListener(onConnect);
-	chrome.extension.onRequestExternal.addListener(onRequestExternal);
+	chrome.extension.onMessageExternal.addListener(onMessageExternal);
 
 })();

+ 1 - 1
WebContent/core/scripts/bg/bgcore.js

@@ -48,7 +48,7 @@
 		this.frameDocData = null;
 		timeoutError = setTimeout(function() {
 			that.processing = false;
-			chrome.extension.sendRequest(that.senderId, {
+			chrome.extension.sendMessage(that.senderId, {
 				processError : true,
 				tabId : tabId
 			});

+ 8 - 14
WebContent/core/scripts/bg/wininfo.js

@@ -19,22 +19,16 @@
  */
 
 var wininfo = {
-	init : function(tabId, processCallback) {
-		function onConnect(port) {
-			if (port.name == "wininfo" && port.sender.tab.id == tabId)
-				port.onMessage.addListener(function(message) {
-					// console.log("winfo.onMessage", tabId, message);
-					if (message.initResponse)
-						processCallback(message.processableDocs);
-					chrome.extension.onConnect.removeListener(onConnect);
-				});
-		}
-
-		chrome.extension.onConnect.addListener(onConnect);
-		chrome.tabs.sendRequest(tabId, {
+	init : function(tabId, callback) {
+		chrome.extension.onMessage.addListener(function(message) {
+			// console.log("wininfo.onMessage", tabId, message);
+			if (message.initResponse)
+				callback(message.processableDocs);
+		});
+		chrome.tabs.sendMessage(tabId, {
 			initRequest : true,
 			winId : "0",
 			index : 0
 		});
 	}
-};
+};

+ 13 - 19
WebContent/core/scripts/content/wininfo.js

@@ -35,7 +35,7 @@ var wininfo = {};
 		this.addEventListener("message", windowMessageListener, false);
 	}
 
-	function executeSetFramesWinId(extensionId, selector, index, winId) {
+	function executeSetFramesWinId(extensionId, index, winId) {
 		function execute(extensionId, elements, index, winId, win) {
 			var i, framesInfo = [], stringify = JSON.stringify || JSON.encode, parse = JSON.parse || JSON.decode;
 
@@ -109,7 +109,7 @@ var wininfo = {};
 					}
 
 					if (frameDoc && top.addEventListener) {
-						execute(extensionId, frameDoc.querySelectorAll(selector), index, frameWinId, frameElement.contentWindow);
+						execute(extensionId, frameDoc.querySelectorAll("iframe, frame"), index, frameWinId, frameElement.contentWindow);
 						addListener(onMessage);
 					} else {
 						frameElement.contentWindow.postMessage(extensionId + "::" + stringify({
@@ -120,7 +120,7 @@ var wininfo = {};
 					}
 				})(i);
 		}
-		execute(extensionId, document.querySelectorAll(selector), index, winId, window);
+		execute(extensionId, document.querySelectorAll("iframe, frame"), index, winId, window);
 	}
 
 	function getContent(frame, callback) {
@@ -153,19 +153,15 @@ var wininfo = {};
 				index : message.index
 			});
 		}, 3000);
-		location.href = "javascript:(" + executeSetFramesWinIdString + ")('" + EXT_ID + "','iframe, frame'," + wininfo.index + ",'" + wininfo.winId
-				+ "'); void 0;";
+		location.href = "javascript:(" + executeSetFramesWinIdString + ")('" + EXT_ID + "'," + wininfo.index + ",'" + wininfo.winId + "'); void 0;";
 	}
 
 	function initResponse(message) {
 		function process() {
-			bgPort = chrome.extension.connect({
-				name : "wininfo"
-			});
 			wininfo.frames = wininfo.frames.filter(function(frame) {
 				return frame.winId;
 			});
-			bgPort.postMessage({
+			chrome.extension.sendMessage({
 				initResponse : true,
 				processableDocs : wininfo.frames.length + 1
 			});
@@ -195,20 +191,18 @@ var wininfo = {};
 		}
 	}
 
-	function onRequest(request) {
-		// console.log("onRequest", request);
-		if (request.initRequest && this == top && document.documentElement instanceof HTMLHtmlElement) {
+	function onExtensionMessage(message) {
+		if (message.initRequest && document.documentElement instanceof HTMLHtmlElement) {
 			contentRequestCallbacks = [];
 			processLength = 0;
 			processIndex = 0;
 			timeoutProcess = null;
 			wininfo.frames = [];
-			initRequest(request);
+			initRequest(message);
 		}
 	}
 
-	function onMessage(message) {
-		// console.log("wininfo", "onMessage", message, window.location.href);
+	function onWindowMessage(message) {
 		if (message.initRequest)
 			initRequest(message);
 		if (message.initResponse)
@@ -217,13 +211,13 @@ var wininfo = {};
 			getContentResponse(message);
 	}
 
-	if (window == top)
+	if (window == top) {
 		wininfo.getContent = getContent;
-	chrome.extension.onRequest.addListener(onRequest);
+		chrome.extension.onMessage.addListener(onExtensionMessage);
+	}
 	addEventListener("contextmenu", function() {
 		window.contextmenuTime = (new Date()).getTime();
 	}, false);
-
-	addListener(onMessage);
+	addListener(onWindowMessage);
 
 })();

+ 17 - 16
WebContent/ui/scripts/bg/background.js

@@ -43,17 +43,17 @@
 	}
 
 	function processable(url) {
-		return !url.indexOf("https://chrome.google.com") == 0 && (url.indexOf("http://") == 0 || url.indexOf("https://") == 0);
+		return url.indexOf("https://chrome.google.com") != 0 && (url.indexOf("http://") == 0 || url.indexOf("https://") == 0);
 	}
 
 	function process(tabId, url, processSelection, processFrame) {
 		var SINGLE_FILE_CORE_EXT_ID = dev ? "onlinihoegnbbcmeeocfeplgbkmoidla" : "jemlklgaibiijojffihnhieihhagocma";
-		
+
 		detectExtension(SINGLE_FILE_CORE_EXT_ID, function(detected) {
 			if (detected) {
 				if (processable(url)) {
 					singlefile.ui.notifyProcessInit(tabId);
-					chrome.extension.sendRequest(SINGLE_FILE_CORE_EXT_ID, {
+					chrome.extension.sendMessage(SINGLE_FILE_CORE_EXT_ID, {
 						processSelection : processSelection,
 						processFrame : processFrame,
 						id : tabId,
@@ -76,13 +76,12 @@
 		if (singlefile.config.get().sendToPageArchiver && request.content)
 			detectExtension(PAGEARCHIVER_EXT_ID, function(detected) {
 				if (detected)
-					chrome.extension.sendRequest(PAGEARCHIVER_EXT_ID, request);
+					chrome.extension.sendMessage(PAGEARCHIVER_EXT_ID, request);
 			});
 	}
 
-	// TODO : onSelectionChanged, getSelected are deprecated
-	chrome.tabs.onSelectionChanged.addListener(function() {
-		chrome.tabs.getSelected(null, function(tab) {
+	chrome.tabs.onActivated.addListener(function(activeInfo) {
+		chrome.tabs.get(activeInfo.tabId, function(tab) {
 			notifyProcessable(tab.id, tab.url);
 		});
 	});
@@ -90,19 +89,19 @@
 		notifyProcessable(tab.id, tab.url);
 	});
 	chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
-		if (changeInfo.status = "loading")
+		if (changeInfo.status = "loading" && tab.url)
 			notifyProcessable(tab.id, tab.url, true);
 	});
 	chrome.tabs.onRemoved.addListener(function(tabId) {
 		singlefile.ui.notifyTabRemoved(tabId);
 	});
 
-	chrome.extension.onRequestExternal.addListener(function(request, sender, sendResponse) {
+	chrome.extension.onMessageExternal.addListener(function(request, sender, sendResponse) {
 		var blob, url;
 		if (request.processStart) {
 			singlefile.ui.notifyProcessStart(request.tabId, request.processingPagesCount);
 			if (request.blockingProcess)
-				chrome.tabs.sendRequest(request.tabId, {
+				chrome.tabs.sendMessage(request.tabId, {
 					processStart : true
 				});
 			notifyPageArchiver(request);
@@ -113,10 +112,12 @@
 		}
 		if (request.processEnd) {
 			if (request.blockingProcess)
-				chrome.tabs.sendRequest(request.tabId, {
+				chrome.tabs.sendMessage(request.tabId, {
 					processEnd : true
 				});
-			blob = new Blob([(new Uint8Array([ 0xEF, 0xBB, 0xBF ])).buffer, request.content]);
+			blob = new Blob([ (new Uint8Array([ 0xEF, 0xBB, 0xBF ])), request.content ], {
+				type : "text/html"
+			});
 			url = webkitURL.createObjectURL(blob);
 			singlefile.ui.notifyProcessEnd(request.tabId, request.processingPagesCount, singlefile.config.get().displayNotification,
 					singlefile.config.get().displayBanner, url, request.title);
@@ -125,13 +126,13 @@
 		if (request.processError)
 			singlefile.ui.notifyProcessError(request.tabId);
 	});
-	chrome.extension.onRequest.addListener(function(request, sender) {
-		if (request.closeBanner)
-			chrome.tabs.sendRequest(sender.tab.id, {
+	chrome.extension.onMessage.addListener(function(message, sender) {
+		if (message.closeBanner)
+			chrome.tabs.sendMessage(sender.tab.id, {
 				closeBanner : true
 			});
 		else
-			process(sender.tab.id, sender.tab.url, false, false);
+			process(tabId, port.sender.tab.url, false, false);
 	});
 	chrome.browserAction.onClicked.addListener(function(tab) {
 		process(tab.id, tab.url, false, false);

+ 1 - 1
WebContent/ui/scripts/bg/ui.js

@@ -109,7 +109,7 @@
 		if (displayNotification)
 			webkitNotifications.createHTMLNotification("/pages/notification.html?" + params).show();
 		if (displayBanner)
-			chrome.tabs.sendRequest(tabId, {
+			chrome.tabs.sendMessage(tabId, {
 				displayBanner : true,
 				url : chrome.extension.getURL("/pages/banner.html") + "?" + params
 			});

+ 1 - 1
WebContent/ui/scripts/content/banner.js

@@ -29,7 +29,7 @@
 	var filename = decodeURIComponent(params[1]) + " (" + time + ")" + ".htm";
 
 	function close() {
-		chrome.extension.sendRequest({
+		chrome.extension.sendMessage({
 			closeBanner : true
 		});
 	}

+ 4 - 3
WebContent/ui/scripts/content/content.js

@@ -79,11 +79,11 @@
 
 	window.addEventListener("keyup", function(event) {
 		if (event.ctrlKey && event.shiftKey && event.keyCode == 83)
-			chrome.extension.sendRequest({});
+			chrome.extension.sendMessage({});
 	}, true);
 
-	if (topWindow)
-		chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
+	if (topWindow) {
+		chrome.extension.onMessage.addListener(function(request) {
 			if (request.processStart)
 				processStart();
 			if (request.processEnd)
@@ -93,5 +93,6 @@
 			if (request.closeBanner)
 				closeBanner();
 		});
+	}
 
 })();