<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[191073] branches/safari-601-branch</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/191073">191073</a></dd>
<dt>Author</dt> <dd>matthew_hanson@apple.com</dd>
<dt>Date</dt> <dd>2015-10-14 15:51:42 -0700 (Wed, 14 Oct 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Merge <a href="http://trac.webkit.org/projects/webkit/changeset/191008">r191008</a>. rdar://problem/23111794</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari601branchChangeLog">branches/safari-601-branch/ChangeLog</a></li>
<li><a href="#branchessafari601branchSourceWebCoreChangeLog">branches/safari-601-branch/Source/WebCore/ChangeLog</a></li>
<li><a href="#branchessafari601branchSourceWebCorepageDOMWindowcpp">branches/safari-601-branch/Source/WebCore/page/DOMWindow.cpp</a></li>
<li><a href="#branchessafari601branchSourceWebCorepageDOMWindowh">branches/safari-601-branch/Source/WebCore/page/DOMWindow.h</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#branchessafari601branchManualTestsdeviceorientationchildframehtml">branches/safari-601-branch/ManualTests/deviceorientation-child-frame.html</a></li>
<li><a href="#branchessafari601branchManualTestsdeviceorientationmainframeonlyhtml">branches/safari-601-branch/ManualTests/deviceorientation-main-frame-only.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchessafari601branchChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-601-branch/ChangeLog (191072 => 191073)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601-branch/ChangeLog        2015-10-14 21:20:50 UTC (rev 191072)
+++ branches/safari-601-branch/ChangeLog        2015-10-14 22:51:42 UTC (rev 191073)
</span><span class="lines">@@ -1,3 +1,21 @@
</span><ins>+2015-10-14  Matthew Hanson  &lt;matthew_hanson@apple.com&gt;
+
+        Merge r191008. rdar://problem/23111794
+
+    2015-10-13  Dean Jackson  &lt;dino@apple.com&gt;
+
+            Device motion and orientation should only be visible from the main frame's security origin
+            https://bugs.webkit.org/show_bug.cgi?id=150072
+            &lt;rdar://problem/23082036&gt;
+
+            Reviewed by Brent Fulgham.
+
+            Add a manual test for cross-origin device orientation events, while
+            we're waiting on the mock client to be supported everywhere.
+
+            * ManualTests/deviceorientation-child-frame.html: Added.
+            * ManualTests/deviceorientation-main-frame-only.html: Added.
+
</ins><span class="cx"> 2015-07-10  Michael Catanzaro  &lt;mcatanzaro@igalia.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [GTK] ar warning when linking static libraries
</span></span></pre></div>
<a id="branchessafari601branchManualTestsdeviceorientationchildframehtml"></a>
<div class="addfile"><h4>Added: branches/safari-601-branch/ManualTests/deviceorientation-child-frame.html (0 => 191073)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601-branch/ManualTests/deviceorientation-child-frame.html                                (rev 0)
+++ branches/safari-601-branch/ManualTests/deviceorientation-child-frame.html        2015-10-14 22:51:42 UTC (rev 191073)
</span><span class="lines">@@ -0,0 +1,23 @@
</span><ins>+&lt;html&gt;
+&lt;head&gt;
+    &lt;script&gt;
+    var results = null;
+
+    function run() {
+        results = document.getElementById(&quot;results&quot;);
+        window.addEventListener(&quot;deviceorientation&quot;, handleDeviceOrientation, false);
+    }
+
+    function handleDeviceOrientation(event) {
+        results.textContent = &quot;ERROR: Saw event in child frame.&quot;;
+        window.removeEventListener(&quot;deviceorientation&quot;, handleDeviceOrientation);
+    }
+
+    window.addEventListener(&quot;load&quot;, run, false);
+    &lt;/script&gt;
+&lt;/head&gt;
+&lt;body&gt;
+    &lt;p&gt;We should not see an event in here.&lt;/p&gt;
+    &lt;p id=&quot;results&quot;&gt;Child frame has not seen event - this is ok.&lt;/p&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="branchessafari601branchManualTestsdeviceorientationmainframeonlyhtml"></a>
<div class="addfile"><h4>Added: branches/safari-601-branch/ManualTests/deviceorientation-main-frame-only.html (0 => 191073)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601-branch/ManualTests/deviceorientation-main-frame-only.html                                (rev 0)
+++ branches/safari-601-branch/ManualTests/deviceorientation-main-frame-only.html        2015-10-14 22:51:42 UTC (rev 191073)
</span><span class="lines">@@ -0,0 +1,26 @@
</span><ins>+&lt;html&gt;
+&lt;head&gt;
+    &lt;script&gt;
+    var results = null;
+
+    function run() {
+        results = document.getElementById(&quot;results&quot;);
+        window.addEventListener(&quot;deviceorientation&quot;, handleDeviceOrientation, false);
+    }
+
+    function handleDeviceOrientation(event) {
+        results.textContent = &quot;Saw event in the main frame - this is ok&quot;;
+        window.removeEventListener(&quot;deviceorientation&quot;, handleDeviceOrientation);
+    }
+
+    window.addEventListener(&quot;load&quot;, run, false);
+    &lt;/script&gt;
+&lt;/head&gt;
+&lt;body&gt;
+    &lt;p&gt;This tests that deviceorientation events are not dispatched in different origin iframes.&lt;/p&gt;
+    &lt;p&gt;&lt;b&gt;REMEMBER TO CHANGE THE SRC OF THE IFRAME TO BE CROSS-ORIGIN&lt;/b&gt;&lt;/p&gt;
+    &lt;p&gt;We should be able to detect the event in the main page, but not in the frame.&lt;/p&gt;
+    &lt;p id=&quot;results&quot;&gt;Main page has not seen event.&lt;/p&gt;
+    &lt;iframe id=&quot;frameA&quot; src=&quot;http://127.0.0.1/device-orientation-child-frame.html&quot;&gt;&lt;/iframe&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="branchessafari601branchSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-601-branch/Source/WebCore/ChangeLog (191072 => 191073)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601-branch/Source/WebCore/ChangeLog        2015-10-14 21:20:50 UTC (rev 191072)
+++ branches/safari-601-branch/Source/WebCore/ChangeLog        2015-10-14 22:51:42 UTC (rev 191073)
</span><span class="lines">@@ -1,5 +1,30 @@
</span><span class="cx"> 2015-10-14  Matthew Hanson  &lt;matthew_hanson@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        Merge r191008. rdar://problem/23111794
+
+    2015-10-13  Dean Jackson  &lt;dino@apple.com&gt;
+
+            Device motion and orientation should only be visible from the main frame's security origin
+            https://bugs.webkit.org/show_bug.cgi?id=150072
+            &lt;rdar://problem/23082036&gt;
+
+            Reviewed by Brent Fulgham.
+
+            There are reports that gyroscope and accelerometer information can
+            be used to detect keyboard entry. One initial step to reduce the
+            risk is to forbid device motion and orientation events from
+            being fired in frames that are a different security origin from the main page.
+
+            Manual test: deviceorientation-main-frame-only.html
+
+            * page/DOMWindow.cpp:
+            (WebCore::DOMWindow::isSameSecurityOriginAsMainFrame): New helper function.
+            (WebCore::DOMWindow::addEventListener): Check if we are the main frame, or the
+            same security origin as the main frame. If not, don't add the event
+            listeners.
+
+2015-10-14  Matthew Hanson  &lt;matthew_hanson@apple.com&gt;
+
</ins><span class="cx">         Merge r188477. rdar://problem/22801969
</span><span class="cx"> 
</span><span class="cx">     2015-08-14  Tim Horton  &lt;timothy_horton@apple.com&gt;
</span></span></pre></div>
<a id="branchessafari601branchSourceWebCorepageDOMWindowcpp"></a>
<div class="modfile"><h4>Modified: branches/safari-601-branch/Source/WebCore/page/DOMWindow.cpp (191072 => 191073)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601-branch/Source/WebCore/page/DOMWindow.cpp        2015-10-14 21:20:50 UTC (rev 191072)
+++ branches/safari-601-branch/Source/WebCore/page/DOMWindow.cpp        2015-10-14 22:51:42 UTC (rev 191073)
</span><span class="lines">@@ -1692,6 +1692,22 @@
</span><span class="cx">     window-&gt;sessionStorage(IGNORE_EXCEPTION);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+bool DOMWindow::isSameSecurityOriginAsMainFrame() const
+{
+    if (!m_frame || !m_frame-&gt;page() || !document())
+        return false;
+
+    if (m_frame-&gt;isMainFrame())
+        return true;
+
+    Document* mainFrameDocument = m_frame-&gt;mainFrame().document();
+
+    if (mainFrameDocument &amp;&amp; document()-&gt;securityOrigin()-&gt;canAccess(mainFrameDocument-&gt;securityOrigin()))
+        return true;
+
+    return false;
+}
+
</ins><span class="cx"> bool DOMWindow::addEventListener(const AtomicString&amp; eventType, PassRefPtr&lt;EventListener&gt; listener, bool useCapture)
</span><span class="cx"> {
</span><span class="cx">     if (!EventTarget::addEventListener(eventType, listener, useCapture))
</span><span class="lines">@@ -1713,17 +1729,28 @@
</span><span class="cx">         addBeforeUnloadEventListener(this);
</span><span class="cx"> #if ENABLE(DEVICE_ORIENTATION)
</span><span class="cx"> #if PLATFORM(IOS)
</span><del>-    else if (eventType == eventNames().devicemotionEvent &amp;&amp; document())
-        document()-&gt;deviceMotionController()-&gt;addDeviceEventListener(this);
-    else if (eventType == eventNames().deviceorientationEvent &amp;&amp; document())
-        document()-&gt;deviceOrientationController()-&gt;addDeviceEventListener(this);
</del><ins>+    else if ((eventType == eventNames().devicemotionEvent || eventType == eventNames().deviceorientationEvent) &amp;&amp; document()) {
+        if (isSameSecurityOriginAsMainFrame()) {
+            if (eventType == eventNames().deviceorientationEvent)
+                document()-&gt;deviceOrientationController()-&gt;addDeviceEventListener(this);
+            else
+                document()-&gt;deviceMotionController()-&gt;addDeviceEventListener(this);
+        } else if (document())
+            document()-&gt;addConsoleMessage(MessageSource::JS, MessageLevel::Warning, ASCIILiteral(&quot;Blocked attempt add device motion or orientation listener from child frame that wasn't the same security origin as the main page.&quot;));
+    }
</ins><span class="cx"> #else
</span><span class="cx">     else if (eventType == eventNames().devicemotionEvent &amp;&amp; RuntimeEnabledFeatures::sharedFeatures().deviceMotionEnabled()) {
</span><del>-        if (DeviceMotionController* controller = DeviceMotionController::from(page()))
-            controller-&gt;addDeviceEventListener(this);
</del><ins>+        if (isSameSecurityOriginAsMainFrame()) {
+            if (DeviceMotionController* controller = DeviceMotionController::from(page()))
+                controller-&gt;addDeviceEventListener(this);
+        } else if (document())
+            document()-&gt;addConsoleMessage(MessageSource::JS, MessageLevel::Warning, ASCIILiteral(&quot;Blocked attempt add device motion listener from child frame that wasn't the same security origin as the main page.&quot;));
</ins><span class="cx">     } else if (eventType == eventNames().deviceorientationEvent &amp;&amp; RuntimeEnabledFeatures::sharedFeatures().deviceOrientationEnabled()) {
</span><del>-        if (DeviceOrientationController* controller = DeviceOrientationController::from(page()))
-            controller-&gt;addDeviceEventListener(this);
</del><ins>+        if (isSameSecurityOriginAsMainFrame()) {
+            if (DeviceOrientationController* controller = DeviceOrientationController::from(page()))
+                controller-&gt;addDeviceEventListener(this);
+        } else if (document())
+            document()-&gt;addConsoleMessage(MessageSource::JS, MessageLevel::Warning, ASCIILiteral(&quot;Blocked attempt add device orientation listener from child frame that wasn't the same security origin as the main page.&quot;));
</ins><span class="cx">     }
</span><span class="cx"> #endif // PLATFORM(IOS)
</span><span class="cx"> #endif // ENABLE(DEVICE_ORIENTATION)
</span></span></pre></div>
<a id="branchessafari601branchSourceWebCorepageDOMWindowh"></a>
<div class="modfile"><h4>Modified: branches/safari-601-branch/Source/WebCore/page/DOMWindow.h (191072 => 191073)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601-branch/Source/WebCore/page/DOMWindow.h        2015-10-14 21:20:50 UTC (rev 191072)
+++ branches/safari-601-branch/Source/WebCore/page/DOMWindow.h        2015-10-14 22:51:42 UTC (rev 191073)
</span><span class="lines">@@ -361,6 +361,8 @@
</span><span class="cx">         void reconnectDOMWindowProperties();
</span><span class="cx">         void willDestroyDocumentInFrame();
</span><span class="cx"> 
</span><ins>+        bool isSameSecurityOriginAsMainFrame() const;
+
</ins><span class="cx"> #if ENABLE(GAMEPAD)
</span><span class="cx">         void incrementGamepadEventListenerCount();
</span><span class="cx">         void decrementGamepadEventListenerCount();
</span></span></pre>
</div>
</div>

</body>
</html>