annotate dwt/browser/HelperAppLauncherDialog.d @ 298:eec6ddb07873

More xpcom/mozilla port
author John Reimer<terminal.node@gmail.com>
date Sun, 10 Aug 2008 22:25:43 -0700
parents 93409d9838c5
children 942da4b6558a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
1 /*******************************************************************************
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2003, 2007 IBM Corporation and others.
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
3 * All rights reserved. This program and the accompanying materials
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
4 * are made available under the terms of the Eclipse Public License v1.0
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
5 * which accompanies this distribution, and is available at
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
6 * http://www.eclipse.org/legal/epl-v10.html
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
7 *
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
8 * Contributors:
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
9 * IBM Corporation - initial API and implementation
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
10 * Port to the D programming language:
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
11 * John Reimer <terminal.node@gmail.com>
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
12 *******************************************************************************/
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
13 module dwt.browser.HelperAppLauncherDialog;
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
14
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
15 import dwt.dwthelper.utils;
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
16
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
17 import Utf = tango.text.convert.Utf;
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
18
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
19 import dwt.DWT;
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
20 //import dwt.internal.C;
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
21 import dwt.internal.mozilla.XPCOM;
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
22 //import dwt.internal.mozilla.XPCOMObject;
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
23 import dwt.internal.mozilla.nsEmbedString;
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
24 import dwt.internal.mozilla.nsID;
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
25 import dwt.internal.mozilla.nsIHelperAppLauncher;
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
26 import dwt.internal.mozilla.nsIHelperAppLauncherDialog;
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
27 import dwt.internal.mozilla.nsIHelperAppLauncher_1_8;
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
28 import dwt.internal.mozilla.nsIHelperAppLauncher_1_9;
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
29 import dwt.internal.mozilla.nsISupports;
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
30 import dwt.widgets.FileDialog;
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
31 import dwt.widgets.Shell;
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
32
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
33 class HelperAppLauncherDialog : nsHelperAppLauncherDialog {
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
34 //XPCOMObject supports;
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
35 //XPCOMObject helperAppLauncherDialog;
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
36 int refCount = 0;
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
37
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
38 this() {
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
39 //createCOMInterfaces ();
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
40 }
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
41
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
42 nsrefcnt AddRef () {
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
43 refCount++;
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
44 return refCount;
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
45 }
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
46 /+
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
47 void createCOMInterfaces () {
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
48 /* Create each of the interfaces that this object implements */
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
49 supports = new XPCOMObject (new int[] {2, 0, 0}) {
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
50 public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);}
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
51 public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();}
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
52 public int /*long*/ method2 (int /*long*/[] args) {return Release ();}
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
53 };
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
54
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
55 helperAppLauncherDialog = new XPCOMObject (new int[] {2, 0, 0, 3, 5}) {
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
56 public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);}
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
57 public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();}
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
58 public int /*long*/ method2 (int /*long*/[] args) {return Release ();}
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
59 public int /*long*/ method3 (int /*long*/[] args) {return Show (args[0], args[1], (int)/*64*/args[2]);}
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
60 public int /*long*/ method4 (int /*long*/[] args) {return PromptForSaveToFile (args[0], args[1], args[2], args[3], args[4]);}
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
61 };
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
62 }
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
63
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
64 void disposeCOMInterfaces () {
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
65 if (supports !is null) {
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
66 supports.dispose ();
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
67 supports = null;
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
68 }
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
69 if (helperAppLauncherDialog !is null) {
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
70 helperAppLauncherDialog.dispose ();
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
71 helperAppLauncherDialog = null;
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
72 }
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
73 }
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
74
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
75 int /*long*/ getAddress () {
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
76 return helperAppLauncherDialog.getAddress ();
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
77 }
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
78 +/
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
79 nsresult QueryInterface (nsID* riid, void** ppvObject) {
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
80 if (riid is null || ppvObject is null) return XPCOM.NS_ERROR_NO_INTERFACE;
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
81 //nsID guid = new nsID ();
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
82 //XPCOM.memmove (guid, riid, nsID.sizeof);
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
83
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
84 if (*riid == nsISupports.IID) {
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
85 *ppvObject = cast(void*)cast(nsISupports)this;
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
86 AddRef ();
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
87 return XPCOM.NS_OK;
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
88 }
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
89 if (*riid == nsIHelperAppLauncherDialog.IID) {
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
90 *ppvObject = cast(void*)cast(nsIHelperAppLauncherDialog)this;
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
91 AddRef ();
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
92 return XPCOM.NS_OK;
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
93 }
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
94
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
95 *ppvObject = null;
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
96 return XPCOM.NS_ERROR_NO_INTERFACE;
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
97 }
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
98
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
99 nsrefcnt Release () {
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
100 refCount--;
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
101 /*
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
102 * Note. This instance lives as long as the download it is binded to.
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
103 * Its reference count is expected to go down to 0 when the download
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
104 * has completed or when it has been cancelled. E.g. when the user
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
105 * cancels the File Dialog, cancels or closes the Download Dialog
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
106 * and when the Download Dialog goes away after the download is completed.
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
107 */
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
108 //if (refCount is 0) disposeCOMInterfaces ();
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
109 return refCount;
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
110 }
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
111
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
112 /* nsIHelperAppLauncherDialog */
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
113
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
114 nsresult Show (nsIHelperAppLauncher aLauncher, nsISupports aContext, PRUint32 aReason) {
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
115 /*
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
116 * The interface for nsIHelperAppLauncher changed in GRE versions 1.8 and 1.9. Query for
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
117 * each of these interfaces in turn until one is found.
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
118 */
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
119 // FIXME: Not sure if this will work because of different versions of
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
120 // nsIHelperAppLauncher. Remember to check. -JJR
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
121 nsIHelperAppLauncher_1_9 helperAppLauncher1;
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
122 int rc = aLauncher.QueryInterface (nsIHelperAppLauncher_1_9.IID, cast(void*)&helperAppLauncher1);
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
123 if (rc is 0) {
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
124 // nsIHelperAppLauncher_1_9 helperAppLauncher = new nsIHelperAppLauncher_1_9 (aLauncher);
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
125 rc = helperAppLauncher1.SaveToDisk (0, 0);
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
126 helperAppLauncher1.Release ();
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
127 return rc;
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
128 }
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
129
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
130 //result[0] = 0;
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
131 nsIHelperAppLauncher_1_8 helperAppLauncher2;
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
132 rc = aLauncher.QueryInterface (nsIHelperAppLauncher_1_8.IID, cast(void*)&helperAppLauncher2);
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
133 if (rc is 0) {
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
134 //nsIHelperAppLauncher_1_8 helperAppLauncher = new nsIHelperAppLauncher_1_8 (aLauncher);
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
135 rc = helperAppLauncher2.SaveToDisk (0, 0);
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
136 helperAppLauncher2.Release ();
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
137 return rc;
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
138 }
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
139
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
140 //nsIHelperAppLauncher helperAppLauncher = new nsIHelperAppLauncher (aLauncher); /* < 1.8 */
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
141 return aLauncher.SaveToDisk (0, 0);
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
142 }
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
143
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
144 int PromptForSaveToFile (nsIHelperAppLauncher arg0, nsISupports arg1, PRUnichar* arg2, PRUnichar* arg3, nsILocalFile* arg4) {
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
145 PRUnichar* aDefaultFile;
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
146 PRUnichar* aSuggestedFileExtension;
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
147 nsILocalFile* _retval;
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
148 bool hasLauncher = false;
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
149
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
150 /*
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
151 * The interface for nsIHelperAppLauncherDialog changed as of mozilla 1.5 when an
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
152 * extra argument was added to the PromptForSaveToFile method (this resulted in all
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
153 * subsequent arguments shifting right). The workaround is to provide an XPCOMObject
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
154 * that fits the newer API, and to use the first argument's type to infer whether
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
155 * the old or new nsIHelperAppLauncherDialog interface is being used (and by extension
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
156 * the ordering of the arguments). In mozilla >= 1.5 the first argument is an
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
157 * nsIHelperAppLauncher.
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
158 */
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
159 /*
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
160 * The interface for nsIHelperAppLauncher changed as of mozilla 1.8, so the first
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
161 * argument must be queried for both the old and new nsIHelperAppLauncher interfaces.
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
162 */
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
163 bool using_1_8 = false, using_1_9 = false;
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
164 // technically this should have an AddRef? -JJR
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
165 nsISupports support = cast(nsISupports)arg0;
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
166 //int /*long*/[] result = new int /*long*/[1];
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
167 if (arg0 is null)
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
168 assert(0);
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
169
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
170 nsIHelperAppLauncher_1_8 helperAppLauncher1;
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
171 int rc = support.QueryInterface (nsIHelperAppLauncher_1_8.IID, cast(void*)&helperAppLauncher1);
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
172 if (rc is 0) {
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
173 using_1_8 = true;
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
174 hasLauncher = true;
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
175 helperAppLauncher1.Release ();
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
176 } else {
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
177 nsIHelperAppLauncher_1_9 helperAppLauncher2;
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
178 rc = support.QueryInterface (nsIHelperAppLauncher_1_9.IID, cast(void*)&helperAppLauncher2);
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
179 if (rc is 0) {
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
180 using_1_9 = true;
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
181 hasLauncher = true;
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
182 helperAppLauncher2.Release;
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
183 } else {
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
184 nsIHelperAppLauncher helperAppLauncher;
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
185 rc = support.QueryInterface (nsIHelperAppLauncher.IID, cast(void*)&helperAppLauncher);
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
186 if (rc is 0) {
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
187 hasLauncher = true;
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
188 helperAppLauncher.Release;
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
189 }
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
190 }
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
191 }
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
192 //result[0] = 0;
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
193
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
194 if (hasLauncher) { /* >= 1.5 */
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
195 aDefaultFile = arg2;
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
196 aSuggestedFileExtension = arg3;
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
197 _retval = arg4;
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
198 } else { /* 1.4 */
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
199 // This call conversion probablywon't work for non-Java
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
200 // and shouldn't get called; fix it later. -JJR
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
201 aDefaultFile = arg1;
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
202 aSuggestedFileExtension = arg2;
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
203 _retval = arg3;
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
204 }
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
205
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
206 int span = XPCOM.strlen_PRUnichar (aDefaultFile);
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
207 // XPCOM.memmove (dest, aDefaultFile, length * 2);
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
208 String defaultFile = Utf.toString (aDefaultFile[0 .. span]));
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
209
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
210 span = XPCOM.strlen_PRUnichar (aSuggestedFileExtension);
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
211 //dest = new char[length];
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
212 //XPCOM.memmove (dest, aSuggestedFileExtension, length * 2);
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
213 String suggestedFileExtension = Utf.toString (aSuggestedFileExtension[0 .. span]);
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
214
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
215 Shell shell = new Shell ();
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
216 FileDialog fileDialog = new FileDialog (shell, DWT.SAVE);
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
217 fileDialog.setFileName (defaultFile);
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
218 String[] tmp ~= suggestedFileExtension;
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
219 fileDialog.setFilterExtensions (tmp);
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
220 String name = fileDialog.open ();
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
221 shell.close ();
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
222 if (name is null) {
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
223 if (hasLauncher) {
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
224 // not sure if these produce correct interface alignment. Check. -JJR
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
225 if (using_1_8) {
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
226 auto launcher = cast(nsIHelperAppLauncher_1_8)cast(void*)arg0;
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
227 rc = launcher.Cancel (XPCOM.NS_BINDING_ABORTED);
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
228 } else if (using_1_9) {
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
229 auto launcher = cast(nsIHelperAppLauncher_1_9)cast(void*)arg0;
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
230 rc = launcher.Cancel (XPCOM.NS_BINDING_ABORTED);
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
231 } else {
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
232 //nsIHelperAppLauncher launcher = new nsIHelperAppLauncher (arg0);
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
233 rc = arg0.Cancel ();
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
234 }
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
235 if (rc !is XPCOM.NS_OK) Mozilla.error (rc);
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
236 return XPCOM.NS_OK;
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
237 }
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
238 return XPCOM.NS_ERROR_FAILURE;
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
239 }
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
240 scope auto path = new nsEmbedString (name);
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
241 nsILocalFile localFile;
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
242 rc = XPCOM.NS_NewLocalFile (cast(nsAString*)path, 1, cast(void*)&localFile);
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
243 //path.dispose ();
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
244 if (rc !is XPCOM.NS_OK) Mozilla.error (rc);
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
245 if (localFile is null) Mozilla.error (XPCOM.NS_ERROR_NULL_POINTER);
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
246 /* Our own nsIDownload has been registered during the Browser initialization. It will be invoked by Mozilla. */
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
247 *_retval = cast(void*)&localFile;
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
248 //XPCOM.memmove (_retval, result, C.PTR_SIZEOF);
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
249 return XPCOM.NS_OK;
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
250 }
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
251 }