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 "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" |
11 #include "content/public/renderer/render_frame.h" | 11 #include "content/public/renderer/render_frame.h" |
12 #include "content/public/renderer/render_view.h" | 12 #include "content/public/renderer/render_view.h" |
| 13 #include "extensions/features/features.h" |
13 #include "third_party/WebKit/public/platform/URLConversion.h" | 14 #include "third_party/WebKit/public/platform/URLConversion.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/WebSecurityOrigin.h" | 16 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" |
16 #include "third_party/WebKit/public/platform/WebURL.h" | 17 #include "third_party/WebKit/public/platform/WebURL.h" |
17 #include "third_party/WebKit/public/web/WebDataSource.h" | 18 #include "third_party/WebKit/public/web/WebDataSource.h" |
18 #include "third_party/WebKit/public/web/WebDocument.h" | 19 #include "third_party/WebKit/public/web/WebDocument.h" |
19 #include "third_party/WebKit/public/web/WebFrameClient.h" | 20 #include "third_party/WebKit/public/web/WebFrameClient.h" |
20 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 21 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
21 #include "third_party/WebKit/public/web/WebView.h" | 22 #include "third_party/WebKit/public/web/WebView.h" |
22 #include "url/origin.h" | 23 #include "url/origin.h" |
23 #include "url/url_constants.h" | 24 #include "url/url_constants.h" |
24 | 25 |
25 #if defined(ENABLE_EXTENSIONS) | 26 #if BUILDFLAG(ENABLE_EXTENSIONS) |
26 #include "extensions/common/constants.h" | 27 #include "extensions/common/constants.h" |
27 #include "extensions/common/extension.h" | 28 #include "extensions/common/extension.h" |
28 #include "extensions/common/permissions/api_permission.h" | 29 #include "extensions/common/permissions/api_permission.h" |
29 #include "extensions/common/permissions/permissions_data.h" | 30 #include "extensions/common/permissions/permissions_data.h" |
30 #include "extensions/renderer/dispatcher.h" | 31 #include "extensions/renderer/dispatcher.h" |
31 #include "extensions/renderer/renderer_extension_registry.h" | 32 #include "extensions/renderer/renderer_extension_registry.h" |
32 #endif | 33 #endif |
33 | 34 |
34 using blink::WebContentSettingCallbacks; | 35 using blink::WebContentSettingCallbacks; |
35 using blink::WebDataSource; | 36 using blink::WebDataSource; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 | 82 |
82 } // namespace | 83 } // namespace |
83 | 84 |
84 ContentSettingsObserver::ContentSettingsObserver( | 85 ContentSettingsObserver::ContentSettingsObserver( |
85 content::RenderFrame* render_frame, | 86 content::RenderFrame* render_frame, |
86 extensions::Dispatcher* extension_dispatcher, | 87 extensions::Dispatcher* extension_dispatcher, |
87 bool should_whitelist) | 88 bool should_whitelist) |
88 : content::RenderFrameObserver(render_frame), | 89 : content::RenderFrameObserver(render_frame), |
89 content::RenderFrameObserverTracker<ContentSettingsObserver>( | 90 content::RenderFrameObserverTracker<ContentSettingsObserver>( |
90 render_frame), | 91 render_frame), |
91 #if defined(ENABLE_EXTENSIONS) | 92 #if BUILDFLAG(ENABLE_EXTENSIONS) |
92 extension_dispatcher_(extension_dispatcher), | 93 extension_dispatcher_(extension_dispatcher), |
93 #endif | 94 #endif |
94 allow_running_insecure_content_(false), | 95 allow_running_insecure_content_(false), |
95 content_setting_rules_(NULL), | 96 content_setting_rules_(NULL), |
96 is_interstitial_page_(false), | 97 is_interstitial_page_(false), |
97 current_request_id_(0), | 98 current_request_id_(0), |
98 should_whitelist_(should_whitelist) { | 99 should_whitelist_(should_whitelist) { |
99 ClearBlockedContentSettings(); | 100 ClearBlockedContentSettings(); |
100 render_frame->GetWebFrame()->setContentSettingsClient(this); | 101 render_frame->GetWebFrame()->setContentSettingsClient(this); |
101 | 102 |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 bool result = false; | 342 bool result = false; |
342 Send(new ChromeViewHostMsg_AllowDOMStorage( | 343 Send(new ChromeViewHostMsg_AllowDOMStorage( |
343 routing_id(), url::Origin(frame->getSecurityOrigin()).GetURL(), | 344 routing_id(), url::Origin(frame->getSecurityOrigin()).GetURL(), |
344 url::Origin(frame->top()->getSecurityOrigin()).GetURL(), local, &result)); | 345 url::Origin(frame->top()->getSecurityOrigin()).GetURL(), local, &result)); |
345 cached_storage_permissions_[key] = result; | 346 cached_storage_permissions_[key] = result; |
346 return result; | 347 return result; |
347 } | 348 } |
348 | 349 |
349 bool ContentSettingsObserver::allowReadFromClipboard(bool default_value) { | 350 bool ContentSettingsObserver::allowReadFromClipboard(bool default_value) { |
350 bool allowed = default_value; | 351 bool allowed = default_value; |
351 #if defined(ENABLE_EXTENSIONS) | 352 #if BUILDFLAG(ENABLE_EXTENSIONS) |
352 extensions::ScriptContext* current_context = | 353 extensions::ScriptContext* current_context = |
353 extension_dispatcher_->script_context_set().GetCurrent(); | 354 extension_dispatcher_->script_context_set().GetCurrent(); |
354 if (current_context) { | 355 if (current_context) { |
355 allowed |= current_context->HasAPIPermission( | 356 allowed |= current_context->HasAPIPermission( |
356 extensions::APIPermission::kClipboardRead); | 357 extensions::APIPermission::kClipboardRead); |
357 } | 358 } |
358 #endif | 359 #endif |
359 return allowed; | 360 return allowed; |
360 } | 361 } |
361 | 362 |
362 bool ContentSettingsObserver::allowWriteToClipboard(bool default_value) { | 363 bool ContentSettingsObserver::allowWriteToClipboard(bool default_value) { |
363 bool allowed = default_value; | 364 bool allowed = default_value; |
364 #if defined(ENABLE_EXTENSIONS) | 365 #if BUILDFLAG(ENABLE_EXTENSIONS) |
365 // All blessed extension pages could historically write to the clipboard, so | 366 // All blessed extension pages could historically write to the clipboard, so |
366 // preserve that for compatibility. | 367 // preserve that for compatibility. |
367 extensions::ScriptContext* current_context = | 368 extensions::ScriptContext* current_context = |
368 extension_dispatcher_->script_context_set().GetCurrent(); | 369 extension_dispatcher_->script_context_set().GetCurrent(); |
369 if (current_context) { | 370 if (current_context) { |
370 if (current_context->effective_context_type() == | 371 if (current_context->effective_context_type() == |
371 extensions::Feature::BLESSED_EXTENSION_CONTEXT) { | 372 extensions::Feature::BLESSED_EXTENSION_CONTEXT) { |
372 allowed = true; | 373 allowed = true; |
373 } else { | 374 } else { |
374 allowed |= current_context->HasAPIPermission( | 375 allowed |= current_context->HasAPIPermission( |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 callbacks.doDeny(); | 465 callbacks.doDeny(); |
465 } | 466 } |
466 | 467 |
467 void ContentSettingsObserver::ClearBlockedContentSettings() { | 468 void ContentSettingsObserver::ClearBlockedContentSettings() { |
468 content_blocked_.clear(); | 469 content_blocked_.clear(); |
469 cached_storage_permissions_.clear(); | 470 cached_storage_permissions_.clear(); |
470 cached_script_permissions_.clear(); | 471 cached_script_permissions_.clear(); |
471 } | 472 } |
472 | 473 |
473 bool ContentSettingsObserver::IsPlatformApp() { | 474 bool ContentSettingsObserver::IsPlatformApp() { |
474 #if defined(ENABLE_EXTENSIONS) | 475 #if BUILDFLAG(ENABLE_EXTENSIONS) |
475 WebFrame* frame = render_frame()->GetWebFrame(); | 476 WebFrame* frame = render_frame()->GetWebFrame(); |
476 WebSecurityOrigin origin = frame->document().getSecurityOrigin(); | 477 WebSecurityOrigin origin = frame->document().getSecurityOrigin(); |
477 const extensions::Extension* extension = GetExtension(origin); | 478 const extensions::Extension* extension = GetExtension(origin); |
478 return extension && extension->is_platform_app(); | 479 return extension && extension->is_platform_app(); |
479 #else | 480 #else |
480 return false; | 481 return false; |
481 #endif | 482 #endif |
482 } | 483 } |
483 | 484 |
484 #if defined(ENABLE_EXTENSIONS) | 485 #if BUILDFLAG(ENABLE_EXTENSIONS) |
485 const extensions::Extension* ContentSettingsObserver::GetExtension( | 486 const extensions::Extension* ContentSettingsObserver::GetExtension( |
486 const WebSecurityOrigin& origin) const { | 487 const WebSecurityOrigin& origin) const { |
487 if (!base::EqualsASCII(base::StringPiece16(origin.protocol()), | 488 if (!base::EqualsASCII(base::StringPiece16(origin.protocol()), |
488 extensions::kExtensionScheme)) | 489 extensions::kExtensionScheme)) |
489 return NULL; | 490 return NULL; |
490 | 491 |
491 const std::string extension_id = origin.host().utf8().data(); | 492 const std::string extension_id = origin.host().utf8().data(); |
492 if (!extension_dispatcher_->IsExtensionActive(extension_id)) | 493 if (!extension_dispatcher_->IsExtensionActive(extension_id)) |
493 return NULL; | 494 return NULL; |
494 | 495 |
(...skipping 24 matching lines...) Expand all Loading... |
519 if (origin.isUnique()) | 520 if (origin.isUnique()) |
520 return false; // Uninitialized document? | 521 return false; // Uninitialized document? |
521 | 522 |
522 base::string16 protocol = origin.protocol(); | 523 base::string16 protocol = origin.protocol(); |
523 if (base::EqualsASCII(protocol, content::kChromeUIScheme)) | 524 if (base::EqualsASCII(protocol, content::kChromeUIScheme)) |
524 return true; // Browser UI elements should still work. | 525 return true; // Browser UI elements should still work. |
525 | 526 |
526 if (base::EqualsASCII(protocol, content::kChromeDevToolsScheme)) | 527 if (base::EqualsASCII(protocol, content::kChromeDevToolsScheme)) |
527 return true; // DevTools UI elements should still work. | 528 return true; // DevTools UI elements should still work. |
528 | 529 |
529 #if defined(ENABLE_EXTENSIONS) | 530 #if BUILDFLAG(ENABLE_EXTENSIONS) |
530 if (base::EqualsASCII(protocol, extensions::kExtensionScheme)) | 531 if (base::EqualsASCII(protocol, extensions::kExtensionScheme)) |
531 return true; | 532 return true; |
532 #endif | 533 #endif |
533 | 534 |
534 // If the scheme is file:, an empty file name indicates a directory listing, | 535 // If the scheme is file:, an empty file name indicates a directory listing, |
535 // which requires JavaScript to function properly. | 536 // which requires JavaScript to function properly. |
536 if (base::EqualsASCII(protocol, url::kFileScheme)) { | 537 if (base::EqualsASCII(protocol, url::kFileScheme)) { |
537 return document_url.SchemeIs(url::kFileScheme) && | 538 return document_url.SchemeIs(url::kFileScheme) && |
538 document_url.ExtractFileName().empty(); | 539 document_url.ExtractFileName().empty(); |
539 } | 540 } |
540 | 541 |
541 return false; | 542 return false; |
542 } | 543 } |
OLD | NEW |