| 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 "chrome/browser/search/iframe_source.h" | 5 #include "chrome/browser/search/iframe_source.h" |
| 6 | 6 |
| 7 #include "base/memory/ref_counted_memory.h" | 7 #include "base/memory/ref_counted_memory.h" |
| 8 #include "base/strings/string_piece.h" | 8 #include "base/strings/string_piece.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "chrome/browser/search/instant_io_context.h" | 10 #include "chrome/browser/search/instant_io_context.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 const std::string& path_and_query) const { | 26 const std::string& path_and_query) const { |
| 27 std::string path(GURL("chrome-search://host/" + path_and_query).path()); | 27 std::string path(GURL("chrome-search://host/" + path_and_query).path()); |
| 28 if (EndsWith(path, ".js", false)) | 28 if (EndsWith(path, ".js", false)) |
| 29 return "application/javascript"; | 29 return "application/javascript"; |
| 30 if (EndsWith(path, ".png", false)) | 30 if (EndsWith(path, ".png", false)) |
| 31 return "image/png"; | 31 return "image/png"; |
| 32 if (EndsWith(path, ".css", false)) | 32 if (EndsWith(path, ".css", false)) |
| 33 return "text/css"; | 33 return "text/css"; |
| 34 if (EndsWith(path, ".html", false)) | 34 if (EndsWith(path, ".html", false)) |
| 35 return "text/html"; | 35 return "text/html"; |
| 36 if (EndsWith(path, ".woff", false)) |
| 37 return "font/woff"; |
| 38 if (EndsWith(path, ".woff2", false)) |
| 39 return "font/woff2"; |
| 36 return ""; | 40 return ""; |
| 37 } | 41 } |
| 38 | 42 |
| 39 bool IframeSource::ShouldServiceRequest( | 43 bool IframeSource::ShouldServiceRequest( |
| 40 const net::URLRequest* request) const { | 44 const net::URLRequest* request) const { |
| 41 const std::string& path = request->url().path(); | 45 const std::string& path = request->url().path(); |
| 42 return InstantIOContext::ShouldServiceRequest(request) && | 46 return InstantIOContext::ShouldServiceRequest(request) && |
| 43 request->url().SchemeIs(chrome::kChromeSearchScheme) && | 47 request->url().SchemeIs(chrome::kChromeSearchScheme) && |
| 44 request->url().host() == GetSource() && | 48 request->url().host() == GetSource() && |
| 45 ServesPath(path); | 49 ServesPath(path); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 callback.Run(NULL); | 92 callback.Run(NULL); |
| 89 return; | 93 return; |
| 90 } | 94 } |
| 91 | 95 |
| 92 base::StringPiece template_js = | 96 base::StringPiece template_js = |
| 93 ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id); | 97 ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id); |
| 94 std::string response(template_js.as_string()); | 98 std::string response(template_js.as_string()); |
| 95 ReplaceFirstSubstringAfterOffset(&response, 0, "{{ORIGIN}}", origin); | 99 ReplaceFirstSubstringAfterOffset(&response, 0, "{{ORIGIN}}", origin); |
| 96 callback.Run(base::RefCountedString::TakeString(&response)); | 100 callback.Run(base::RefCountedString::TakeString(&response)); |
| 97 } | 101 } |
| OLD | NEW |