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

Side by Side 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 unified diff | Download patch
« 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/content_settings_observer.h" 5 #include "chrome/renderer/content_settings_observer.h"
6 6
7 #include "chrome/common/render_messages.h" 7 #include "chrome/common/render_messages.h"
8 #include "chrome/common/ssl_insecure_content.h" 8 #include "chrome/common/ssl_insecure_content.h"
9 #include "content/public/common/url_constants.h" 9 #include "content/public/common/url_constants.h"
10 #include "content/public/renderer/document_state.h" 10 #include "content/public/renderer/document_state.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 // The |top_origin| is unique ("null") e.g., for file:// URLs. Use the 50 // The |top_origin| is unique ("null") e.g., for file:// URLs. Use the
51 // document URL as the primary URL in those cases. 51 // document URL as the primary URL in those cases.
52 // TODO(alexmos): This is broken for --site-per-process, since top() can be a 52 // TODO(alexmos): This is broken for --site-per-process, since top() can be a
53 // WebRemoteFrame which does not have a document(), and the WebRemoteFrame's 53 // WebRemoteFrame which does not have a document(), and the WebRemoteFrame's
54 // URL is not replicated. See https://crbug.com/628759. 54 // URL is not replicated. See https://crbug.com/628759.
55 if (top_origin.unique() && frame->top()->isWebLocalFrame()) 55 if (top_origin.unique() && frame->top()->isWebLocalFrame())
56 return frame->top()->document().url(); 56 return frame->top()->document().url();
57 return top_origin.GetURL(); 57 return top_origin.GetURL();
58 } 58 }
59 59
60 // Allow passing both WebURL and GURL here, so that we can early return without
61 // allocating a new backing string if only the default rule matches.
62 template <typename URL>
60 ContentSetting GetContentSettingFromRules( 63 ContentSetting GetContentSettingFromRules(
61 const ContentSettingsForOneType& rules, 64 const ContentSettingsForOneType& rules,
62 const WebFrame* frame, 65 const WebFrame* frame,
63 const GURL& secondary_url) { 66 const URL& secondary_url) {
64 ContentSettingsForOneType::const_iterator it; 67 ContentSettingsForOneType::const_iterator it;
65 // If there is only one rule, it's the default rule and we don't need to match 68 // If there is only one rule, it's the default rule and we don't need to match
66 // the patterns. 69 // the patterns.
67 if (rules.size() == 1) { 70 if (rules.size() == 1) {
68 DCHECK(rules[0].primary_pattern == ContentSettingsPattern::Wildcard()); 71 DCHECK(rules[0].primary_pattern == ContentSettingsPattern::Wildcard());
69 DCHECK(rules[0].secondary_pattern == ContentSettingsPattern::Wildcard()); 72 DCHECK(rules[0].secondary_pattern == ContentSettingsPattern::Wildcard());
70 return rules[0].setting; 73 return rules[0].setting;
71 } 74 }
72 const GURL& primary_url = GetOriginOrURL(frame); 75 const GURL& primary_url = GetOriginOrURL(frame);
76 const GURL& secondary_gurl = secondary_url;
73 for (it = rules.begin(); it != rules.end(); ++it) { 77 for (it = rules.begin(); it != rules.end(); ++it) {
74 if (it->primary_pattern.Matches(primary_url) && 78 if (it->primary_pattern.Matches(primary_url) &&
75 it->secondary_pattern.Matches(secondary_url)) { 79 it->secondary_pattern.Matches(secondary_gurl)) {
76 return it->setting; 80 return it->setting;
77 } 81 }
78 } 82 }
79 NOTREACHED(); 83 NOTREACHED();
80 return CONTENT_SETTING_DEFAULT; 84 return CONTENT_SETTING_DEFAULT;
81 } 85 }
82 86
83 } // namespace 87 } // namespace
84 88
85 ContentSettingsObserver::ContentSettingsObserver( 89 ContentSettingsObserver::ContentSettingsObserver(
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 const WebURL& image_url) { 248 const WebURL& image_url) {
245 bool allow = enabled_per_settings; 249 bool allow = enabled_per_settings;
246 if (enabled_per_settings) { 250 if (enabled_per_settings) {
247 if (is_interstitial_page_) 251 if (is_interstitial_page_)
248 return true; 252 return true;
249 253
250 if (IsWhitelistedForContentSettings()) 254 if (IsWhitelistedForContentSettings())
251 return true; 255 return true;
252 256
253 if (content_setting_rules_) { 257 if (content_setting_rules_) {
254 GURL secondary_url(image_url); 258 allow = GetContentSettingFromRules(content_setting_rules_->image_rules,
255 allow = 259 render_frame()->GetWebFrame(),
256 GetContentSettingFromRules(content_setting_rules_->image_rules, 260 image_url) != CONTENT_SETTING_BLOCK;
257 render_frame()->GetWebFrame(),
258 secondary_url) != CONTENT_SETTING_BLOCK;
259 } 261 }
260 } 262 }
261 if (!allow) 263 if (!allow)
262 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES); 264 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES);
263 return allow; 265 return allow;
264 } 266 }
265 267
266 bool ContentSettingsObserver::allowIndexedDB(const WebString& name, 268 bool ContentSettingsObserver::allowIndexedDB(const WebString& name,
267 const WebSecurityOrigin& origin) { 269 const WebSecurityOrigin& origin) {
268 WebFrame* frame = render_frame()->GetWebFrame(); 270 WebFrame* frame = render_frame()->GetWebFrame();
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 const blink::WebURL& script_url) { 315 const blink::WebURL& script_url) {
314 if (!enabled_per_settings) 316 if (!enabled_per_settings)
315 return false; 317 return false;
316 if (is_interstitial_page_) 318 if (is_interstitial_page_)
317 return true; 319 return true;
318 320
319 bool allow = true; 321 bool allow = true;
320 if (content_setting_rules_) { 322 if (content_setting_rules_) {
321 ContentSetting setting = 323 ContentSetting setting =
322 GetContentSettingFromRules(content_setting_rules_->script_rules, 324 GetContentSettingFromRules(content_setting_rules_->script_rules,
323 render_frame()->GetWebFrame(), 325 render_frame()->GetWebFrame(), script_url);
324 GURL(script_url));
325 allow = setting != CONTENT_SETTING_BLOCK; 326 allow = setting != CONTENT_SETTING_BLOCK;
326 } 327 }
327 return allow || IsWhitelistedForContentSettings(); 328 return allow || IsWhitelistedForContentSettings();
328 } 329 }
329 330
330 bool ContentSettingsObserver::allowStorage(bool local) { 331 bool ContentSettingsObserver::allowStorage(bool local) {
331 WebFrame* frame = render_frame()->GetWebFrame(); 332 WebFrame* frame = render_frame()->GetWebFrame();
332 if (frame->getSecurityOrigin().isUnique() || 333 if (frame->getSecurityOrigin().isUnique() ||
333 frame->top()->getSecurityOrigin().isUnique()) 334 frame->top()->getSecurityOrigin().isUnique())
334 return false; 335 return false;
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 530
530 // If the scheme is file:, an empty file name indicates a directory listing, 531 // If the scheme is file:, an empty file name indicates a directory listing,
531 // which requires JavaScript to function properly. 532 // which requires JavaScript to function properly.
532 if (base::EqualsASCII(protocol, url::kFileScheme)) { 533 if (base::EqualsASCII(protocol, url::kFileScheme)) {
533 return document_url.SchemeIs(url::kFileScheme) && 534 return document_url.SchemeIs(url::kFileScheme) &&
534 document_url.ExtractFileName().empty(); 535 document_url.ExtractFileName().empty();
535 } 536 }
536 537
537 return false; 538 return false;
538 } 539 }
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