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

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

Issue 2492623002: Implementation for feature policy - vibrate. (Closed)
Patch Set: Codereview update Created 4 years, 1 month 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
« no previous file with comments | « third_party/WebKit/Source/bindings/core/v8/ConditionalFeatures.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "bindings/core/v8/ConditionalFeatures.h"
22 #include "core/dom/Document.h" 23 #include "core/dom/Document.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"
27 #include "core/page/Page.h" 28 #include "core/page/Page.h"
28 #include "modules/vibration/VibrationController.h" 29 #include "modules/vibration/VibrationController.h"
29 #include "platform/Histogram.h" 30 #include "platform/Histogram.h"
30 #include "platform/UserGestureIndicator.h" 31 #include "platform/UserGestureIndicator.h"
31 32
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 if (!frame) 71 if (!frame)
71 return false; 72 return false;
72 collectHistogramMetrics(*frame); 73 collectHistogramMetrics(*frame);
73 74
74 DCHECK(frame->document()); 75 DCHECK(frame->document());
75 DCHECK(frame->page()); 76 DCHECK(frame->page());
76 77
77 if (!frame->page()->isPageVisible()) 78 if (!frame->page()->isPageVisible())
78 return false; 79 return false;
79 80
80 if (frame->isCrossOriginSubframe()) { 81 // TODO(lunalu): When FeaturePolicy is ready, take out the check for the
81 // TODO(binlu): Once FeaturePolicy is ready, exploring using it to 82 // runtime flag.
82 // remove the API instead of having it return false. 83 if (RuntimeEnabledFeatures::featurePolicyEnabled()) {
84 if (!isFeatureEnabledInFrame(blink::kVibrateFeature, frame)) {
85 frame->localDOMWindow()->printErrorMessage(
86 "Navigator.vibrate() is not enabled in feature policy for this "
87 "frame.");
88 return false;
89 }
90 } else if (frame->isCrossOriginSubframe()) {
83 frame->localDOMWindow()->printErrorMessage( 91 frame->localDOMWindow()->printErrorMessage(
84 "A call of navigator.vibrate will be no-op inside cross-origin " 92 "A call of navigator.vibrate will be no-op inside cross-origin "
85 "iframes: https://www.chromestatus.com/feature/5682658461876224."); 93 "iframes: https://www.chromestatus.com/feature/5682658461876224.");
86 return false; 94 return false;
87 } 95 }
raymes 2016/11/16 23:21:07 nit: Should we rework this so that only the error
lunalu1 2016/11/17 21:47:20 Done.
88 96
89 return NavigatorVibration::from(navigator).controller(*frame)->vibrate( 97 return NavigatorVibration::from(navigator).controller(*frame)->vibrate(
90 pattern); 98 pattern);
91 } 99 }
92 100
93 // static 101 // static
94 void NavigatorVibration::collectHistogramMetrics(const LocalFrame& frame) { 102 void NavigatorVibration::collectHistogramMetrics(const LocalFrame& frame) {
95 NavigatorVibrationType type; 103 NavigatorVibrationType type;
96 bool userGesture = UserGestureIndicator::processingUserGesture(); 104 bool userGesture = UserGestureIndicator::processingUserGesture();
97 UseCounter::count(&frame, UseCounter::NavigatorVibrate); 105 UseCounter::count(&frame, UseCounter::NavigatorVibrate);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 } 141 }
134 } 142 }
135 143
136 DEFINE_TRACE(NavigatorVibration) { 144 DEFINE_TRACE(NavigatorVibration) {
137 visitor->trace(m_controller); 145 visitor->trace(m_controller);
138 Supplement<Navigator>::trace(visitor); 146 Supplement<Navigator>::trace(visitor);
139 ContextLifecycleObserver::trace(visitor); 147 ContextLifecycleObserver::trace(visitor);
140 } 148 }
141 149
142 } // namespace blink 150 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/bindings/core/v8/ConditionalFeatures.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698