diff options
author | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-14 04:15:16 +0000 |
---|---|---|
committer | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-14 04:15:16 +0000 |
commit | 0afe827a49501c6801c3c9efbbdb1f64aa010beb (patch) | |
tree | dba6031dd45eb3f0a0435b9750976b1cd432abc1 /chrome/renderer/user_script_slave.cc | |
parent | 27eef9c8edf84061f4e36a3bd26ff7538092a22b (diff) | |
download | chromium_src-0afe827a49501c6801c3c9efbbdb1f64aa010beb.zip chromium_src-0afe827a49501c6801c3c9efbbdb1f64aa010beb.tar.gz chromium_src-0afe827a49501c6801c3c9efbbdb1f64aa010beb.tar.bz2 |
Add early-injection capability to user scripts.
Review URL: http://codereview.chromium.org/19624
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9822 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/user_script_slave.cc')
-rw-r--r-- | chrome/renderer/user_script_slave.cc | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/chrome/renderer/user_script_slave.cc b/chrome/renderer/user_script_slave.cc index 8fc1e3a..bb4f54d 100644 --- a/chrome/renderer/user_script_slave.cc +++ b/chrome/renderer/user_script_slave.cc @@ -4,7 +4,9 @@ #include "chrome/renderer/user_script_slave.h" +#include "base/histogram.h" #include "base/logging.h" +#include "base/perftimer.h" #include "base/pickle.h" #include "base/shared_memory.h" #include "chrome/common/resource_bundle.h" @@ -89,10 +91,15 @@ bool UserScriptSlave::UpdateScripts(base::SharedMemoryHandle shared_memory) { return true; } -bool UserScriptSlave::InjectScripts(WebFrame* frame) { +bool UserScriptSlave::InjectScripts(WebFrame* frame, + UserScript::RunLocation location) { + PerfTimer timer; + int num_matched = 0; + for (std::vector<UserScript*>::iterator script = scripts_.begin(); script != scripts_.end(); ++script) { - if ((*script)->MatchesUrl(frame->GetURL())) { + if ((*script)->MatchesUrl(frame->GetURL()) && + (*script)->run_location() == location) { std::string inject(kUserScriptHead); inject.append(api_js_.as_string()); inject.append(script_contents_[*script].as_string()); @@ -100,8 +107,17 @@ bool UserScriptSlave::InjectScripts(WebFrame* frame) { frame->ExecuteJavaScript(inject, GURL((*script)->url().spec()), -user_script_start_line_); + ++num_matched; } } + if (location == UserScript::DOCUMENT_START) { + HISTOGRAM_COUNTS_100(L"UserScripts:DocStart:Count", num_matched); + HISTOGRAM_TIMES(L"UserScripts:DocStart:Time", timer.Elapsed()); + } else { + HISTOGRAM_COUNTS_100(L"UserScripts:DocEnd:Count", num_matched); + HISTOGRAM_TIMES(L"UserScripts:DocEnd:Time", timer.Elapsed()); + } + return true; } |