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/local_ntp_source.h" | 5 #include "chrome/browser/search/local_ntp_source.h" |
6 | 6 |
7 #include "base/json/json_string_value_serializer.h" | 7 #include "base/json/json_string_value_serializer.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/ref_counted_memory.h" | 9 #include "base/memory/ref_counted_memory.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 kResources[i].identifier, scale_factor)); | 177 kResources[i].identifier, scale_factor)); |
178 callback.Run(response.get()); | 178 callback.Run(response.get()); |
179 return; | 179 return; |
180 } | 180 } |
181 } | 181 } |
182 callback.Run(NULL); | 182 callback.Run(NULL); |
183 } | 183 } |
184 | 184 |
185 std::string LocalNtpSource::GetMimeType( | 185 std::string LocalNtpSource::GetMimeType( |
186 const std::string& path) const { | 186 const std::string& path) const { |
187 const std::string stripped_path = StripParameters(path); | 187 const std::string& stripped_path = StripParameters(path); |
| 188 std::string filename; |
| 189 webui::ParsePathAndScale(GURL(GetLocalNtpPath() + stripped_path), &filename, |
| 190 NULL); |
188 for (size_t i = 0; i < arraysize(kResources); ++i) { | 191 for (size_t i = 0; i < arraysize(kResources); ++i) { |
189 if (stripped_path == kResources[i].filename) | 192 if (filename == kResources[i].filename) |
190 return kResources[i].mime_type; | 193 return kResources[i].mime_type; |
191 } | 194 } |
192 return std::string(); | 195 return std::string(); |
193 } | 196 } |
194 | 197 |
195 bool LocalNtpSource::ShouldServiceRequest( | 198 bool LocalNtpSource::ShouldServiceRequest( |
196 const net::URLRequest* request) const { | 199 const net::URLRequest* request) const { |
197 DCHECK(request->url().host() == chrome::kChromeSearchLocalNtpHost); | 200 DCHECK(request->url().host() == chrome::kChromeSearchLocalNtpHost); |
198 if (!InstantIOContext::ShouldServiceRequest(request)) | 201 if (!InstantIOContext::ShouldServiceRequest(request)) |
199 return false; | 202 return false; |
200 | 203 |
201 if (request->url().SchemeIs(chrome::kChromeSearchScheme)) { | 204 if (request->url().SchemeIs(chrome::kChromeSearchScheme)) { |
202 std::string filename; | 205 std::string filename; |
203 webui::ParsePathAndScale(request->url(), &filename, NULL); | 206 webui::ParsePathAndScale(request->url(), &filename, NULL); |
204 for (size_t i = 0; i < arraysize(kResources); ++i) { | 207 for (size_t i = 0; i < arraysize(kResources); ++i) { |
205 if (filename == kResources[i].filename) | 208 if (filename == kResources[i].filename) |
206 return true; | 209 return true; |
207 } | 210 } |
208 } | 211 } |
209 return false; | 212 return false; |
210 } | 213 } |
211 | 214 |
212 std::string LocalNtpSource::GetContentSecurityPolicyFrameSrc() const { | 215 std::string LocalNtpSource::GetContentSecurityPolicyFrameSrc() const { |
213 // Allow embedding of most visited iframes. | 216 // Allow embedding of most visited iframes. |
214 return base::StringPrintf("frame-src %s;", | 217 return base::StringPrintf("frame-src %s;", |
215 chrome::kChromeSearchMostVisitedUrl); | 218 chrome::kChromeSearchMostVisitedUrl); |
216 } | 219 } |
OLD | NEW |