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 #ifndef MOJO_APPS_JS_JS_APP_H_ | |
6 #define MOJO_APPS_JS_JS_APP_H_ | |
7 | |
8 #include "base/memory/ref_counted.h" | |
9 #include "base/single_thread_task_runner.h" | |
10 #include "base/threading/thread.h" | |
11 #include "gin/public/isolate_holder.h" | |
12 #include "gin/shell_runner.h" | |
13 #include "mojo/apps/js/mojo_runner_delegate.h" | |
14 #include "mojo/services/public/interfaces/content_handler/content_handler.mojom. h" | |
15 | |
16 namespace mojo { | |
17 namespace apps { | |
18 | |
19 class JSApp; | |
20 class ApplicationDelegateImpl; | |
21 | |
22 // Adds the "mojo" builtin JS module. Most of the mojo module's methods | |
23 // are defined by JSApp. | |
24 | |
25 class JSAppRunnerDelegate : public MojoRunnerDelegate { | |
Aaron Boodman
2014/09/11 05:24:53
Why subclass MojoRunnerDelegate? It looks like all
hansmuller
2014/09/11 16:44:44
Good point, I've eliminated the JSAppRunnerDelegat
| |
26 public: | |
27 JSAppRunnerDelegate(JSApp* js_app); | |
28 }; | |
29 | |
30 // Each JavaScript app started by content handler runs on its own thread and | |
31 // in its own V8 isolate. This class represents one running JS app. | |
32 // | |
33 // The lifetime of this class is defined by the content handler's internal | |
34 // "app_vector" list. | |
35 | |
36 class JSApp { | |
37 public: | |
38 JSApp(ApplicationDelegateImpl* content_handler_app, | |
39 const std::string& url, | |
40 URLResponsePtr content); | |
41 ~JSApp(); | |
42 | |
43 bool Start(); | |
44 void Quit(); | |
45 Handle ConnectToService(const std::string& application_url, | |
46 const std::string& interface_name); | |
47 | |
48 private: | |
49 void Run(); | |
50 void Terminate(); | |
51 | |
52 // Used to CHECK that we're running on the correct thread. | |
53 bool on_content_handler_thread() const; | |
54 bool on_js_app_thread() const; | |
55 | |
56 ApplicationDelegateImpl* content_handler_app_; | |
57 std::string url_; | |
58 URLResponsePtr content_; | |
59 base::Thread thread_; | |
60 scoped_refptr<base::SingleThreadTaskRunner> content_handler_task_runner_; | |
61 scoped_refptr<base::SingleThreadTaskRunner> js_app_task_runner_; | |
62 JSAppRunnerDelegate runner_delegate_; | |
63 scoped_ptr<gin::IsolateHolder> isolate_holder_; | |
64 scoped_ptr<gin::ShellRunner> shell_runner_; | |
65 | |
66 DISALLOW_COPY_AND_ASSIGN(JSApp); | |
67 }; | |
68 | |
69 } // namespace apps | |
70 } // namespace mojo | |
71 | |
72 #endif // MOJO_APPS_JS_JS_APP_H_ | |
OLD | NEW |