summaryrefslogtreecommitdiffstats
path: root/http/kazehakase/90_xulrunner_1.9.dpatch
blob: f208d125a94263a4dd69cfb1eb4b292a5dda6455 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
#! /bin/sh /usr/share/dpatch/dpatch-run
## 90_xulrunner_1.9.dpatch by Mike Hommey <glandium@debian.org>
##
## DP: Better support for xulrunner 1.9

@DPATCH@
--- kazehakase-0.5.4.orig/module/embed/gecko/GtkPromptService.cpp	2008-03-29 09:20:40.000000000 +0100
+++ kazehakase-0.5.4/module/embed/gecko/GtkPromptService.cpp	2008-06-15 15:13:19.385610265 +0200
@@ -36,6 +36,7 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "config.h"
 #include "GtkPromptService.h"
 #include <nsIWindowWatcher.h>
 #include <nsIWebBrowserChrome.h>
@@ -49,6 +50,23 @@
 #include <nsIDOMCharacterData.h>
 #include <nsIDOMText.h>
 #include <nsMemory.h>
+#ifdef HAVE_GECKO_1_9
+#include <nsIAuthInformation.h>
+#include <nsIStringBundle.h>
+#include <nsServiceManagerUtils.h>
+/* That is ugly but I didn't find another way, except including
+ * NS_GetAuthHostPort */
+#define kNotFound -1
+NS_COM void AppendUTF16toUTF8( const nsAString& aSource, nsACString& aDest );
+#include <nsStringAPI.h>
+#include <nsIProxiedChannel.h>
+#include <nsIProxyInfo.h>
+#include <nsIIDNService.h>
+#include <nsNetCID.h>
+#include <nsIURI.h>
+#include <nsNetUtil.h>
+#include <nsPromptUtils.h>
+#endif
 
 #include <glib/gi18n.h>
 #include "kz-prompt-dialog.h"
@@ -89,8 +107,11 @@
 {
 }
 
-
+#ifdef HAVE_GECKO_1_9
+NS_IMPL_ISUPPORTS2(GtkPromptService, nsIPromptService, nsIPromptService2)
+#else
 NS_IMPL_ISUPPORTS1(GtkPromptService, nsIPromptService)
+#endif
 
 NS_IMETHODIMP
 GtkPromptService::Alert(nsIDOMWindow* aParent, const PRUnichar* aDialogTitle, 
@@ -338,10 +359,12 @@
 	KzPromptDialog *prompt = KZ_PROMPT_DIALOG(kz_prompt_dialog_new_with_parent
 	    						(TYPE_PROMPT_USER_PASS,
 	    					         GTK_WINDOW(GetGtkWindowForDOMWindow(aParent))));
+#ifndef HAVE_GECKO_1_9
 	gchar *host = GetURIForDOMWindow(aParent);
 	kz_prompt_dialog_set_host (prompt, host);
 	if (host)
 		g_free(host);
+#endif
 	kz_prompt_dialog_set_title(prompt,
 	    			   aDialogTitle ? cTitle.get() : _("Prompt"));
 	kz_prompt_dialog_set_message_text(prompt, cText.get());
@@ -391,10 +414,12 @@
 	KzPromptDialog *prompt = KZ_PROMPT_DIALOG(kz_prompt_dialog_new_with_parent
 	    						(TYPE_PROMPT_PASS,
 	    					         GTK_WINDOW(GetGtkWindowForDOMWindow(aParent))));
+#ifndef HAVE_GECKO_1_9
 	gchar *host = GetURIForDOMWindow(aParent);
 	kz_prompt_dialog_set_host (prompt, host);
 	if (host)
 		g_free(host);
+#endif
 	kz_prompt_dialog_set_title(prompt,
 	    			   aDialogTitle ? cTitle.get() : _("Prompt"));
 	kz_prompt_dialog_set_message_text(prompt, cText.get());
@@ -510,3 +535,147 @@
 	NS_UTF16ToCString(uri, NS_CSTRING_ENCODING_UTF8, c_uri);
 	return g_strdup(c_uri.get());
 }
