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

Side by Side Diff: third_party/WebKit/Source/core/dom/Fullscreen.cpp

Issue 2585363002: Use FeaturePolicy to implement iframe[allowfullscreen] (Closed)
Patch Set: Update test expectations Created 3 years, 12 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org)
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All
7 * rights reserved. 7 * rights reserved.
8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved.
9 * (http://www.torchmobile.com/) 9 * (http://www.torchmobile.com/)
10 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) 10 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 55
56 // https://html.spec.whatwg.org/multipage/embedded-content.html#allowed-to-use 56 // https://html.spec.whatwg.org/multipage/embedded-content.html#allowed-to-use
57 bool allowedToUseFullscreen(const Frame* frame) { 57 bool allowedToUseFullscreen(const Frame* frame) {
58 // To determine whether a Document object |document| is allowed to use the 58 // To determine whether a Document object |document| is allowed to use the
59 // feature indicated by attribute name |allowattribute|, run these steps: 59 // feature indicated by attribute name |allowattribute|, run these steps:
60 60
61 // 1. If |document| has no browsing context, then return false. 61 // 1. If |document| has no browsing context, then return false.
62 if (!frame) 62 if (!frame)
63 return false; 63 return false;
64 64
65 // 2. If |document|'s browsing context is a top-level browsing context, then 65 if (!RuntimeEnabledFeatures::featurePolicyEnabled()) {
66 // return true. 66 // 2. If |document|'s browsing context is a top-level browsing context, then
67 if (frame->isMainFrame()) 67 // return true.
68 if (frame->isMainFrame())
69 return true;
70
71 // 3. If |document|'s browsing context has a browsing context container that
72 // is an iframe element with an |allowattribute| attribute specified, and
73 // whose node document is allowed to use the feature indicated by
74 // |allowattribute|, then return true.
75 if (frame->owner() && frame->owner()->allowFullscreen())
76 return allowedToUseFullscreen(frame->tree().parent());
77
78 // 4. Return false.
79 return false;
80 }
81
82 // If Feature Policy is enabled, then we need this hack to support it, until
83 // we have proper support for <iframe allowfullscreen> in FP:
84
85 // 1. If FP, by itself, enables fullscreen in this document, then fullscreen
86 // is allowed.
87 if (frame->securityContext()->getFeaturePolicy()->isFeatureEnabled(
88 kFullscreenFeature)) {
68 return true; 89 return true;
90 }
69 91
70 // 3. If |document|'s browsing context has a browsing context container that 92 // 2. Otherwise, if the embedding frame's document is allowed to use
foolip 2017/01/19 17:14:18 Can this part be turned into a step 4 before the r
iclelland 2017/01/19 19:32:15 I was trying to maintain the integrity of the orig
71 // is an iframe element with an |allowattribute| attribute specified, and 93 // fullscreen (either through FP or otherwise), and either:
72 // whose node document is allowed to use the feature indicated by 94 // a) this is a same-origin embedded document, or
73 // |allowattribute|, then return true. 95 // b) this document's iframe has the allowfullscreen attribute set,
74 if (frame->owner() && frame->owner()->allowFullscreen()) 96 // then fullscreen is allowed.
75 return allowedToUseFullscreen(frame->tree().parent()); 97 if (!frame->isMainFrame()) {
98 if (allowedToUseFullscreen(frame->tree().parent())) {
99 return (frame->owner() && frame->owner()->allowFullscreen()) ||
100 frame->tree()
101 .parent()
102 ->securityContext()
103 ->getSecurityOrigin()
104 ->isSameSchemeHostPortAndSuborigin(
105 frame->securityContext()->getSecurityOrigin());
106 }
107 }
76 108
77 // 4. Return false. 109 // Otherwise, fullscreen is not allowed. (If we reach here and this is the
110 // main frame, then fullscreen must have been disabled by FP.)
78 return false; 111 return false;
79 } 112 }
80 113
81 bool allowedToRequestFullscreen(Document& document) { 114 bool allowedToRequestFullscreen(Document& document) {
82 // An algorithm is allowed to request fullscreen if one of the following is 115 // An algorithm is allowed to request fullscreen if one of the following is
83 // true: 116 // true:
84 117
85 // The algorithm is triggered by a user activation. 118 // The algorithm is triggered by a user activation.
86 if (UserGestureIndicator::utilizeUserGesture()) 119 if (UserGestureIndicator::utilizeUserGesture())
87 return true; 120 return true;
88 121
89 // The algorithm is triggered by a user generated orientation change. 122 // The algorithm is triggered by a user generated orientation change.
90 if (ScopedOrientationChangeIndicator::processingOrientationChange()) { 123 if (ScopedOrientationChangeIndicator::processingOrientationChange()) {
91 UseCounter::count(document, 124 UseCounter::count(document,
92 UseCounter::FullscreenAllowedByOrientationChange); 125 UseCounter::FullscreenAllowedByOrientationChange);
93 return true; 126 return true;
94 } 127 }
95 128
96 String message = ExceptionMessages::failedToExecute( 129 String message = ExceptionMessages::failedToExecute(
97 "requestFullscreen", "Element", 130 "requestFullscreen", "Element",
98 "API can only be initiated by a user gesture."); 131 "API can only be initiated by a user gesture.");
99 document.addConsoleMessage( 132 document.addConsoleMessage(
100 ConsoleMessage::create(JSMessageSource, WarningMessageLevel, message)); 133 ConsoleMessage::create(JSMessageSource, WarningMessageLevel, message));
101 134
102 return false; 135 return false;
103 } 136 }
104 137
105 // https://fullscreen.spec.whatwg.org/#fullscreen-is-supported 138 // https://fullscreen.spec.whatwg.org/#fullscreen-is-supported
106 // TODO(lunalu): update the placement of the feature policy code once it is in 139 bool fullscreenIsSupported(const Document& document) {
107 // https://fullscreen.spec.whatwg.org/.
108 bool fullscreenIsSupported(Document& document) {
109 LocalFrame* frame = document.frame(); 140 LocalFrame* frame = document.frame();
110 if (!frame) 141 if (!frame)
111 return false; 142 return false;
112 143
113 // Fullscreen is supported if there is no previously-established user 144 // Fullscreen is supported if there is no previously-established user
114 // preference, security risk, or platform limitation. 145 // preference, security risk, or platform limitation.
115 bool fullscreenSupported = 146 return !document.settings() || document.settings()->fullscreenSupported();
116 !document.settings() || document.settings()->fullscreenSupported();
117
118 if (!RuntimeEnabledFeatures::featurePolicyEnabled()) {
119 return fullscreenSupported;
120 }
121
122 // TODO(lunalu): clean all of this up once iframe attributes are supported
123 // for feature policy.
124 if (Frame* parent = frame->tree().parent()) {
125 // If FeaturePolicy is enabled, check the fullscreen is not disabled by
126 // policy in the parent frame.
127 if (fullscreenSupported &&
128 parent->securityContext()->getFeaturePolicy()->isFeatureEnabled(
129 kFullscreenFeature)) {
130 return true;
131 }
132 }
133 // Even if the iframe allowfullscreen attribute is not present, allow
134 // fullscreen to be enabled by feature policy.
135 else if (isFeatureEnabledInFrame(kFullscreenFeature, frame)) {
136 return true;
137 }
138
139 document.addConsoleMessage(ConsoleMessage::create(
140 JSMessageSource, WarningMessageLevel,
lunalu1 2017/01/10 18:14:57 Do we want to be more implicit when fullscreen is
141 "Fullscreen API is disabled by feature policy for this frame"));
142 return false;
143 } 147 }
144 148
145 // https://fullscreen.spec.whatwg.org/#fullscreen-element-ready-check 149 // https://fullscreen.spec.whatwg.org/#fullscreen-element-ready-check
146 bool fullscreenElementReady(const Element& element) { 150 bool fullscreenElementReady(const Element& element) {
147 // A fullscreen element ready check for an element |element| returns true if 151 // A fullscreen element ready check for an element |element| returns true if
148 // all of the following are true, and false otherwise: 152 // all of the following are true, and false otherwise:
149 153
150 // |element| is in a document. 154 // |element| is in a document.
151 if (!element.isConnected()) 155 if (!element.isConnected())
152 return false; 156 return false;
(...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 DEFINE_TRACE(Fullscreen) { 830 DEFINE_TRACE(Fullscreen) {
827 visitor->trace(m_pendingFullscreenElement); 831 visitor->trace(m_pendingFullscreenElement);
828 visitor->trace(m_fullscreenElementStack); 832 visitor->trace(m_fullscreenElementStack);
829 visitor->trace(m_currentFullScreenElement); 833 visitor->trace(m_currentFullScreenElement);
830 visitor->trace(m_eventQueue); 834 visitor->trace(m_eventQueue);
831 Supplement<Document>::trace(visitor); 835 Supplement<Document>::trace(visitor);
832 ContextLifecycleObserver::trace(visitor); 836 ContextLifecycleObserver::trace(visitor);
833 } 837 }
834 838
835 } // namespace blink 839 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/virtual/feature-policy/http/tests/feature-policy/fullscreen-enabledforall-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698