1 // Copyright 2015 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 CONTENT_BROWSER_MOJO_MOJO_SHELL_CONTEXT_H_
6 #define CONTENT_BROWSER_MOJO_MOJO_SHELL_CONTEXT_H_
10 #include "base/callback_forward.h"
11 #include "base/compiler_specific.h"
12 #include "base/lazy_instance.h"
13 #include "base/macros.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "content/common/content_export.h"
16 #include "mojo/shell/application_manager.h"
21 class ApplicationDelegate
;
26 // MojoShellContext hosts the browser's ApplicationManager, coordinating
27 // app registration and interconnection.
28 class CONTENT_EXPORT MojoShellContext
29 : public NON_EXPORTED_BASE(mojo::shell::ApplicationManager::Delegate
) {
31 using StaticApplicationMap
=
32 std::map
<GURL
, base::Callback
<scoped_ptr
<mojo::ApplicationDelegate
>()>>;
35 ~MojoShellContext() override
;
37 // Connects an application at |url| and gets a handle to its exposed services.
38 // This is only intended for use in browser code that's not part of some Mojo
39 // application. May be called from any thread. |requestor_url| is given to
40 // the target application as the requestor's URL upon connection.
41 static void ConnectToApplication(
43 const GURL
& requestor_url
,
44 mojo::InterfaceRequest
<mojo::ServiceProvider
> request
,
45 mojo::ServiceProviderPtr exposed_services
,
46 mojo::CapabilityFilterPtr filter
);
48 static void SetApplicationsForTest(const StaticApplicationMap
* apps
);
54 void ConnectToApplicationOnOwnThread(
56 const GURL
& requestor_url
,
57 mojo::InterfaceRequest
<mojo::ServiceProvider
> request
,
58 mojo::ServiceProviderPtr exposed_services
,
59 mojo::CapabilityFilterPtr filter
);
61 // mojo::shell::ApplicationManager::Delegate:
62 GURL
ResolveMappings(const GURL
& url
) override
;
63 GURL
ResolveMojoURL(const GURL
& url
) override
;
66 const mojo::shell::Fetcher::FetchCallback
& loader_callback
) override
;
68 static base::LazyInstance
<scoped_ptr
<Proxy
>> proxy_
;
70 scoped_ptr
<mojo::shell::ApplicationManager
> application_manager_
;
72 DISALLOW_COPY_AND_ASSIGN(MojoShellContext
);
75 } // namespace content
77 #endif // CONTENT_BROWSER_MOJO_MOJO_SHELL_CONTEXT_H_