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

Unified Diff: third_party/WebKit/Source/modules/vibration/NavigatorVibration.cpp

Issue 2778693004: Remove navigator.vibrate without user gesture. (Closed)
Patch Set: Add entries in histograms.xml to fix the broken about_flags_unittest. Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/vibration/NavigatorVibration.cpp
diff --git a/third_party/WebKit/Source/modules/vibration/NavigatorVibration.cpp b/third_party/WebKit/Source/modules/vibration/NavigatorVibration.cpp
index b4dd1b77011ea8b5bf442281fe2b681abb63fc76..6eafc2d2d325ab9f89af64195dd129e94f1cf31e 100644
--- a/third_party/WebKit/Source/modules/vibration/NavigatorVibration.cpp
+++ b/third_party/WebKit/Source/modules/vibration/NavigatorVibration.cpp
@@ -20,10 +20,12 @@
#include "modules/vibration/NavigatorVibration.h"
#include "core/dom/Document.h"
+#include "core/frame/FrameConsole.h"
#include "core/frame/LocalDOMWindow.h"
#include "core/frame/LocalFrame.h"
#include "core/frame/Navigator.h"
#include "core/frame/UseCounter.h"
+#include "core/inspector/ConsoleMessage.h"
#include "core/page/Page.h"
#include "modules/vibration/VibrationController.h"
#include "platform/Histogram.h"
@@ -78,8 +80,33 @@ bool NavigatorVibration::vibrate(Navigator& navigator,
if (!frame->page()->isPageVisible())
return false;
+ if (!frame->hasReceivedUserGesture()) {
+ if (frame->isCrossOriginSubframe()) {
+ frame->domWindow()->printErrorMessage(
Rick Byers 2017/03/29 18:01:40 Can you please have all these messages use Interve
binlu 2017/04/11 21:54:25 Done.
+ "Blocked call to navigator.vibrate inside a cross-origin iframe "
+ "because the frame has never been activated by the user: "
+ "https://www.chromestatus.com/feature/5682658461876224.");
+ return false;
+ }
+ // For other frames (except x-origin iframe) including top-level page.
+ if (!RuntimeEnabledFeatures::vibrateRequiresUserGestureEnabled()) {
+ // Just print a warning.
+ frame->domWindow()->frameConsole()->addMessage(ConsoleMessage::create(
+ JSMessageSource, WarningMessageLevel,
+ "A call to navigator.vibrate will soon require user tap on "
+ "the frame or any embedded frame: "
+ "https://www.chromestatus.com/feature/5644273861001216."));
+ } else {
+ frame->domWindow()->printErrorMessage(
+ "Blocked call to navigator.vibrate because user hasn't tapped on "
+ "the frame or any embedded frame yet: "
+ "https://www.chromestatus.com/feature/5644273861001216.");
+ return false;
+ }
+ }
+
// TODO(lunalu): When FeaturePolicy is ready, take out the check for the
- // runtime flag. Please pay attention to the user gesture code below.
+ // runtime flag. Please pay attention to the user gesture code above.
if (RuntimeEnabledFeatures::featurePolicyEnabled() &&
!frame->isFeatureEnabled(blink::WebFeaturePolicyFeature::Vibrate)) {
frame->domWindow()->printErrorMessage(
@@ -88,15 +115,6 @@ bool NavigatorVibration::vibrate(Navigator& navigator,
return false;
}
- if (!RuntimeEnabledFeatures::featurePolicyEnabled() &&
- frame->isCrossOriginSubframe() && !frame->hasReceivedUserGesture()) {
- frame->domWindow()->printErrorMessage(
- "Blocked call to navigator.vibrate inside a cross-origin iframe "
- "because the frame has never been activated by the user: "
- "https://www.chromestatus.com/feature/5682658461876224.");
- return false;
- }
-
return NavigatorVibration::from(navigator).controller(*frame)->vibrate(
pattern);
}
@@ -104,7 +122,7 @@ bool NavigatorVibration::vibrate(Navigator& navigator,
// static
void NavigatorVibration::collectHistogramMetrics(const LocalFrame& frame) {
NavigatorVibrationType type;
- bool userGesture = UserGestureIndicator::processingUserGesture();
+ bool userGesture = frame.hasReceivedUserGesture();
UseCounter::count(&frame, UseCounter::NavigatorVibrate);
if (!frame.isMainFrame()) {
UseCounter::count(&frame, UseCounter::NavigatorVibrateSubFrame);

Powered by Google App Engine
This is Rietveld 408576698