Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qq_34031325
engine
提交
48d4d99f
E
engine
项目概览
qq_34031325
/
engine
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
engine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
48d4d99f
编写于
4月 05, 2016
作者:
J
John McCutchan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Merge pull request #2574 from johnmccutchan/fix_canonicalization
Fix uri canonicalization in DartLibraryProviderFiles
上级
4f39fd21
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
135 addition
and
53 deletion
+135
-53
sky/shell/dart/dart_library_provider_files.cc
sky/shell/dart/dart_library_provider_files.cc
+63
-24
sky/shell/dart/dart_library_provider_files.h
sky/shell/dart/dart_library_provider_files.h
+3
-2
sky/tools/sky_snapshot/loader.cc
sky/tools/sky_snapshot/loader.cc
+69
-27
未找到文件。
sky/shell/dart/dart_library_provider_files.cc
浏览文件 @
48d4d99f
...
...
@@ -15,9 +15,31 @@ namespace sky {
namespace
shell
{
namespace
{
void
CopyComplete
(
base
::
FilePath
file
,
bool
success
)
{
void
CopyComplete
(
base
::
FilePath
file
,
std
::
string
uri
,
bool
success
)
{
if
(
!
success
)
LOG
(
FATAL
)
<<
"Failed to load "
<<
file
.
AsUTF8Unsafe
();
LOG
(
FATAL
)
<<
"Failed to load "
<<
file
.
AsUTF8Unsafe
()
<<
" ("
<<
uri
<<
")"
;
}
// Extract the scheme prefix ('package:' or 'file:' from )
static
std
::
string
ExtractSchemePrefix
(
std
::
string
url
)
{
if
(
base
::
StartsWithASCII
(
url
,
"package:"
,
true
))
{
return
"package:"
;
}
else
if
(
base
::
StartsWithASCII
(
url
,
"file:"
,
true
))
{
return
"file:"
;
}
return
""
;
}
// Extract the path from a package: or file: url.
static
std
::
string
ExtractPath
(
std
::
string
url
)
{
if
(
base
::
StartsWithASCII
(
url
,
"package:"
,
true
))
{
base
::
ReplaceFirstSubstringAfterOffset
(
&
url
,
0
,
"package:"
,
""
);
}
else
if
(
base
::
StartsWithASCII
(
url
,
"file:"
,
true
))
{
base
::
ReplaceFirstSubstringAfterOffset
(
&
url
,
0
,
"file:"
,
""
);
}
return
url
;
}
base
::
FilePath
SimplifyPath
(
const
base
::
FilePath
&
path
)
{
...
...
@@ -66,15 +88,47 @@ void DartLibraryProviderFiles::GetLibraryAsStream(
blink
::
DataPipeConsumerCallback
callback
)
{
mojo
::
DataPipe
pipe
;
callback
.
Run
(
pipe
.
consumer_handle
.
Pass
());
base
::
FilePath
source
(
name
);
std
::
string
path
=
GetFilePathForURL
(
name
);
base
::
FilePath
source
(
path
);
scoped_refptr
<
base
::
TaskRunner
>
runner
=
base
::
WorkerPool
::
GetTaskRunner
(
true
);
mojo
::
common
::
CopyFromFile
(
source
,
pipe
.
producer_handle
.
Pass
(),
0
,
runner
.
get
(),
base
::
Bind
(
&
CopyComplete
,
source
));
runner
.
get
(),
base
::
Bind
(
&
CopyComplete
,
source
,
name
));
}
Dart_Handle
DartLibraryProviderFiles
::
CanonicalizeURL
(
Dart_Handle
library
,
Dart_Handle
url
)
{
std
::
string
string
=
blink
::
StdStringFromDart
(
url
);
if
(
base
::
StartsWithASCII
(
string
,
"dart:"
,
true
))
return
url
;
if
(
base
::
StartsWithASCII
(
string
,
"package:"
,
true
))
return
url
;
if
(
base
::
StartsWithASCII
(
string
,
"file:"
,
true
))
{
base
::
ReplaceFirstSubstringAfterOffset
(
&
string
,
0
,
"file:"
,
""
);
return
blink
::
StdStringToDart
(
string
);;
}
std
::
string
library_url
=
blink
::
StdStringFromDart
(
Dart_LibraryUrl
(
library
));
std
::
string
prefix
=
ExtractSchemePrefix
(
library_url
);
std
::
string
path
=
ExtractPath
(
library_url
);
base
::
FilePath
base_path
(
path
);
base
::
FilePath
resolved_path
=
base_path
.
DirName
().
Append
(
string
);
base
::
FilePath
normalized_path
=
SimplifyPath
(
resolved_path
);
return
blink
::
StdStringToDart
(
prefix
+
normalized_path
.
AsUTF8Unsafe
());
}
std
::
string
DartLibraryProviderFiles
::
GetFilePathForURL
(
std
::
string
url
)
{
if
(
base
::
StartsWithASCII
(
url
,
"package:"
,
true
))
return
GetFilePathForPackageURL
(
url
);
if
(
base
::
StartsWithASCII
(
url
,
"file:"
,
true
))
return
GetFilePathForFileURL
(
url
);
return
url
;
}
std
::
string
DartLibraryProviderFiles
::
CanonicalizePackageURL
(
std
::
string
url
)
{
std
::
string
DartLibraryProviderFiles
::
GetFilePathForPackageURL
(
std
::
string
url
)
{
DCHECK
(
base
::
StartsWithASCII
(
url
,
"package:"
,
true
));
base
::
ReplaceFirstSubstringAfterOffset
(
&
url
,
0
,
"package:"
,
""
);
size_t
slash
=
url
.
find
(
'/'
);
...
...
@@ -93,26 +147,11 @@ std::string DartLibraryProviderFiles::CanonicalizePackageURL(std::string url) {
return
SimplifyPath
(
path
).
AsUTF8Unsafe
();
}
std
::
string
DartLibraryProviderFiles
::
Canonicalize
FileURL
(
std
::
string
url
)
{
DCHECK
(
base
::
StartsWithASCII
(
url
,
"file:"
,
true
));
base
::
ReplaceFirstSubstringAfterOffset
(
&
url
,
0
,
"file:"
,
""
);
std
::
string
DartLibraryProviderFiles
::
GetFilePathFor
FileURL
(
std
::
string
url
)
{
DCHECK
(
base
::
StartsWithASCII
(
url
,
"file:
//
"
,
true
));
base
::
ReplaceFirstSubstringAfterOffset
(
&
url
,
0
,
"file:
//
"
,
""
);
return
url
;
}
Dart_Handle
DartLibraryProviderFiles
::
CanonicalizeURL
(
Dart_Handle
library
,
Dart_Handle
url
)
{
std
::
string
string
=
blink
::
StdStringFromDart
(
url
);
if
(
base
::
StartsWithASCII
(
string
,
"dart:"
,
true
))
return
url
;
if
(
base
::
StartsWithASCII
(
string
,
"package:"
,
true
))
return
blink
::
StdStringToDart
(
CanonicalizePackageURL
(
string
));
if
(
base
::
StartsWithASCII
(
string
,
"file:"
,
true
))
return
blink
::
StdStringToDart
(
CanonicalizeFileURL
(
string
));
base
::
FilePath
base_path
(
blink
::
StdStringFromDart
(
Dart_LibraryUrl
(
library
)));
base
::
FilePath
resolved_path
=
base_path
.
DirName
().
Append
(
string
);
base
::
FilePath
normalized_path
=
SimplifyPath
(
resolved_path
);
return
blink
::
StdStringToDart
(
normalized_path
.
AsUTF8Unsafe
());
}
}
// namespace shell
}
// namespace sky
sky/shell/dart/dart_library_provider_files.h
浏览文件 @
48d4d99f
...
...
@@ -26,8 +26,9 @@ class DartLibraryProviderFiles : public blink::DartLibraryProvider {
Dart_Handle
CanonicalizeURL
(
Dart_Handle
library
,
Dart_Handle
url
)
override
;
private:
std
::
string
CanonicalizePackageURL
(
std
::
string
url
);
std
::
string
CanonicalizeFileURL
(
std
::
string
url
);
std
::
string
GetFilePathForURL
(
std
::
string
url
);
std
::
string
GetFilePathForPackageURL
(
std
::
string
url
);
std
::
string
GetFilePathForFileURL
(
std
::
string
url
);
base
::
FilePath
packages_
;
tonic
::
PackagesMap
packages_map_
;
...
...
sky/tools/sky_snapshot/loader.cc
浏览文件 @
48d4d99f
...
...
@@ -18,6 +18,26 @@
namespace
{
// Extract the scheme prefix ('package:' or 'file:' from )
static
std
::
string
ExtractSchemePrefix
(
std
::
string
url
)
{
if
(
base
::
StartsWithASCII
(
url
,
"package:"
,
true
))
{
return
"package:"
;
}
else
if
(
base
::
StartsWithASCII
(
url
,
"file:"
,
true
))
{
return
"file:"
;
}
return
""
;
}
// Extract the path from a package: or file: url.
static
std
::
string
ExtractPath
(
std
::
string
url
)
{
if
(
base
::
StartsWithASCII
(
url
,
"package:"
,
true
))
{
base
::
ReplaceFirstSubstringAfterOffset
(
&
url
,
0
,
"package:"
,
""
);
}
else
if
(
base
::
StartsWithASCII
(
url
,
"file:"
,
true
))
{
base
::
ReplaceFirstSubstringAfterOffset
(
&
url
,
0
,
"file:"
,
""
);
}
return
url
;
}
base
::
FilePath
SimplifyPath
(
const
base
::
FilePath
&
path
)
{
std
::
vector
<
base
::
FilePath
::
StringType
>
components
;
path
.
GetComponents
(
&
components
);
...
...
@@ -43,8 +63,10 @@ class Loader {
const
std
::
set
<
std
::
string
>&
dependencies
()
const
{
return
dependencies_
;
}
std
::
string
CanonicalizePackageURL
(
std
::
string
url
);
Dart_Handle
CanonicalizeURL
(
Dart_Handle
library
,
Dart_Handle
url
);
std
::
string
GetFilePathForURL
(
std
::
string
url
);
std
::
string
GetFilePathForPackageURL
(
std
::
string
url
);
std
::
string
GetFilePathForFileURL
(
std
::
string
url
);
std
::
string
Fetch
(
const
std
::
string
&
url
);
Dart_Handle
Import
(
Dart_Handle
url
);
Dart_Handle
Source
(
Dart_Handle
library
,
Dart_Handle
url
);
...
...
@@ -83,10 +105,39 @@ void Loader::LoadPackagesMap(const base::FilePath& packages) {
}
}
std
::
string
Loader
::
CanonicalizePackageURL
(
std
::
string
url
)
{
Dart_Handle
Loader
::
CanonicalizeURL
(
Dart_Handle
library
,
Dart_Handle
url
)
{
std
::
string
string
=
StringFromDart
(
url
);
if
(
base
::
StartsWithASCII
(
string
,
"dart:"
,
true
))
return
url
;
if
(
base
::
StartsWithASCII
(
string
,
"package:"
,
true
))
return
url
;
if
(
base
::
StartsWithASCII
(
string
,
"file:"
,
true
))
{
base
::
ReplaceFirstSubstringAfterOffset
(
&
string
,
0
,
"file:"
,
""
);
return
StringToDart
(
string
);;
}
std
::
string
library_url
=
StringFromDart
(
Dart_LibraryUrl
(
library
));
std
::
string
prefix
=
ExtractSchemePrefix
(
library_url
);
std
::
string
path
=
ExtractPath
(
library_url
);
base
::
FilePath
base_path
(
path
);
base
::
FilePath
resolved_path
=
base_path
.
DirName
().
Append
(
string
);
base
::
FilePath
normalized_path
=
SimplifyPath
(
resolved_path
);
return
StringToDart
(
prefix
+
normalized_path
.
AsUTF8Unsafe
());
}
std
::
string
Loader
::
GetFilePathForURL
(
std
::
string
url
)
{
if
(
base
::
StartsWithASCII
(
url
,
"package:"
,
true
))
return
GetFilePathForPackageURL
(
url
);
if
(
base
::
StartsWithASCII
(
url
,
"file:"
,
true
))
return
GetFilePathForFileURL
(
url
);
return
url
;
}
std
::
string
Loader
::
GetFilePathForPackageURL
(
std
::
string
url
)
{
DCHECK
(
base
::
StartsWithASCII
(
url
,
"package:"
,
true
));
base
::
ReplaceFirstSubstringAfterOffset
(
&
url
,
0
,
"package:"
,
""
);
if
(
packages_map_
)
{
size_t
slash
=
url
.
find
(
'/'
);
if
(
slash
==
std
::
string
::
npos
)
return
std
::
string
();
...
...
@@ -98,24 +149,15 @@ std::string Loader::CanonicalizePackageURL(std::string url) {
if
(
base
::
StartsWithASCII
(
package_path
,
"file://"
,
true
))
{
base
::
ReplaceFirstSubstringAfterOffset
(
&
package_path
,
0
,
"file://"
,
""
);
return
package_path
+
library_path
;
}
else
{
}
auto
path
=
packages_
.
DirName
().
Append
(
package_path
).
Append
(
library_path
);
return
SimplifyPath
(
path
).
AsUTF8Unsafe
();
}
}
return
package_root_
.
Append
(
url
).
AsUTF8Unsafe
();
}
Dart_Handle
Loader
::
CanonicalizeURL
(
Dart_Handle
library
,
Dart_Handle
url
)
{
std
::
string
string
=
StringFromDart
(
url
);
if
(
base
::
StartsWithASCII
(
string
,
"dart:"
,
true
))
std
::
string
Loader
::
GetFilePathForFileURL
(
std
::
string
url
)
{
DCHECK
(
base
::
StartsWithASCII
(
url
,
"file://"
,
true
)
);
base
::
ReplaceFirstSubstringAfterOffset
(
&
url
,
0
,
"file://"
,
""
);
return
url
;
if
(
base
::
StartsWithASCII
(
string
,
"package:"
,
true
))
return
StringToDart
(
CanonicalizePackageURL
(
string
));
base
::
FilePath
base_path
(
StringFromDart
(
Dart_LibraryUrl
(
library
)));
base
::
FilePath
resolved_path
=
base_path
.
DirName
().
Append
(
string
);
base
::
FilePath
normalized_path
=
SimplifyPath
(
resolved_path
);
return
StringToDart
(
normalized_path
.
AsUTF8Unsafe
());
}
std
::
string
Loader
::
Fetch
(
const
std
::
string
&
url
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录