| 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" | 7 #include "base/json/string_escape.h" |
| 8 #include "base/memory/ref_counted_memory.h" | 8 #include "base/memory/ref_counted_memory.h" |
| 9 #include "base/strings/string_piece.h" | 9 #include "base/strings/string_piece.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 content::RenderViewHost* rvh = | 57 content::RenderViewHost* rvh = |
| 58 content::RenderViewHost::FromID(render_process_id, render_view_id); | 58 content::RenderViewHost::FromID(render_process_id, render_view_id); |
| 59 if (rvh == NULL) | 59 if (rvh == NULL) |
| 60 return false; | 60 return false; |
| 61 content::WebContents* contents = | 61 content::WebContents* contents = |
| 62 content::WebContents::FromRenderViewHost(rvh); | 62 content::WebContents::FromRenderViewHost(rvh); |
| 63 if (contents == NULL) | 63 if (contents == NULL) |
| 64 return false; | 64 return false; |
| 65 *origin = contents->GetURL().GetOrigin().spec(); | 65 *origin = contents->GetURL().GetOrigin().spec(); |
| 66 // Origin should not include a trailing slash. That is part of the path. | 66 // Origin should not include a trailing slash. That is part of the path. |
| 67 TrimString(*origin, "/", origin); | 67 base::TrimString(*origin, "/", origin); |
| 68 return true; | 68 return true; |
| 69 } | 69 } |
| 70 | 70 |
| 71 void IframeSource::SendResource( | 71 void IframeSource::SendResource( |
| 72 int resource_id, | 72 int resource_id, |
| 73 const content::URLDataSource::GotDataCallback& callback) { | 73 const content::URLDataSource::GotDataCallback& callback) { |
| 74 scoped_refptr<base::RefCountedStaticMemory> response( | 74 scoped_refptr<base::RefCountedStaticMemory> response( |
| 75 ResourceBundle::GetSharedInstance().LoadDataResourceBytes(resource_id)); | 75 ResourceBundle::GetSharedInstance().LoadDataResourceBytes(resource_id)); |
| 76 callback.Run(response.get()); | 76 callback.Run(response.get()); |
| 77 } | 77 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 88 } | 88 } |
| 89 | 89 |
| 90 std::string js_escaped_origin; | 90 std::string js_escaped_origin; |
| 91 base::JsonDoubleQuote(origin, false, &js_escaped_origin); | 91 base::JsonDoubleQuote(origin, false, &js_escaped_origin); |
| 92 base::StringPiece template_js = | 92 base::StringPiece template_js = |
| 93 ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id); | 93 ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id); |
| 94 std::string response(template_js.as_string()); | 94 std::string response(template_js.as_string()); |
| 95 ReplaceFirstSubstringAfterOffset(&response, 0, "{{ORIGIN}}", origin); | 95 ReplaceFirstSubstringAfterOffset(&response, 0, "{{ORIGIN}}", origin); |
| 96 callback.Run(base::RefCountedString::TakeString(&response)); | 96 callback.Run(base::RefCountedString::TakeString(&response)); |
| 97 } | 97 } |
| OLD | NEW |