| 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_APPS_JS_CONTENT_HANDLER_H_ | 5 #ifndef MOJO_APPS_JS_CONTENT_HANDLER_H_ |
| 6 #define MOJO_APPS_JS_CONTENT_HANDLER_H_ | 6 #define MOJO_APPS_JS_CONTENT_HANDLER_H_ |
| 7 | 7 |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
| 10 #include "mojo/public/cpp/application/application_delegate.h" | 10 #include "mojo/public/cpp/application/application_delegate.h" |
| 11 #include "mojo/public/cpp/application/interface_factory_impl.h" | 11 #include "mojo/public/cpp/system/message_pipe.h" |
| 12 #include "mojo/services/public/interfaces/content_handler/content_handler.mojom.
h" | |
| 13 | 12 |
| 14 namespace mojo { | 13 namespace mojo { |
| 15 | 14 |
| 16 class ApplcationImpl; | 15 class ApplcationImpl; |
| 17 | 16 |
| 18 namespace apps { | 17 namespace apps { |
| 19 | 18 |
| 20 class ApplicationDelegateImpl; | 19 class ApplicationDelegateImpl; |
| 21 class JSApp; | 20 class JSApp; |
| 22 | 21 |
| 23 // Starts a new JSApp for each OnConnect call(). | |
| 24 | |
| 25 class ContentHandlerImpl : public InterfaceImpl<ContentHandler> { | |
| 26 public: | |
| 27 ContentHandlerImpl(ApplicationDelegateImpl* content_handler); | |
| 28 virtual ~ContentHandlerImpl(); | |
| 29 | |
| 30 private: | |
| 31 virtual void OnConnect( | |
| 32 const mojo::String& url, | |
| 33 URLResponsePtr content, | |
| 34 InterfaceRequest<ServiceProvider> service_provider) override; | |
| 35 | |
| 36 ApplicationDelegateImpl* content_handler_; | |
| 37 }; | |
| 38 | |
| 39 // Manages the JSApps started by this content handler. This class owns the one | 22 // Manages the JSApps started by this content handler. This class owns the one |
| 40 // reference to the Mojo shell. JSApps post a task to the content handler's | 23 // reference to the Mojo shell. JSApps post a task to the content handler's |
| 41 // thread to connect to a service or to quit.l | 24 // thread to connect to a service or to quit. |
| 25 // |
| 26 // The lifetime each JSApp is defined by its entry in AppVector. When the entry |
| 27 // is removed ("erased") by QuitJSApp(), the JSApp is destroyed. |
| 42 | 28 |
| 43 class ApplicationDelegateImpl : public ApplicationDelegate { | 29 class ApplicationDelegateImpl : public ApplicationDelegate { |
| 44 public: | 30 public: |
| 45 ApplicationDelegateImpl(); | 31 ApplicationDelegateImpl(); |
| 46 virtual ~ApplicationDelegateImpl(); | 32 virtual ~ApplicationDelegateImpl(); |
| 47 | 33 |
| 48 void StartJSApp(const std::string& url, URLResponsePtr content); | 34 // Add app to the AppVector and call its Start() method. |
| 49 void QuitJSApp(JSApp* app); | 35 void StartJSApp(scoped_ptr<JSApp> app); |
| 36 |
| 37 // Remove app from the AppVector; destroys the app. |
| 38 void QuitJSApp(JSApp *app); |
| 50 | 39 |
| 51 void ConnectToService(ScopedMessagePipeHandle pipe_handle, | 40 void ConnectToService(ScopedMessagePipeHandle pipe_handle, |
| 52 const std::string& application_url, | 41 const std::string& application_url, |
| 53 const std::string& interface_name); | 42 const std::string& interface_name); |
| 54 | 43 |
| 44 protected: |
| 45 // ApplicationDelegate: |
| 46 virtual void Initialize(ApplicationImpl* app) override; |
| 47 |
| 55 private: | 48 private: |
| 56 typedef ScopedVector<JSApp> AppVector; | 49 typedef ScopedVector<JSApp> AppVector; |
| 57 | |
| 58 // ApplicationDelegate methods | |
| 59 virtual void Initialize(ApplicationImpl* app) override; | |
| 60 virtual bool ConfigureIncomingConnection( | |
| 61 ApplicationConnection* connection) override; | |
| 62 | |
| 63 ApplicationImpl* application_impl_; | 50 ApplicationImpl* application_impl_; |
| 64 InterfaceFactoryImplWithContext<ContentHandlerImpl, ApplicationDelegateImpl> | |
| 65 content_handler_factory_; | |
| 66 AppVector app_vector_; | 51 AppVector app_vector_; |
| 67 }; | 52 }; |
| 68 | 53 |
| 69 } // namespace apps | 54 } // namespace apps |
| 70 } // namespace mojo | 55 } // namespace mojo |
| 71 | 56 |
| 72 #endif // MOJO_APPS_JS_CONTENT_HANDLER_H_ | 57 #endif // MOJO_APPS_JS_CONTENT_HANDLER_H_ |
| OLD | NEW |