OLD | NEW |
| (Empty) |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/files/file_util.h" | |
6 #include "base/i18n/icu_util.h" | |
7 #include "mojo/application/application_runner_chromium.h" | |
8 #include "mojo/apps/js/application_delegate_impl.h" | |
9 #include "mojo/apps/js/js_app.h" | |
10 #include "mojo/public/c/system/main.h" | |
11 #include "mojo/public/cpp/application/application_delegate.h" | |
12 #include "mojo/public/cpp/application/application_impl.h" | |
13 | |
14 namespace mojo { | |
15 namespace apps { | |
16 | |
17 class StandaloneJSApp : public JSApp { | |
18 public: | |
19 StandaloneJSApp(ApplicationDelegateImpl* app_delegate_impl, | |
20 const base::FilePath& path) | |
21 : JSApp(app_delegate_impl), | |
22 path_(path) { | |
23 } | |
24 | |
25 bool Load(std::string* source, std::string* file_name) override { | |
26 *file_name = path_.AsUTF8Unsafe(); | |
27 return ReadFileToString(path_, source); | |
28 } | |
29 | |
30 virtual MessagePipeHandle RequestorMessagePipeHandle() override { | |
31 return MessagePipeHandle(); | |
32 } | |
33 | |
34 private: | |
35 base::FilePath path_; | |
36 }; | |
37 | |
38 class StandaloneApplicationDelegateImpl : public ApplicationDelegateImpl { | |
39 private: | |
40 void Initialize(ApplicationImpl* app) override { | |
41 base::i18n::InitializeICU(); | |
42 ApplicationDelegateImpl::Initialize(app); | |
43 | |
44 for (size_t i = 1; i < app->args().size(); i++) { | |
45 base::FilePath path(base::FilePath::FromUTF8Unsafe(app->args()[i])); | |
46 scoped_ptr<JSApp> js_app(new StandaloneJSApp(this, path)); | |
47 StartJSApp(js_app.Pass()); | |
48 } | |
49 } | |
50 }; | |
51 | |
52 } // namespace apps | |
53 } // namespace mojo | |
54 | |
55 MojoResult MojoMain(MojoHandle shell_handle) { | |
56 mojo::ApplicationRunnerChromium runner( | |
57 new mojo::apps::StandaloneApplicationDelegateImpl()); | |
58 return runner.Run(shell_handle); | |
59 } | |
OLD | NEW |