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

Side by Side Diff: chrome/browser/search/iframe_source.cc

Issue 2481923002: [WIP] make GURL::path() return a StringPiece (Closed)
Patch Set: thanks asan Created 4 years, 1 month 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
OLDNEW
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"
11 #include "chrome/common/url_constants.h" 11 #include "chrome/common/url_constants.h"
12 #include "content/public/browser/navigation_entry.h" 12 #include "content/public/browser/navigation_entry.h"
13 #include "content/public/browser/render_frame_host.h" 13 #include "content/public/browser/render_frame_host.h"
14 #include "content/public/browser/web_contents.h" 14 #include "content/public/browser/web_contents.h"
15 #include "net/url_request/url_request.h" 15 #include "net/url_request/url_request.h"
16 #include "ui/base/resource/resource_bundle.h" 16 #include "ui/base/resource/resource_bundle.h"
17 #include "url/gurl.h" 17 #include "url/gurl.h"
18 18
19 IframeSource::IframeSource() { 19 IframeSource::IframeSource() {
20 } 20 }
21 21
22 IframeSource::~IframeSource() { 22 IframeSource::~IframeSource() {
23 } 23 }
24 24
25 std::string IframeSource::GetMimeType( 25 std::string IframeSource::GetMimeType(
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 GURL url(GURL("chrome-search://host/" + path_and_query));
28 base::StringPiece path = url.path();
28 if (base::EndsWith(path, ".js", base::CompareCase::INSENSITIVE_ASCII)) 29 if (base::EndsWith(path, ".js", base::CompareCase::INSENSITIVE_ASCII))
29 return "application/javascript"; 30 return "application/javascript";
30 if (base::EndsWith(path, ".png", base::CompareCase::INSENSITIVE_ASCII)) 31 if (base::EndsWith(path, ".png", base::CompareCase::INSENSITIVE_ASCII))
31 return "image/png"; 32 return "image/png";
32 if (base::EndsWith(path, ".css", base::CompareCase::INSENSITIVE_ASCII)) 33 if (base::EndsWith(path, ".css", base::CompareCase::INSENSITIVE_ASCII))
33 return "text/css"; 34 return "text/css";
34 if (base::EndsWith(path, ".html", base::CompareCase::INSENSITIVE_ASCII)) 35 if (base::EndsWith(path, ".html", base::CompareCase::INSENSITIVE_ASCII))
35 return "text/html"; 36 return "text/html";
36 return std::string(); 37 return std::string();
37 } 38 }
38 39
39 bool IframeSource::ShouldServiceRequest( 40 bool IframeSource::ShouldServiceRequest(
40 const net::URLRequest* request) const { 41 const net::URLRequest* request) const {
41 const std::string& path = request->url().path(); 42 const std::string& path = request->url().path().as_string();
42 return InstantIOContext::ShouldServiceRequest(request) && 43 return InstantIOContext::ShouldServiceRequest(request) &&
43 request->url().SchemeIs(chrome::kChromeSearchScheme) && 44 request->url().SchemeIs(chrome::kChromeSearchScheme) &&
44 request->url().host_piece() == GetSource() && ServesPath(path); 45 request->url().host_piece() == GetSource() && ServesPath(path);
45 } 46 }
46 47
47 bool IframeSource::ShouldDenyXFrameOptions() const { 48 bool IframeSource::ShouldDenyXFrameOptions() const {
48 return false; 49 return false;
49 } 50 }
50 51
51 bool IframeSource::GetOrigin( 52 bool IframeSource::GetOrigin(
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 callback.Run(NULL); 85 callback.Run(NULL);
85 return; 86 return;
86 } 87 }
87 88
88 base::StringPiece template_js = 89 base::StringPiece template_js =
89 ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id); 90 ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id);
90 std::string response(template_js.as_string()); 91 std::string response(template_js.as_string());
91 base::ReplaceFirstSubstringAfterOffset(&response, 0, "{{ORIGIN}}", origin); 92 base::ReplaceFirstSubstringAfterOffset(&response, 0, "{{ORIGIN}}", origin);
92 callback.Run(base::RefCountedString::TakeString(&response)); 93 callback.Run(base::RefCountedString::TakeString(&response));
93 } 94 }
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_avatar_icon_util.cc ('k') | chrome/browser/search/most_visited_iframe_source.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698