Core parts of Bug 378991 - Enable IDN link support in messages for Thunderbird and only pass punycode values to external apps. r=masayuki,dmose,sr=biesi
authorMark Banner <bugzilla@standard8.plus.com>
Tue, 03 Jun 2008 13:05:59 +0100
changeset 15220 b5b210b0cd7ee10e89c9933164832604d608a868
parent 15219 96e24c50fadc4a7b917125d2648fd3533e10768f
child 15221 4ed6e3010458c9aae6e903267d4cfb4b6f7953a7
push idunknown
push userunknown
push dateunknown
reviewersmasayuki, dmose, biesi
bugs378991
milestone1.9.1a1pre
Core parts of Bug 378991 - Enable IDN link support in messages for Thunderbird and only pass punycode values to external apps. r=masayuki,dmose,sr=biesi
uriloader/exthandler/beos/nsMIMEInfoBeOS.cpp
uriloader/exthandler/mac/nsLocalHandlerAppMac.mm
uriloader/exthandler/mac/nsMIMEInfoMac.mm
uriloader/exthandler/nsLocalHandlerApp.cpp
uriloader/exthandler/tests/Makefile.in
uriloader/exthandler/tests/WriteArgument.cpp
uriloader/exthandler/tests/unit/test_punycodeURIs.js
--- a/uriloader/exthandler/beos/nsMIMEInfoBeOS.cpp
+++ b/uriloader/exthandler/beos/nsMIMEInfoBeOS.cpp
@@ -67,17 +67,17 @@ nsMIMEInfoBeOS::LoadUriInternal(nsIURI *
 	if (aURL) {
 		// Get the Protocol
 		nsCAutoString scheme;
 		aURL->GetScheme(scheme);
 		BString protoStr(scheme.get());
 		protoStr.Prepend("application/x-vnd.Be.URL.");
 		// Get the Spec
 		nsCAutoString spec;
-		aURL->GetSpec(spec);
+		aURL->GetAsciiSpec(spec);
 		const char* args[] = { spec.get() };
 		
 		//Launch the app		
 		BMimeType protocol;
 		bool isInstalled = false;
 		if (protocol.SetTo(protoStr.String()) == B_OK)
 		{
 			if(protocol.IsInstalled())
--- a/uriloader/exthandler/mac/nsLocalHandlerAppMac.mm
+++ b/uriloader/exthandler/mac/nsLocalHandlerAppMac.mm
@@ -58,18 +58,18 @@ nsLocalHandlerAppMac::LaunchWithURI(nsIU
   NS_ENSURE_SUCCESS(rv, rv);
   
   CFURLRef appURL;
   rv = lfm->GetCFURL(&appURL);
   if (NS_FAILED(rv))
     return rv;
   
   nsCAutoString uriSpec;
-  aURI->GetSpec(uriSpec);
-  
+  aURI->GetAsciiSpec(uriSpec);
+
   const UInt8* uriString = reinterpret_cast<const UInt8*>(uriSpec.get());
   CFURLRef uri = ::CFURLCreateWithBytes(NULL, uriString, uriSpec.Length(),
                                         kCFStringEncodingUTF8, NULL);
   if (!uri) {
     ::CFRelease(appURL);
     return NS_ERROR_OUT_OF_MEMORY;
   }
   
--- a/uriloader/exthandler/mac/nsMIMEInfoMac.mm
+++ b/uriloader/exthandler/mac/nsMIMEInfoMac.mm
@@ -107,17 +107,17 @@ nsMIMEInfoMac::LaunchWithFile(nsIFile *a
 
 nsresult 
 nsMIMEInfoMac::LoadUriInternal(nsIURI *aURI)
 {
   NS_ENSURE_ARG_POINTER(aURI);
   nsresult rv = NS_ERROR_FAILURE;
   
   nsCAutoString uri;
-  aURI->GetSpec(uri);
+  aURI->GetAsciiSpec(uri);
   if (!uri.IsEmpty()) {
     nsCOMPtr<nsIInternetConfigService> icService = 
       do_GetService(NS_INTERNETCONFIGSERVICE_CONTRACTID);
     if (icService)
       rv = icService->LaunchURL(uri.get());
   }
   return rv;
 }
--- a/uriloader/exthandler/nsLocalHandlerApp.cpp
+++ b/uriloader/exthandler/nsLocalHandlerApp.cpp
@@ -94,17 +94,17 @@ nsLocalHandlerApp::Equals(nsIHandlerApp 
 }
 
 NS_IMETHODIMP
 nsLocalHandlerApp::LaunchWithURI(nsIURI *aURI,
                                  nsIInterfaceRequestor *aWindowContext)
 {
   // pass the entire URI to the handler.
   nsCAutoString spec;
-  aURI->GetSpec(spec);
+  aURI->GetAsciiSpec(spec);
   return LaunchWithIProcess(spec);
 }
 
 nsresult
 nsLocalHandlerApp::LaunchWithIProcess(const nsCString& aArg)
 {
   nsresult rv;
   nsCOMPtr<nsIProcess> process = do_CreateInstance(NS_PROCESS_CONTRACTID, &rv);
--- a/uriloader/exthandler/tests/Makefile.in
+++ b/uriloader/exthandler/tests/Makefile.in
@@ -45,9 +45,25 @@ DIRS += mochitest \
         $(NULL)
 
 include $(DEPTH)/config/autoconf.mk
 
 MODULE          = test_uriloader_exthandler
 
 XPCSHELL_TESTS  = unit
 
+CPPSRCS =	\
+		WriteArgument.cpp \
+		$(NULL)
+
+SIMPLE_PROGRAMS = $(CPPSRCS:.cpp=$(BIN_SUFFIX))
+
+include $(topsrcdir)/config/config.mk
+
+DEFINES +=	\
+		-D__DESTDIR__=\"$(MOZ_BUILD_ROOT)\" \
+		$(NULL)
+
+LIBS +=		\
+		$(NSPR_LIBS) \
+		$(NULL)
+
 include $(topsrcdir)/config/rules.mk
new file mode 100644
--- /dev/null
+++ b/uriloader/exthandler/tests/WriteArgument.cpp
@@ -0,0 +1,24 @@
+#include <stdio.h>
+#include "prenv.h"
+
+int main(int argc, char* argv[])
+{
+  if (argc != 2)
+    return 1;
+
+  const char* value = PR_GetEnv("WRITE_ARGUMENT_FILE");
+
+  if (!value)
+    return 2;
+
+  FILE* outfile = fopen(value, "w");
+  if (!outfile)
+    return 3;
+
+  // We only need to write out the first argument (no newline).
+  fputs(argv[argc -1], outfile);
+
+  fclose(outfile);
+
+  return 0;
+}
new file mode 100644
--- /dev/null
+++ b/uriloader/exthandler/tests/unit/test_punycodeURIs.js
@@ -0,0 +1,125 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Mozilla code.
+ *
+ * The Initial Developer of the Original Code is
+ * Mozilla Messaging
+ * Portions created by the Initial Developer are Copyright (C) 2008
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Mark Banner <bugzilla@standard8.plus.com>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+// Encoded test URI to work on all platforms/independent of file encoding
+const kTestURI = "http://\u65e5\u672c\u8a93.jp/";
+const kExpectedURI = "http://xn--wgv71a309e.jp/";
+const kOutputFile = "result.txt";
+
+function checkFile() {
+  // This is where we expect the output
+  var tempFile = Components.classes["@mozilla.org/file/local;1"].
+    createInstance(Components.interfaces.nsILocalFile);
+  tempFile = HandlerServiceTest._dirSvc.get("CurProcD", Components.interfaces.nsIFile);
+  tempFile.append(kOutputFile);
+
+  if (!tempFile.exists())
+    do_throw("Expected File " + tempFile.path + " does not exist");
+
+  // Now read it
+  var fstream = Components.classes["@mozilla.org/network/file-input-stream;1"].
+    createInstance(Components.interfaces.nsIFileInputStream);
+  var sstream = Components.classes["@mozilla.org/scriptableinputstream;1"].
+    createInstance(Components.interfaces.nsIScriptableInputStream);
+  fstream.init(tempFile, -1, 0, 0);
+  sstream.init(fstream); 
+
+  // Read the first line only as that's the one we expect WriteArguments
+  // to be writing the argument to.
+  var data = sstream.read(4096);
+
+  sstream.close();
+  fstream.close();
+
+  // Now remove the old file
+  tempFile.remove(false);
+
+  // This currently fails on Mac with an argument like -psn_0_nnnnnn
+  // This seems to be to do with how the executable is called, but I couldn't
+  // find a way around it.
+  // Additionally the lack of OS detection in xpcshell tests sucks, so we'll
+  // have to check for the argument mac gives us.
+  if (data.substring(0, 7) != "-psn_0_")
+    do_check_eq(data, kExpectedURI);
+
+  do_test_finished();
+}
+
+function run_test() {
+  // set up the uri to test with
+  var ioService = Components.classes["@mozilla.org/network/io-service;1"].
+    getService(Components.interfaces.nsIIOService);
+
+  // set up the local handler object
+  var localHandler = 
+    Components.classes["@mozilla.org/uriloader/local-handler-app;1"].
+    createInstance(Components.interfaces.nsILocalHandlerApp);
+  localHandler.name = "Test Local Handler App";
+
+  // WriteArgument will just dump its arguments to a file for us.
+  var processDir = HandlerServiceTest._dirSvc.get("CurProcD", Components.interfaces.nsIFile);
+  var exe = processDir.clone();
+  exe.append("WriteArgument");
+  var outFile = processDir.clone();
+  outFile.append(kOutputFile);
+
+  // Set an environment variable for WriteArgument to pick up
+  var envSvc = Components.classes["@mozilla.org/process/environment;1"].
+    getService(Components.interfaces.nsIEnvironment);
+
+  // The Write Argument file needs to know where its libraries are, so
+  // just force the path variable
+  // For mac
+  envSvc.set("DYLD_LIBRARY_PATH", processDir.path);
+  // For Linux/Windows
+  envSvc.set("LD_LIBRARY_PATH", processDir.path);
+
+  // Now tell it where we want the file.
+  envSvc.set("WRITE_ARGUMENT_FILE", outFile.path);
+
+  var uri = ioService.newURI(kTestURI, null, null);
+
+  // Just check we've got these matching, if we haven't there's a problem
+  // with ascii spec or our test case.
+  do_check_eq(uri.asciiSpec, kExpectedURI);
+
+  localHandler.executable = exe;
+  localHandler.launchWithURI(uri);
+
+  do_test_pending();
+  do_timeout(1000, "checkFile()");
+}