| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 | 66 |
| 67 *origin = entry->GetURL().GetOrigin().spec(); | 67 *origin = entry->GetURL().GetOrigin().spec(); |
| 68 // Origin should not include a trailing slash. That is part of the path. | 68 // Origin should not include a trailing slash. That is part of the path. |
| 69 base::TrimString(*origin, "/", origin); | 69 base::TrimString(*origin, "/", origin); |
| 70 return true; | 70 return true; |
| 71 } | 71 } |
| 72 | 72 |
| 73 void IframeSource::SendResource( | 73 void IframeSource::SendResource( |
| 74 int resource_id, | 74 int resource_id, |
| 75 const content::URLDataSource::GotDataCallback& callback) { | 75 const content::URLDataSource::GotDataCallback& callback) { |
| 76 scoped_refptr<base::RefCountedStaticMemory> response( | 76 scoped_refptr<base::RefCountedMemory> response( |
| 77 ResourceBundle::GetSharedInstance().LoadDataResourceBytes(resource_id)); | 77 ResourceBundle::GetSharedInstance().LoadDataResourceBytes(resource_id)); |
| 78 callback.Run(response.get()); | 78 callback.Run(response.get()); |
| 79 } | 79 } |
| 80 | 80 |
| 81 void IframeSource::SendJSWithOrigin( | 81 void IframeSource::SendJSWithOrigin( |
| 82 int resource_id, | 82 int resource_id, |
| 83 int render_process_id, | 83 int render_process_id, |
| 84 int render_frame_id, | 84 int render_frame_id, |
| 85 const content::URLDataSource::GotDataCallback& callback) { | 85 const content::URLDataSource::GotDataCallback& callback) { |
| 86 std::string origin; | 86 std::string origin; |
| 87 if (!GetOrigin(render_process_id, render_frame_id, &origin)) { | 87 if (!GetOrigin(render_process_id, render_frame_id, &origin)) { |
| 88 callback.Run(NULL); | 88 callback.Run(NULL); |
| 89 return; | 89 return; |
| 90 } | 90 } |
| 91 | 91 |
| 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 base::ReplaceFirstSubstringAfterOffset(&response, 0, "{{ORIGIN}}", origin); | 95 base::ReplaceFirstSubstringAfterOffset(&response, 0, "{{ORIGIN}}", origin); |
| 96 callback.Run(base::RefCountedString::TakeString(&response)); | 96 callback.Run(base::RefCountedString::TakeString(&response)); |
| 97 } | 97 } |
| OLD | NEW |