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

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

Issue 2778693004: Remove navigator.vibrate without user gesture. (Closed)
Patch Set: rebase 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 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 0ab176f09d805274672cf723fb519c39104ff57c..03212573977cf1b49a4e2fd9d72c953512778c00 100644
--- a/third_party/WebKit/Source/modules/vibration/NavigatorVibration.cpp
+++ b/third_party/WebKit/Source/modules/vibration/NavigatorVibration.cpp
@@ -20,10 +20,13 @@
#include "modules/vibration/NavigatorVibration.h"
#include "core/dom/Document.h"
+#include "core/frame/Deprecation.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"
@@ -89,13 +92,31 @@ 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;
+ if (!frame->HasReceivedUserGesture()) {
+ String message;
+ MessageLevel level = kErrorMessageLevel;
+ if (frame->IsCrossOriginSubframe()) {
+ message =
+ "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.";
+ } else if (RuntimeEnabledFeatures::vibrateRequiresUserGestureEnabled()) {
+ // The actual blocking is targeting M60.
+ message =
+ "Blocked call to navigator.vibrate because user hasn't tapped "
+ "on the frame or any embedded frame yet: "
+ "https://www.chromestatus.com/feature/5644273861001216.";
+ } else { // Just shows the deprecation message in M59.
+ level = kWarningMessageLevel;
+ Deprecation::CountDeprecation(frame,
+ UseCounter::kVibrateWithoutUserGesture);
+ }
+
+ if (level == kErrorMessageLevel) {
+ frame->DomWindow()->GetFrameConsole()->AddMessage(
+ ConsoleMessage::Create(kInterventionMessageSource, level, message));
+ return false;
+ }
}
return NavigatorVibration::From(navigator).Controller(*frame)->Vibrate(

Powered by Google App Engine
This is Rietveld 408576698