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

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

Issue 2354433002: Block navigator.vibrate in cross-domain iframe. (Closed)
Patch Set: Change the error message to: "A call of navigator.vibrate will be no-op inside cross-origin iframes" Created 4 years, 2 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 unified diff | Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/http/tests/security/vibrate_in_same_origin_iframe_allowed-expected.txt ('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 "core/dom/Document.h" 22 #include "core/dom/Document.h"
23 #include "core/frame/LocalDOMWindow.h"
23 #include "core/frame/LocalFrame.h" 24 #include "core/frame/LocalFrame.h"
24 #include "core/frame/Navigator.h" 25 #include "core/frame/Navigator.h"
25 #include "core/frame/UseCounter.h" 26 #include "core/frame/UseCounter.h"
26 #include "core/page/Page.h" 27 #include "core/page/Page.h"
27 #include "modules/vibration/VibrationController.h" 28 #include "modules/vibration/VibrationController.h"
28 #include "platform/Histogram.h" 29 #include "platform/Histogram.h"
29 #include "platform/UserGestureIndicator.h" 30 #include "platform/UserGestureIndicator.h"
30 31
31 namespace blink { 32 namespace blink {
32 33
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 if (!frame) 75 if (!frame)
75 return false; 76 return false;
76 collectHistogramMetrics(*frame); 77 collectHistogramMetrics(*frame);
77 78
78 DCHECK(frame->document()); 79 DCHECK(frame->document());
79 DCHECK(frame->page()); 80 DCHECK(frame->page());
80 81
81 if (!frame->page()->isPageVisible()) 82 if (!frame->page()->isPageVisible())
82 return false; 83 return false;
83 84
85 if (frame->isCrossOriginSubframe()) {
86 // TODO(binlu): Once FeaturePolicy is ready, exploring using it to
87 // remove the API instead of having it return false.
88 frame->localDOMWindow()->printErrorMessage(
89 "A call of navigator.vibrate will be no-op inside cross-origin ifram es: https://www.chromestatus.com/feature/5682658461876224.");
90 return false;
91 }
92
84 return NavigatorVibration::from(navigator).controller(*frame)->vibrate(patte rn); 93 return NavigatorVibration::from(navigator).controller(*frame)->vibrate(patte rn);
85 } 94 }
86 95
87 // static 96 // static
88 void NavigatorVibration::collectHistogramMetrics(const LocalFrame& frame) 97 void NavigatorVibration::collectHistogramMetrics(const LocalFrame& frame)
89 { 98 {
90 NavigatorVibrationType type; 99 NavigatorVibrationType type;
91 bool userGesture = UserGestureIndicator::processingUserGesture(); 100 bool userGesture = UserGestureIndicator::processingUserGesture();
92 UseCounter::count(&frame, UseCounter::NavigatorVibrate); 101 UseCounter::count(&frame, UseCounter::NavigatorVibrate);
93 if (!frame.isMainFrame()) { 102 if (!frame.isMainFrame()) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 } 139 }
131 140
132 DEFINE_TRACE(NavigatorVibration) 141 DEFINE_TRACE(NavigatorVibration)
133 { 142 {
134 visitor->trace(m_controller); 143 visitor->trace(m_controller);
135 Supplement<Navigator>::trace(visitor); 144 Supplement<Navigator>::trace(visitor);
136 ContextLifecycleObserver::trace(visitor); 145 ContextLifecycleObserver::trace(visitor);
137 } 146 }
138 147
139 } // namespace blink 148 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/http/tests/security/vibrate_in_same_origin_iframe_allowed-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698