+
+#ifdef HAVE_GECKO_1_9
+static nsresult
+MakeDialogText(nsIChannel* aChannel, nsIAuthInformation* aAuthInfo,
+               nsString& message)
+{
+  nsresult rv;
+  nsCOMPtr<nsIStringBundleService> bundleSvc =
+    do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  nsCOMPtr<nsIStringBundle> bundle;
+  rv = bundleSvc->CreateBundle("chrome://global/locale/prompts.properties",
+                               getter_AddRefs(bundle));
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  // figure out what message to display...
+  nsCAutoString host;
+  PRInt32 port;
+  NS_GetAuthHostPort(aChannel, aAuthInfo, PR_FALSE, host, &port);
+
+  nsAutoString displayHost;
+  CopyUTF8toUTF16(host, displayHost);
+
+  nsCOMPtr<nsIURI> uri;
+  aChannel->GetURI(getter_AddRefs(uri));
+
+  nsCAutoString scheme;
+  uri->GetScheme(scheme);
+
+  nsAutoString username;
+  aAuthInfo->GetUsername(username);
+
+  PRUint32 flags;
+  aAuthInfo->GetFlags(&flags);
+  PRBool proxyAuth = (flags & nsIAuthInformation::AUTH_PROXY) != 0;
+
+  nsAutoString realm;
+  aAuthInfo->GetRealm(realm);
+
+  // Append the port if it was specified
+  if (port != -1) {
+    displayHost.Append(PRUnichar(':'));
+    displayHost.AppendInt(port);
+  }
+
+  NS_NAMED_LITERAL_STRING(proxyText, "EnterLoginForProxy");
+  NS_NAMED_LITERAL_STRING(originText, "EnterLoginForRealm");
+  NS_NAMED_LITERAL_STRING(noRealmText, "EnterUserPasswordFor");
+  NS_NAMED_LITERAL_STRING(passwordText, "EnterPasswordFor");
+
+  const PRUnichar *text;
+  if (proxyAuth) {
+    text = proxyText.get();
+  } else {
+    text = originText.get();
+
+    // prepend "scheme://"
+    nsAutoString schemeU;
+    CopyASCIItoUTF16(scheme, schemeU);
+    schemeU.AppendLiteral("://");
+    displayHost.Insert(schemeU, 0);
+  }
+
+  const PRUnichar *strings[] = { realm.get(), displayHost.get() };
+  PRUint32 count = NS_ARRAY_LENGTH(strings);
+
+  if (flags & nsIAuthInformation::ONLY_PASSWORD) {
+    text = passwordText.get();
+    strings[0] = username.get();
+  } else if (!proxyAuth && realm.IsEmpty()) {
+    text = noRealmText.get();
+    count--;
+    strings[0] = strings[1];
+  }
+
+  rv = bundle->FormatStringFromName(text, strings, count, getter_Copies(message));
+  return rv;
+}
+
+NS_METHOD
+GtkPromptService::PromptAuth(nsIDOMWindow *aParent,
+                              nsIChannel *aChannel,
+                              PRUint32 level,
+                              nsIAuthInformation *authInfo,
+                              const PRUnichar *checkboxLabel,
+                              PRBool *checkValue,
+                              PRBool *retval)
+{
+	NS_ENSURE_ARG_POINTER (retval);
+	NS_ENSURE_ARG_POINTER (authInfo);
+
+  nsString message;
+  MakeDialogText(aChannel, authInfo, message);
+
+  nsAutoString defaultUser, defaultDomain, defaultPass;
+  authInfo->GetUsername(defaultUser);
+  authInfo->GetDomain(defaultDomain);
+  authInfo->GetPassword(defaultPass);
+
+  PRUint32 flags;
+  authInfo->GetFlags(&flags);
+
+  if ((flags & nsIAuthInformation::NEED_DOMAIN) && !defaultDomain.IsEmpty()) {
+    defaultDomain.Append(PRUnichar('\\'));
+    defaultUser.Insert(defaultDomain, 0);
+  }
+
+  // NOTE: Allocation failure is not fatal here (just default to empty string
+  // if allocation fails)
+  PRUnichar *user = ToNewUnicode(defaultUser),
+    *pass = ToNewUnicode(defaultPass);
+  nsresult rv;
+  if (flags & nsIAuthInformation::ONLY_PASSWORD)
+    rv = PromptPassword(aParent, nsnull, message.get(),
+                                  &pass, checkboxLabel,
+                                  checkValue, retval);
+  else
+    rv = PromptUsernameAndPassword(aParent, nsnull, message.get(),
+                                             &user, &pass, checkboxLabel,
+                                             checkValue, retval);
+
+  nsString userStr(user);
+  nsString passStr(pass);
+  authInfo->SetUsername(userStr);
+  authInfo->SetPassword(passStr);
+
+  return rv;
+}
+
+NS_METHOD GtkPromptService::AsyncPromptAuth(nsIDOMWindow *aParent,
+                                            nsIChannel *aChannel,
+                                            nsIAuthPromptCallback *aCallback,
+                                            nsISupports *aContext,
+                                            PRUint32 level,
+                                            nsIAuthInformation *authInfo,
+                                            const PRUnichar *checkboxLabel,
+                                            PRBool *checkValue,
+                                            nsICancelable **retval)
+{
+  return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+#endif
--- kazehakase-0.5.4/module/embed/gecko/GtkPromptService.h	2008-03-29 09:20:40.000000000 +0100
+++ kazehakase-0.5.4.new/module/embed/gecko/GtkPromptService.h	2008-06-15 13:42:32.787114122 +0200
@@ -37,7 +37,11 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
+#ifdef HAVE_GECKO_1_9
+#include <nsIPromptService2.h>
+#else
 #include <nsIPromptService.h>
+#endif
 #include <gtk/gtk.h>
 
 #define NS_PROMPTSERVICE_CID \
@@ -45,7 +49,12 @@
 
 class nsIDOMWindow;
 
-class GtkPromptService : public nsIPromptService
+class GtkPromptService :
+#ifdef HAVE_GECKO_1_9
+	public nsIPromptService2
+#else
+	public nsIPromptService
+#endif
 {
 public:
 	GtkPromptService();
@@ -53,6 +62,9 @@
 
 	NS_DECL_ISUPPORTS
 	NS_DECL_NSIPROMPTSERVICE
+#ifdef HAVE_GECKO_1_9
+	NS_DECL_NSIPROMPTSERVICE2
+#endif
 
 private:
 	const char *GetButtonLabel(PRUint32 aFlags, PRUint32 aPos,
--- kazehakase-0.5.4.orig/module/embed/gecko/kz-mozutils.h	2008-03-29 09:20:40.000000000 +0100
+++ kazehakase-0.5.4/module/embed/gecko/kz-mozutils.h	2008-06-15 14:58:46.665612336 +0200
@@ -49,6 +49,8 @@
  * The following functions is taken from include/necko/nsNetUtils.h in mozilla
  */
 
+#ifndef nsNetUtil_h__
+
 inline nsresult
 GetIOService (nsIIOService **ioService)
 {
@@ -245,6 +247,6 @@
 
   return resultBuffer;
 }
-
+#endif
 
 #endif /* __KZ_MOZ_UTILS_H__ */