| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/renderer/user_script_slave.h" | 5 #include "chrome/renderer/user_script_slave.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/pickle.h" | 8 #include "base/pickle.h" |
| 9 #include "base/shared_memory.h" | 9 #include "base/shared_memory.h" |
| 10 #include "chrome/common/resource_bundle.h" | 10 #include "chrome/common/resource_bundle.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 int body_length = 0; | 80 int body_length = 0; |
| 81 CHECK(pickle.ReadData(&iter, &body, &body_length)); | 81 CHECK(pickle.ReadData(&iter, &body, &body_length)); |
| 82 | 82 |
| 83 scripts_.push_back(script); | 83 scripts_.push_back(script); |
| 84 script_contents_[script] = StringPiece(body, body_length); | 84 script_contents_[script] = StringPiece(body, body_length); |
| 85 } | 85 } |
| 86 | 86 |
| 87 return true; | 87 return true; |
| 88 } | 88 } |
| 89 | 89 |
| 90 bool UserScriptSlave::InjectScripts(WebFrame* frame) { | 90 bool UserScriptSlave::InjectScripts(WebFrame* frame, |
| 91 UserScript::RunLocation location) { |
| 91 for (std::vector<UserScript*>::iterator script = scripts_.begin(); | 92 for (std::vector<UserScript*>::iterator script = scripts_.begin(); |
| 92 script != scripts_.end(); ++script) { | 93 script != scripts_.end(); ++script) { |
| 93 if ((*script)->MatchesUrl(frame->GetURL())) { | 94 if ((*script)->MatchesUrl(frame->GetURL()) && |
| 95 (*script)->run_location() == location) { |
| 94 std::string inject(kUserScriptHead); | 96 std::string inject(kUserScriptHead); |
| 95 inject.append(api_js_.as_string()); | 97 inject.append(api_js_.as_string()); |
| 96 inject.append(script_contents_[*script].as_string()); | 98 inject.append(script_contents_[*script].as_string()); |
| 97 inject.append(kUserScriptTail); | 99 inject.append(kUserScriptTail); |
| 98 frame->ExecuteJavaScript(inject, | 100 frame->ExecuteJavaScript(inject, |
| 99 GURL((*script)->url().spec()), | 101 GURL((*script)->url().spec()), |
| 100 -user_script_start_line_); | 102 -user_script_start_line_); |
| 101 } | 103 } |
| 102 } | 104 } |
| 103 | 105 |
| 104 return true; | 106 return true; |
| 105 } | 107 } |
| OLD | NEW |