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 #include "mojo/fetcher/base_application_fetcher.h"
7 #include "mojo/fetcher/about_fetcher.h"
8 #include "mojo/fetcher/local_fetcher.h"
9 #include "mojo/fetcher/network_fetcher.h"
10 #include "mojo/fetcher/switches.h"
11 #include "mojo/fetcher/update_fetcher.h"
12 #include "mojo/shell/application_manager.h"
13 #include "mojo/shell/query_util.h"
14 #include "mojo/util/filename_util.h"
20 BaseApplicationFetcher::BaseApplicationFetcher(
21 const base::FilePath
& shell_file_root
)
22 : application_manager_(nullptr),
23 disable_cache_(base::CommandLine::ForCurrentProcess()->HasSwitch(
24 switches::kDisableCache
)) {
25 if (!shell_file_root
.empty()) {
26 GURL mojo_root_file_url
=
27 util::FilePathToFileURL(shell_file_root
).Resolve(std::string());
28 url_resolver_
.reset(new URLResolver(mojo_root_file_url
));
32 BaseApplicationFetcher::~BaseApplicationFetcher() {
35 void BaseApplicationFetcher::SetApplicationManager(
36 shell::ApplicationManager
* manager
) {
37 application_manager_
= manager
;
40 GURL
BaseApplicationFetcher::ResolveURL(const GURL
& url
) {
41 return url_resolver_
.get() ? url_resolver_
->ResolveMojoURL(url
) : url
;
44 void BaseApplicationFetcher::FetchRequest(
45 URLRequestPtr request
,
46 const shell::Fetcher::FetchCallback
& loader_callback
) {
47 GURL
url(request
->url
);
48 if (url
.SchemeIs(AboutFetcher::kAboutScheme
)) {
49 AboutFetcher::Start(url
, loader_callback
);
53 GURL resolved_url
= ResolveURL(url
);
55 if (resolved_url
.SchemeIsFile()) {
56 // LocalFetcher uses the network service to infer MIME types from URLs.
57 // Skip this for mojo URLs to avoid recursively loading the network service.
58 if (!network_service_
&& !url
.SchemeIs("mojo")) {
59 application_manager_
->ConnectToService(GURL("mojo:network_service"),
62 // Ownership of this object is transferred to |loader_callback|.
63 // TODO(beng): this is eff'n weird.
65 network_service_
.get(), resolved_url
,
66 shell::GetBaseURLAndQuery(resolved_url
, nullptr),
72 // TODO(beng): figure out how this should be integrated now that mapped_url
74 // TODO(scottmg): to quote someone I know, if you liked this you shouldda put
76 if (url
.SchemeIs("mojo") &&
77 base::CommandLine::ForCurrentProcess()->HasSwitch(
78 switches::kUseUpdater
)) {
79 application_manager_
->ConnectToService(GURL("mojo:updater"), &updater_
);
80 // Ownership of this object is transferred to |loader_callback|.
81 // TODO(beng): this is eff'n weird.
82 new UpdateFetcher(url
, updater_
.get(), loader_callback
);
87 if (!url_loader_factory_
) {
88 application_manager_
->ConnectToService(GURL("mojo:network_service"),
89 &url_loader_factory_
);
92 // Ownership of this object is transferred to |loader_callback|.
93 // TODO(beng): this is eff'n weird.
94 new NetworkFetcher(disable_cache_
, request
.Pass(), url_loader_factory_
.get(),
98 } // namespace fetcher