| OLD | NEW |
| 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/FrameConsole.h" |
| 23 #include "core/frame/LocalDOMWindow.h" | 24 #include "core/frame/LocalDOMWindow.h" |
| 24 #include "core/frame/LocalFrame.h" | 25 #include "core/frame/LocalFrame.h" |
| 25 #include "core/frame/Navigator.h" | 26 #include "core/frame/Navigator.h" |
| 26 #include "core/frame/UseCounter.h" | 27 #include "core/frame/UseCounter.h" |
| 28 #include "core/inspector/ConsoleMessage.h" |
| 27 #include "core/page/Page.h" | 29 #include "core/page/Page.h" |
| 28 #include "modules/vibration/VibrationController.h" | 30 #include "modules/vibration/VibrationController.h" |
| 29 #include "platform/Histogram.h" | 31 #include "platform/Histogram.h" |
| 30 #include "platform/UserGestureIndicator.h" | 32 #include "platform/UserGestureIndicator.h" |
| 31 #include "public/platform/site_engagement.mojom-blink.h" | 33 #include "public/platform/site_engagement.mojom-blink.h" |
| 32 | 34 |
| 33 namespace blink { | 35 namespace blink { |
| 34 | 36 |
| 35 NavigatorVibration::NavigatorVibration(Navigator& navigator) | 37 NavigatorVibration::NavigatorVibration(Navigator& navigator) |
| 36 : ContextLifecycleObserver(navigator.GetFrame()->GetDocument()) {} | 38 : ContextLifecycleObserver(navigator.GetFrame()->GetDocument()) {} |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 // runtime flag. Please pay attention to the user gesture code below. | 84 // runtime flag. Please pay attention to the user gesture code below. |
| 83 if (RuntimeEnabledFeatures::featurePolicyEnabled() && | 85 if (RuntimeEnabledFeatures::featurePolicyEnabled() && |
| 84 RuntimeEnabledFeatures::featurePolicyExperimentalFeaturesEnabled() && | 86 RuntimeEnabledFeatures::featurePolicyExperimentalFeaturesEnabled() && |
| 85 !frame->IsFeatureEnabled(blink::WebFeaturePolicyFeature::kVibrate)) { | 87 !frame->IsFeatureEnabled(blink::WebFeaturePolicyFeature::kVibrate)) { |
| 86 frame->DomWindow()->PrintErrorMessage( | 88 frame->DomWindow()->PrintErrorMessage( |
| 87 "Navigator.vibrate() is not enabled in feature policy for this " | 89 "Navigator.vibrate() is not enabled in feature policy for this " |
| 88 "frame."); | 90 "frame."); |
| 89 return false; | 91 return false; |
| 90 } | 92 } |
| 91 | 93 |
| 92 if (!RuntimeEnabledFeatures::featurePolicyEnabled() && | 94 if (!frame->HasReceivedUserGesture()) { |
| 93 frame->IsCrossOriginSubframe() && !frame->HasReceivedUserGesture()) { | 95 String message; |
| 94 frame->DomWindow()->PrintErrorMessage( | 96 MessageLevel level = kErrorMessageLevel; |
| 95 "Blocked call to navigator.vibrate inside a cross-origin iframe " | 97 if (frame->IsCrossOriginSubframe()) { |
| 96 "because the frame has never been activated by the user: " | 98 message = |
| 97 "https://www.chromestatus.com/feature/5682658461876224."); | 99 "Blocked call to navigator.vibrate inside a cross-origin " |
| 98 return false; | 100 "iframe because the frame has never been activated by the user: " |
| 101 "https://www.chromestatus.com/feature/5682658461876224."; |
| 102 } else if (RuntimeEnabledFeatures::vibrateRequiresUserGestureEnabled()) { |
| 103 message = |
| 104 "Blocked call to navigator.vibrate because user hasn't tapped " |
| 105 "on the frame or any embedded frame yet: " |
| 106 "https://www.chromestatus.com/feature/5644273861001216."; |
| 107 } else { // Just print a warning. |
| 108 level = kWarningMessageLevel; |
| 109 message = |
| 110 "A call to navigator.vibrate will soon require user tap on " |
| 111 "the frame or any embedded frame: " |
| 112 "https://www.chromestatus.com/feature/5644273861001216."; |
| 113 } |
| 114 |
| 115 frame->DomWindow()->GetFrameConsole()->AddMessage( |
| 116 ConsoleMessage::Create(kInterventionMessageSource, level, message)); |
| 117 if (level == kErrorMessageLevel) { |
| 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 Loading... |
| 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 |
| OLD | NEW |