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
3 // found in the LICENSE file.
5 #ifndef MOJO_APPLICATION_MANAGER_APPLICATION_LOADER_H_
6 #define MOJO_APPLICATION_MANAGER_APPLICATION_LOADER_H_
8 #include "base/memory/ref_counted.h"
9 #include "mojo/application_manager/application_manager_export.h"
10 #include "mojo/public/cpp/system/core.h"
11 #include "mojo/services/public/interfaces/network/url_loader.mojom.h"
16 class ApplicationManager;
18 // Interface to allowing loading behavior to be established for schemes,
19 // specific urls or as the default.
20 // A ApplicationLoader is responsible to using whatever mechanism is appropriate
21 // to load the application at url.
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
25 class MOJO_APPLICATION_MANAGER_EXPORT ApplicationLoader {
27 class MOJO_APPLICATION_MANAGER_EXPORT LoadCallbacks
28 : public base::RefCounted<LoadCallbacks> {
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;
35 // Load the requested application with a content handler.
36 virtual void LoadWithContentHandler(const GURL& content_handler_url,
37 URLResponsePtr response) = 0;
40 friend base::RefCounted<LoadCallbacks>;
41 virtual ~LoadCallbacks() {}
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 {
49 SimpleLoadCallbacks(ScopedMessagePipeHandle shell_handle);
50 virtual ScopedMessagePipeHandle RegisterApplication() OVERRIDE;
51 virtual void LoadWithContentHandler(const GURL& content_handler_url,
52 URLResponsePtr response) OVERRIDE;
55 ScopedMessagePipeHandle shell_handle_;
56 virtual ~SimpleLoadCallbacks();
59 virtual ~ApplicationLoader() {}
61 // Load the application named |url|. Applications can be loaded two ways:
63 // 1. |url| can refer directly to a Mojo application. In this case, call
64 // callbacks->RegisterApplication(). The returned handle should be used to
65 // implement the mojo.Application interface. Note that the returned handle
66 // can be invalid in the case where the application has already been
69 // 2. |url| can refer to some content that can be handled by some other Mojo
70 // application. In this case, call callbacks->LoadWithContentHandler() and
71 // specify the URL of the application that should handle the content.
72 // The specified application must implement the mojo.ContentHandler
74 virtual void Load(ApplicationManager* application_manager,
76 scoped_refptr<LoadCallbacks> callbacks) = 0;
78 virtual void OnServiceError(ApplicationManager* manager, const GURL& url) = 0;
81 ApplicationLoader() {}
86 #endif // MOJO_APPLICATION_MANAGER_APPLICATION_LOADER_H_