| Index: services/dart/dart_app.cc
|
| diff --git a/services/dart/dart_app.cc b/services/dart/dart_app.cc
|
| index cf13608aa6107761a2d9c46a4c9d53cb80622c2d..600a61c0012d0f87a854c323f3fff7865cdd2966 100644
|
| --- a/services/dart/dart_app.cc
|
| +++ b/services/dart/dart_app.cc
|
| @@ -15,6 +15,7 @@
|
| #include "mojo/dart/embedder/dart_state.h"
|
| #include "mojo/public/cpp/bindings/interface_request.h"
|
| #include "third_party/zlib/google/zip_reader.h"
|
| +#include "url/gurl.h"
|
|
|
| using mojo::Application;
|
|
|
| @@ -38,6 +39,59 @@ DartApp::DartApp(mojo::InterfaceRequest<Application> application_request,
|
| base::Bind(&DartApp::OnAppLoaded, base::Unretained(this)));
|
| }
|
|
|
| +// Assume that |url| ends in a file name, and as a peer to the filename
|
| +// is the packages directory.
|
| +// 1) Strip the filename.
|
| +// 2) Append with packages/.
|
| +// 3) Reconstruct full url.
|
| +static std::string SimplePackageRootFromUrl(std::string url) {
|
| + GURL gurl = GURL(url);
|
| + base::FilePath path = base::FilePath(gurl.path());
|
| + path = path.DirName();
|
| + path = path.Append("packages");
|
| + path = path.AsEndingWithSeparator();
|
| + const std::string& path_string = path.value();
|
| + GURL::Replacements path_replacement;
|
| + path_replacement.SetPath(path_string.data(),
|
| + url::Component(0, path_string.size()));
|
| + gurl = gurl.ReplaceComponents(path_replacement);
|
| + return gurl.spec();
|
| +}
|
| +
|
| +// Returns the path component from |url|.
|
| +static std::string ExtractPath(std::string url) {
|
| + GURL gurl = GURL(url);
|
| + return gurl.path();
|
| +}
|
| +
|
| +static bool IsFileScheme(std::string url) {
|
| + GURL gurl = GURL(url);
|
| + return gurl.SchemeIsFile();
|
| +}
|
| +
|
| +DartApp::DartApp(mojo::InterfaceRequest<Application> application_request,
|
| + const std::string& url,
|
| + bool strict)
|
| + : application_request_(application_request.Pass()) {
|
| + config_.application_data = reinterpret_cast<void*>(this);
|
| + config_.strict_compilation = strict;
|
| + if (IsFileScheme(url)) {
|
| + // Strip file:// and use the path directly.
|
| + config_.script_uri = ExtractPath(url);
|
| + config_.package_root = ExtractPath(SimplePackageRootFromUrl(url));
|
| + config_.use_network_loader = false;
|
| + } else {
|
| + // Use the full url.
|
| + config_.script_uri = url;
|
| + config_.package_root = SimplePackageRootFromUrl(url);
|
| + config_.use_network_loader = true;
|
| + }
|
| + config_.SetVmFlags(nullptr, 0);
|
| +
|
| + base::MessageLoop::current()->PostTask(FROM_HERE,
|
| + base::Bind(&DartApp::OnAppLoaded, base::Unretained(this)));
|
| +}
|
| +
|
| DartApp::~DartApp() {
|
| }
|
|
|
|
|