| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #import "ios/web/public/test/response_providers/file_based_response_provider_imp
l.h" | |
| 6 | |
| 7 #include "base/files/file_util.h" | |
| 8 #import "ios/web/public/test/response_providers/response_provider.h" | |
| 9 #include "url/gurl.h" | |
| 10 | |
| 11 namespace web { | |
| 12 | |
| 13 FileBasedResponseProviderImpl::FileBasedResponseProviderImpl( | |
| 14 const base::FilePath& path) | |
| 15 : path_(path) {} | |
| 16 | |
| 17 FileBasedResponseProviderImpl::~FileBasedResponseProviderImpl() {} | |
| 18 | |
| 19 bool FileBasedResponseProviderImpl::CanHandleRequest( | |
| 20 const ResponseProvider::Request& request) { | |
| 21 return base::PathExists(BuildTargetPath(request.url)); | |
| 22 } | |
| 23 | |
| 24 base::FilePath FileBasedResponseProviderImpl::BuildTargetPath(const GURL& url) { | |
| 25 base::FilePath result = path_; | |
| 26 const std::string kLocalhostHost = "localhost"; | |
| 27 if (url.host() != kLocalhostHost) { | |
| 28 result = result.Append(url.host()); | |
| 29 } | |
| 30 std::string url_path = url.path(); | |
| 31 // Remove the leading slash in url path. | |
| 32 if (url_path.length() > 0 && url_path[0] == '/') { | |
| 33 url_path.erase(0, 1); | |
| 34 } | |
| 35 if (!url_path.empty()) | |
| 36 result = result.Append(url_path); | |
| 37 return result; | |
| 38 } | |
| 39 | |
| 40 } // namespace web | |
| OLD | NEW |