Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: chrome/renderer/user_script_slave.cc

Issue 412008: Introduce a new 'all_frames' property to content scripts and (Closed)
Patch Set: responses to comments Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 if (frame_url.host() == GURL(Extension::kGalleryBrowseUrl).host()) 134 if (frame_url.host() == GURL(Extension::kGalleryBrowseUrl).host())
135 return true; 135 return true;
136 136
137 PerfTimer timer; 137 PerfTimer timer;
138 int num_css = 0; 138 int num_css = 0;
139 int num_scripts = 0; 139 int num_scripts = 0;
140 140
141 for (size_t i = 0; i < scripts_.size(); ++i) { 141 for (size_t i = 0; i < scripts_.size(); ++i) {
142 std::vector<WebScriptSource> sources; 142 std::vector<WebScriptSource> sources;
143 UserScript* script = scripts_[i]; 143 UserScript* script = scripts_[i];
144
145 if (frame->parent() && !script->match_all_frames())
146 continue; // Only match subframes if the script declared it wanted to.
147
144 if (!script->MatchesUrl(frame->url())) 148 if (!script->MatchesUrl(frame->url()))
145 continue; // This frame doesn't match the script url pattern, skip it. 149 continue; // This frame doesn't match the script url pattern, skip it.
146 150
147 // CSS files are always injected on document start before js scripts. 151 // CSS files are always injected on document start before js scripts.
148 if (location == UserScript::DOCUMENT_START) { 152 if (location == UserScript::DOCUMENT_START) {
149 num_css += script->css_scripts().size(); 153 num_css += script->css_scripts().size();
150 for (size_t j = 0; j < script->css_scripts().size(); ++j) { 154 for (size_t j = 0; j < script->css_scripts().size(); ++j) {
151 PerfTimer insert_timer; 155 PerfTimer insert_timer;
152 UserScript::File& file = script->css_scripts()[j]; 156 UserScript::File& file = script->css_scripts()[j];
153 frame->insertStyleText( 157 frame->insertStyleText(
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 if (num_scripts) 216 if (num_scripts)
213 UMA_HISTOGRAM_TIMES("Extensions.InjectIdle_Time", timer.Elapsed()); 217 UMA_HISTOGRAM_TIMES("Extensions.InjectIdle_Time", timer.Elapsed());
214 } else { 218 } else {
215 NOTREACHED(); 219 NOTREACHED();
216 } 220 }
217 221
218 LOG(INFO) << "Injected " << num_scripts << " scripts and " << num_css << 222 LOG(INFO) << "Injected " << num_scripts << " scripts and " << num_css <<
219 "css files into " << frame->url().spec().data(); 223 "css files into " << frame->url().spec().data();
220 return true; 224 return true;
221 } 225 }
OLDNEW
« no previous file with comments | « chrome/common/extensions/user_script.cc ('k') | chrome/test/data/extensions/api_test/content_script_all_frames/all_frames.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698