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

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

Issue 475883003: [wip] Respect the clipboardRead and clipboardWrite permissions in content scripts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
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"
11 #include "chrome/common/url_constants.h" 11 #include "chrome/common/url_constants.h"
12 #include "content/public/renderer/document_state.h" 12 #include "content/public/renderer/document_state.h"
13 #include "content/public/renderer/navigation_state.h" 13 #include "content/public/renderer/navigation_state.h"
14 #include "content/public/renderer/render_frame.h" 14 #include "content/public/renderer/render_frame.h"
15 #include "content/public/renderer/render_view.h" 15 #include "content/public/renderer/render_view.h"
16 #include "third_party/WebKit/public/platform/WebPermissionCallbacks.h" 16 #include "third_party/WebKit/public/platform/WebPermissionCallbacks.h"
17 #include "third_party/WebKit/public/platform/WebURL.h" 17 #include "third_party/WebKit/public/platform/WebURL.h"
18 #include "third_party/WebKit/public/web/WebDataSource.h" 18 #include "third_party/WebKit/public/web/WebDataSource.h"
19 #include "third_party/WebKit/public/web/WebDocument.h" 19 #include "third_party/WebKit/public/web/WebDocument.h"
20 #include "third_party/WebKit/public/web/WebFrame.h" 20 #include "third_party/WebKit/public/web/WebFrame.h"
21 #include "third_party/WebKit/public/web/WebFrameClient.h" 21 #include "third_party/WebKit/public/web/WebFrameClient.h"
22 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" 22 #include "third_party/WebKit/public/web/WebSecurityOrigin.h"
23 #include "third_party/WebKit/public/web/WebView.h" 23 #include "third_party/WebKit/public/web/WebView.h"
24 24
25 #if defined(ENABLE_EXTENSIONS) 25 #if defined(ENABLE_EXTENSIONS)
26 #include "chrome/common/extensions/chrome_extension_messages.h" 26 #include "chrome/common/extensions/chrome_extension_messages.h"
27 #include "extensions/common/constants.h" 27 #include "extensions/common/constants.h"
28 #include "extensions/common/extension.h" 28 #include "extensions/common/extension.h"
29 #include "extensions/common/permissions/api_permission.h"
30 #include "extensions/common/permissions/permissions_data.h"
29 #include "extensions/renderer/dispatcher.h" 31 #include "extensions/renderer/dispatcher.h"
30 #endif 32 #endif
31 33
32 using blink::WebDataSource; 34 using blink::WebDataSource;
33 using blink::WebDocument; 35 using blink::WebDocument;
34 using blink::WebFrame; 36 using blink::WebFrame;
35 using blink::WebPermissionCallbacks; 37 using blink::WebPermissionCallbacks;
36 using blink::WebSecurityOrigin; 38 using blink::WebSecurityOrigin;
37 using blink::WebString; 39 using blink::WebString;
38 using blink::WebURL; 40 using blink::WebURL;
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 routing_id(), GURL(frame->document().securityOrigin().toString()), 405 routing_id(), GURL(frame->document().securityOrigin().toString()),
404 GURL(frame->top()->document().securityOrigin().toString()), 406 GURL(frame->top()->document().securityOrigin().toString()),
405 local, &result)); 407 local, &result));
406 cached_storage_permissions_[key] = result; 408 cached_storage_permissions_[key] = result;
407 return result; 409 return result;
408 } 410 }
409 411
410 bool ContentSettingsObserver::allowReadFromClipboard(bool default_value) { 412 bool ContentSettingsObserver::allowReadFromClipboard(bool default_value) {
411 bool allowed = false; 413 bool allowed = false;
412 #if defined(ENABLE_EXTENSIONS) 414 #if defined(ENABLE_EXTENSIONS)
413 WebFrame* frame = render_frame()->GetWebFrame(); 415 // There was a time when this bounced off the browser. That was technically
414 // TODO(dcheng): Should we consider a toURL() method on WebSecurityOrigin? 416 // *safer* but made it impossible to take into account content script
415 Send(new ChromeViewHostMsg_CanTriggerClipboardRead( 417 // permissions.
dcheng 2014/08/14 21:11:57 I think this is fine. Ultimately, this permission
416 GURL(frame->document().securityOrigin().toString()), &allowed)); 418 extensions::ScriptContext* calling_context =
419 extension_dispatcher_->script_context_set().GetCalling();
420 if (calling_context) {
421 const extensions::Extension* extension = calling_context->extension();
422 allowed = extension &&
423 extension->permissions_data()->HasAPIPermission(
424 extensions::APIPermission::kClipboardRead);
425 }
417 #endif 426 #endif
418 return allowed; 427 return allowed;
419 } 428 }
420 429
421 bool ContentSettingsObserver::allowWriteToClipboard(bool default_value) { 430 bool ContentSettingsObserver::allowWriteToClipboard(bool default_value) {
422 bool allowed = false; 431 bool allowed = false;
423 #if defined(ENABLE_EXTENSIONS) 432 #if defined(ENABLE_EXTENSIONS)
424 WebFrame* frame = render_frame()->GetWebFrame(); 433 // See comment in allowReadFromClipboard.
425 Send(new ChromeViewHostMsg_CanTriggerClipboardWrite( 434 // Additionally, since all blessed extension pages could historically write
426 GURL(frame->document().securityOrigin().toString()), &allowed)); 435 // to the clipboard, preserve it for compatibility.
436 extensions::ScriptContext* calling_context =
437 extension_dispatcher_->script_context_set().GetCalling();
438 if (calling_context) {
439 if (calling_context->context_type() ==
440 extensions::Feature::BLESSED_EXTENSION_CONTEXT) {
441 allowed = true;
442 } else {
443 const extensions::Extension* extension = calling_context->extension();
444 allowed = extension &&
445 extension->permissions_data()->HasAPIPermission(
446 extensions::APIPermission::kClipboardWrite);
447 }
448 }
427 #endif 449 #endif
428 return allowed; 450 return allowed;
429 } 451 }
430 452
431 bool ContentSettingsObserver::allowMutationEvents(bool default_value) { 453 bool ContentSettingsObserver::allowMutationEvents(bool default_value) {
432 return IsPlatformApp() ? false : default_value; 454 return IsPlatformApp() ? false : default_value;
433 } 455 }
434 456
435 bool ContentSettingsObserver::allowPushState() { 457 bool ContentSettingsObserver::allowPushState() {
436 return !IsPlatformApp(); 458 return !IsPlatformApp();
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 717
696 // 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,
697 // which requires JavaScript to function properly. 719 // which requires JavaScript to function properly.
698 if (EqualsASCII(origin.protocol(), url::kFileScheme)) { 720 if (EqualsASCII(origin.protocol(), url::kFileScheme)) {
699 return document_url.SchemeIs(url::kFileScheme) && 721 return document_url.SchemeIs(url::kFileScheme) &&
700 document_url.ExtractFileName().empty(); 722 document_url.ExtractFileName().empty();
701 } 723 }
702 724
703 return false; 725 return false;
704 } 726 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698