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

Side by Side Diff: third_party/WebKit/Source/modules/vibration/NavigatorVibration.cpp

Issue 2778693004: Remove navigator.vibrate without user gesture. (Closed)
Patch Set: Use the Deprecation class for warning Created 3 years, 8 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) 2012 Samsung Electronics 2 * Copyright (C) 2012 Samsung Electronics
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details. 12 * Library General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU Library General Public License 14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to 15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA. 17 * Boston, MA 02110-1301, USA.
18 */ 18 */
19 19
20 #include "modules/vibration/NavigatorVibration.h" 20 #include "modules/vibration/NavigatorVibration.h"
21 21
22 #include "core/dom/Document.h" 22 #include "core/dom/Document.h"
23 #include "core/frame/Deprecation.h"
24 #include "core/frame/FrameConsole.h"
23 #include "core/frame/LocalDOMWindow.h" 25 #include "core/frame/LocalDOMWindow.h"
24 #include "core/frame/LocalFrame.h" 26 #include "core/frame/LocalFrame.h"
25 #include "core/frame/Navigator.h" 27 #include "core/frame/Navigator.h"
26 #include "core/frame/UseCounter.h" 28 #include "core/frame/UseCounter.h"
29 #include "core/inspector/ConsoleMessage.h"
27 #include "core/page/Page.h" 30 #include "core/page/Page.h"
28 #include "modules/vibration/VibrationController.h" 31 #include "modules/vibration/VibrationController.h"
29 #include "platform/Histogram.h" 32 #include "platform/Histogram.h"
30 #include "platform/UserGestureIndicator.h" 33 #include "platform/UserGestureIndicator.h"
31 #include "public/platform/site_engagement.mojom-blink.h" 34 #include "public/platform/site_engagement.mojom-blink.h"
32 35
33 namespace blink { 36 namespace blink {
34 37
35 NavigatorVibration::NavigatorVibration(Navigator& navigator) 38 NavigatorVibration::NavigatorVibration(Navigator& navigator)
36 : ContextLifecycleObserver(navigator.GetFrame()->GetDocument()) {} 39 : ContextLifecycleObserver(navigator.GetFrame()->GetDocument()) {}
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 // runtime flag. Please pay attention to the user gesture code below. 85 // runtime flag. Please pay attention to the user gesture code below.
83 if (RuntimeEnabledFeatures::featurePolicyEnabled() && 86 if (RuntimeEnabledFeatures::featurePolicyEnabled() &&
84 RuntimeEnabledFeatures::featurePolicyExperimentalFeaturesEnabled() && 87 RuntimeEnabledFeatures::featurePolicyExperimentalFeaturesEnabled() &&
85 !frame->IsFeatureEnabled(blink::WebFeaturePolicyFeature::kVibrate)) { 88 !frame->IsFeatureEnabled(blink::WebFeaturePolicyFeature::kVibrate)) {
86 frame->DomWindow()->PrintErrorMessage( 89 frame->DomWindow()->PrintErrorMessage(
87 "Navigator.vibrate() is not enabled in feature policy for this " 90 "Navigator.vibrate() is not enabled in feature policy for this "
88 "frame."); 91 "frame.");
89 return false; 92 return false;
90 } 93 }
91 94
92 if (!RuntimeEnabledFeatures::featurePolicyEnabled() && 95 if (!frame->HasReceivedUserGesture()) {
93 frame->IsCrossOriginSubframe() && !frame->HasReceivedUserGesture()) { 96 String message;
94 frame->DomWindow()->PrintErrorMessage( 97 MessageLevel level = kErrorMessageLevel;
95 "Blocked call to navigator.vibrate inside a cross-origin iframe " 98 if (frame->IsCrossOriginSubframe()) {
96 "because the frame has never been activated by the user: " 99 message =
jochen (gone - plz use gerrit) 2017/04/18 15:51:10 can you add a UseCounter here as well?
binlu 2017/04/18 16:14:43 Those metrics are already collected in CollectHist
97 "https://www.chromestatus.com/feature/5682658461876224."); 100 "Blocked call to navigator.vibrate inside a cross-origin "
98 return false; 101 "iframe because the frame has never been activated by the user: "
102 "https://www.chromestatus.com/feature/5682658461876224.";
103 } else if (RuntimeEnabledFeatures::vibrateRequiresUserGestureEnabled()) {
104 // The actual blocking is targeting M60.
105 message =
jochen (gone - plz use gerrit) 2017/04/18 15:51:10 same here?
binlu 2017/04/18 16:14:43 ditto.
106 "Blocked call to navigator.vibrate because user hasn't tapped "
107 "on the frame or any embedded frame yet: "
108 "https://www.chromestatus.com/feature/5644273861001216.";
109 } else { // Just shows the deprecation message in M59.
110 level = kWarningMessageLevel;
111 Deprecation::CountDeprecation(frame,
112 UseCounter::kVibrateWithoutUserGesture);
113 }
114
115 if (level == kErrorMessageLevel) {
116 frame->DomWindow()->GetFrameConsole()->AddMessage(
117 ConsoleMessage::Create(kInterventionMessageSource, level, message));
118 return false;
119 }
99 } 120 }
100 121
101 return NavigatorVibration::From(navigator).Controller(*frame)->Vibrate( 122 return NavigatorVibration::From(navigator).Controller(*frame)->Vibrate(
102 pattern); 123 pattern);
103 } 124 }
104 125
105 // static 126 // static
106 void NavigatorVibration::CollectHistogramMetrics(const LocalFrame& frame) { 127 void NavigatorVibration::CollectHistogramMetrics(const LocalFrame& frame) {
107 NavigatorVibrationType type; 128 NavigatorVibrationType type;
108 bool user_gesture = frame.HasReceivedUserGesture(); 129 bool user_gesture = frame.HasReceivedUserGesture();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 } 187 }
167 } 188 }
168 189
169 DEFINE_TRACE(NavigatorVibration) { 190 DEFINE_TRACE(NavigatorVibration) {
170 visitor->Trace(controller_); 191 visitor->Trace(controller_);
171 Supplement<Navigator>::Trace(visitor); 192 Supplement<Navigator>::Trace(visitor);
172 ContextLifecycleObserver::Trace(visitor); 193 ContextLifecycleObserver::Trace(visitor);
173 } 194 }
174 195
175 } // namespace blink 196 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/frame/UseCounter.h ('k') | third_party/WebKit/Source/platform/RuntimeEnabledFeatures.json5 » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698