Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "chrome/common/chrome_switches.h" | 9 #include "chrome/common/chrome_switches.h" |
| 10 #include "chrome/common/render_messages.h" | 10 #include "chrome/common/render_messages.h" |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 static const char kGoogleDotCom[] = "google.com"; | 108 static const char kGoogleDotCom[] = "google.com"; |
| 109 | 109 |
| 110 static bool IsHostInDomain(const std::string& host, const std::string& domain) { | 110 static bool IsHostInDomain(const std::string& host, const std::string& domain) { |
| 111 return (EndsWith(host, domain, false) && | 111 return (EndsWith(host, domain, false) && |
| 112 (host.length() == domain.length() || | 112 (host.length() == domain.length() || |
| 113 (host.length() > domain.length() && | 113 (host.length() > domain.length() && |
| 114 host[host.length() - domain.length() - 1] == '.'))); | 114 host[host.length() - domain.length() - 1] == '.'))); |
| 115 } | 115 } |
| 116 | 116 |
| 117 GURL GetOriginOrURL(const WebFrame* frame) { | 117 GURL GetOriginOrURL(const WebFrame* frame) { |
| 118 WebString top_origin = frame->top()->document().securityOrigin().toString(); | 118 WebString top_origin = frame->top()->securityOrigin().toString(); |
|
markusheintz_
2014/12/16 13:04:43
What security origin are you using for file URLs?
alexmos
2014/12/16 20:13:26
Correct, file URLs will result in a "null" origin
| |
| 119 // The the |top_origin| is unique ("null") e.g., for file:// URLs. Use the | 119 // The |top_origin| is unique ("null") e.g., for file:// URLs. Use the |
| 120 // document URL as the primary URL in those cases. | 120 // document URL as the primary URL in those cases. |
| 121 // TODO(alexmos): This is broken for --site-per-process, since top() can be a | |
| 122 // WebRemoteFrame which does not have a document(), and the WebRemoteFrame's | |
| 123 // URL is not replicated. | |
| 121 if (top_origin == "null") | 124 if (top_origin == "null") |
| 122 return frame->top()->document().url(); | 125 return frame->top()->document().url(); |
| 123 return GURL(top_origin); | 126 return GURL(top_origin); |
| 124 } | 127 } |
| 125 | 128 |
| 126 ContentSetting GetContentSettingFromRules( | 129 ContentSetting GetContentSettingFromRules( |
| 127 const ContentSettingsForOneType& rules, | 130 const ContentSettingsForOneType& rules, |
| 128 const WebFrame* frame, | 131 const WebFrame* frame, |
| 129 const GURL& secondary_url) { | 132 const GURL& secondary_url) { |
| 130 ContentSettingsForOneType::const_iterator it; | 133 ContentSettingsForOneType::const_iterator it; |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 262 // If we start failing this DCHECK, please makes sure we don't regress | 265 // If we start failing this DCHECK, please makes sure we don't regress |
| 263 // this bug: http://code.google.com/p/chromium/issues/detail?id=79304 | 266 // this bug: http://code.google.com/p/chromium/issues/detail?id=79304 |
| 264 DCHECK(frame->document().securityOrigin().toString() == "null" || | 267 DCHECK(frame->document().securityOrigin().toString() == "null" || |
| 265 !url.SchemeIs(url::kDataScheme)); | 268 !url.SchemeIs(url::kDataScheme)); |
| 266 } | 269 } |
| 267 | 270 |
| 268 bool ContentSettingsObserver::allowDatabase(const WebString& name, | 271 bool ContentSettingsObserver::allowDatabase(const WebString& name, |
| 269 const WebString& display_name, | 272 const WebString& display_name, |
| 270 unsigned long estimated_size) { | 273 unsigned long estimated_size) { |
| 271 WebFrame* frame = render_frame()->GetWebFrame(); | 274 WebFrame* frame = render_frame()->GetWebFrame(); |
| 272 if (frame->document().securityOrigin().isUnique() || | 275 if (frame->securityOrigin().isUnique() || |
| 273 frame->top()->document().securityOrigin().isUnique()) | 276 frame->top()->securityOrigin().isUnique()) |
| 274 return false; | 277 return false; |
| 275 | 278 |
| 276 bool result = false; | 279 bool result = false; |
| 277 Send(new ChromeViewHostMsg_AllowDatabase( | 280 Send(new ChromeViewHostMsg_AllowDatabase( |
| 278 routing_id(), GURL(frame->document().securityOrigin().toString()), | 281 routing_id(), GURL(frame->securityOrigin().toString()), |
| 279 GURL(frame->top()->document().securityOrigin().toString()), | 282 GURL(frame->top()->securityOrigin().toString()), name, display_name, |
| 280 name, display_name, &result)); | 283 &result)); |
| 281 return result; | 284 return result; |
| 282 } | 285 } |
| 283 | 286 |
| 284 void ContentSettingsObserver::requestFileSystemAccessAsync( | 287 void ContentSettingsObserver::requestFileSystemAccessAsync( |
| 285 const WebPermissionCallbacks& callbacks) { | 288 const WebPermissionCallbacks& callbacks) { |
| 286 WebFrame* frame = render_frame()->GetWebFrame(); | 289 WebFrame* frame = render_frame()->GetWebFrame(); |
| 287 if (frame->document().securityOrigin().isUnique() || | 290 if (frame->securityOrigin().isUnique() || |
| 288 frame->top()->document().securityOrigin().isUnique()) { | 291 frame->top()->securityOrigin().isUnique()) { |
| 289 WebPermissionCallbacks permissionCallbacks(callbacks); | 292 WebPermissionCallbacks permissionCallbacks(callbacks); |
| 290 permissionCallbacks.doDeny(); | 293 permissionCallbacks.doDeny(); |
| 291 return; | 294 return; |
| 292 } | 295 } |
| 293 ++current_request_id_; | 296 ++current_request_id_; |
| 294 std::pair<PermissionRequestMap::iterator, bool> insert_result = | 297 std::pair<PermissionRequestMap::iterator, bool> insert_result = |
| 295 permission_requests_.insert( | 298 permission_requests_.insert( |
| 296 std::make_pair(current_request_id_, callbacks)); | 299 std::make_pair(current_request_id_, callbacks)); |
| 297 | 300 |
| 298 // Verify there are no duplicate insertions. | 301 // Verify there are no duplicate insertions. |
| 299 DCHECK(insert_result.second); | 302 DCHECK(insert_result.second); |
| 300 | 303 |
| 301 Send(new ChromeViewHostMsg_RequestFileSystemAccessAsync( | 304 Send(new ChromeViewHostMsg_RequestFileSystemAccessAsync( |
| 302 routing_id(), | 305 routing_id(), current_request_id_, |
| 303 current_request_id_, | 306 GURL(frame->securityOrigin().toString()), |
| 304 GURL(frame->document().securityOrigin().toString()), | 307 GURL(frame->top()->securityOrigin().toString()))); |
| 305 GURL(frame->top()->document().securityOrigin().toString()))); | |
| 306 } | 308 } |
| 307 | 309 |
| 308 bool ContentSettingsObserver::allowImage(bool enabled_per_settings, | 310 bool ContentSettingsObserver::allowImage(bool enabled_per_settings, |
| 309 const WebURL& image_url) { | 311 const WebURL& image_url) { |
| 310 bool allow = enabled_per_settings; | 312 bool allow = enabled_per_settings; |
| 311 if (enabled_per_settings) { | 313 if (enabled_per_settings) { |
| 312 if (is_interstitial_page_) | 314 if (is_interstitial_page_) |
| 313 return true; | 315 return true; |
| 314 | 316 |
| 315 if (IsWhitelistedForContentSettings(render_frame())) | 317 if (IsWhitelistedForContentSettings(render_frame())) |
| 316 return true; | 318 return true; |
| 317 | 319 |
| 318 if (content_setting_rules_) { | 320 if (content_setting_rules_) { |
| 319 GURL secondary_url(image_url); | 321 GURL secondary_url(image_url); |
| 320 allow = | 322 allow = |
| 321 GetContentSettingFromRules(content_setting_rules_->image_rules, | 323 GetContentSettingFromRules(content_setting_rules_->image_rules, |
| 322 render_frame()->GetWebFrame(), | 324 render_frame()->GetWebFrame(), |
| 323 secondary_url) != CONTENT_SETTING_BLOCK; | 325 secondary_url) != CONTENT_SETTING_BLOCK; |
| 324 } | 326 } |
| 325 } | 327 } |
| 326 if (!allow) | 328 if (!allow) |
| 327 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES); | 329 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES); |
| 328 return allow; | 330 return allow; |
| 329 } | 331 } |
| 330 | 332 |
| 331 bool ContentSettingsObserver::allowIndexedDB(const WebString& name, | 333 bool ContentSettingsObserver::allowIndexedDB(const WebString& name, |
| 332 const WebSecurityOrigin& origin) { | 334 const WebSecurityOrigin& origin) { |
| 333 WebFrame* frame = render_frame()->GetWebFrame(); | 335 WebFrame* frame = render_frame()->GetWebFrame(); |
| 334 if (frame->document().securityOrigin().isUnique() || | 336 if (frame->securityOrigin().isUnique() || |
| 335 frame->top()->document().securityOrigin().isUnique()) | 337 frame->top()->securityOrigin().isUnique()) |
| 336 return false; | 338 return false; |
| 337 | 339 |
| 338 bool result = false; | 340 bool result = false; |
| 339 Send(new ChromeViewHostMsg_AllowIndexedDB( | 341 Send(new ChromeViewHostMsg_AllowIndexedDB( |
| 340 routing_id(), GURL(frame->document().securityOrigin().toString()), | 342 routing_id(), GURL(frame->securityOrigin().toString()), |
| 341 GURL(frame->top()->document().securityOrigin().toString()), | 343 GURL(frame->top()->securityOrigin().toString()), name, &result)); |
| 342 name, &result)); | |
| 343 return result; | 344 return result; |
| 344 } | 345 } |
| 345 | 346 |
| 346 bool ContentSettingsObserver::allowPlugins(bool enabled_per_settings) { | 347 bool ContentSettingsObserver::allowPlugins(bool enabled_per_settings) { |
| 347 return enabled_per_settings; | 348 return enabled_per_settings; |
| 348 } | 349 } |
| 349 | 350 |
| 350 bool ContentSettingsObserver::allowScript(bool enabled_per_settings) { | 351 bool ContentSettingsObserver::allowScript(bool enabled_per_settings) { |
| 351 if (!enabled_per_settings) | 352 if (!enabled_per_settings) |
| 352 return false; | 353 return false; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 390 GetContentSettingFromRules(content_setting_rules_->script_rules, | 391 GetContentSettingFromRules(content_setting_rules_->script_rules, |
| 391 render_frame()->GetWebFrame(), | 392 render_frame()->GetWebFrame(), |
| 392 GURL(script_url)); | 393 GURL(script_url)); |
| 393 allow = setting != CONTENT_SETTING_BLOCK; | 394 allow = setting != CONTENT_SETTING_BLOCK; |
| 394 } | 395 } |
| 395 return allow || IsWhitelistedForContentSettings(render_frame()); | 396 return allow || IsWhitelistedForContentSettings(render_frame()); |
| 396 } | 397 } |
| 397 | 398 |
| 398 bool ContentSettingsObserver::allowStorage(bool local) { | 399 bool ContentSettingsObserver::allowStorage(bool local) { |
| 399 WebFrame* frame = render_frame()->GetWebFrame(); | 400 WebFrame* frame = render_frame()->GetWebFrame(); |
| 400 if (frame->document().securityOrigin().isUnique() || | 401 if (frame->securityOrigin().isUnique() || |
| 401 frame->top()->document().securityOrigin().isUnique()) | 402 frame->top()->securityOrigin().isUnique()) |
| 402 return false; | 403 return false; |
| 403 bool result = false; | 404 bool result = false; |
| 404 | 405 |
| 405 StoragePermissionsKey key( | 406 StoragePermissionsKey key( |
| 406 GURL(frame->document().securityOrigin().toString()), local); | 407 GURL(frame->document().securityOrigin().toString()), local); |
| 407 std::map<StoragePermissionsKey, bool>::const_iterator permissions = | 408 std::map<StoragePermissionsKey, bool>::const_iterator permissions = |
| 408 cached_storage_permissions_.find(key); | 409 cached_storage_permissions_.find(key); |
| 409 if (permissions != cached_storage_permissions_.end()) | 410 if (permissions != cached_storage_permissions_.end()) |
| 410 return permissions->second; | 411 return permissions->second; |
| 411 | 412 |
| 412 Send(new ChromeViewHostMsg_AllowDOMStorage( | 413 Send(new ChromeViewHostMsg_AllowDOMStorage( |
| 413 routing_id(), GURL(frame->document().securityOrigin().toString()), | 414 routing_id(), GURL(frame->securityOrigin().toString()), |
| 414 GURL(frame->top()->document().securityOrigin().toString()), | 415 GURL(frame->top()->securityOrigin().toString()), local, &result)); |
| 415 local, &result)); | |
| 416 cached_storage_permissions_[key] = result; | 416 cached_storage_permissions_[key] = result; |
| 417 return result; | 417 return result; |
| 418 } | 418 } |
| 419 | 419 |
| 420 bool ContentSettingsObserver::allowReadFromClipboard(bool default_value) { | 420 bool ContentSettingsObserver::allowReadFromClipboard(bool default_value) { |
| 421 bool allowed = false; | 421 bool allowed = false; |
| 422 #if defined(ENABLE_EXTENSIONS) | 422 #if defined(ENABLE_EXTENSIONS) |
| 423 extensions::ScriptContext* calling_context = | 423 extensions::ScriptContext* calling_context = |
| 424 extension_dispatcher_->script_context_set().GetCalling(); | 424 extension_dispatcher_->script_context_set().GetCalling(); |
| 425 if (calling_context) { | 425 if (calling_context) { |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 723 | 723 |
| 724 // If the scheme is file:, an empty file name indicates a directory listing, | 724 // If the scheme is file:, an empty file name indicates a directory listing, |
| 725 // which requires JavaScript to function properly. | 725 // which requires JavaScript to function properly. |
| 726 if (EqualsASCII(origin.protocol(), url::kFileScheme)) { | 726 if (EqualsASCII(origin.protocol(), url::kFileScheme)) { |
| 727 return document_url.SchemeIs(url::kFileScheme) && | 727 return document_url.SchemeIs(url::kFileScheme) && |
| 728 document_url.ExtractFileName().empty(); | 728 document_url.ExtractFileName().empty(); |
| 729 } | 729 } |
| 730 | 730 |
| 731 return false; | 731 return false; |
| 732 } | 732 } |
| OLD | NEW |