author | sveerabhadra |
Tue, 12 Dec 2017 12:31:49 +0530 | |
changeset 48287 | e53948132278 |
parent 47216 | 71c04702a3d5 |
child 49303 | 440ba068d981 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
36903 | 2 |
* Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
23621
b253f11270a8
8035858: [parfait] JNI exception pending in jdk/src/windows/native/sun/windows/awt_Desktop.cpp
azvegint
parents:
16469
diff
changeset
|
26 |
#include "jni_util.h" |
1954 | 27 |
#include "awt.h" |
2 | 28 |
#include <jni.h> |
29 |
#include <shellapi.h> |
|
30 |
#include <float.h> |
|
36903 | 31 |
#include <shlobj.h> |
32 |
#include "awt_Toolkit.h" |
|
33 |
||
34 |
#define BUFFER_LIMIT MAX_PATH+1 |
|
35 |
||
36 |
#define NOTIFY_FOR_ALL_SESSIONS 1 |
|
37 |
#define NOTIFY_FOR_THIS_SESSION 0 |
|
38 |
||
39 |
typedef BOOL (WINAPI *WTSRegisterSessionNotification)(HWND,DWORD); |
|
40 |
static WTSRegisterSessionNotification fn_WTSRegisterSessionNotification; |
|
41 |
||
42 |
BOOL isSuddenTerminationEnabled = TRUE; |
|
2 | 43 |
|
44 |
#ifdef __cplusplus |
|
45 |
extern "C" { |
|
46 |
#endif |
|
47 |
||
48 |
/* |
|
49 |
* Class: sun_awt_windows_WDesktopPeer |
|
36903 | 50 |
* Method: init |
51 |
* Signature: ()V |
|
52 |
*/ |
|
53 |
JNIEXPORT void JNICALL Java_sun_awt_windows_WDesktopPeer_init |
|
54 |
(JNIEnv *, jclass) { |
|
55 |
static HMODULE libWtsapi32 = NULL; |
|
56 |
if (libWtsapi32 == NULL) { |
|
57 |
libWtsapi32 = JDK_LoadSystemLibrary("Wtsapi32.dll"); |
|
58 |
if (libWtsapi32) { |
|
59 |
fn_WTSRegisterSessionNotification = (WTSRegisterSessionNotification) |
|
60 |
GetProcAddress(libWtsapi32, "WTSRegisterSessionNotification"); |
|
61 |
if (fn_WTSRegisterSessionNotification) { |
|
62 |
HWND hwnd = AwtToolkit::GetInstance().GetHWnd(); |
|
63 |
//used for UserSessionListener |
|
64 |
fn_WTSRegisterSessionNotification(hwnd, NOTIFY_FOR_THIS_SESSION); |
|
65 |
} |
|
66 |
} |
|
67 |
} |
|
68 |
} |
|
69 |
||
70 |
/* |
|
71 |
* Class: sun_awt_windows_WDesktopPeer |
|
2 | 72 |
* Method: ShellExecute |
73 |
* Signature: (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String; |
|
74 |
*/ |
|
75 |
JNIEXPORT jstring JNICALL Java_sun_awt_windows_WDesktopPeer_ShellExecute |
|
16469
169f9bf9b5d6
6550588: java.awt.Desktop cannot open file with Windows UNC filename
alitvinov
parents:
7668
diff
changeset
|
76 |
(JNIEnv *env, jclass cls, jstring fileOrUri_j, jstring verb_j) |
2 | 77 |
{ |
16469
169f9bf9b5d6
6550588: java.awt.Desktop cannot open file with Windows UNC filename
alitvinov
parents:
7668
diff
changeset
|
78 |
LPCWSTR fileOrUri_c = JNU_GetStringPlatformChars(env, fileOrUri_j, JNI_FALSE); |
23621
b253f11270a8
8035858: [parfait] JNI exception pending in jdk/src/windows/native/sun/windows/awt_Desktop.cpp
azvegint
parents:
16469
diff
changeset
|
79 |
CHECK_NULL_RETURN(fileOrUri_c, NULL); |
1954 | 80 |
LPCWSTR verb_c = JNU_GetStringPlatformChars(env, verb_j, JNI_FALSE); |
23621
b253f11270a8
8035858: [parfait] JNI exception pending in jdk/src/windows/native/sun/windows/awt_Desktop.cpp
azvegint
parents:
16469
diff
changeset
|
81 |
if (verb_c == NULL) { |
b253f11270a8
8035858: [parfait] JNI exception pending in jdk/src/windows/native/sun/windows/awt_Desktop.cpp
azvegint
parents:
16469
diff
changeset
|
82 |
JNU_ReleaseStringPlatformChars(env, fileOrUri_j, fileOrUri_c); |
b253f11270a8
8035858: [parfait] JNI exception pending in jdk/src/windows/native/sun/windows/awt_Desktop.cpp
azvegint
parents:
16469
diff
changeset
|
83 |
return NULL; |
b253f11270a8
8035858: [parfait] JNI exception pending in jdk/src/windows/native/sun/windows/awt_Desktop.cpp
azvegint
parents:
16469
diff
changeset
|
84 |
} |
2 | 85 |
|
86 |
// 6457572: ShellExecute possibly changes FPU control word - saving it here |
|
87 |
unsigned oldcontrol87 = _control87(0, 0); |
|
16469
169f9bf9b5d6
6550588: java.awt.Desktop cannot open file with Windows UNC filename
alitvinov
parents:
7668
diff
changeset
|
88 |
HINSTANCE retval = ::ShellExecute(NULL, verb_c, fileOrUri_c, NULL, NULL, SW_SHOWNORMAL); |
29005
7d7a78defc8f
8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
26751
diff
changeset
|
89 |
DWORD error = ::GetLastError(); |
2 | 90 |
_control87(oldcontrol87, 0xffffffff); |
91 |
||
16469
169f9bf9b5d6
6550588: java.awt.Desktop cannot open file with Windows UNC filename
alitvinov
parents:
7668
diff
changeset
|
92 |
JNU_ReleaseStringPlatformChars(env, fileOrUri_j, fileOrUri_c); |
1954 | 93 |
JNU_ReleaseStringPlatformChars(env, verb_j, verb_c); |
2 | 94 |
|
95 |
if ((int)retval <= 32) { |
|
96 |
// ShellExecute failed. |
|
1954 | 97 |
LPTSTR buffer = NULL; |
98 |
int len = ::FormatMessage( |
|
2 | 99 |
FORMAT_MESSAGE_ALLOCATE_BUFFER | |
100 |
FORMAT_MESSAGE_FROM_SYSTEM | |
|
101 |
FORMAT_MESSAGE_IGNORE_INSERTS, |
|
102 |
NULL, |
|
29005
7d7a78defc8f
8064934: Incorrect Exception message from java.awt.Desktop.open()
dmarkov
parents:
26751
diff
changeset
|
103 |
error, |
2 | 104 |
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language |
1954 | 105 |
(LPTSTR)&buffer, |
2 | 106 |
0, |
107 |
NULL ); |
|
108 |
||
6641
4a5fb08cce1c
6860270: JVM crash is occuring when verifying whether Browse action is supported on WinVista 64 bit
art
parents:
5506
diff
changeset
|
109 |
if (buffer) { |
4a5fb08cce1c
6860270: JVM crash is occuring when verifying whether Browse action is supported on WinVista 64 bit
art
parents:
5506
diff
changeset
|
110 |
jstring errmsg = JNU_NewStringPlatform(env, buffer); |
4a5fb08cce1c
6860270: JVM crash is occuring when verifying whether Browse action is supported on WinVista 64 bit
art
parents:
5506
diff
changeset
|
111 |
LocalFree(buffer); |
4a5fb08cce1c
6860270: JVM crash is occuring when verifying whether Browse action is supported on WinVista 64 bit
art
parents:
5506
diff
changeset
|
112 |
return errmsg; |
4a5fb08cce1c
6860270: JVM crash is occuring when verifying whether Browse action is supported on WinVista 64 bit
art
parents:
5506
diff
changeset
|
113 |
} |
2 | 114 |
} |
115 |
||
116 |
return NULL; |
|
117 |
} |
|
118 |
||
36903 | 119 |
/* |
120 |
* Class: sun_awt_windows_WDesktopPeer |
|
121 |
* Method: moveToTrash |
|
122 |
* Signature: (Ljava/lang/String;)Z |
|
123 |
*/ |
|
124 |
JNIEXPORT jboolean JNICALL Java_sun_awt_windows_WDesktopPeer_moveToTrash |
|
125 |
(JNIEnv *env, jclass, jstring jpath) |
|
126 |
{ |
|
127 |
LPCTSTR pathStr = JNU_GetStringPlatformChars(env, jpath, (jboolean *)NULL); |
|
128 |
if (pathStr) { |
|
129 |
try { |
|
130 |
LPTSTR fileBuffer = new TCHAR[BUFFER_LIMIT]; |
|
131 |
memset(fileBuffer, 0, BUFFER_LIMIT * sizeof(TCHAR)); |
|
132 |
// the fileBuffer is double null terminated string |
|
133 |
_tcsncpy(fileBuffer, pathStr, BUFFER_LIMIT - 2); |
|
134 |
||
135 |
SHFILEOPSTRUCT fop; |
|
136 |
memset(&fop, 0, sizeof(SHFILEOPSTRUCT)); |
|
137 |
fop.hwnd = NULL; |
|
138 |
fop.wFunc = FO_DELETE; |
|
139 |
fop.pFrom = fileBuffer; |
|
48287
e53948132278
8190515: java.awt.Desktop.moveToTrash(File) prompts on Windows 7 but not on Mac
sveerabhadra
parents:
47216
diff
changeset
|
140 |
fop.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION | FOF_NOERRORUI; |
36903 | 141 |
|
142 |
int res = SHFileOperation(&fop); |
|
143 |
||
144 |
delete[] fileBuffer; |
|
145 |
JNU_ReleaseStringPlatformChars(env, jpath, pathStr); |
|
146 |
||
147 |
return !res ? JNI_TRUE : JNI_FALSE; |
|
148 |
} catch (std::bad_alloc&) { |
|
149 |
JNU_ReleaseStringPlatformChars(env, jpath, pathStr); |
|
150 |
} |
|
151 |
} |
|
152 |
return JNI_FALSE; |
|
153 |
} |
|
154 |
||
155 |
/* |
|
156 |
* Class: sun_awt_windows_WDesktopPeer |
|
157 |
* Method: setSuddenTerminationEnabled |
|
158 |
* Signature: (Z)V |
|
159 |
*/ |
|
160 |
JNIEXPORT void JNICALL Java_sun_awt_windows_WDesktopPeer_setSuddenTerminationEnabled |
|
161 |
(JNIEnv *, jclass, jboolean enabled) |
|
162 |
{ |
|
163 |
isSuddenTerminationEnabled = enabled; |
|
164 |
} |
|
165 |
||
2 | 166 |
#ifdef __cplusplus |
167 |
} |
|
168 |
#endif |