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_APPS_JS_CONTENT_HANDLER_H_
6 #define MOJO_APPS_JS_CONTENT_HANDLER_H_
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_vector.h"
10 #include "mojo/public/cpp/application/application_delegate.h"
11 #include "mojo/public/cpp/application/interface_factory_impl.h"
12 #include "mojo/services/public/interfaces/content_handler/content_handler.mojom.h"
20 class ApplicationDelegateImpl
;
23 // Starts a new JSApp for each OnConnect call().
25 class ContentHandlerImpl
: public InterfaceImpl
<ContentHandler
> {
27 ContentHandlerImpl(ApplicationDelegateImpl
* content_handler
);
28 virtual ~ContentHandlerImpl();
31 virtual void OnConnect(const mojo::String
& url
,
32 URLResponsePtr content
,
33 InterfaceRequest
<ServiceProvider
> service_provider
)
36 ApplicationDelegateImpl
* content_handler_
;
39 // 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
41 // thread to connect to a service or to quit.l
43 class ApplicationDelegateImpl
: public ApplicationDelegate
{
45 ApplicationDelegateImpl();
46 virtual ~ApplicationDelegateImpl();
48 void StartJSApp(const std::string
& url
, URLResponsePtr content
);
49 void QuitJSApp(JSApp
* app
);
51 void ConnectToService(ScopedMessagePipeHandle pipe_handle
,
52 const std::string
& application_url
,
53 const std::string
& interface_name
);
56 typedef ScopedVector
<JSApp
> AppVector
;
58 // ApplicationDelegate methods
59 virtual void Initialize(ApplicationImpl
* app
) MOJO_OVERRIDE
;
60 virtual bool ConfigureIncomingConnection(ApplicationConnection
* connection
)
63 ApplicationImpl
* application_impl_
;
64 InterfaceFactoryImplWithContext
<ContentHandlerImpl
, ApplicationDelegateImpl
>
65 content_handler_factory_
;
66 AppVector app_vector_
;
72 #endif // MOJO_APPS_JS_CONTENT_HANDLER_H_