OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "mojo/runner/context.h" | 5 #include "mojo/runner/context.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 #include "mojo/runner/in_process_native_runner.h" | 29 #include "mojo/runner/in_process_native_runner.h" |
30 #include "mojo/runner/out_of_process_native_runner.h" | 30 #include "mojo/runner/out_of_process_native_runner.h" |
31 #include "mojo/runner/switches.h" | 31 #include "mojo/runner/switches.h" |
32 #include "mojo/services/tracing/tracing.mojom.h" | 32 #include "mojo/services/tracing/tracing.mojom.h" |
33 #include "mojo/shell/application_loader.h" | 33 #include "mojo/shell/application_loader.h" |
34 #include "mojo/shell/application_manager.h" | 34 #include "mojo/shell/application_manager.h" |
35 #include "mojo/util/filename_util.h" | 35 #include "mojo/util/filename_util.h" |
36 #include "url/gurl.h" | 36 #include "url/gurl.h" |
37 | 37 |
38 namespace mojo { | 38 namespace mojo { |
39 namespace shell { | 39 namespace runner { |
40 namespace { | 40 namespace { |
41 | 41 |
42 // Used to ensure we only init once. | 42 // Used to ensure we only init once. |
43 class Setup { | 43 class Setup { |
44 public: | 44 public: |
45 Setup() { | 45 Setup() { |
46 embedder::Init(make_scoped_ptr(new embedder::SimplePlatformSupport())); | 46 embedder::Init(make_scoped_ptr(new embedder::SimplePlatformSupport())); |
47 } | 47 } |
48 | 48 |
49 ~Setup() {} | 49 ~Setup() {} |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 const GURL to = context->ResolveCommandLineURL(pair.second); | 96 const GURL to = context->ResolveCommandLineURL(pair.second); |
97 if (!from.is_valid() || !to.is_valid()) | 97 if (!from.is_valid() || !to.is_valid()) |
98 return false; | 98 return false; |
99 resolver->AddURLMapping(from, to); | 99 resolver->AddURLMapping(from, to); |
100 } | 100 } |
101 } | 101 } |
102 | 102 |
103 return true; | 103 return true; |
104 } | 104 } |
105 | 105 |
106 void InitContentHandlers(ApplicationManager* manager, | 106 void InitContentHandlers(shell::ApplicationManager* manager, |
107 const base::CommandLine& command_line) { | 107 const base::CommandLine& command_line) { |
108 // Default content handlers. | 108 // Default content handlers. |
109 manager->RegisterContentHandler("application/pdf", GURL("mojo:pdf_viewer")); | 109 manager->RegisterContentHandler("application/pdf", GURL("mojo:pdf_viewer")); |
110 manager->RegisterContentHandler("image/png", GURL("mojo:png_viewer")); | 110 manager->RegisterContentHandler("image/png", GURL("mojo:png_viewer")); |
111 manager->RegisterContentHandler("text/html", GURL("mojo:html_viewer")); | 111 manager->RegisterContentHandler("text/html", GURL("mojo:html_viewer")); |
112 | 112 |
113 // Command-line-specified content handlers. | 113 // Command-line-specified content handlers. |
114 std::string handlers_spec = | 114 std::string handlers_spec = |
115 command_line.GetSwitchValueASCII(switches::kContentHandlers); | 115 command_line.GetSwitchValueASCII(switches::kContentHandlers); |
116 if (handlers_spec.empty()) | 116 if (handlers_spec.empty()) |
(...skipping 26 matching lines...) Expand all Loading... |
143 LOG(ERROR) << "Invalid value for switch " << switches::kContentHandlers | 143 LOG(ERROR) << "Invalid value for switch " << switches::kContentHandlers |
144 << ": '" << parts[i + 1] << "' is not a valid URL."; | 144 << ": '" << parts[i + 1] << "' is not a valid URL."; |
145 return; | 145 return; |
146 } | 146 } |
147 // TODO(eseidel): We should also validate that the mimetype is valid | 147 // TODO(eseidel): We should also validate that the mimetype is valid |
148 // net/base/mime_util.h could do this, but we don't want to depend on net. | 148 // net/base/mime_util.h could do this, but we don't want to depend on net. |
149 manager->RegisterContentHandler(parts[i], url); | 149 manager->RegisterContentHandler(parts[i], url); |
150 } | 150 } |
151 } | 151 } |
152 | 152 |
153 void InitNativeOptions(ApplicationManager* manager, | 153 void InitNativeOptions(shell::ApplicationManager* manager, |
154 const base::CommandLine& command_line) { | 154 const base::CommandLine& command_line) { |
155 std::vector<std::string> force_in_process_url_list; | 155 std::vector<std::string> force_in_process_url_list; |
156 base::SplitString(command_line.GetSwitchValueASCII(switches::kForceInProcess), | 156 base::SplitString(command_line.GetSwitchValueASCII(switches::kForceInProcess), |
157 ',', &force_in_process_url_list); | 157 ',', &force_in_process_url_list); |
158 for (const auto& force_in_process_url : force_in_process_url_list) { | 158 for (const auto& force_in_process_url : force_in_process_url_list) { |
159 GURL gurl(force_in_process_url); | 159 GURL gurl(force_in_process_url); |
160 if (!gurl.is_valid()) { | 160 if (!gurl.is_valid()) { |
161 LOG(ERROR) << "Invalid value for switch " << switches::kForceInProcess | 161 LOG(ERROR) << "Invalid value for switch " << switches::kForceInProcess |
162 << ": '" << force_in_process_url << "'is not a valid URL."; | 162 << ": '" << force_in_process_url << "'is not a valid URL."; |
163 return; | 163 return; |
164 } | 164 } |
165 | 165 |
166 NativeRunnerFactory::Options options; | 166 shell::NativeRunnerFactory::Options options; |
167 options.force_in_process = true; | 167 options.force_in_process = true; |
168 manager->SetNativeOptionsForURL(options, gurl); | 168 manager->SetNativeOptionsForURL(options, gurl); |
169 } | 169 } |
170 } | 170 } |
171 | 171 |
172 class TracingServiceProvider : public ServiceProvider { | 172 class TracingServiceProvider : public ServiceProvider { |
173 public: | 173 public: |
174 explicit TracingServiceProvider(InterfaceRequest<ServiceProvider> request) | 174 explicit TracingServiceProvider(InterfaceRequest<ServiceProvider> request) |
175 : binding_(this, request.Pass()) {} | 175 : binding_(this, request.Pass()) {} |
176 ~TracingServiceProvider() override {} | 176 ~TracingServiceProvider() override {} |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 if (!shell_file_root_.is_valid()) | 248 if (!shell_file_root_.is_valid()) |
249 return false; | 249 return false; |
250 if (!ConfigureURLMappings(command_line, this)) | 250 if (!ConfigureURLMappings(command_line, this)) |
251 return false; | 251 return false; |
252 | 252 |
253 // TODO(vtl): This should be MASTER, not NONE. | 253 // TODO(vtl): This should be MASTER, not NONE. |
254 embedder::InitIPCSupport( | 254 embedder::InitIPCSupport( |
255 embedder::ProcessType::NONE, task_runners_->shell_runner(), this, | 255 embedder::ProcessType::NONE, task_runners_->shell_runner(), this, |
256 task_runners_->io_runner(), embedder::ScopedPlatformHandle()); | 256 task_runners_->io_runner(), embedder::ScopedPlatformHandle()); |
257 | 257 |
258 scoped_ptr<NativeRunnerFactory> runner_factory; | 258 scoped_ptr<shell::NativeRunnerFactory> runner_factory; |
259 if (command_line.HasSwitch(switches::kEnableMultiprocess)) | 259 if (command_line.HasSwitch(switches::kEnableMultiprocess)) |
260 runner_factory.reset(new OutOfProcessNativeRunnerFactory(this)); | 260 runner_factory.reset(new OutOfProcessNativeRunnerFactory(this)); |
261 else | 261 else |
262 runner_factory.reset(new InProcessNativeRunnerFactory(this)); | 262 runner_factory.reset(new InProcessNativeRunnerFactory(this)); |
263 application_manager_.set_blocking_pool(task_runners_->blocking_pool()); | 263 application_manager_.set_blocking_pool(task_runners_->blocking_pool()); |
264 application_manager_.set_native_runner_factory(runner_factory.Pass()); | 264 application_manager_.set_native_runner_factory(runner_factory.Pass()); |
265 application_manager_.set_disable_cache( | 265 application_manager_.set_disable_cache( |
266 base::CommandLine::ForCurrentProcess()->HasSwitch( | 266 base::CommandLine::ForCurrentProcess()->HasSwitch( |
267 switches::kDisableCache)); | 267 switches::kDisableCache)); |
268 | 268 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 if (app_urls_.find(url) != app_urls_.end()) { | 315 if (app_urls_.find(url) != app_urls_.end()) { |
316 app_urls_.erase(url); | 316 app_urls_.erase(url); |
317 if (app_urls_.empty() && base::MessageLoop::current()->is_running()) { | 317 if (app_urls_.empty() && base::MessageLoop::current()->is_running()) { |
318 DCHECK_EQ(base::MessageLoop::current()->task_runner(), | 318 DCHECK_EQ(base::MessageLoop::current()->task_runner(), |
319 task_runners_->shell_runner()); | 319 task_runners_->shell_runner()); |
320 base::MessageLoop::current()->Quit(); | 320 base::MessageLoop::current()->Quit(); |
321 } | 321 } |
322 } | 322 } |
323 } | 323 } |
324 | 324 |
325 } // namespace shell | 325 } // namespace runner |
326 } // namespace mojo | 326 } // namespace mojo |
OLD | NEW |