Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Side by Side Diff: shell/application_manager/application_manager.cc

Issue 972473003: Strip query string before applying url mapping. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Follow review Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « shell/application_manager/BUILD.gn ('k') | shell/application_manager/query_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "shell/application_manager/application_manager.h" 5 #include "shell/application_manager/application_manager.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/stl_util.h" 13 #include "base/stl_util.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "mojo/public/cpp/bindings/binding.h" 15 #include "mojo/public/cpp/bindings/binding.h"
16 #include "mojo/public/cpp/bindings/error_handler.h" 16 #include "mojo/public/cpp/bindings/error_handler.h"
17 #include "mojo/public/interfaces/application/shell.mojom.h" 17 #include "mojo/public/interfaces/application/shell.mojom.h"
18 #include "mojo/services/content_handler/public/interfaces/content_handler.mojom. h" 18 #include "mojo/services/content_handler/public/interfaces/content_handler.mojom. h"
19 #include "shell/application_manager/fetcher.h" 19 #include "shell/application_manager/fetcher.h"
20 #include "shell/application_manager/local_fetcher.h" 20 #include "shell/application_manager/local_fetcher.h"
21 #include "shell/application_manager/network_fetcher.h" 21 #include "shell/application_manager/network_fetcher.h"
22 #include "shell/application_manager/query_util.h"
22 23
23 namespace mojo { 24 namespace mojo {
24 25
25 namespace { 26 namespace {
26 // Used by TestAPI. 27 // Used by TestAPI.
27 bool has_created_instance = false; 28 bool has_created_instance = false;
28 29
29 GURL StripQueryFromURL(const GURL& url) {
30 GURL::Replacements repl;
31 repl.SetQueryStr("");
32 std::string result = url.ReplaceComponents(repl).spec();
33
34 // Remove the dangling '?' because it's ugly.
35 base::ReplaceChars(result, "?", "", &result);
36 return GURL(result);
37 }
38
39 } // namespace 30 } // namespace
40 31
41 ApplicationManager::Delegate::~Delegate() { 32 ApplicationManager::Delegate::~Delegate() {
42 } 33 }
43 34
44 void ApplicationManager::Delegate::OnApplicationError(const GURL& url) { 35 void ApplicationManager::Delegate::OnApplicationError(const GURL& url) {
45 LOG(ERROR) << "Communication error with application: " << url.spec(); 36 LOG(ERROR) << "Communication error with application: " << url.spec();
46 } 37 }
47 38
48 GURL ApplicationManager::Delegate::ResolveURL(const GURL& url) { 39 GURL ApplicationManager::Delegate::ResolveURL(const GURL& url) {
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 default_loader_.get())) { 144 default_loader_.get())) {
154 return; 145 return;
155 } 146 }
156 147
157 auto callback = base::Bind(&ApplicationManager::HandleFetchCallback, 148 auto callback = base::Bind(&ApplicationManager::HandleFetchCallback,
158 weak_ptr_factory_.GetWeakPtr(), requested_url, 149 weak_ptr_factory_.GetWeakPtr(), requested_url,
159 requestor_url, base::Passed(services.Pass()), 150 requestor_url, base::Passed(services.Pass()),
160 base::Passed(exposed_services.Pass())); 151 base::Passed(exposed_services.Pass()));
161 152
162 if (resolved_url.SchemeIsFile()) { 153 if (resolved_url.SchemeIsFile()) {
163 new LocalFetcher(resolved_url, StripQueryFromURL(resolved_url), 154 new LocalFetcher(resolved_url, GetBaseURLAndQuery(resolved_url, nullptr),
164 base::Bind(callback, NativeRunner::DontDeleteAppPath)); 155 base::Bind(callback, NativeRunner::DontDeleteAppPath));
165 return; 156 return;
166 } 157 }
167 158
168 if (!network_service_) 159 if (!network_service_)
169 ConnectToService(GURL("mojo:network_service"), &network_service_); 160 ConnectToService(GURL("mojo:network_service"), &network_service_);
170 161
171 new NetworkFetcher(disable_cache_, resolved_url, network_service_.get(), 162 new NetworkFetcher(disable_cache_, resolved_url, network_service_.get(),
172 base::Bind(callback, NativeRunner::DeleteAppPath)); 163 base::Bind(callback, NativeRunner::DeleteAppPath));
173 } 164 }
174 165
175 bool ApplicationManager::ConnectToRunningApplication( 166 bool ApplicationManager::ConnectToRunningApplication(
176 const GURL& resolved_url, 167 const GURL& resolved_url,
177 const GURL& requestor_url, 168 const GURL& requestor_url,
178 InterfaceRequest<ServiceProvider>* services, 169 InterfaceRequest<ServiceProvider>* services,
179 ServiceProviderPtr* exposed_services) { 170 ServiceProviderPtr* exposed_services) {
180 GURL application_url = StripQueryFromURL(resolved_url); 171 GURL application_url = GetBaseURLAndQuery(resolved_url, nullptr);
181 ShellImpl* shell_impl = GetShellImpl(application_url); 172 ShellImpl* shell_impl = GetShellImpl(application_url);
182 if (!shell_impl) 173 if (!shell_impl)
183 return false; 174 return false;
184 175
185 ConnectToClient(shell_impl, resolved_url, requestor_url, services->Pass(), 176 ConnectToClient(shell_impl, resolved_url, requestor_url, services->Pass(),
186 exposed_services->Pass()); 177 exposed_services->Pass());
187 return true; 178 return true;
188 } 179 }
189 180
190 bool ApplicationManager::ConnectToApplicationWithLoader( 181 bool ApplicationManager::ConnectToApplicationWithLoader(
(...skipping 11 matching lines...) Expand all
202 services->Pass(), exposed_services->Pass())); 193 services->Pass(), exposed_services->Pass()));
203 return true; 194 return true;
204 } 195 }
205 196
206 InterfaceRequest<Application> ApplicationManager::RegisterShell( 197 InterfaceRequest<Application> ApplicationManager::RegisterShell(
207 const GURL& original_url, 198 const GURL& original_url,
208 const GURL& resolved_url, 199 const GURL& resolved_url,
209 const GURL& requestor_url, 200 const GURL& requestor_url,
210 InterfaceRequest<ServiceProvider> services, 201 InterfaceRequest<ServiceProvider> services,
211 ServiceProviderPtr exposed_services) { 202 ServiceProviderPtr exposed_services) {
212 GURL app_url = StripQueryFromURL(resolved_url); 203 GURL app_url = GetBaseURLAndQuery(resolved_url, nullptr);
213 204
214 ApplicationPtr application; 205 ApplicationPtr application;
215 InterfaceRequest<Application> application_request = GetProxy(&application); 206 InterfaceRequest<Application> application_request = GetProxy(&application);
216 ShellImpl* shell = 207 ShellImpl* shell =
217 new ShellImpl(application.Pass(), this, original_url, app_url); 208 new ShellImpl(application.Pass(), this, original_url, app_url);
218 url_to_shell_impl_[app_url] = shell; 209 url_to_shell_impl_[app_url] = shell;
219 shell->InitializeApplication(GetArgsForURL(original_url)); 210 shell->InitializeApplication(GetArgsForURL(original_url));
220 ConnectToClient(shell, resolved_url, requestor_url, services.Pass(), 211 ConnectToClient(shell, resolved_url, requestor_url, services.Pass(),
221 exposed_services.Pass()); 212 exposed_services.Pass());
222 return application_request.Pass(); 213 return application_request.Pass();
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 delete it->second; 375 delete it->second;
385 scheme_to_loader_[scheme] = loader.release(); 376 scheme_to_loader_[scheme] = loader.release();
386 } 377 }
387 378
388 void ApplicationManager::SetArgsForURL(const std::vector<std::string>& args, 379 void ApplicationManager::SetArgsForURL(const std::vector<std::string>& args,
389 const GURL& url) { 380 const GURL& url) {
390 url_to_args_[url] = args; 381 url_to_args_[url] = args;
391 } 382 }
392 383
393 ApplicationLoader* ApplicationManager::GetLoaderForURL(const GURL& url) { 384 ApplicationLoader* ApplicationManager::GetLoaderForURL(const GURL& url) {
394 auto url_it = url_to_loader_.find(StripQueryFromURL(url)); 385 auto url_it = url_to_loader_.find(GetBaseURLAndQuery(url, nullptr));
395 if (url_it != url_to_loader_.end()) 386 if (url_it != url_to_loader_.end())
396 return url_it->second; 387 return url_it->second;
397 auto scheme_it = scheme_to_loader_.find(url.scheme()); 388 auto scheme_it = scheme_to_loader_.find(url.scheme());
398 if (scheme_it != scheme_to_loader_.end()) 389 if (scheme_it != scheme_to_loader_.end())
399 return scheme_it->second; 390 return scheme_it->second;
400 return NULL; 391 return NULL;
401 } 392 }
402 393
403 void ApplicationManager::OnShellImplError(ShellImpl* shell_impl) { 394 void ApplicationManager::OnShellImplError(ShellImpl* shell_impl) {
404 // Called from ~ShellImpl, so we do not need to call Destroy here. 395 // Called from ~ShellImpl, so we do not need to call Destroy here.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 return Array<String>::From(args_it->second); 429 return Array<String>::From(args_it->second);
439 return Array<String>(); 430 return Array<String>();
440 } 431 }
441 432
442 void ApplicationManager::CleanupRunner(NativeRunner* runner) { 433 void ApplicationManager::CleanupRunner(NativeRunner* runner) {
443 native_runners_.erase( 434 native_runners_.erase(
444 std::find(native_runners_.begin(), native_runners_.end(), runner)); 435 std::find(native_runners_.begin(), native_runners_.end(), runner));
445 } 436 }
446 437
447 } // namespace mojo 438 } // namespace mojo
OLDNEW
« no previous file with comments | « shell/application_manager/BUILD.gn ('k') | shell/application_manager/query_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698