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

Unified Diff: chrome/renderer/content_settings_observer.cc

Issue 2617803002: Avoid URL allocation for GetContentSettingFromRules fast path (Closed)
Patch Set: Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/content_settings_observer.cc
diff --git a/chrome/renderer/content_settings_observer.cc b/chrome/renderer/content_settings_observer.cc
index afbaab30f3b3dbf5533629e2e07589799e96cc44..de57921904d0b983a2cd5c1b5d662b108af3cb61 100644
--- a/chrome/renderer/content_settings_observer.cc
+++ b/chrome/renderer/content_settings_observer.cc
@@ -57,10 +57,13 @@ GURL GetOriginOrURL(const WebFrame* frame) {
return top_origin.GetURL();
}
+// Allow passing both WebURL and GURL here, so that we can early return without
+// allocating a new backing string if only the default rule matches.
+template <typename URL>
ContentSetting GetContentSettingFromRules(
const ContentSettingsForOneType& rules,
const WebFrame* frame,
- const GURL& secondary_url) {
+ const URL& secondary_url) {
ContentSettingsForOneType::const_iterator it;
// If there is only one rule, it's the default rule and we don't need to match
// the patterns.
@@ -70,9 +73,10 @@ ContentSetting GetContentSettingFromRules(
return rules[0].setting;
}
const GURL& primary_url = GetOriginOrURL(frame);
+ const GURL& secondary_gurl = secondary_url;
for (it = rules.begin(); it != rules.end(); ++it) {
if (it->primary_pattern.Matches(primary_url) &&
- it->secondary_pattern.Matches(secondary_url)) {
+ it->secondary_pattern.Matches(secondary_gurl)) {
return it->setting;
}
}
@@ -251,11 +255,9 @@ bool ContentSettingsObserver::allowImage(bool enabled_per_settings,
return true;
if (content_setting_rules_) {
- GURL secondary_url(image_url);
- allow =
- GetContentSettingFromRules(content_setting_rules_->image_rules,
- render_frame()->GetWebFrame(),
- secondary_url) != CONTENT_SETTING_BLOCK;
+ allow = GetContentSettingFromRules(content_setting_rules_->image_rules,
+ render_frame()->GetWebFrame(),
+ image_url) != CONTENT_SETTING_BLOCK;
}
}
if (!allow)
@@ -320,8 +322,7 @@ bool ContentSettingsObserver::allowScriptFromSource(
if (content_setting_rules_) {
ContentSetting setting =
GetContentSettingFromRules(content_setting_rules_->script_rules,
- render_frame()->GetWebFrame(),
- GURL(script_url));
+ render_frame()->GetWebFrame(), script_url);
allow = setting != CONTENT_SETTING_BLOCK;
}
return allow || IsWhitelistedForContentSettings();
« 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