| 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_APPLICATION_MANAGER_APPLICATION_LOADER_H_ | 5 #ifndef MOJO_APPLICATION_MANAGER_APPLICATION_LOADER_H_ |
| 6 #define MOJO_APPLICATION_MANAGER_APPLICATION_LOADER_H_ | 6 #define MOJO_APPLICATION_MANAGER_APPLICATION_LOADER_H_ |
| 7 | 7 |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "mojo/application_manager/application_manager_export.h" | 9 #include "mojo/application_manager/application_manager_export.h" |
| 10 #include "mojo/public/cpp/system/core.h" | 10 #include "mojo/public/cpp/system/core.h" |
| 11 #include "mojo/services/public/interfaces/network/url_loader.mojom.h" | 11 #include "mojo/services/public/interfaces/network/url_loader.mojom.h" |
| 12 #include "url/gurl.h" | 12 #include "url/gurl.h" |
| 13 | 13 |
| 14 namespace mojo { | 14 namespace mojo { |
| 15 | 15 |
| 16 class ApplicationManager; | 16 class ApplicationManager; |
| 17 | 17 |
| 18 // Interface to allowing loading behavior to be established for schemes, | 18 // Interface to allowing loading behavior to be established for schemes, |
| 19 // specific urls or as the default. | 19 // specific urls or as the default. |
| 20 // A ApplicationLoader is responsible to using whatever mechanism is appropriate | 20 // A ApplicationLoader is responsible to using whatever mechanism is appropriate |
| 21 // to load the application at url. | 21 // to load the application at url. |
| 22 // The handle to the shell is passed to that application so it can bind it to | 22 // The handle to the shell is passed to that application so it can bind it to |
| 23 // a Shell instance. This will give the Application a way to connect to other | 23 // a Shell instance. This will give the Application a way to connect to other |
| 24 // apps and services. | 24 // apps and services. |
| 25 class MOJO_APPLICATION_MANAGER_EXPORT ApplicationLoader { | 25 class MOJO_APPLICATION_MANAGER_EXPORT ApplicationLoader { |
| 26 public: | 26 public: |
| 27 class MOJO_APPLICATION_MANAGER_EXPORT LoadCallbacks | 27 typedef base::Callback< |
| 28 : public base::RefCounted<LoadCallbacks> { | 28 void(const GURL&, ScopedMessagePipeHandle, URLResponsePtr)> LoadCallback; |
| 29 public: | |
| 30 // Register the requested application with ApplicationManager. If the | |
| 31 // returned handle is valid, it should be used to implement the | |
| 32 // mojo::Application interface. | |
| 33 virtual ScopedMessagePipeHandle RegisterApplication() = 0; | |
| 34 | |
| 35 // Load the requested application with a content handler. | |
| 36 virtual void LoadWithContentHandler(const GURL& content_handler_url, | |
| 37 URLResponsePtr url_response) = 0; | |
| 38 | |
| 39 protected: | |
| 40 friend base::RefCounted<LoadCallbacks>; | |
| 41 virtual ~LoadCallbacks() {} | |
| 42 }; | |
| 43 | |
| 44 // Implements RegisterApplication() by returning a handle that was specified | |
| 45 // at construction time. LoadWithContentHandler() is not supported. | |
| 46 class MOJO_APPLICATION_MANAGER_EXPORT SimpleLoadCallbacks | |
| 47 : public LoadCallbacks { | |
| 48 public: | |
| 49 SimpleLoadCallbacks(ScopedMessagePipeHandle shell_handle); | |
| 50 ScopedMessagePipeHandle RegisterApplication() override; | |
| 51 void LoadWithContentHandler(const GURL& content_handler_url, | |
| 52 URLResponsePtr response) override; | |
| 53 | |
| 54 private: | |
| 55 ScopedMessagePipeHandle shell_handle_; | |
| 56 ~SimpleLoadCallbacks() override; | |
| 57 }; | |
| 58 | |
| 59 virtual ~ApplicationLoader() {} | 29 virtual ~ApplicationLoader() {} |
| 60 | 30 |
| 61 // Load the application named |url|. Applications can be loaded two ways: | 31 // Load the application named |url|. Applications can be loaded two ways: |
| 62 // | 32 // |
| 63 // 1. |url| can refer directly to a Mojo application. In this case, call | 33 // 1. |url| can refer directly to a Mojo application. In this case, |
| 64 // callbacks->RegisterApplication(). The returned handle should be used to | 34 // shell_handle should be used to implement the mojo.Application interface. |
| 65 // implement the mojo.Application interface. Note that the returned handle | |
| 66 // can be invalid in the case where the application has already been | |
| 67 // loaded. | |
| 68 // | 35 // |
| 69 // 2. |url| can refer to some content that can be handled by some other Mojo | 36 // 2. |url| can refer to some content that can be handled by some other Mojo |
| 70 // application. In this case, call callbacks->LoadWithContentHandler() and | 37 // application. In this case, call callbacks and specify the URL of the |
| 71 // specify the URL of the application that should handle the content. | 38 // application that should handle the content. The specified application |
| 72 // The specified application must implement the mojo.ContentHandler | 39 // must implement the mojo.ContentHandler interface. |
| 73 // interface. | |
| 74 virtual void Load(ApplicationManager* application_manager, | 40 virtual void Load(ApplicationManager* application_manager, |
| 75 const GURL& url, | 41 const GURL& url, |
| 76 scoped_refptr<LoadCallbacks> callbacks) = 0; | 42 ScopedMessagePipeHandle shell_handle, |
| 43 LoadCallback callbacks) = 0; |
| 77 | 44 |
| 78 // Called when the Application exits. | 45 // Called when the Application exits. |
| 79 virtual void OnApplicationError(ApplicationManager* manager, | 46 virtual void OnApplicationError(ApplicationManager* manager, |
| 80 const GURL& url) = 0; | 47 const GURL& url) = 0; |
| 81 | 48 |
| 82 protected: | 49 protected: |
| 83 ApplicationLoader() {} | 50 ApplicationLoader() {} |
| 84 }; | 51 }; |
| 85 | 52 |
| 86 } // namespace mojo | 53 } // namespace mojo |
| 87 | 54 |
| 88 #endif // MOJO_APPLICATION_MANAGER_APPLICATION_LOADER_H_ | 55 #endif // MOJO_APPLICATION_MANAGER_APPLICATION_LOADER_H_ |
| OLD | NEW |