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

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

Issue 2799010: Revert 48693 - Only inject content scripts into HTML documents. Previously we... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 years, 6 months 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/command_line.h" 8 #include "base/command_line.h"
9 #include "base/histogram.h" 9 #include "base/histogram.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/perftimer.h" 11 #include "base/perftimer.h"
12 #include "base/pickle.h" 12 #include "base/pickle.h"
13 #include "base/shared_memory.h" 13 #include "base/shared_memory.h"
14 #include "base/string_util.h" 14 #include "base/string_util.h"
15 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.h"
16 #include "chrome/common/extensions/extension.h" 16 #include "chrome/common/extensions/extension.h"
17 #include "chrome/common/extensions/extension_constants.h" 17 #include "chrome/common/extensions/extension_constants.h"
18 #include "chrome/renderer/extension_groups.h" 18 #include "chrome/renderer/extension_groups.h"
19 #include "chrome/renderer/render_thread.h" 19 #include "chrome/renderer/render_thread.h"
20 #include "googleurl/src/gurl.h" 20 #include "googleurl/src/gurl.h"
21 #include "third_party/WebKit/WebKit/chromium/public/WebDocument.h"
22 #include "third_party/WebKit/WebKit/chromium/public/WebElement.h"
23 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" 21 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
24 22
25 #include "grit/renderer_resources.h" 23 #include "grit/renderer_resources.h"
26 24
27 using WebKit::WebFrame; 25 using WebKit::WebFrame;
28 using WebKit::WebString; 26 using WebKit::WebString;
29 27
30 // These two strings are injected before and after the Greasemonkey API and 28 // These two strings are injected before and after the Greasemonkey API and
31 // user script to wrap it in an anonymous scope. 29 // user script to wrap it in an anonymous scope.
32 static const char kUserScriptHead[] = "(function (unsafeWindow) {\n"; 30 static const char kUserScriptHead[] = "(function (unsafeWindow) {\n";
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 incognito ? "true" : "false")))); 142 incognito ? "true" : "false"))));
145 } 143 }
146 144
147 bool UserScriptSlave::InjectScripts(WebFrame* frame, 145 bool UserScriptSlave::InjectScripts(WebFrame* frame,
148 UserScript::RunLocation location) { 146 UserScript::RunLocation location) {
149 GURL frame_url = GURL(frame->url()); 147 GURL frame_url = GURL(frame->url());
150 // Don't bother if this is not a URL we inject script into. 148 // Don't bother if this is not a URL we inject script into.
151 if (!URLPattern::IsValidScheme(frame_url.scheme())) 149 if (!URLPattern::IsValidScheme(frame_url.scheme()))
152 return true; 150 return true;
153 151
154 // Only inject user scripts into documents with an <html> tag as the root
155 // element. Note that WebCore fixes up html pages that lack a root HTML
156 // element so that they include one. Also, documents like text/plain and
157 // image/* are wrapped in a simple HTML document.
158 //
159 // Basically, this check filters out SVG documents and other types of XML
160 // documents.
161 if (frame->document().isNull() ||
162 frame->document().documentElement().isNull() ||
163 !frame->document().documentElement().hasTagName("html")) {
164 return true;
165 }
166
167 // Don't inject user scripts into the gallery itself. This prevents 152 // Don't inject user scripts into the gallery itself. This prevents
168 // a user script from removing the "report abuse" link, for example. 153 // a user script from removing the "report abuse" link, for example.
169 if (frame_url.host() == GURL(extension_urls::kGalleryBrowsePrefix).host()) 154 if (frame_url.host() == GURL(extension_urls::kGalleryBrowsePrefix).host())
170 return true; 155 return true;
171 156
172 PerfTimer timer; 157 PerfTimer timer;
173 int num_css = 0; 158 int num_css = 0;
174 int num_scripts = 0; 159 int num_scripts = 0;
175 160
176 for (size_t i = 0; i < scripts_.size(); ++i) { 161 for (size_t i = 0; i < scripts_.size(); ++i) {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 if (num_scripts) 236 if (num_scripts)
252 UMA_HISTOGRAM_TIMES("Extensions.InjectIdle_Time", timer.Elapsed()); 237 UMA_HISTOGRAM_TIMES("Extensions.InjectIdle_Time", timer.Elapsed());
253 } else { 238 } else {
254 NOTREACHED(); 239 NOTREACHED();
255 } 240 }
256 241
257 LOG(INFO) << "Injected " << num_scripts << " scripts and " << num_css << 242 LOG(INFO) << "Injected " << num_scripts << " scripts and " << num_css <<
258 " css files into " << frame->url().spec().data(); 243 " css files into " << frame->url().spec().data();
259 return true; 244 return true;
260 } 245 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698