Index: shell/dynamic_application_loader.cc |
diff --git a/shell/dynamic_application_loader.cc b/shell/dynamic_application_loader.cc |
index afc9a5395c241d4861400bc0d6feb4cddba02956..50c0db5effc3b115885b8427d9acbbef9aeddd88 100644 |
--- a/shell/dynamic_application_loader.cc |
+++ b/shell/dynamic_application_loader.cc |
@@ -28,6 +28,9 @@ |
#include "shell/context.h" |
#include "shell/data_pipe_peek.h" |
#include "shell/filename_util.h" |
+#if defined(MOJO_USE_NACL) |
+#include "shell/nacl/nacl_service_runner.h" |
+#endif |
#include "shell/switches.h" |
#include "url/url_util.h" |
@@ -81,6 +84,17 @@ class DynamicApplicationLoader::Loader { |
base::TaskRunner* task_runner, |
base::Callback<void(const base::FilePath&, bool)> callback) = 0; |
+ virtual GURL URL() = 0; |
+ |
+ std::string Extension() { |
+ std::string filename = URL().ExtractFileName(); |
+ size_t dot = filename.rfind('.'); |
+ if (dot != std::string::npos) { |
+ return filename.substr(dot); |
+ } |
+ return ""; |
+ } |
+ |
virtual std::string MimeType() = 0; |
virtual bool HasMojoMagic() = 0; |
@@ -112,6 +126,14 @@ class DynamicApplicationLoader::Loader { |
// header, or looking for some specific mojo signature prepended to the |
// library. |
+ // TODO(ncbray) sniff or infer the content type at a previous stage in the |
+ // pipeline. |
+ if (Extension() == ".nexe") { |
+ AsPath(context_->task_runners()->blocking_pool(), |
+ base::Bind(&Loader::RunNexe, weak_ptr_factory_.GetWeakPtr())); |
+ return; |
+ } |
+ |
AsPath(context_->task_runners()->blocking_pool(), |
base::Bind(&Loader::RunLibrary, weak_ptr_factory_.GetWeakPtr())); |
} |
@@ -149,6 +171,25 @@ class DynamicApplicationLoader::Loader { |
base::Bind(&Loader::ReportComplete, weak_ptr_factory_.GetWeakPtr())); |
} |
+ void RunNexe(const base::FilePath& path, bool path_exists) { |
+ DCHECK(application_request_.is_pending()); |
+ |
+ if (!path_exists) { |
+ LOG(ERROR) << "Library not started because library path '" << path.value() |
+ << "' does not exist."; |
+ ReportComplete(); |
+ return; |
+ } |
+ |
+#if defined(MOJO_USE_NACL) |
+ nacl_runner_.reset(new NaClServiceRunner(context_)); |
+ nacl_runner_->Start(path, application_request_.Pass()); |
+#else |
+ LOG(ERROR) << "Library not started because Native Client is not enabled."; |
+ ReportComplete(); |
+#endif |
+ } |
+ |
DynamicServiceRunner::CleanupBehavior cleanup_behavior_; |
InterfaceRequest<Application> application_request_; |
ApplicationLoader::LoadCallback load_callback_; |
@@ -157,6 +198,9 @@ class DynamicApplicationLoader::Loader { |
MimeTypeToURLMap* mime_type_to_url_; |
DynamicServiceRunnerFactory* runner_factory_; |
scoped_ptr<DynamicServiceRunner> runner_; |
+#if defined(MOJO_USE_NACL) |
+ scoped_ptr<NaClServiceRunner> nacl_runner_; |
+#endif |
base::WeakPtrFactory<Loader> weak_ptr_factory_; |
}; |
@@ -224,6 +268,8 @@ class DynamicApplicationLoader::LocalLoader : public Loader { |
FROM_HERE, base::Bind(callback, path_, base::PathExists(path_))); |
} |
+ GURL URL() override { return url_; } |
+ |
std::string MimeType() override { return ""; } |
bool HasMojoMagic() override { |
@@ -391,6 +437,8 @@ class DynamicApplicationLoader::NetworkLoader : public Loader { |
weak_ptr_factory_.GetWeakPtr(), callback)); |
} |
+ GURL URL() override { return url_; } |
+ |
std::string MimeType() override { |
DCHECK(response_); |
return response_->mime_type; |