| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 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 SHELL_CONTEXT_H_ | |
| 6 #define SHELL_CONTEXT_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/macros.h" | |
| 11 #include "mojo/edk/embedder/process_delegate.h" | |
| 12 #include "mojo/shell/application_manager/application_manager.h" | |
| 13 #include "mojo/shell/task_runners.h" | |
| 14 #include "mojo/shell/url_resolver.h" | |
| 15 | |
| 16 namespace mojo { | |
| 17 namespace shell { | |
| 18 | |
| 19 class NativeApplicationLoader; | |
| 20 | |
| 21 // The "global" context for the shell's main process. | |
| 22 class Context : public ApplicationManager::Delegate, | |
| 23 public embedder::ProcessDelegate { | |
| 24 public: | |
| 25 Context(); | |
| 26 ~Context() override; | |
| 27 | |
| 28 static void EnsureEmbedderIsInitialized(); | |
| 29 | |
| 30 // Point to the directory containing installed services, such as the network | |
| 31 // service. By default this directory is used as the base URL for resolving | |
| 32 // unknown mojo: URLs. The network service will be loaded from this directory, | |
| 33 // even when the base URL for unknown mojo: URLs is overridden. | |
| 34 void SetShellFileRoot(const base::FilePath& path); | |
| 35 | |
| 36 // Resolve an URL relative to the shell file root. This is a nop for | |
| 37 // everything but relative file URLs or URLs without a scheme. | |
| 38 GURL ResolveShellFileURL(const std::string& path); | |
| 39 | |
| 40 // Override the CWD, which is used for resolving file URLs passed in from the | |
| 41 // command line. | |
| 42 void SetCommandLineCWD(const base::FilePath& path); | |
| 43 | |
| 44 // Resolve an URL relative to the CWD mojo_shell was invoked from. This is a | |
| 45 // nop for everything but relative file URLs or URLs without a scheme. | |
| 46 GURL ResolveCommandLineURL(const std::string& path); | |
| 47 | |
| 48 // This must be called with a message loop set up for the current thread, | |
| 49 // which must remain alive until after Shutdown() is called. Returns true on | |
| 50 // success. | |
| 51 bool Init(); | |
| 52 | |
| 53 // If Init() was called and succeeded, this must be called before destruction. | |
| 54 void Shutdown(); | |
| 55 | |
| 56 void Run(const GURL& url); | |
| 57 | |
| 58 TaskRunners* task_runners() { return task_runners_.get(); } | |
| 59 ApplicationManager* application_manager() { return &application_manager_; } | |
| 60 URLResolver* url_resolver() { return &url_resolver_; } | |
| 61 | |
| 62 private: | |
| 63 class NativeViewportApplicationLoader; | |
| 64 | |
| 65 // ApplicationManager::Delegate overrides. | |
| 66 GURL ResolveMappings(const GURL& url) override; | |
| 67 GURL ResolveMojoURL(const GURL& url) override; | |
| 68 | |
| 69 // ProcessDelegate implementation. | |
| 70 void OnShutdownComplete() override; | |
| 71 | |
| 72 void OnApplicationEnd(const GURL& url); | |
| 73 | |
| 74 std::set<GURL> app_urls_; | |
| 75 scoped_ptr<TaskRunners> task_runners_; | |
| 76 ApplicationManager application_manager_; | |
| 77 URLResolver url_resolver_; | |
| 78 GURL shell_file_root_; | |
| 79 GURL command_line_cwd_; | |
| 80 | |
| 81 DISALLOW_COPY_AND_ASSIGN(Context); | |
| 82 }; | |
| 83 | |
| 84 } // namespace shell | |
| 85 } // namespace mojo | |
| 86 | |
| 87 #endif // SHELL_CONTEXT_H_ | |
| OLD | NEW |