| 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 MOJO_SERVICES_JS_JS_APP_H_ | 5 #ifndef SERVICES_JS_JS_APP_H_ | 
| 6 #define MOJO_SERVICES_JS_JS_APP_H_ | 6 #define SERVICES_JS_JS_APP_H_ | 
| 7 | 7 | 
| 8 #include "base/memory/ref_counted.h" |  | 
| 9 #include "base/threading/thread.h" |  | 
| 10 #include "gin/public/isolate_holder.h" | 8 #include "gin/public/isolate_holder.h" | 
| 11 #include "gin/shell_runner.h" | 9 #include "gin/shell_runner.h" | 
| 12 #include "mojo/application/content_handler_factory.h" | 10 #include "mojo/application/content_handler_factory.h" | 
| 13 #include "mojo/edk/js/mojo_runner_delegate.h" | 11 #include "mojo/public/cpp/system/message_pipe.h" | 
| 14 #include "mojo/public/cpp/application/application_delegate.h" |  | 
| 15 #include "mojo/public/interfaces/application/application.mojom.h" | 12 #include "mojo/public/interfaces/application/application.mojom.h" | 
| 16 #include "mojo/public/interfaces/application/shell.mojom.h" | 13 #include "mojo/public/interfaces/application/shell.mojom.h" | 
| 17 #include "mojo/services/public/interfaces/network/url_loader.mojom.h" | 14 #include "services/js/js_app_runner_delegate.h" | 
|  | 15 #include "v8/include/v8.h" | 
| 18 | 16 | 
| 19 namespace mojo { | 17 namespace mojo { | 
| 20 namespace js { | 18 namespace js { | 
| 21 | 19 | 
| 22 class JSApp; | 20 class JSApp; | 
| 23 class ApplicationDelegateImpl; | 21 class ApplicationDelegateImpl; | 
| 24 | 22 | 
| 25 // Each JavaScript app started by content handler runs on its own thread and | 23 // Each JavaScript app started by the content handler runs on its own thread | 
| 26 // 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. | 
| 27 | 25 | 
| 28 class JSApp : public InterfaceImpl<Application>, | 26 class JSApp : public InterfaceImpl<Application>, | 
| 29               public ContentHandlerFactory::HandledApplicationHolder { | 27               public ContentHandlerFactory::HandledApplicationHolder { | 
| 30  public: | 28  public: | 
| 31   JSApp(ShellPtr shell, URLResponsePtr response); | 29   JSApp(ShellPtr shell, URLResponsePtr response); | 
| 32   virtual ~JSApp(); | 30   virtual ~JSApp(); | 
| 33 | 31 | 
| 34   // Called by the JS mojo module to quit this JS app. See mojo.js. | 32   // This method just delegates to shell_->ConnectToApplication(). | 
|  | 33   void ConnectToApplication(const std::string& application_url, | 
|  | 34                             ScopedMessagePipeHandle service_provider); | 
|  | 35 | 
| 35   void Quit(); | 36   void Quit(); | 
| 36 | 37 | 
| 37   // Called by the JS mojo module to connect to a Mojo application. | 38  private: | 
| 38   MessagePipeHandle ConnectToApplication(const std::string& application_url); | 39   static const char kMainModuleName[]; | 
| 39 | 40 | 
| 40   // Called by the JS mojo module to retrieve the ServiceProvider message | 41   void OnAppLoaded(std::string url, v8::Handle<v8::Value> module); | 
| 41   // pipe handle passed to the JS application's AcceptConnection() method. |  | 
| 42   MessagePipeHandle RequestorMessagePipeHandle(); |  | 
| 43 | 42 | 
| 44  private: |  | 
| 45   // Application methods: | 43   // Application methods: | 
| 46   void AcceptConnection(const String& requestor_url, | 44   void AcceptConnection(const String& requestor_url, | 
| 47                         ServiceProviderPtr provider) override; | 45                         ServiceProviderPtr provider) override; | 
| 48   void Initialize(Array<String> args) override; | 46   void Initialize(Array<String> args) override; | 
| 49 | 47 | 
|  | 48   void CallAppInstanceMethod( | 
|  | 49       const std::string& name, int argc, v8::Handle<v8::Value> argv[]); | 
|  | 50 | 
| 50   void QuitInternal(); | 51   void QuitInternal(); | 
| 51 | 52 | 
| 52   ShellPtr shell_; | 53   ShellPtr shell_; | 
| 53   js::MojoRunnerDelegate runner_delegate; | 54   JSAppRunnerDelegate runner_delegate_; | 
| 54   gin::IsolateHolder isolate_holder_; | 55   gin::IsolateHolder isolate_holder_; | 
| 55   scoped_ptr<gin::ShellRunner> shell_runner_; | 56   scoped_ptr<gin::ShellRunner> shell_runner_; | 
| 56   std::string source_; | 57   v8::Persistent<v8::Object> app_instance_; | 
| 57   std::string file_name_; |  | 
| 58   ScopedMessagePipeHandle requestor_handle_; |  | 
| 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 | 63 }  // namespace mojo | 
| 65 | 64 | 
| 66 #endif  // MOJO_SERVICES_JS_JS_APP_H_ | 65 #endif  // SERVICES_JS_JS_APP_H_ | 
| OLD | NEW | 
|---|