| 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 #ifndef SERVICES_JS_JS_APP_H_ | 5 #ifndef SERVICES_JS_JS_APP_H_ |
| 6 #define SERVICES_JS_JS_APP_H_ | 6 #define SERVICES_JS_JS_APP_H_ |
| 7 | 7 |
| 8 #include "gin/public/isolate_holder.h" | 8 #include "gin/public/isolate_holder.h" |
| 9 #include "gin/shell_runner.h" | 9 #include "gin/shell_runner.h" |
| 10 #include "mojo/application/content_handler_factory.h" | 10 #include "mojo/application/content_handler_factory.h" |
| 11 #include "mojo/public/cpp/system/message_pipe.h" | 11 #include "mojo/public/cpp/system/message_pipe.h" |
| 12 #include "mojo/public/interfaces/application/application.mojom.h" | 12 #include "mojo/public/interfaces/application/application.mojom.h" |
| 13 #include "mojo/public/interfaces/application/shell.mojom.h" | 13 #include "mojo/public/interfaces/application/shell.mojom.h" |
| 14 #include "services/js/js_app_runner_delegate.h" | 14 #include "services/js/js_app_runner_delegate.h" |
| 15 #include "v8/include/v8.h" | 15 #include "v8/include/v8.h" |
| 16 | 16 |
| 17 namespace mojo { | |
| 18 namespace js { | 17 namespace js { |
| 19 | 18 |
| 20 class JSApp; | 19 class JSApp; |
| 21 class JSAppMessageLoopObservers; | 20 class JSAppMessageLoopObservers; |
| 22 class ApplicationDelegateImpl; | 21 class ApplicationDelegateImpl; |
| 23 | 22 |
| 24 // Each JavaScript app started by the content handler runs on its own thread | 23 // Each JavaScript app started by the content handler runs on its own thread |
| 25 // and in its own V8 isolate. This class represents one running JS app. | 24 // and in its own V8 isolate. This class represents one running JS app. |
| 26 | 25 |
| 27 class JSApp : public InterfaceImpl<Application>, | 26 class JSApp : public mojo::InterfaceImpl<mojo::Application>, |
| 28 public ContentHandlerFactory::HandledApplicationHolder { | 27 public mojo::ContentHandlerFactory::HandledApplicationHolder { |
| 29 public: | 28 public: |
| 30 JSApp(ShellPtr shell, URLResponsePtr response); | 29 JSApp(mojo::ShellPtr shell, mojo::URLResponsePtr response); |
| 31 virtual ~JSApp(); | 30 virtual ~JSApp(); |
| 32 | 31 |
| 33 // This method delegates to shell_->ConnectToApplication(). | 32 // This method delegates to shell_->ConnectToApplication(). |
| 34 void ConnectToApplication(const std::string& application_url, | 33 void ConnectToApplication(const std::string& application_url, |
| 35 v8::Handle<v8::Value> service_provider); | 34 v8::Handle<v8::Value> service_provider); |
| 36 void Quit(); | 35 void Quit(); |
| 37 | 36 |
| 38 private: | 37 private: |
| 39 static const char kMainModuleName[]; | 38 static const char kMainModuleName[]; |
| 40 | 39 |
| 41 void OnAppLoaded(std::string url, v8::Handle<v8::Value> module); | 40 void OnAppLoaded(std::string url, v8::Handle<v8::Value> module); |
| 42 | 41 |
| 43 // Application methods: | 42 // Application methods: |
| 44 void AcceptConnection(const String& requestor_url, | 43 void AcceptConnection(const mojo::String& requestor_url, |
| 45 ServiceProviderPtr provider) override; | 44 mojo::ServiceProviderPtr provider) override; |
| 46 void Initialize(Array<String> args) override; | 45 void Initialize(mojo::Array<mojo::String> args) override; |
| 47 | 46 |
| 48 void CallAppInstanceMethod( | 47 void CallAppInstanceMethod( |
| 49 const std::string& name, int argc, v8::Handle<v8::Value> argv[]); | 48 const std::string& name, int argc, v8::Handle<v8::Value> argv[]); |
| 50 | 49 |
| 51 void QuitInternal(); | 50 void QuitInternal(); |
| 52 | 51 |
| 53 ShellPtr shell_; | 52 mojo::ShellPtr shell_; |
| 54 JSAppRunnerDelegate runner_delegate_; | 53 JSAppRunnerDelegate runner_delegate_; |
| 55 gin::IsolateHolder isolate_holder_; | 54 gin::IsolateHolder isolate_holder_; |
| 56 scoped_ptr<gin::ShellRunner> shell_runner_; | 55 scoped_ptr<gin::ShellRunner> shell_runner_; |
| 57 v8::Persistent<v8::Object> app_instance_; | 56 v8::Persistent<v8::Object> app_instance_; |
| 58 scoped_ptr<JSAppMessageLoopObservers> message_loop_observers_; | 57 scoped_ptr<JSAppMessageLoopObservers> message_loop_observers_; |
| 59 | 58 |
| 60 DISALLOW_COPY_AND_ASSIGN(JSApp); | 59 DISALLOW_COPY_AND_ASSIGN(JSApp); |
| 61 }; | 60 }; |
| 62 | 61 |
| 63 } // namespace js | 62 } // namespace js |
| 64 } // namespace mojo | |
| 65 | 63 |
| 66 #endif // SERVICES_JS_JS_APP_H_ | 64 #endif // SERVICES_JS_JS_APP_H_ |
| OLD | NEW |