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 "app/resource_bundle.h" | 7 #include "app/resource_bundle.h" |
8 #include "base/histogram.h" | 8 #include "base/histogram.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/perftimer.h" | 10 #include "base/perftimer.h" |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 UserScript* script = scripts_[i]; | 123 UserScript* script = scripts_[i]; |
124 if (!script->MatchesUrl(frame->url())) | 124 if (!script->MatchesUrl(frame->url())) |
125 continue; // This frame doesn't match the script url pattern, skip it. | 125 continue; // This frame doesn't match the script url pattern, skip it. |
126 | 126 |
127 ++num_matched; | 127 ++num_matched; |
128 // CSS files are always injected on document start before js scripts. | 128 // CSS files are always injected on document start before js scripts. |
129 if (location == UserScript::DOCUMENT_START) { | 129 if (location == UserScript::DOCUMENT_START) { |
130 for (size_t j = 0; j < script->css_scripts().size(); ++j) { | 130 for (size_t j = 0; j < script->css_scripts().size(); ++j) { |
131 UserScript::File& file = script->css_scripts()[j]; | 131 UserScript::File& file = script->css_scripts()[j]; |
132 frame->insertStyleText( | 132 frame->insertStyleText( |
133 WebString::fromUTF8(file.GetContent().as_string())); | 133 WebString::fromUTF8(file.GetContent().as_string()), WebString()); |
134 } | 134 } |
135 } | 135 } |
136 if (script->run_location() == location) { | 136 if (script->run_location() == location) { |
137 for (size_t j = 0; j < script->js_scripts().size(); ++j) { | 137 for (size_t j = 0; j < script->js_scripts().size(); ++j) { |
138 UserScript::File &file = script->js_scripts()[j]; | 138 UserScript::File &file = script->js_scripts()[j]; |
139 std::string content = file.GetContent().as_string(); | 139 std::string content = file.GetContent().as_string(); |
140 | 140 |
141 // We add this dumb function wrapper for standalone user script to | 141 // We add this dumb function wrapper for standalone user script to |
142 // emulate what Greasemonkey does. | 142 // emulate what Greasemonkey does. |
143 if (script->is_standalone()) { | 143 if (script->is_standalone()) { |
(...skipping 29 matching lines...) Expand all Loading... |
173 HISTOGRAM_TIMES("UserScripts:DocStart:Time", timer.Elapsed()); | 173 HISTOGRAM_TIMES("UserScripts:DocStart:Time", timer.Elapsed()); |
174 } else { | 174 } else { |
175 HISTOGRAM_COUNTS_100("UserScripts:DocEnd:Count", num_matched); | 175 HISTOGRAM_COUNTS_100("UserScripts:DocEnd:Count", num_matched); |
176 HISTOGRAM_TIMES("UserScripts:DocEnd:Time", timer.Elapsed()); | 176 HISTOGRAM_TIMES("UserScripts:DocEnd:Time", timer.Elapsed()); |
177 } | 177 } |
178 | 178 |
179 LOG(INFO) << "Injected " << num_matched << " user scripts into " << | 179 LOG(INFO) << "Injected " << num_matched << " user scripts into " << |
180 frame->url().spec().data(); | 180 frame->url().spec().data(); |
181 return true; | 181 return true; |
182 } | 182 } |
OLD | NEW |