Index: Source/modules/screen_orientation/ScreenOrientationController.cpp |
diff --git a/Source/modules/screen_orientation/ScreenOrientationController.cpp b/Source/modules/screen_orientation/ScreenOrientationController.cpp |
index 0e1520d5e3d921f0d0ff7dd9954f2811c033780a..ba39015a566a473c51787c7665b6e553dc66339d 100644 |
--- a/Source/modules/screen_orientation/ScreenOrientationController.cpp |
+++ b/Source/modules/screen_orientation/ScreenOrientationController.cpp |
@@ -12,6 +12,7 @@ |
#include "modules/screen_orientation/ScreenOrientation.h" |
#include "platform/LayoutTestSupport.h" |
#include "platform/PlatformScreen.h" |
+#include "public/platform/Platform.h" |
#include "public/platform/WebScreenOrientationClient.h" |
namespace WebCore { |
@@ -43,6 +44,7 @@ ScreenOrientationController::ScreenOrientationController(LocalFrame& frame, blin |
: PageLifecycleObserver(frame.page()) |
, m_client(client) |
, m_frame(frame) |
+ , m_platformListening(false) |
{ |
} |
@@ -95,6 +97,8 @@ void ScreenOrientationController::updateOrientation() |
void ScreenOrientationController::pageVisibilityChanged() |
{ |
+ notifyPlatform(); |
+ |
if (!m_orientation || !page() || page()->visibilityState() != PageVisibilityStateVisible) |
return; |
@@ -145,6 +149,8 @@ void ScreenOrientationController::setOrientation(ScreenOrientation* orientation) |
m_orientation = orientation; |
if (m_orientation) |
updateOrientation(); |
+ |
+ notifyPlatform(); |
} |
void ScreenOrientationController::lock(blink::WebScreenOrientationLockType orientation, blink::WebLockOrientationCallback* callback) |
@@ -170,6 +176,18 @@ const LocalFrame& ScreenOrientationController::frame() const |
return m_frame; |
} |
+void ScreenOrientationController::notifyPlatform() |
+{ |
+ bool shouldListen = !!m_orientation && page() && page()->visibilityState() == PageVisibilityStateVisible; |
+ |
+ if (m_platformListening == shouldListen) |
+ return; |
+ |
+ shouldListen ? blink::Platform::current()->startScreenOrientationListening() |
+ : blink::Platform::current()->stopScreenOrientationListening(); |
+ m_platformListening = shouldListen; |
+} |
+ |
void ScreenOrientationController::trace(Visitor* visitor) |
{ |
visitor->trace(m_orientation); |