# HG changeset patch
# User t_mrc-ct@sourceforge.jp
# Date 1349258798 -32400
# Branch GECKO2450_2014042411_RELBRANCH
# Node ID 1524c6a3cd2d80cba023503abb7f928595bc5cdd
# Parent  d558730bbf87744780a0f0f1866fb6ff52b63fb9
add updatesOverlay files

diff --git a/mail/base/content/updatesOverlay.js b/mail/base/content/updatesOverlay.js
new file mode 100644
--- /dev/null
+++ b/mail/base/content/updatesOverlay.js
@@ -0,0 +1,249 @@
+Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
+Components.utils.import("resource://gre/modules/FileUtils.jsm");
+
+const PREF_TFB_UPDATE_URL_DOWNLOAD = "tenfourbird.update.url.download";
+
+const PREF_APP_UPDATE_CHANNEL             = "app.update.channel";
+const PREF_PARTNER_BRANCH                 = "app.partner.";
+
+const PREF_APP_DISTRIBUTION               = "distribution.id";
+const PREF_APP_DISTRIBUTION_VERSION       = "distribution.version";
+const PREF_APP_DISTRIBUTION_ABOUT         = "distribution.about";
+
+const FILE_UPDATE_LOCALE  = "update.locale";
+
+const KEY_APPDIR          = "XCurProcD";
+const KEY_GRED            = "GreD";
+
+// not used yet
+const PATH_CMD_MACHINE = "/usr/bin/machine";
+const PATH_STDIN = "/dev/stdout";
+
+function UpdateURLFormatter(update)
+	{
+	this.update = update;
+
+	XPCOMUtils.defineLazyGetter(this, "gABI", function()
+		{
+		let abi = null;
+		try
+			{
+			abi = Services.appinfo.XPCOMABI;
+			}
+		catch (e)
+			{
+			LOG("gABI - XPCOM ABI unknown: updates are not possible.");
+			}
+		// Mac universal build should report a different ABI than either macppc
+		// or mactel.
+		let macutils = CoC["@mozilla.org/xpcom/mac-utils;1"].getService(CoI.nsIMacUtils);
+
+		if (macutils.isUniversalBinary)
+			{
+			abi += "-u-" + macutils.architecturesInBinary;
+			}
+#ifdef MOZ_SHARK
+		// Disambiguate optimised and shark nightlies
+		abi += "-shark"
+#endif
+		return abi;
+		});
+	XPCOMUtils.defineLazyGetter(this, "gOSVersion", function()
+		{
+		let osVersion;
+		let sysInfo = CoC["@mozilla.org/system-info;1"].getService(CoI.nsIPropertyBag2);
+		try
+			{
+			osVersion = sysInfo.getProperty("name") + " " + sysInfo.getProperty("version");
+			}
+		catch (e)
+			{
+			LOG("gOSVersion - OS Version unknown: updates are not possible.");
+			}
+		if (osVersion)
+			{
+			try
+				{
+				osVersion += " (" + sysInfo.getProperty("secondaryLibrary") + ")";
+				}
+			catch (e)
+				{
+				// Not all platforms have a secondary widget library, so an error is nothing to worry about.
+				}
+			osVersion = encodeURIComponent(osVersion);
+			}
+		return osVersion;
+		});
+	}
+
+/**
+ * Gets the locale from the update.locale file for replacing %LOCALE% in the
+ * update url. The update.locale file can be located in the application
+ * directory or the GRE directory with preference given to it being located in
+ * the application directory.
+ */
+UpdateURLFormatter.prototype.getLocale = function()
+	{
+	if (gLocale)
+		{
+		return gLocale;
+		}
+	var localeFile = FileUtils.getFile(KEY_APPDIR, [FILE_UPDATE_LOCALE]);
+	if (!localeFile.exists())
+		{
+		localeFile = FileUtils.getFile(KEY_GRED, [FILE_UPDATE_LOCALE]);
+		}
+
+	if (!localeFile.exists())
+		{
+		throw Components.Exception(FILE_UPDATE_LOCALE + " file doesn't exist in " +
+			"either the " + KEY_APPDIR + " or " + KEY_GRED +
+			" directories", CoR.NS_ERROR_FILE_NOT_FOUND);
+		}
+	gLocale = this.readStringFromFile(localeFile);
+	LOG("getLocale - getting locale from file: " + localeFile.path +
+		", locale: " + gLocale);
+	return gLocale;
+	}
+/**
+ * Read the update channel from defaults only.  We do this to ensure that
+ * the channel is tightly coupled with the application and does not apply
+ * to other instances of the application that may use the same profile.
+ */
+UpdateURLFormatter.prototype.getUpdateChannel = function()
+	{
+	var channel = "default";
+	var prefName;
+	var prefValue;
+	try
+		{
+		channel = Services.prefs.getDefaultBranch(null).getCharPref(PREF_APP_UPDATE_CHANNEL);
+		}
+	catch (e)
+		{
+		 // use default when pref not found
+		}
+
+	try
+		{
+		var partners = Services.prefs.getChildList(PREF_PARTNER_BRANCH);
+		if (partners.length)
+			{
+			channel += "-cck";
+			partners.sort();
+
+			for each (prefName in partners)
+				{
+				prefValue = Services.prefs.getCharPref(prefName);
+				channel += "-" + prefValue;
+				}
+			}
+		}
+	catch (e)
+		{
+		Components.utils.reportError(e);
+		}
+	return channel;
+	}
+/* Get the distribution pref values, from defaults only */
+UpdateURLFormatter.prototype.getDistributionPrefValue = function(aPrefName)
+	{
+	var prefValue = "default";
+	try
+		{
+		prefValue = Services.prefs.getDefaultBranch(null).getCharPref(aPrefName);
+		}
+	catch (e)
+		{
+		// use default when pref not found
+		}
+	return prefValue;
+	}
+/**
+ * Reads a string of text from a file.  A trailing newline will be removed
+ * before the result is returned.  This function only works with ASCII text.
+ */
+UpdateURLFormatter.prototype.readStringFromFile = function(file)
+	{
+	if (!file.exists())
+		{
+		LOG("readStringFromFile - file doesn't exist: " + file.path);
+		return null;
+		}
+	var fis = CoC["@mozilla.org/network/file-input-stream;1"].createInstance(CoI.nsIFileInputStream);
+	fis.init(file, FileUtils.MODE_RDONLY, FileUtils.PERMS_FILE, 0);
+	var sis = CoC["@mozilla.org/scriptableinputstream;1"].createInstance(CoI.nsIScriptableInputStream);
+	sis.init(fis);
+	var text = sis.read(sis.available());
+	sis.close();
+	if (text[text.length - 1] == "\n")
+		{
+		text = text.slice(0, -1);
+		}
+	return text;
+	}
+
+UpdateURLFormatter.prototype.format = function(url)
+	{
+	/* from Checker:getUpdateURL (nsUpdateService.js) */
+	url = url.replace(/%PRODUCT%/g, Services.appinfo.name);
+	url = url.replace(/%VERSION%/g, Services.appinfo.version);
+	url = url.replace(/%BUILD_ID%/g, Services.appinfo.appBuildID);
+	url = url.replace(/%BUILD_TARGET%/g, Services.appinfo.OS + "_" + this.gABI);
+	url = url.replace(/%OS_VERSION%/g, this.gOSVersion);
+	if (/%LOCALE%/.test(url))
+		{
+		url = url.replace(/%LOCALE%/g, this.getLocale());
+		}
+	url = url.replace(/%CHANNEL%/g, this.getUpdateChannel());
+	url = url.replace(/%PLATFORM_VERSION%/g, Services.appinfo.platformVersion);
+	url = url.replace(/%DISTRIBUTION%/g,　this.getDistributionPrefValue(PREF_APP_DISTRIBUTION));
+	url = url.replace(/%DISTRIBUTION_VERSION%/g,　this.getDistributionPrefValue(PREF_APP_DISTRIBUTION_VERSION));
+
+	url = url.replace(/%UPDATE_TYPE%/g, this.update.type);
+	url = url.replace(/%UPDATE_VERSION%/g, this.update.appVersion);
+	url = url.replace(/%UPDATE_BUILD_ID%/g, this.update.buildID);
+
+	url = url.replace(/\+/g, "%2B");
+	return url;
+	}
+
+function ManualUpdatePage_TFBird(target_id)
+	{
+	this.targetId = target_id;
+	}
+ManualUpdatePage_TFBird.prototype.onPageShow = function()
+	{
+	var url = getPref("getCharPref", PREF_TFB_UPDATE_URL_DOWNLOAD, null);
+	var fmt;
+
+	if(url != null && url.length > 0)
+		{
+		fmt = new UpdateURLFormatter(gUpdates.update);
+		url = fmt.format(url);
+		}
+	else
+		{
+		url = getPref("getCharPref", PREF_APP_UPDATE_MANUAL_URL, null);
+
+		if(url = null || url == "")
+			{
+			LOG("ManualUpdatePage_TFBird(\"" + this.targetId + "\"):onPageShow - update URL not defined");
+			}
+		}
+
+	var manualUpdateLinkLabel = document.getElementById(this.targetId);
+	manualUpdateLinkLabel.value = url;
+	manualUpdateLinkLabel.setAttribute("url", url);
+
+	gUpdates.setButtons(null, "noThanksButton", "okButton", true);
+	gUpdates.wiz.getButton("finish").focus();
+	}
+ManualUpdatePage_TFBird.prototype.onExtra2 = function()
+	{
+	gUpdates.never();
+	gUpdates.wiz.cancel();
+	}
+
+var gManualUpdate2Page_TFBird = new ManualUpdatePage_TFBird("manualUpdate2LinkLabel");
+var gManualUpdate3Page_TFBird = new ManualUpdatePage_TFBird("manualUpdate3LinkLabel");
\ No newline at end of file
diff --git a/mail/base/content/updatesOverlay.xul b/mail/base/content/updatesOverlay.xul
new file mode 100644
--- /dev/null
+++ b/mail/base/content/updatesOverlay.xul
@@ -0,0 +1,46 @@
+<?xml version="1.0"?>
+<!DOCTYPE overlay [
+
+<!ENTITY % brandDTD SYSTEM "chrome://branding/locale/brand.dtd">
+%brandDTD;
+<!ENTITY % updatesDTD SYSTEM "chrome://messenger/locale/updatesOverlay.dtd">
+%updatesDTD;
+
+]>
+<overlay id="TenfourbirdUpdateOverlay" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+<wizard id="updates">
+
+  <script type="application/javascript" src="chrome://messenger/content/updatesOverlay.js"/>
+
+  <wizardpage id="manualUpdate2" removeelement="true"/>
+  <wizardpage id="manualUpdate2" pageid="manualUpdate2" object="gManualUpdate2Page_TFBird"
+	onpageshow="gManualUpdate2Page_TFBird.onPageShow();" onextra2="gManualUpdate2Page_TFBird.onExtra2();">
+    <updateheader label="&manualUpdate2.title;"/>
+    <vbox class="update-content" flex="1">
+      <label id="manualUpdate2Desc">&manualUpdate2.desc;</label>
+      <separator class="thin"/>
+      <label>&manualUpdate2GetMsg.label;</label>
+      <hbox>
+        <label class="text-link" id="manualUpdate2LinkLabel" value=""
+               onclick="openUpdateURL(event);"/>
+      </hbox>
+    </vbox>
+  </wizardpage>
+
+  <wizardpage id="manualUpdate3" removeelement="true"/>
+  <wizardpage id="manualUpdate3" pageid="manualUpdate3" object="gManualUpdate3Page_TFBird"
+	onpageshow="gManualUpdate3Page_TFBird.onPageShow();" onextra2="gManualUpdate3Page_TFBird.onExtra2();">
+    <updateheader label="&manualUpdate3.title;"/>
+    <vbox class="update-content" flex="1">
+      <label id="manualUpdate3Desc">&manualUpdate3.desc;</label>
+      <separator class="thin"/>
+      <label>&manualUpdate3GetMsg.label;</label>
+      <hbox>
+        <label class="text-link" id="manualUpdate3LinkLabel" value=""
+               onclick="openUpdateURL(event);"/>
+      </hbox>
+    </vbox>
+  </wizardpage>
+
+</wizard>
+</overlay>
\ No newline at end of file
diff --git a/mail/locales/en-US/chrome/messenger/updatesOverlay.dtd b/mail/locales/en-US/chrome/messenger/updatesOverlay.dtd
new file mode 100644
--- /dev/null
+++ b/mail/locales/en-US/chrome/messenger/updatesOverlay.dtd
@@ -0,0 +1,12 @@
+<!ENTITY  manualUpdate2.title              "Update Available">
+<!ENTITY  manualUpdate2.desc               "A recommended security and stability update is available.
+                                           You should download and install it to make sure &brandShortName; is up to date.">
+<!ENTITY  manualUpdate2.space.desc         "A recommended security and stability update is available, but you do
+                                           not have enough space to install it.">
+<!ENTITY  manualUpdate2GetMsg.label        "Visit the main download page to get the &brandShortName; update:">
+
+<!ENTITY  manualUpdate3.title              "Download Update Now">
+<!ENTITY  manualUpdate3.desc               "You are now ready to update.">
+<!ENTITY  manualUpdate3.space.desc         "A recommended security and stability update is available, but you do
+                                           not have enough space to install it.">
+<!ENTITY  manualUpdate3GetMsg.label        "Visit the main download page to get the &brandShortName; update:">
\ No newline at end of file
