|
Lines 1826-1875
bool DOMWindow::addEventListener(const AtomicString& eventType, Ref<EventListene
a/Source/WebCore/page/DOMWindow.cpp_sec1
|
| 1826 |
else if (eventNames().isGamepadEventType(eventType)) |
1826 |
else if (eventNames().isGamepadEventType(eventType)) |
| 1827 |
incrementGamepadEventListenerCount(); |
1827 |
incrementGamepadEventListenerCount(); |
| 1828 |
#endif |
1828 |
#endif |
|
|
1829 |
#if ENABLE(DEVICE_ORIENTATION) |
| 1830 |
else if (eventType == eventNames().deviceorientationEvent) |
| 1831 |
startListeningForDeviceOrientationIfNecessary(); |
| 1832 |
else if (eventType == eventNames().devicemotionEvent) |
| 1833 |
startListeningForDeviceMotionIfNecessary(); |
| 1834 |
#endif |
| 1835 |
|
| 1836 |
return true; |
| 1837 |
} |
| 1829 |
|
1838 |
|
| 1830 |
#if ENABLE(DEVICE_ORIENTATION) |
1839 |
#if ENABLE(DEVICE_ORIENTATION) |
| 1831 |
if (frame() && frame()->settings().deviceOrientationEventEnabled() && document() && document()->loader() && document()->loader()->deviceOrientationEventEnabled()) { |
1840 |
|
|
|
1841 |
DeviceOrientationController* DOMWindow::deviceOrientationController() const |
| 1842 |
{ |
| 1832 |
#if PLATFORM(IOS_FAMILY) |
1843 |
#if PLATFORM(IOS_FAMILY) |
| 1833 |
if ((eventType == eventNames().devicemotionEvent || eventType == eventNames().deviceorientationEvent)) { |
1844 |
return document() ? &document()->deviceOrientationController() : nullptr; |
| 1834 |
if (isSameSecurityOriginAsMainFrame() && isSecureContext()) { |
|
|
| 1835 |
if (eventType == eventNames().deviceorientationEvent) |
| 1836 |
document()->deviceOrientationController().addDeviceEventListener(*this); |
| 1837 |
else |
| 1838 |
document()->deviceMotionController().addDeviceEventListener(*this); |
| 1839 |
} else if (document()) { |
| 1840 |
if (isSecureContext()) |
| 1841 |
document()->addConsoleMessage(MessageSource::JS, MessageLevel::Warning, "Blocked attempt to add a device motion or orientation listener from child frame that wasn't the same security origin as the main page."_s); |
| 1842 |
else |
| 1843 |
document()->addConsoleMessage(MessageSource::JS, MessageLevel::Warning, "Blocked attempt to add a device motion or orientation listener because the browsing context is not secure."_s); |
| 1844 |
} |
| 1845 |
} |
| 1846 |
#else |
1845 |
#else |
| 1847 |
if (eventType == eventNames().devicemotionEvent) { |
1846 |
return DeviceOrientationController::from(page()); |
| 1848 |
if (isSameSecurityOriginAsMainFrame() && isSecureContext()) { |
1847 |
#endif |
| 1849 |
if (DeviceMotionController* controller = DeviceMotionController::from(page())) |
1848 |
} |
| 1850 |
controller->addDeviceEventListener(*this); |
1849 |
|
| 1851 |
} else |
1850 |
DeviceMotionController* DOMWindow::deviceMotionController() const |
| 1852 |
document()->addConsoleMessage(MessageSource::JS, MessageLevel::Warning, "Blocked attempt to add a device motion listener from child frame that wasn't the same security origin as the main page."_s); |
1851 |
{ |
| 1853 |
} else if (eventType == eventNames().deviceorientationEvent) { |
1852 |
#if PLATFORM(IOS_FAMILY) |
| 1854 |
if (isSameSecurityOriginAsMainFrame() && isSecureContext()) { |
1853 |
return document() ? &document()->deviceMotionController() : nullptr; |
| 1855 |
if (DeviceOrientationController* controller = DeviceOrientationController::from(page())) |
1854 |
#else |
| 1856 |
controller->addDeviceEventListener(*this); |
1855 |
return DeviceMotionController::from(page()); |
| 1857 |
} else { |
1856 |
#endif |
| 1858 |
if (isSecureContext()) |
1857 |
} |
| 1859 |
document()->addConsoleMessage(MessageSource::JS, MessageLevel::Warning, "Blocked attempt to add a device orientation listener from child frame that wasn't the same security origin as the main page."_s); |
1858 |
|
| 1860 |
else |
1859 |
bool DOMWindow::isAllowedToUseDeviceMotionOrientation(String& message) const |
| 1861 |
document()->addConsoleMessage(MessageSource::JS, MessageLevel::Warning, "Blocked attempt to add a device motion or orientation listener because the browsing context is not secure."_s); |
1860 |
{ |
| 1862 |
} |
1861 |
if (!frame() || !frame()->settings().deviceOrientationEventEnabled() || !document() || !document()->loader() || !document()->loader()->deviceOrientationEventEnabled()) { |
|
|
1862 |
message = "API is disabled"_s; |
| 1863 |
return false; |
| 1864 |
} |
| 1865 |
|
| 1866 |
if (!isSecureContext()) { |
| 1867 |
message = "Browsing context is not secure"_s; |
| 1868 |
return false; |
| 1869 |
} |
| 1870 |
|
| 1871 |
if (!isSameSecurityOriginAsMainFrame()) { |
| 1872 |
message = "Source frame did not have the same security origin as the main page"_s; |
| 1873 |
return false; |
| 1874 |
} |
| 1875 |
return true; |
| 1876 |
} |
| 1877 |
|
| 1878 |
bool DOMWindow::isAllowedToAddDeviceMotionOrientationListener(const String& eventType, String& message) const |
| 1879 |
{ |
| 1880 |
String innerMessage; |
| 1881 |
if (!isAllowedToUseDeviceMotionOrientation(innerMessage)) { |
| 1882 |
message = makeString("Blocked attempt to add a ", eventType, " event listener, reason: ", innerMessage, "."); |
| 1883 |
return false; |
| 1884 |
} |
| 1885 |
|
| 1886 |
if (frame()->settings().deviceOrientationPermissionAPIEnabled()) { |
| 1887 |
auto permissionState = (eventType == eventNames().deviceorientationEvent) ? document()->deviceOrientationAccessState() : document()->deviceMotionAccessState(); |
| 1888 |
if (permissionState && !*permissionState) { |
| 1889 |
message = makeString("No ", eventType, " events will be fired because permission to use the API was denied."); |
| 1890 |
return false; |
| 1863 |
} |
1891 |
} |
| 1864 |
#endif // PLATFORM(IOS_FAMILY) |
1892 |
if (!permissionState) { |
| 1865 |
} else if (eventType == eventNames().devicemotionEvent) |
1893 |
message = makeString("No ", eventType, " events will be fired until permission has been requested and granted."); |
| 1866 |
failedToRegisterDeviceMotionEventListener(); |
1894 |
return false; |
| 1867 |
#endif // ENABLE(DEVICE_ORIENTATION) |
1895 |
} |
|
|
1896 |
} |
| 1868 |
|
1897 |
|
| 1869 |
return true; |
1898 |
return true; |
| 1870 |
} |
1899 |
} |
| 1871 |
|
1900 |
|
| 1872 |
#if ENABLE(DEVICE_ORIENTATION) |
1901 |
void DOMWindow::startListeningForDeviceOrientationIfNecessary() |
|
|
1902 |
{ |
| 1903 |
if (!hasEventListeners(eventNames().deviceorientationEvent)) |
| 1904 |
return; |
| 1905 |
|
| 1906 |
auto* deviceController = deviceOrientationController(); |
| 1907 |
if (!deviceController || deviceController->hasDeviceEventListener(*this)) |
| 1908 |
return; |
| 1909 |
|
| 1910 |
String errorMessage; |
| 1911 |
if (!isAllowedToAddDeviceMotionOrientationListener(eventNames().deviceorientationEvent, errorMessage)) { |
| 1912 |
if (auto* document = this->document()) |
| 1913 |
document->addConsoleMessage(MessageSource::JS, MessageLevel::Warning, errorMessage); |
| 1914 |
return; |
| 1915 |
} |
| 1916 |
|
| 1917 |
deviceController->addDeviceEventListener(*this); |
| 1918 |
} |
| 1919 |
|
| 1920 |
void DOMWindow::stopListeningForDeviceOrientationIfNecessary() |
| 1921 |
{ |
| 1922 |
if (hasEventListeners(eventNames().deviceorientationEvent)) |
| 1923 |
return; |
| 1924 |
|
| 1925 |
if (auto* deviceController = deviceOrientationController()) |
| 1926 |
deviceController->removeDeviceEventListener(*this); |
| 1927 |
} |
| 1928 |
|
| 1929 |
void DOMWindow::startListeningForDeviceMotionIfNecessary() |
| 1930 |
{ |
| 1931 |
if (!hasEventListeners(eventNames().devicemotionEvent)) |
| 1932 |
return; |
| 1933 |
|
| 1934 |
auto* deviceController = deviceMotionController(); |
| 1935 |
if (!deviceController || deviceController->hasDeviceEventListener(*this)) |
| 1936 |
return; |
| 1937 |
|
| 1938 |
String errorMessage; |
| 1939 |
if (!isAllowedToAddDeviceMotionOrientationListener(eventNames().devicemotionEvent, errorMessage)) { |
| 1940 |
failedToRegisterDeviceMotionEventListener(); |
| 1941 |
if (auto* document = this->document()) |
| 1942 |
document->addConsoleMessage(MessageSource::JS, MessageLevel::Warning, errorMessage); |
| 1943 |
return; |
| 1944 |
} |
| 1945 |
|
| 1946 |
deviceController->addDeviceEventListener(*this); |
| 1947 |
} |
| 1948 |
|
| 1949 |
void DOMWindow::stopListeningForDeviceMotionIfNecessary() |
| 1950 |
{ |
| 1951 |
if (hasEventListeners(eventNames().devicemotionEvent)) |
| 1952 |
return; |
| 1953 |
|
| 1954 |
if (auto* deviceController = deviceMotionController()) |
| 1955 |
deviceController->removeDeviceEventListener(*this); |
| 1956 |
} |
| 1873 |
|
1957 |
|
| 1874 |
void DOMWindow::failedToRegisterDeviceMotionEventListener() |
1958 |
void DOMWindow::failedToRegisterDeviceMotionEventListener() |
| 1875 |
{ |
1959 |
{ |
|
Lines 1941-1962
bool DOMWindow::removeEventListener(const AtomicString& eventType, EventListener
a/Source/WebCore/page/DOMWindow.cpp_sec2
|
| 1941 |
removeUnloadEventListener(this); |
2025 |
removeUnloadEventListener(this); |
| 1942 |
else if (eventType == eventNames().beforeunloadEvent && allowsBeforeUnloadListeners(this)) |
2026 |
else if (eventType == eventNames().beforeunloadEvent && allowsBeforeUnloadListeners(this)) |
| 1943 |
removeBeforeUnloadEventListener(this); |
2027 |
removeBeforeUnloadEventListener(this); |
| 1944 |
#if ENABLE(DEVICE_ORIENTATION) |
|
|
| 1945 |
#if PLATFORM(IOS_FAMILY) |
| 1946 |
else if (eventType == eventNames().devicemotionEvent && document()) |
| 1947 |
document()->deviceMotionController().removeDeviceEventListener(*this); |
| 1948 |
else if (eventType == eventNames().deviceorientationEvent && document()) |
| 1949 |
document()->deviceOrientationController().removeDeviceEventListener(*this); |
| 1950 |
#else |
| 1951 |
else if (eventType == eventNames().devicemotionEvent) { |
| 1952 |
if (DeviceMotionController* controller = DeviceMotionController::from(page())) |
| 1953 |
controller->removeDeviceEventListener(*this); |
| 1954 |
} else if (eventType == eventNames().deviceorientationEvent) { |
| 1955 |
if (DeviceOrientationController* controller = DeviceOrientationController::from(page())) |
| 1956 |
controller->removeDeviceEventListener(*this); |
| 1957 |
} |
| 1958 |
#endif // PLATFORM(IOS_FAMILY) |
| 1959 |
#endif // ENABLE(DEVICE_ORIENTATION) |
| 1960 |
#if PLATFORM(IOS_FAMILY) |
2028 |
#if PLATFORM(IOS_FAMILY) |
| 1961 |
else if (eventType == eventNames().scrollEvent) |
2029 |
else if (eventType == eventNames().scrollEvent) |
| 1962 |
decrementScrollEventListenersCount(); |
2030 |
decrementScrollEventListenersCount(); |
|
Lines 1977-1982
bool DOMWindow::removeEventListener(const AtomicString& eventType, EventListener
a/Source/WebCore/page/DOMWindow.cpp_sec3
|
| 1977 |
else if (eventNames().isGamepadEventType(eventType)) |
2045 |
else if (eventNames().isGamepadEventType(eventType)) |
| 1978 |
decrementGamepadEventListenerCount(); |
2046 |
decrementGamepadEventListenerCount(); |
| 1979 |
#endif |
2047 |
#endif |
|
|
2048 |
#if ENABLE(DEVICE_ORIENTATION) |
| 2049 |
else if (eventType == eventNames().deviceorientationEvent) |
| 2050 |
stopListeningForDeviceOrientationIfNecessary(); |
| 2051 |
else if (eventType == eventNames().devicemotionEvent) |
| 2052 |
stopListeningForDeviceMotionIfNecessary(); |
| 2053 |
#endif |
| 1980 |
|
2054 |
|
| 1981 |
return true; |
2055 |
return true; |
| 1982 |
} |
2056 |
} |
|
Lines 2059-2076
void DOMWindow::removeAllEventListeners()
a/Source/WebCore/page/DOMWindow.cpp_sec4
|
| 2059 |
EventTarget::removeAllEventListeners(); |
2133 |
EventTarget::removeAllEventListeners(); |
| 2060 |
|
2134 |
|
| 2061 |
#if ENABLE(DEVICE_ORIENTATION) |
2135 |
#if ENABLE(DEVICE_ORIENTATION) |
| 2062 |
#if PLATFORM(IOS_FAMILY) |
2136 |
stopListeningForDeviceOrientationIfNecessary(); |
| 2063 |
if (Document* document = this->document()) { |
2137 |
stopListeningForDeviceMotionIfNecessary(); |
| 2064 |
document->deviceMotionController().removeAllDeviceEventListeners(*this); |
2138 |
#endif |
| 2065 |
document->deviceOrientationController().removeAllDeviceEventListeners(*this); |
|
|
| 2066 |
} |
| 2067 |
#else |
| 2068 |
if (DeviceMotionController* controller = DeviceMotionController::from(page())) |
| 2069 |
controller->removeAllDeviceEventListeners(*this); |
| 2070 |
if (DeviceOrientationController* controller = DeviceOrientationController::from(page())) |
| 2071 |
controller->removeAllDeviceEventListeners(*this); |
| 2072 |
#endif // PLATFORM(IOS_FAMILY) |
| 2073 |
#endif // ENABLE(DEVICE_ORIENTATION) |
| 2074 |
|
2139 |
|
| 2075 |
#if PLATFORM(IOS_FAMILY) |
2140 |
#if PLATFORM(IOS_FAMILY) |
| 2076 |
if (m_scrollEventListenerCount) { |
2141 |
if (m_scrollEventListenerCount) { |