| 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 "components/content_settings/content/common/content_settings_messages.h
" | 9 #include "components/content_settings/content/common/content_settings_messages.h
" |
| 10 #include "content/public/child/url_conversion.h" |
| 10 #include "content/public/common/url_constants.h" | 11 #include "content/public/common/url_constants.h" |
| 11 #include "content/public/renderer/document_state.h" | 12 #include "content/public/renderer/document_state.h" |
| 12 #include "content/public/renderer/render_frame.h" | 13 #include "content/public/renderer/render_frame.h" |
| 13 #include "content/public/renderer/render_view.h" | 14 #include "content/public/renderer/render_view.h" |
| 14 #include "third_party/WebKit/public/platform/WebContentSettingCallbacks.h" | 15 #include "third_party/WebKit/public/platform/WebContentSettingCallbacks.h" |
| 15 #include "third_party/WebKit/public/platform/WebURL.h" | 16 #include "third_party/WebKit/public/platform/WebURL.h" |
| 16 #include "third_party/WebKit/public/web/WebDataSource.h" | 17 #include "third_party/WebKit/public/web/WebDataSource.h" |
| 17 #include "third_party/WebKit/public/web/WebDocument.h" | 18 #include "third_party/WebKit/public/web/WebDocument.h" |
| 18 #include "third_party/WebKit/public/web/WebFrameClient.h" | 19 #include "third_party/WebKit/public/web/WebFrameClient.h" |
| 19 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 20 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 | 116 |
| 116 GURL GetOriginOrURL(const WebFrame* frame) { | 117 GURL GetOriginOrURL(const WebFrame* frame) { |
| 117 WebString top_origin = frame->top()->securityOrigin().toString(); | 118 WebString top_origin = frame->top()->securityOrigin().toString(); |
| 118 // 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 |
| 119 // document URL as the primary URL in those cases. | 120 // document URL as the primary URL in those cases. |
| 120 // TODO(alexmos): This is broken for --site-per-process, since top() can be a | 121 // TODO(alexmos): This is broken for --site-per-process, since top() can be a |
| 121 // WebRemoteFrame which does not have a document(), and the WebRemoteFrame's | 122 // WebRemoteFrame which does not have a document(), and the WebRemoteFrame's |
| 122 // URL is not replicated. | 123 // URL is not replicated. |
| 123 if (top_origin == "null") | 124 if (top_origin == "null") |
| 124 return frame->top()->document().url(); | 125 return frame->top()->document().url(); |
| 125 return GURL(top_origin); | 126 return content::WebStringToGURL(top_origin); |
| 126 } | 127 } |
| 127 | 128 |
| 128 ContentSetting GetContentSettingFromRules( | 129 ContentSetting GetContentSettingFromRules( |
| 129 const ContentSettingsForOneType& rules, | 130 const ContentSettingsForOneType& rules, |
| 130 const WebFrame* frame, | 131 const WebFrame* frame, |
| 131 const GURL& secondary_url) { | 132 const GURL& secondary_url) { |
| 132 ContentSettingsForOneType::const_iterator it; | 133 ContentSettingsForOneType::const_iterator it; |
| 133 // If there is only one rule, it's the default rule and we don't need to match | 134 // If there is only one rule, it's the default rule and we don't need to match |
| 134 // the patterns. | 135 // the patterns. |
| 135 if (rules.size() == 1) { | 136 if (rules.size() == 1) { |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 bool ContentSettingsObserver::allowDatabase(const WebString& name, | 277 bool ContentSettingsObserver::allowDatabase(const WebString& name, |
| 277 const WebString& display_name, | 278 const WebString& display_name, |
| 278 unsigned long estimated_size) { | 279 unsigned long estimated_size) { |
| 279 WebFrame* frame = render_frame()->GetWebFrame(); | 280 WebFrame* frame = render_frame()->GetWebFrame(); |
| 280 if (frame->securityOrigin().isUnique() || | 281 if (frame->securityOrigin().isUnique() || |
| 281 frame->top()->securityOrigin().isUnique()) | 282 frame->top()->securityOrigin().isUnique()) |
| 282 return false; | 283 return false; |
| 283 | 284 |
| 284 bool result = false; | 285 bool result = false; |
| 285 Send(new ChromeViewHostMsg_AllowDatabase( | 286 Send(new ChromeViewHostMsg_AllowDatabase( |
| 286 routing_id(), GURL(frame->securityOrigin().toString()), | 287 routing_id(), |
| 287 GURL(frame->top()->securityOrigin().toString()), name, display_name, | 288 content::WebStringToGURL(frame->securityOrigin().toString()), |
| 288 &result)); | 289 content::WebStringToGURL(frame->top()->securityOrigin().toString()), |
| 290 name, display_name, &result)); |
| 289 return result; | 291 return result; |
| 290 } | 292 } |
| 291 | 293 |
| 292 void ContentSettingsObserver::requestFileSystemAccessAsync( | 294 void ContentSettingsObserver::requestFileSystemAccessAsync( |
| 293 const WebContentSettingCallbacks& callbacks) { | 295 const WebContentSettingCallbacks& callbacks) { |
| 294 WebFrame* frame = render_frame()->GetWebFrame(); | 296 WebFrame* frame = render_frame()->GetWebFrame(); |
| 295 if (frame->securityOrigin().isUnique() || | 297 if (frame->securityOrigin().isUnique() || |
| 296 frame->top()->securityOrigin().isUnique()) { | 298 frame->top()->securityOrigin().isUnique()) { |
| 297 WebContentSettingCallbacks permissionCallbacks(callbacks); | 299 WebContentSettingCallbacks permissionCallbacks(callbacks); |
| 298 permissionCallbacks.doDeny(); | 300 permissionCallbacks.doDeny(); |
| 299 return; | 301 return; |
| 300 } | 302 } |
| 301 ++current_request_id_; | 303 ++current_request_id_; |
| 302 std::pair<PermissionRequestMap::iterator, bool> insert_result = | 304 std::pair<PermissionRequestMap::iterator, bool> insert_result = |
| 303 permission_requests_.insert( | 305 permission_requests_.insert( |
| 304 std::make_pair(current_request_id_, callbacks)); | 306 std::make_pair(current_request_id_, callbacks)); |
| 305 | 307 |
| 306 // Verify there are no duplicate insertions. | 308 // Verify there are no duplicate insertions. |
| 307 DCHECK(insert_result.second); | 309 DCHECK(insert_result.second); |
| 308 | 310 |
| 309 Send(new ChromeViewHostMsg_RequestFileSystemAccessAsync( | 311 Send(new ChromeViewHostMsg_RequestFileSystemAccessAsync( |
| 310 routing_id(), current_request_id_, | 312 routing_id(), current_request_id_, |
| 311 GURL(frame->securityOrigin().toString()), | 313 content::WebStringToGURL(frame->securityOrigin().toString()), |
| 312 GURL(frame->top()->securityOrigin().toString()))); | 314 content::WebStringToGURL(frame->top()->securityOrigin().toString()))); |
| 313 } | 315 } |
| 314 | 316 |
| 315 bool ContentSettingsObserver::allowImage(bool enabled_per_settings, | 317 bool ContentSettingsObserver::allowImage(bool enabled_per_settings, |
| 316 const WebURL& image_url) { | 318 const WebURL& image_url) { |
| 317 bool allow = enabled_per_settings; | 319 bool allow = enabled_per_settings; |
| 318 if (enabled_per_settings) { | 320 if (enabled_per_settings) { |
| 319 if (is_interstitial_page_) | 321 if (is_interstitial_page_) |
| 320 return true; | 322 return true; |
| 321 | 323 |
| 322 if (IsWhitelistedForContentSettings()) | 324 if (IsWhitelistedForContentSettings()) |
| (...skipping 14 matching lines...) Expand all Loading... |
| 337 | 339 |
| 338 bool ContentSettingsObserver::allowIndexedDB(const WebString& name, | 340 bool ContentSettingsObserver::allowIndexedDB(const WebString& name, |
| 339 const WebSecurityOrigin& origin) { | 341 const WebSecurityOrigin& origin) { |
| 340 WebFrame* frame = render_frame()->GetWebFrame(); | 342 WebFrame* frame = render_frame()->GetWebFrame(); |
| 341 if (frame->securityOrigin().isUnique() || | 343 if (frame->securityOrigin().isUnique() || |
| 342 frame->top()->securityOrigin().isUnique()) | 344 frame->top()->securityOrigin().isUnique()) |
| 343 return false; | 345 return false; |
| 344 | 346 |
| 345 bool result = false; | 347 bool result = false; |
| 346 Send(new ChromeViewHostMsg_AllowIndexedDB( | 348 Send(new ChromeViewHostMsg_AllowIndexedDB( |
| 347 routing_id(), GURL(frame->securityOrigin().toString()), | 349 routing_id(), |
| 348 GURL(frame->top()->securityOrigin().toString()), name, &result)); | 350 content::WebStringToGURL(frame->securityOrigin().toString()), |
| 351 content::WebStringToGURL(frame->top()->securityOrigin().toString()), |
| 352 name, &result)); |
| 349 return result; | 353 return result; |
| 350 } | 354 } |
| 351 | 355 |
| 352 bool ContentSettingsObserver::allowPlugins(bool enabled_per_settings) { | 356 bool ContentSettingsObserver::allowPlugins(bool enabled_per_settings) { |
| 353 return enabled_per_settings; | 357 return enabled_per_settings; |
| 354 } | 358 } |
| 355 | 359 |
| 356 bool ContentSettingsObserver::allowScript(bool enabled_per_settings) { | 360 bool ContentSettingsObserver::allowScript(bool enabled_per_settings) { |
| 357 if (!enabled_per_settings) | 361 if (!enabled_per_settings) |
| 358 return false; | 362 return false; |
| 359 if (is_interstitial_page_) | 363 if (is_interstitial_page_) |
| 360 return true; | 364 return true; |
| 361 | 365 |
| 362 WebFrame* frame = render_frame()->GetWebFrame(); | 366 WebFrame* frame = render_frame()->GetWebFrame(); |
| 363 std::map<WebFrame*, bool>::const_iterator it = | 367 std::map<WebFrame*, bool>::const_iterator it = |
| 364 cached_script_permissions_.find(frame); | 368 cached_script_permissions_.find(frame); |
| 365 if (it != cached_script_permissions_.end()) | 369 if (it != cached_script_permissions_.end()) |
| 366 return it->second; | 370 return it->second; |
| 367 | 371 |
| 368 // Evaluate the content setting rules before | 372 // Evaluate the content setting rules before |
| 369 // |IsWhitelistedForContentSettings|; if there is only the default rule | 373 // |IsWhitelistedForContentSettings|; if there is only the default rule |
| 370 // allowing all scripts, it's quicker this way. | 374 // allowing all scripts, it's quicker this way. |
| 371 bool allow = true; | 375 bool allow = true; |
| 372 if (content_setting_rules_) { | 376 if (content_setting_rules_) { |
| 373 ContentSetting setting = GetContentSettingFromRules( | 377 ContentSetting setting = GetContentSettingFromRules( |
| 374 content_setting_rules_->script_rules, | 378 content_setting_rules_->script_rules, |
| 375 frame, | 379 frame, |
| 376 GURL(frame->document().securityOrigin().toString())); | 380 content::WebStringToGURL( |
| 381 frame->document().securityOrigin().toString())); |
| 377 allow = setting != CONTENT_SETTING_BLOCK; | 382 allow = setting != CONTENT_SETTING_BLOCK; |
| 378 } | 383 } |
| 379 allow = allow || IsWhitelistedForContentSettings(); | 384 allow = allow || IsWhitelistedForContentSettings(); |
| 380 | 385 |
| 381 cached_script_permissions_[frame] = allow; | 386 cached_script_permissions_[frame] = allow; |
| 382 return allow; | 387 return allow; |
| 383 } | 388 } |
| 384 | 389 |
| 385 bool ContentSettingsObserver::allowScriptFromSource( | 390 bool ContentSettingsObserver::allowScriptFromSource( |
| 386 bool enabled_per_settings, | 391 bool enabled_per_settings, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 402 } | 407 } |
| 403 | 408 |
| 404 bool ContentSettingsObserver::allowStorage(bool local) { | 409 bool ContentSettingsObserver::allowStorage(bool local) { |
| 405 WebFrame* frame = render_frame()->GetWebFrame(); | 410 WebFrame* frame = render_frame()->GetWebFrame(); |
| 406 if (frame->securityOrigin().isUnique() || | 411 if (frame->securityOrigin().isUnique() || |
| 407 frame->top()->securityOrigin().isUnique()) | 412 frame->top()->securityOrigin().isUnique()) |
| 408 return false; | 413 return false; |
| 409 bool result = false; | 414 bool result = false; |
| 410 | 415 |
| 411 StoragePermissionsKey key( | 416 StoragePermissionsKey key( |
| 412 GURL(frame->document().securityOrigin().toString()), local); | 417 content::WebStringToGURL(frame->document().securityOrigin().toString()), |
| 418 local); |
| 413 std::map<StoragePermissionsKey, bool>::const_iterator permissions = | 419 std::map<StoragePermissionsKey, bool>::const_iterator permissions = |
| 414 cached_storage_permissions_.find(key); | 420 cached_storage_permissions_.find(key); |
| 415 if (permissions != cached_storage_permissions_.end()) | 421 if (permissions != cached_storage_permissions_.end()) |
| 416 return permissions->second; | 422 return permissions->second; |
| 417 | 423 |
| 418 Send(new ChromeViewHostMsg_AllowDOMStorage( | 424 Send(new ChromeViewHostMsg_AllowDOMStorage( |
| 419 routing_id(), GURL(frame->securityOrigin().toString()), | 425 routing_id(), |
| 420 GURL(frame->top()->securityOrigin().toString()), local, &result)); | 426 content::WebStringToGURL(frame->securityOrigin().toString()), |
| 427 content::WebStringToGURL(frame->top()->securityOrigin().toString()), |
| 428 local, &result)); |
| 421 cached_storage_permissions_[key] = result; | 429 cached_storage_permissions_[key] = result; |
| 422 return result; | 430 return result; |
| 423 } | 431 } |
| 424 | 432 |
| 425 bool ContentSettingsObserver::allowReadFromClipboard(bool default_value) { | 433 bool ContentSettingsObserver::allowReadFromClipboard(bool default_value) { |
| 426 bool allowed = default_value; | 434 bool allowed = default_value; |
| 427 #if defined(ENABLE_EXTENSIONS) | 435 #if defined(ENABLE_EXTENSIONS) |
| 428 extensions::ScriptContext* current_context = | 436 extensions::ScriptContext* current_context = |
| 429 extension_dispatcher_->script_context_set().GetCurrent(); | 437 extension_dispatcher_->script_context_set().GetCurrent(); |
| 430 if (current_context) { | 438 if (current_context) { |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 return false; | 598 return false; |
| 591 } | 599 } |
| 592 | 600 |
| 593 return true; | 601 return true; |
| 594 } | 602 } |
| 595 | 603 |
| 596 void ContentSettingsObserver::didUseKeygen() { | 604 void ContentSettingsObserver::didUseKeygen() { |
| 597 WebFrame* frame = render_frame()->GetWebFrame(); | 605 WebFrame* frame = render_frame()->GetWebFrame(); |
| 598 Send(new ChromeViewHostMsg_DidUseKeygen( | 606 Send(new ChromeViewHostMsg_DidUseKeygen( |
| 599 routing_id(), | 607 routing_id(), |
| 600 GURL(frame->securityOrigin().toString()))); | 608 content::WebStringToGURL(frame->securityOrigin().toString()))); |
| 601 } | 609 } |
| 602 | 610 |
| 603 void ContentSettingsObserver::didNotAllowPlugins() { | 611 void ContentSettingsObserver::didNotAllowPlugins() { |
| 604 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS); | 612 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS); |
| 605 } | 613 } |
| 606 | 614 |
| 607 void ContentSettingsObserver::didNotAllowScript() { | 615 void ContentSettingsObserver::didNotAllowScript() { |
| 608 DidBlockContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT); | 616 DidBlockContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT); |
| 609 } | 617 } |
| 610 | 618 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 731 | 739 |
| 732 // If the scheme is file:, an empty file name indicates a directory listing, | 740 // If the scheme is file:, an empty file name indicates a directory listing, |
| 733 // which requires JavaScript to function properly. | 741 // which requires JavaScript to function properly. |
| 734 if (base::EqualsASCII(protocol, url::kFileScheme)) { | 742 if (base::EqualsASCII(protocol, url::kFileScheme)) { |
| 735 return document_url.SchemeIs(url::kFileScheme) && | 743 return document_url.SchemeIs(url::kFileScheme) && |
| 736 document_url.ExtractFileName().empty(); | 744 document_url.ExtractFileName().empty(); |
| 737 } | 745 } |
| 738 | 746 |
| 739 return false; | 747 return false; |
| 740 } | 748 } |
| OLD | NEW |