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