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/json/string_escape.h" | |
8 #include "base/memory/ref_counted_memory.h" | 7 #include "base/memory/ref_counted_memory.h" |
9 #include "base/strings/string_piece.h" | 8 #include "base/strings/string_piece.h" |
10 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
11 #include "chrome/browser/search/instant_io_context.h" | 10 #include "chrome/browser/search/instant_io_context.h" |
12 #include "chrome/common/url_constants.h" | 11 #include "chrome/common/url_constants.h" |
13 #include "content/public/browser/render_view_host.h" | 12 #include "content/public/browser/render_view_host.h" |
14 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
15 #include "grit/browser_resources.h" | 14 #include "grit/browser_resources.h" |
16 #include "net/url_request/url_request.h" | 15 #include "net/url_request/url_request.h" |
17 #include "ui/base/resource/resource_bundle.h" | 16 #include "ui/base/resource/resource_bundle.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 int resource_id, | 79 int resource_id, |
81 int render_process_id, | 80 int render_process_id, |
82 int render_view_id, | 81 int render_view_id, |
83 const content::URLDataSource::GotDataCallback& callback) { | 82 const content::URLDataSource::GotDataCallback& callback) { |
84 std::string origin; | 83 std::string origin; |
85 if (!GetOrigin(render_process_id, render_view_id, &origin)) { | 84 if (!GetOrigin(render_process_id, render_view_id, &origin)) { |
86 callback.Run(NULL); | 85 callback.Run(NULL); |
87 return; | 86 return; |
88 } | 87 } |
89 | 88 |
90 std::string js_escaped_origin; | |
91 base::JsonDoubleQuote(origin, false, &js_escaped_origin); | |
92 base::StringPiece template_js = | 89 base::StringPiece template_js = |
93 ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id); | 90 ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id); |
94 std::string response(template_js.as_string()); | 91 std::string response(template_js.as_string()); |
95 ReplaceFirstSubstringAfterOffset(&response, 0, "{{ORIGIN}}", origin); | 92 ReplaceFirstSubstringAfterOffset(&response, 0, "{{ORIGIN}}", origin); |
96 callback.Run(base::RefCountedString::TakeString(&response)); | 93 callback.Run(base::RefCountedString::TakeString(&response)); |
97 } | 94 } |
OLD | NEW |