OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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/package_manager/package_manager_impl.h" | 5 #include "mojo/package_manager/package_manager_impl.h" |
6 | 6 |
7 #include "mojo/fetcher/about_fetcher.h" | 7 #include "mojo/fetcher/about_fetcher.h" |
8 #include "mojo/fetcher/data_fetcher.h" | 8 #include "mojo/fetcher/data_fetcher.h" |
9 #include "mojo/fetcher/local_fetcher.h" | 9 #include "mojo/fetcher/local_fetcher.h" |
10 #include "mojo/fetcher/network_fetcher.h" | 10 #include "mojo/fetcher/network_fetcher.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 const std::string& qualifier) { | 49 const std::string& qualifier) { |
50 application_package_alias_[alias] = | 50 application_package_alias_[alias] = |
51 std::make_pair(content_handler_package, qualifier); | 51 std::make_pair(content_handler_package, qualifier); |
52 } | 52 } |
53 | 53 |
54 void PackageManagerImpl::SetApplicationManager( | 54 void PackageManagerImpl::SetApplicationManager( |
55 shell::ApplicationManager* manager) { | 55 shell::ApplicationManager* manager) { |
56 application_manager_ = manager; | 56 application_manager_ = manager; |
57 } | 57 } |
58 | 58 |
| 59 GURL PackageManagerImpl::ResolveURL(const GURL& url) { |
| 60 return url_resolver_.get() ? url_resolver_->ResolveMojoURL(url) : url; |
| 61 } |
| 62 |
59 void PackageManagerImpl::FetchRequest( | 63 void PackageManagerImpl::FetchRequest( |
60 URLRequestPtr request, | 64 URLRequestPtr request, |
61 const shell::Fetcher::FetchCallback& loader_callback) { | 65 const shell::Fetcher::FetchCallback& loader_callback) { |
62 GURL url(request->url); | 66 GURL url(request->url); |
63 if (url.SchemeIs(fetcher::AboutFetcher::kAboutScheme)) { | 67 if (url.SchemeIs(fetcher::AboutFetcher::kAboutScheme)) { |
64 fetcher::AboutFetcher::Start(url, loader_callback); | 68 fetcher::AboutFetcher::Start(url, loader_callback); |
65 return; | 69 return; |
66 } | 70 } |
67 | 71 |
68 if (url.SchemeIs(url::kDataScheme)) { | 72 if (url.SchemeIs(url::kDataScheme)) { |
69 fetcher::DataFetcher::Start(url, loader_callback); | 73 fetcher::DataFetcher::Start(url, loader_callback); |
70 return; | 74 return; |
71 } | 75 } |
72 | 76 |
73 GURL resolved_url = ResolveURL(url); | 77 GURL resolved_url = ResolveURL(url); |
| 78 |
74 if (resolved_url.SchemeIsFile()) { | 79 if (resolved_url.SchemeIsFile()) { |
75 // LocalFetcher uses the network service to infer MIME types from URLs. | 80 // LocalFetcher uses the network service to infer MIME types from URLs. |
76 // Skip this for mojo URLs to avoid recursively loading the network service. | 81 // Skip this for mojo URLs to avoid recursively loading the network service. |
77 if (!network_service_ && !url.SchemeIs("mojo")) { | 82 if (!network_service_ && !url.SchemeIs("mojo")) { |
78 shell::ConnectToService(application_manager_, | 83 shell::ConnectToService(application_manager_, |
79 GURL("mojo:network_service"), &network_service_); | 84 GURL("mojo:network_service"), &network_service_); |
80 } | 85 } |
81 // Ownership of this object is transferred to |loader_callback|. | 86 // Ownership of this object is transferred to |loader_callback|. |
82 // TODO(beng): this is eff'n weird. | 87 // TODO(beng): this is eff'n weird. |
83 new fetcher::LocalFetcher( | 88 new fetcher::LocalFetcher( |
(...skipping 25 matching lines...) Expand all Loading... |
109 &url_loader_factory_); | 114 &url_loader_factory_); |
110 } | 115 } |
111 | 116 |
112 // Ownership of this object is transferred to |loader_callback|. | 117 // Ownership of this object is transferred to |loader_callback|. |
113 // TODO(beng): this is eff'n weird. | 118 // TODO(beng): this is eff'n weird. |
114 new fetcher::NetworkFetcher(disable_cache_, request.Pass(), | 119 new fetcher::NetworkFetcher(disable_cache_, request.Pass(), |
115 url_loader_factory_.get(), loader_callback); | 120 url_loader_factory_.get(), loader_callback); |
116 } | 121 } |
117 | 122 |
118 bool PackageManagerImpl::HandleWithContentHandler(shell::Fetcher* fetcher, | 123 bool PackageManagerImpl::HandleWithContentHandler(shell::Fetcher* fetcher, |
119 const GURL& url, | 124 const GURL& unresolved_url, |
120 base::TaskRunner* task_runner, | 125 base::TaskRunner* task_runner, |
121 URLResponsePtr* new_response, | 126 URLResponsePtr* new_response, |
122 GURL* content_handler_url, | 127 GURL* content_handler_url, |
123 std::string* qualifier) { | 128 std::string* qualifier) { |
124 // TODO(beng): it seems like some delegate should/would want to have a say in | 129 // TODO(beng): it seems like some delegate should/would want to have a say in |
125 // configuring the qualifier also. | 130 // configuring the qualifier also. |
126 bool enable_multi_process = base::CommandLine::ForCurrentProcess()->HasSwitch( | 131 bool enable_multi_process = base::CommandLine::ForCurrentProcess()->HasSwitch( |
127 switches::kEnableMultiprocess); | 132 switches::kEnableMultiprocess); |
128 | 133 |
129 // The response begins with a #!mojo <content-handler-url>. | 134 // The response begins with a #!mojo <content-handler-url>. |
(...skipping 10 matching lines...) Expand all Loading... |
140 MimeTypeToURLMap::iterator iter = mime_type_to_url_.find(fetcher->MimeType()); | 145 MimeTypeToURLMap::iterator iter = mime_type_to_url_.find(fetcher->MimeType()); |
141 if (iter != mime_type_to_url_.end()) { | 146 if (iter != mime_type_to_url_.end()) { |
142 *new_response = fetcher->AsURLResponse(task_runner, 0); | 147 *new_response = fetcher->AsURLResponse(task_runner, 0); |
143 *content_handler_url = iter->second; | 148 *content_handler_url = iter->second; |
144 *qualifier = enable_multi_process ? (*new_response)->site.To<std::string>() | 149 *qualifier = enable_multi_process ? (*new_response)->site.To<std::string>() |
145 : std::string(); | 150 : std::string(); |
146 return true; | 151 return true; |
147 } | 152 } |
148 | 153 |
149 // The response URL matches a registered content handler. | 154 // The response URL matches a registered content handler. |
150 auto alias_iter = application_package_alias_.find(url); | 155 auto alias_iter = application_package_alias_.find(unresolved_url); |
151 if (alias_iter != application_package_alias_.end()) { | 156 if (alias_iter != application_package_alias_.end()) { |
152 // We replace the qualifier with the one our package alias requested. | 157 // We replace the qualifier with the one our package alias requested. |
153 *new_response = URLResponse::New(); | 158 *new_response = URLResponse::New(); |
154 (*new_response)->url = url.spec(); | 159 (*new_response)->url = unresolved_url.spec(); |
155 | 160 |
156 // Why can't we use this in single process mode? Because of | 161 // Why can't we use this in single process mode? Because of |
157 // base::AtExitManager. If you link in ApplicationRunner into your code, and | 162 // base::AtExitManager. If you link in ApplicationRunner into your code, and |
158 // then we make initialize multiple copies of the application, we end up | 163 // then we make initialize multiple copies of the application, we end up |
159 // with multiple AtExitManagers and will check on the second one being | 164 // with multiple AtExitManagers and will check on the second one being |
160 // created. | 165 // created. |
161 // | 166 // |
162 // Why doesn't that happen when running different apps? Because | 167 // Why doesn't that happen when running different apps? Because |
163 // your_thing.mojo!base::AtExitManager and | 168 // your_thing.mojo!base::AtExitManager and |
164 // my_thing.mojo!base::AtExitManager are different symbols. | 169 // my_thing.mojo!base::AtExitManager are different symbols. |
165 *qualifier = enable_multi_process ? alias_iter->second.second | 170 *qualifier = enable_multi_process ? alias_iter->second.second |
166 : std::string(); | 171 : std::string(); |
167 *content_handler_url = alias_iter->second.first; | 172 *content_handler_url = alias_iter->second.first; |
168 return true; | 173 return true; |
169 } | 174 } |
170 | 175 |
171 return false; | 176 return false; |
172 } | 177 } |
173 | 178 |
174 GURL PackageManagerImpl::ResolveURL(const GURL& url) { | |
175 return url_resolver_.get() ? url_resolver_->ResolveMojoURL(url) : url; | |
176 } | |
177 | |
178 } // namespace package_manager | 179 } // namespace package_manager |
179 } // namespace mojo | 180 } // namespace mojo |
OLD | NEW |