OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef CONTENT_PUBLIC_BROWSER_MOJO_SHELL_CONTEXT_H_ |
| 6 #define CONTENT_PUBLIC_BROWSER_MOJO_SHELL_CONTEXT_H_ |
| 7 |
| 8 #include "base/bind.h" |
| 9 #include "base/macros.h" |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "mojo/shell/application_loader.h" |
| 12 #include "url/gurl.h" |
| 13 |
| 14 namespace mojo { |
| 15 class ApplicationDelegate; |
| 16 } // namespace mojo |
| 17 |
| 18 namespace content { |
| 19 |
| 20 // The global Mojo shell context for content embedders. By default this will |
| 21 // load new application instances in a utility process. A content embedder may |
| 22 // configure the global shell by overriding |
| 23 // |ContentBrowserClient::ConfigureMojoShell|. |
| 24 class MojoShellContext { |
| 25 public: |
| 26 MojoShellContext() {} |
| 27 virtual ~MojoShellContext() {} |
| 28 |
| 29 // Adds a mapping from |url| to the given |loader|, overriding the default |
| 30 // loader used by content's Mojo shell. |
| 31 virtual void AddCustomLoader( |
| 32 const GURL& url, |
| 33 scoped_ptr<mojo::shell::ApplicationLoader> loader) = 0; |
| 34 |
| 35 // Adds a mapping from |url| to an in-process, static loader for a given |
| 36 // |mojo::ApplicationDelegate| type. |
| 37 template <typename DelegateType> |
| 38 void AddInProcessStaticLoader(const GURL& url) { |
| 39 AddCustomLoader( |
| 40 url, CreateStaticLoader( |
| 41 url.spec(), |
| 42 base::Bind( |
| 43 &MojoShellContext::LoadStaticApplication<DelegateType>))); |
| 44 } |
| 45 |
| 46 // Creates a new MojoShellContext. |
| 47 static scoped_ptr<MojoShellContext> Create(); |
| 48 |
| 49 private: |
| 50 static scoped_ptr<mojo::shell::ApplicationLoader> CreateStaticLoader( |
| 51 const std::string& name, |
| 52 const base::Callback<scoped_ptr<mojo::ApplicationDelegate>()>& factory); |
| 53 |
| 54 template <typename DelegateType> |
| 55 static scoped_ptr<mojo::ApplicationDelegate> LoadStaticApplication() { |
| 56 return scoped_ptr<mojo::ApplicationDelegate>(new DelegateType); |
| 57 } |
| 58 |
| 59 DISALLOW_COPY_AND_ASSIGN(MojoShellContext); |
| 60 }; |
| 61 |
| 62 } // namespace content |
| 63 |
| 64 #endif // CONTENT_PUBLIC_BROWSER_MOJO_SHELL_CONTEXT_H_ |
OLD | NEW |