Chromium Code Reviews| 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); |