Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
4f5ee193
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
4f5ee193
编写于
4月 13, 2009
作者:
D
denis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
6590857: Drag & Drop arbitrary file copy
Reviewed-by: uta
上级
3edfa1d6
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
143 addition
and
12 deletion
+143
-12
src/share/classes/sun/awt/datatransfer/DataTransferer.java
src/share/classes/sun/awt/datatransfer/DataTransferer.java
+143
-12
未找到文件。
src/share/classes/sun/awt/datatransfer/DataTransferer.java
浏览文件 @
4f5ee193
...
...
@@ -65,10 +65,13 @@ import java.lang.reflect.Modifier;
import
java.rmi.MarshalledObject
;
import
java.security.AccessControlContext
;
import
java.security.AccessControlException
;
import
java.security.AccessController
;
import
java.security.PrivilegedAction
;
import
java.security.PrivilegedActionException
;
import
java.security.PrivilegedExceptionAction
;
import
java.security.ProtectionDomain
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
...
...
@@ -111,6 +114,8 @@ import javax.imageio.stream.ImageOutputStream;
import
sun.awt.image.ImageRepresentation
;
import
sun.awt.image.ToolkitImage
;
import
java.io.FilePermission
;
/**
* Provides a set of functions to be shared among the DataFlavor class and
...
...
@@ -1177,8 +1182,10 @@ search:
(
String
.
class
.
equals
(
flavor
.
getRepresentationClass
())
&&
isFlavorCharsetTextType
(
flavor
)
&&
isTextFormat
(
format
)))
{
String
str
=
removeSuspectedData
(
flavor
,
contents
,
(
String
)
obj
);
return
translateTransferableString
(
(
String
)
obj
,
str
,
format
);
// Source data is a Reader. Convert to a String and recur. In the
...
...
@@ -1286,6 +1293,11 @@ search:
throw
new
IOException
(
"data translation failed"
);
}
final
List
list
=
(
List
)
obj
;
final
ArrayList
fileList
=
new
ArrayList
();
final
ProtectionDomain
userProtectionDomain
=
getUserProtectionDomain
(
contents
);
int
nFiles
=
0
;
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
Object
o
=
list
.
get
(
i
);
...
...
@@ -1293,17 +1305,18 @@ search:
nFiles
++;
}
}
final
String
[]
files
=
new
String
[
nFiles
];
try
{
AccessController
.
doPrivileged
(
new
PrivilegedExceptionAction
()
{
public
Object
run
()
throws
IOException
{
for
(
int
i
=
0
,
j
=
0
;
i
<
list
.
size
();
i
++)
{
Object
o
=
list
.
get
(
i
);
if
(
o
instanceof
File
)
{
files
[
j
++]
=
((
File
)
o
).
getCanonicalPath
();
}
else
if
(
o
instanceof
String
)
{
files
[
j
++]
=
(
String
)
o
;
for
(
Object
fileObject
:
list
)
{
File
file
=
castToFile
(
fileObject
);
if
(
null
==
System
.
getSecurityManager
()
||
!(
isFileInWebstartedCache
(
file
)
||
isForbiddenToRead
(
file
,
userProtectionDomain
)))
{
fileList
.
add
(
file
.
getCanonicalPath
());
}
}
return
null
;
...
...
@@ -1313,10 +1326,11 @@ search:
throw
new
IOException
(
pae
.
getMessage
());
}
for
(
int
i
=
0
;
i
<
files
.
length
;
i
++)
{
byte
[]
bytes
=
files
[
i
].
getBytes
();
if
(
i
!=
0
)
bos
.
write
(
0
);
bos
.
write
(
bytes
,
0
,
bytes
.
length
);
for
(
int
i
=
0
;
i
<
fileList
.
size
();
i
++)
{
byte
[]
bytes
=
((
String
)
fileList
.
get
(
i
)).
getBytes
();
if
(
i
!=
0
)
bos
.
write
(
0
);
bos
.
write
(
bytes
,
0
,
bytes
.
length
);
}
// Source data is an InputStream. For arbitrary flavors, just grab the
...
...
@@ -1366,6 +1380,123 @@ search:
return
ret
;
}
private
String
removeSuspectedData
(
DataFlavor
flavor
,
final
Transferable
contents
,
final
String
str
)
throws
IOException
{
if
(
null
==
System
.
getSecurityManager
()
||
!
flavor
.
isMimeTypeEqual
(
"text/uri-list"
))
{
return
str
;
}
String
ret_val
=
""
;
final
ProtectionDomain
userProtectionDomain
=
getUserProtectionDomain
(
contents
);
try
{
ret_val
=
(
String
)
AccessController
.
doPrivileged
(
new
PrivilegedExceptionAction
()
{
public
Object
run
()
{
StringBuffer
allowedFiles
=
new
StringBuffer
(
str
.
length
());
String
[]
uriArray
=
str
.
split
(
"(\\s)+"
);
for
(
String
fileName
:
uriArray
)
{
File
file
=
new
File
(
fileName
);
if
(
file
.
exists
()
&&
!(
isFileInWebstartedCache
(
file
)
||
isForbiddenToRead
(
file
,
userProtectionDomain
)))
{
if
(
0
!=
allowedFiles
.
length
())
{
allowedFiles
.
append
(
"\\r\\n"
);
}
allowedFiles
.
append
(
fileName
);
}
}
return
allowedFiles
.
toString
();
}
});
}
catch
(
PrivilegedActionException
pae
)
{
throw
new
IOException
(
pae
.
getMessage
(),
pae
);
}
return
ret_val
;
}
private
static
ProtectionDomain
getUserProtectionDomain
(
Transferable
contents
)
{
return
contents
.
getClass
().
getProtectionDomain
();
}
private
boolean
isForbiddenToRead
(
File
file
,
ProtectionDomain
protectionDomain
)
{
if
(
null
==
protectionDomain
)
{
return
false
;
}
try
{
FilePermission
filePermission
=
new
FilePermission
(
file
.
getCanonicalPath
(),
"read, delete"
);
if
(
protectionDomain
.
implies
(
filePermission
))
{
return
false
;
}
}
catch
(
IOException
e
)
{}
return
true
;
}
// It is important do not use user's successors
// of File class.
private
File
castToFile
(
Object
fileObject
)
throws
IOException
{
String
filePath
=
null
;
if
(
fileObject
instanceof
File
)
{
filePath
=
((
File
)
fileObject
).
getCanonicalPath
();
}
else
if
(
fileObject
instanceof
String
)
{
filePath
=
(
String
)
fileObject
;
}
return
new
File
(
filePath
);
}
private
final
static
String
[]
DEPLOYMENT_CACHE_PROPERTIES
=
{
"deployment.system.cachedir"
,
"deployment.user.cachedir"
,
"deployment.javaws.cachedir"
,
"deployment.javapi.cachedir"
};
private
final
static
ArrayList
<
File
>
deploymentCacheDirectoryList
=
new
ArrayList
<
File
>();
private
static
boolean
isFileInWebstartedCache
(
File
f
)
{
if
(
deploymentCacheDirectoryList
.
isEmpty
())
{
for
(
String
cacheDirectoryProperty
:
DEPLOYMENT_CACHE_PROPERTIES
)
{
String
cacheDirectoryPath
=
System
.
getProperty
(
cacheDirectoryProperty
);
if
(
cacheDirectoryPath
!=
null
)
{
try
{
File
cacheDirectory
=
(
new
File
(
cacheDirectoryPath
)).
getCanonicalFile
();
if
(
cacheDirectory
!=
null
)
{
deploymentCacheDirectoryList
.
add
(
cacheDirectory
);
}
}
catch
(
IOException
ioe
)
{}
}
}
}
for
(
File
deploymentCacheDirectory
:
deploymentCacheDirectoryList
)
{
for
(
File
dir
=
f
;
dir
!=
null
;
dir
=
dir
.
getParentFile
())
{
if
(
dir
.
equals
(
deploymentCacheDirectory
))
{
return
true
;
}
}
}
return
false
;
}
public
Object
translateBytes
(
byte
[]
bytes
,
DataFlavor
flavor
,
long
format
,
Transferable
localeTransferable
)
throws
IOException
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录