Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / content / browser / mojo / mojo_shell_context.h
blob897c01bb9ac4db5d1a6e7d29f60fd5627d826c48
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_
8 #include <map>
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/application/public/interfaces/shell.mojom.h"
17 #include "mojo/shell/application_manager.h"
19 class GURL;
21 namespace mojo {
22 class ApplicationDelegate;
25 namespace content {
27 // MojoShellContext hosts the browser's ApplicationManager, coordinating
28 // app registration and interconnection.
29 class CONTENT_EXPORT MojoShellContext
30 : public NON_EXPORTED_BASE(mojo::shell::ApplicationManager::Delegate) {
31 public:
32 using StaticApplicationMap =
33 std::map<GURL, base::Callback<scoped_ptr<mojo::ApplicationDelegate>()>>;
35 MojoShellContext();
36 ~MojoShellContext() override;
38 // Connects an application at |url| and gets a handle to its exposed services.
39 // This is only intended for use in browser code that's not part of some Mojo
40 // application. May be called from any thread. |requestor_url| is given to
41 // the target application as the requestor's URL upon connection.
42 static void ConnectToApplication(
43 const GURL& url,
44 const GURL& requestor_url,
45 mojo::InterfaceRequest<mojo::ServiceProvider> request,
46 mojo::ServiceProviderPtr exposed_services,
47 const mojo::shell::CapabilityFilter& filter,
48 const mojo::Shell::ConnectToApplicationCallback& callback);
50 static void SetApplicationsForTest(const StaticApplicationMap* apps);
52 private:
53 class Proxy;
54 friend class Proxy;
56 void ConnectToApplicationOnOwnThread(
57 const GURL& url,
58 const GURL& requestor_url,
59 mojo::InterfaceRequest<mojo::ServiceProvider> request,
60 mojo::ServiceProviderPtr exposed_services,
61 const mojo::shell::CapabilityFilter& filter,
62 const mojo::Shell::ConnectToApplicationCallback& callback);
64 // mojo::shell::ApplicationManager::Delegate:
65 GURL ResolveMappings(const GURL& url) override;
66 GURL ResolveMojoURL(const GURL& url) override;
67 bool CreateFetcher(
68 const GURL& url,
69 const mojo::shell::Fetcher::FetchCallback& loader_callback) override;
71 static base::LazyInstance<scoped_ptr<Proxy>> proxy_;
73 scoped_ptr<mojo::shell::ApplicationManager> application_manager_;
75 DISALLOW_COPY_AND_ASSIGN(MojoShellContext);
78 } // namespace content
80 #endif // CONTENT_BROWSER_MOJO_MOJO_SHELL_CONTEXT_H_