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

Side by Side Diff: chrome/renderer/content_settings_observer.cc

Issue 789063002: Implement clipboardRead/Write content capabilities (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix id generation in test Created 6 years 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
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 "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 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
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) {
426 const extensions::Extension* extension = 426 allowed = calling_context->HasAPIPermission(
427 calling_context->effective_extension(); 427 extensions::APIPermission::kClipboardRead);
428 allowed = extension &&
429 extension->permissions_data()->HasAPIPermission(
430 extensions::APIPermission::kClipboardRead);
431 } 428 }
432 #endif 429 #endif
433 return allowed; 430 return allowed;
434 } 431 }
435 432
436 bool ContentSettingsObserver::allowWriteToClipboard(bool default_value) { 433 bool ContentSettingsObserver::allowWriteToClipboard(bool default_value) {
437 bool allowed = false; 434 bool allowed = false;
438 #if defined(ENABLE_EXTENSIONS) 435 #if defined(ENABLE_EXTENSIONS)
439 // All blessed extension pages could historically write to the clipboard, so 436 // All blessed extension pages could historically write to the clipboard, so
440 // preserve that for compatibility. 437 // preserve that for compatibility.
441 extensions::ScriptContext* calling_context = 438 extensions::ScriptContext* calling_context =
442 extension_dispatcher_->script_context_set().GetCalling(); 439 extension_dispatcher_->script_context_set().GetCalling();
443 if (calling_context) { 440 if (calling_context) {
444 if (calling_context->effective_context_type() == 441 if (calling_context->effective_context_type() ==
445 extensions::Feature::BLESSED_EXTENSION_CONTEXT) { 442 extensions::Feature::BLESSED_EXTENSION_CONTEXT) {
446 allowed = true; 443 allowed = true;
447 } else { 444 } else {
448 const extensions::Extension* extension = 445 allowed = calling_context->HasAPIPermission(
449 calling_context->effective_extension(); 446 extensions::APIPermission::kClipboardWrite);
450 allowed = extension &&
451 extension->permissions_data()->HasAPIPermission(
452 extensions::APIPermission::kClipboardWrite);
453 } 447 }
454 } 448 }
455 #endif 449 #endif
456 return allowed; 450 return allowed;
457 } 451 }
458 452
459 bool ContentSettingsObserver::allowMutationEvents(bool default_value) { 453 bool ContentSettingsObserver::allowMutationEvents(bool default_value) {
460 return IsPlatformApp() ? false : default_value; 454 return IsPlatformApp() ? false : default_value;
461 } 455 }
462 456
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 717
724 // If the scheme is file:, an empty file name indicates a directory listing, 718 // If the scheme is file:, an empty file name indicates a directory listing,
725 // which requires JavaScript to function properly. 719 // which requires JavaScript to function properly.
726 if (EqualsASCII(origin.protocol(), url::kFileScheme)) { 720 if (EqualsASCII(origin.protocol(), url::kFileScheme)) {
727 return document_url.SchemeIs(url::kFileScheme) && 721 return document_url.SchemeIs(url::kFileScheme) &&
728 document_url.ExtractFileName().empty(); 722 document_url.ExtractFileName().empty();
729 } 723 }
730 724
731 return false; 725 return false;
732 } 726 }
OLDNEW
« no previous file with comments | « chrome/chrome_tests.gypi ('k') | chrome/test/data/extensions/content_capabilities/bar.example.com.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698