[Extensions UI Mac] Make the toolbar bubbles use native OS X style buttons
[chromium-blink-merge.git] / mojo / runner / context.h
blob78cd1631a0948e1475589e33a9382e6057603d81
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.
5 #ifndef MOJO_RUNNER_CONTEXT_H_
6 #define MOJO_RUNNER_CONTEXT_H_
8 #include <string>
10 #include "base/macros.h"
11 #include "mojo/edk/embedder/process_delegate.h"
12 #include "mojo/runner/task_runners.h"
13 #include "mojo/runner/url_resolver.h"
14 #include "mojo/shell/application_manager.h"
16 namespace mojo {
17 namespace runner {
19 class NativeApplicationLoader;
21 // The "global" context for the shell's main process.
22 class Context : public shell::ApplicationManager::Delegate,
23 public embedder::ProcessDelegate {
24 public:
25 Context();
26 ~Context() override;
28 static void EnsureEmbedderIsInitialized();
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);
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);
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);
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);
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();
53 // If Init() was called and succeeded, this must be called before destruction.
54 void Shutdown();
56 void Run(const GURL& url);
58 // Run the application specified on the commandline.
59 void RunCommandLineApplication();
61 TaskRunners* task_runners() { return task_runners_.get(); }
62 shell::ApplicationManager* application_manager() {
63 return &application_manager_;
65 URLResolver* url_resolver() { return &url_resolver_; }
67 private:
68 class NativeViewportApplicationLoader;
70 // ApplicationManager::Delegate overrides.
71 GURL ResolveMappings(const GURL& url) override;
72 GURL ResolveMojoURL(const GURL& url) override;
73 bool CreateFetcher(
74 const GURL& url,
75 const shell::Fetcher::FetchCallback& loader_callback) override;
77 // ProcessDelegate implementation.
78 void OnShutdownComplete() override;
80 void OnApplicationEnd(const GURL& url);
82 std::set<GURL> app_urls_;
83 scoped_ptr<TaskRunners> task_runners_;
84 shell::ApplicationManager application_manager_;
85 URLResolver url_resolver_;
86 GURL shell_file_root_;
87 GURL command_line_cwd_;
89 DISALLOW_COPY_AND_ASSIGN(Context);
92 } // namespace runner
93 } // namespace mojo
95 #endif // MOJO_RUNNER_CONTEXT_H_