Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(149)

Side by Side Diff: mojo/apps/js/js_app.h

Issue 687273002: mojo: Update content handler API (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Rename content_handler.h Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #ifndef MOJO_APPS_JS_JS_APP_H_ 5 #ifndef MOJO_APPS_JS_JS_APP_H_
6 #define MOJO_APPS_JS_JS_APP_H_ 6 #define MOJO_APPS_JS_JS_APP_H_
7 7
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/threading/thread.h" 9 #include "base/threading/thread.h"
10 #include "gin/public/isolate_holder.h" 10 #include "gin/public/isolate_holder.h"
11 #include "gin/shell_runner.h" 11 #include "gin/shell_runner.h"
12 #include "mojo/application/content_handler_factory.h"
12 #include "mojo/apps/js/mojo_runner_delegate.h" 13 #include "mojo/apps/js/mojo_runner_delegate.h"
13 #include "mojo/services/public/interfaces/content_handler/content_handler.mojom. h" 14 #include "mojo/public/cpp/application/application_delegate.h"
15 #include "mojo/public/interfaces/application/application.mojom.h"
16 #include "mojo/public/interfaces/application/shell.mojom.h"
17 #include "mojo/services/public/interfaces/network/url_loader.mojom.h"
14 18
15 namespace mojo { 19 namespace mojo {
16 namespace apps { 20 namespace apps {
17 21
18 class JSApp; 22 class JSApp;
19 class ApplicationDelegateImpl; 23 class ApplicationDelegateImpl;
20 24
21 // Each JavaScript app started by content handler runs on its own thread and 25 // Each JavaScript app started by content handler runs on its own thread and
22 // in its own V8 isolate. This class represents one running JS app. 26 // in its own V8 isolate. This class represents one running JS app.
23 27
24 class JSApp { 28 class JSApp : public InterfaceImpl<Application>,
29 public ContentHandlerFactory::HandledApplicationHolder {
25 public: 30 public:
26 JSApp(ApplicationDelegateImpl* app_delegate_impl); 31 JSApp(ShellPtr shell, URLResponsePtr response);
27 virtual ~JSApp(); 32 virtual ~JSApp();
28 33
29 // Launch this app on a new thread. This method can be called on any thread.
30 // This method causes Load() and then Run() to run on a new thread.
31 bool Start();
32
33 // Subclasses must return the JS source code for this app's main script and
34 // the filename or URL that identifies the script's origin. This method will
35 // be called from this app's thread.
36 virtual bool Load(std::string* source, std::string* file_name) = 0;
37
38 // Called by the JS mojo module to quit this JS app. See mojo.js. 34 // Called by the JS mojo module to quit this JS app. See mojo.js.
39 void Quit(); 35 void Quit();
40 36
41 // Called by the JS mojo module to connect to a Mojo application. 37 // Called by the JS mojo module to connect to a Mojo application.
42 MessagePipeHandle ConnectToApplication(const std::string& application_url); 38 MessagePipeHandle ConnectToApplication(const std::string& application_url);
43 39
44 // Called by the JS mojo module to retrieve the ServiceProvider message 40 // Called by the JS mojo module to retrieve the ServiceProvider message
45 // pipe handle passed to the JS content handler's OnConnect() method. 41 // pipe handle passed to the JS content handler's OnConnect() method.
46 // If this app was not launched by the content handler then return an 42 MessagePipeHandle RequestorMessagePipeHandle();
hansmuller 2014/10/31 16:14:44 The comment for this method is no longer correct.
qsr 2014/10/31 16:31:36 Done.
47 // invalid Mojo handle.
48 virtual MessagePipeHandle RequestorMessagePipeHandle() = 0;
49 43
50 private: 44 private:
51 void Run(); 45 // Application methods:
52 void Terminate(); 46 void AcceptConnection(const String& requestor_url,
47 ServiceProviderPtr provider) override;
48 void Initialize(Array<String> args) override;
53 49
54 // Used to CHECK that we're running on the correct thread. 50 void QuitInternal();
55 bool on_app_delegate_impl_thread() const;
56 bool on_js_app_thread() const;
57 51
58 ApplicationDelegateImpl* app_delegate_impl_; 52 ShellPtr shell_;
59 base::Thread thread_; 53 MojoRunnerDelegate runner_delegate;
60 scoped_refptr<base::SingleThreadTaskRunner> app_delegate_impl_task_runner_; 54 gin::IsolateHolder isolate_holder_;
61 scoped_refptr<base::SingleThreadTaskRunner> js_app_task_runner_;
62 MojoRunnerDelegate runner_delegate_;
63 scoped_ptr<gin::IsolateHolder> isolate_holder_;
64 scoped_ptr<gin::ShellRunner> shell_runner_; 55 scoped_ptr<gin::ShellRunner> shell_runner_;
56 std::string source_;
57 std::string file_name_;
58 ScopedMessagePipeHandle requestor_handle_;
65 59
66 DISALLOW_COPY_AND_ASSIGN(JSApp); 60 DISALLOW_COPY_AND_ASSIGN(JSApp);
67 }; 61 };
68 62
69 } // namespace apps 63 } // namespace apps
70 } // namespace mojo 64 } // namespace mojo
71 65
72 #endif // MOJO_APPS_JS_JS_APP_H_ 66 #endif // MOJO_APPS_JS_JS_APP_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698