summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--content/public/renderer/render_view_observer.cc17
-rw-r--r--content/public/renderer/render_view_observer.h6
-rw-r--r--content/renderer/renderer_webkitplatformsupport_impl.cc5
-rw-r--r--content/renderer/renderer_webkitplatformsupport_impl.h2
-rw-r--r--content/renderer/screen_orientation/mock_screen_orientation_controller.cc25
-rw-r--r--content/renderer/screen_orientation/mock_screen_orientation_controller.h14
-rw-r--r--content/test/layouttest_support.cc5
7 files changed, 65 insertions, 9 deletions
diff --git a/content/public/renderer/render_view_observer.cc b/content/public/renderer/render_view_observer.cc
index 612fb15..8289da9 100644
--- a/content/public/renderer/render_view_observer.cc
+++ b/content/public/renderer/render_view_observer.cc
@@ -13,7 +13,7 @@ namespace content {
RenderViewObserver::RenderViewObserver(RenderView* render_view)
: render_view_(render_view),
routing_id_(MSG_ROUTING_NONE) {
- // |render_view| can be NULL on unit testing.
+ // |render_view| can be NULL on unit testing or if Observe() is used.
if (render_view) {
RenderViewImpl* impl = static_cast<RenderViewImpl*>(render_view);
routing_id_ = impl->routing_id();
@@ -53,4 +53,19 @@ void RenderViewObserver::RenderViewGone() {
render_view_ = NULL;
}
+void RenderViewObserver::Observe(RenderView* render_view) {
+ RenderViewImpl* impl = static_cast<RenderViewImpl*>(render_view_);
+ if (impl) {
+ impl->RemoveObserver(this);
+ routing_id_ = 0;
+ }
+
+ render_view_ = render_view;
+ impl = static_cast<RenderViewImpl*>(render_view_);
+ if (impl) {
+ routing_id_ = impl->routing_id();
+ impl->AddObserver(this);
+ }
+}
+
} // namespace content
diff --git a/content/public/renderer/render_view_observer.h b/content/public/renderer/render_view_observer.h
index 84a7e4c..dfd147c 100644
--- a/content/public/renderer/render_view_observer.h
+++ b/content/public/renderer/render_view_observer.h
@@ -109,6 +109,12 @@ class CONTENT_EXPORT RenderViewObserver : public IPC::Listener,
explicit RenderViewObserver(RenderView* render_view);
virtual ~RenderViewObserver();
+ // Sets |render_view_| to track.
+ // Removes itself of previous (if any) |render_view_| observer list and adds
+ // to the new |render_view|. Since it assumes that observer outlives
+ // render_view, OnDestruct should be overridden.
+ void Observe(RenderView* render_view);
+
private:
friend class RenderViewImpl;
diff --git a/content/renderer/renderer_webkitplatformsupport_impl.cc b/content/renderer/renderer_webkitplatformsupport_impl.cc
index cd8628f..611137c 100644
--- a/content/renderer/renderer_webkitplatformsupport_impl.cc
+++ b/content/renderer/renderer_webkitplatformsupport_impl.cc
@@ -7,6 +7,7 @@
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/lazy_instance.h"
+#include "base/logging.h"
#include "base/memory/shared_memory.h"
#include "base/message_loop/message_loop_proxy.h"
#include "base/metrics/histogram.h"
@@ -1083,6 +1084,7 @@ void RendererWebKitPlatformSupportImpl::SetMockDeviceMotionDataForTesting(
// static
void RendererWebKitPlatformSupportImpl::ResetMockScreenOrientationForTesting()
{
+ DCHECK(!(g_test_screen_orientation_controller == 0));
g_test_screen_orientation_controller.Get().ResetData();
}
@@ -1177,9 +1179,10 @@ void RendererWebKitPlatformSupportImpl::unlockOrientation() {
// static
void RendererWebKitPlatformSupportImpl::SetMockScreenOrientationForTesting(
+ RenderView* render_view,
blink::WebScreenOrientationType orientation) {
g_test_screen_orientation_controller.Get()
- .UpdateDeviceOrientation(orientation);
+ .UpdateDeviceOrientation(render_view, orientation);
}
//------------------------------------------------------------------------------
diff --git a/content/renderer/renderer_webkitplatformsupport_impl.h b/content/renderer/renderer_webkitplatformsupport_impl.h
index 0dfb4dc..7e36823 100644
--- a/content/renderer/renderer_webkitplatformsupport_impl.h
+++ b/content/renderer/renderer_webkitplatformsupport_impl.h
@@ -41,6 +41,7 @@ class DeviceMotionEventPump;
class DeviceOrientationEventPump;
class QuotaMessageFilter;
class RendererClipboardClient;
+class RenderView;
class ScreenOrientationDispatcher;
class ThreadSafeSender;
class WebClipboardImpl;
@@ -183,6 +184,7 @@ class CONTENT_EXPORT RendererWebKitPlatformSupportImpl
const blink::WebDeviceOrientationData& data);
// Forces the screen orientation for testing purposes.
static void SetMockScreenOrientationForTesting(
+ RenderView* render_view,
blink::WebScreenOrientationType);
// Resets the mock screen orientation data used for testing.
static void ResetMockScreenOrientationForTesting();
diff --git a/content/renderer/screen_orientation/mock_screen_orientation_controller.cc b/content/renderer/screen_orientation/mock_screen_orientation_controller.cc
index bbff907..f0b1a6d 100644
--- a/content/renderer/screen_orientation/mock_screen_orientation_controller.cc
+++ b/content/renderer/screen_orientation/mock_screen_orientation_controller.cc
@@ -7,12 +7,14 @@
#include "base/bind.h"
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
+#include "content/renderer/render_view_impl.h"
#include "third_party/WebKit/public/platform/WebScreenOrientationListener.h"
namespace content {
MockScreenOrientationController::MockScreenOrientationController()
- : current_lock_(blink::WebScreenOrientationLockDefault),
+ : RenderViewObserver(NULL),
+ current_lock_(blink::WebScreenOrientationLockDefault),
device_orientation_(blink::WebScreenOrientationPortraitPrimary),
current_orientation_(blink::WebScreenOrientationPortraitPrimary),
listener_(NULL) {
@@ -30,6 +32,9 @@ void MockScreenOrientationController::SetListener(
}
void MockScreenOrientationController::ResetData() {
+ if (render_view_impl())
+ render_view_impl()->RemoveObserver(this);
+
current_lock_ = blink::WebScreenOrientationLockDefault;
device_orientation_ = blink::WebScreenOrientationPortraitPrimary;
current_orientation_ = blink::WebScreenOrientationPortraitPrimary;
@@ -64,7 +69,15 @@ void MockScreenOrientationController::ResetLockSync() {
}
void MockScreenOrientationController::UpdateDeviceOrientation(
+ RenderView* render_view,
blink::WebScreenOrientationType orientation) {
+ if (this->render_view()) {
+ // Make sure that render_view_ did not change during test.
+ DCHECK_EQ(this->render_view(), render_view);
+ } else {
+ Observe(render_view);
+ }
+
if (device_orientation_ == orientation)
return;
device_orientation_ = orientation;
@@ -73,11 +86,18 @@ void MockScreenOrientationController::UpdateDeviceOrientation(
UpdateScreenOrientation(orientation);
}
+RenderViewImpl* MockScreenOrientationController::render_view_impl() const {
+ return static_cast<RenderViewImpl*>(render_view());
+}
+
void MockScreenOrientationController::UpdateScreenOrientation(
blink::WebScreenOrientationType orientation) {
if (current_orientation_ == orientation)
return;
current_orientation_ = orientation;
+ if (render_view_impl())
+ render_view_impl()->SetScreenOrientationForTesting(orientation);
+
if (listener_)
listener_->didChangeScreenOrientation(current_orientation_);
}
@@ -124,4 +144,7 @@ MockScreenOrientationController::SuitableOrientationForCurrentLock() {
}
}
+void MockScreenOrientationController::OnDestruct() {
+}
+
} // namespace content
diff --git a/content/renderer/screen_orientation/mock_screen_orientation_controller.h b/content/renderer/screen_orientation/mock_screen_orientation_controller.h
index 3142055..4d7f0eb 100644
--- a/content/renderer/screen_orientation/mock_screen_orientation_controller.h
+++ b/content/renderer/screen_orientation/mock_screen_orientation_controller.h
@@ -8,6 +8,7 @@
#include "base/lazy_instance.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
+#include "content/public/renderer/render_view_observer.h"
#include "third_party/WebKit/public/platform/WebScreenOrientationLockType.h"
#include "third_party/WebKit/public/platform/WebScreenOrientationType.h"
@@ -16,9 +17,12 @@ class WebScreenOrientationListener;
}
namespace content {
+class RenderView;
+class RenderViewImpl;
class MockScreenOrientationController
- : public base::RefCountedThreadSafe<MockScreenOrientationController> {
+ : public base::RefCountedThreadSafe<MockScreenOrientationController>,
+ public RenderViewObserver {
public:
MockScreenOrientationController();
@@ -26,7 +30,9 @@ class MockScreenOrientationController
void ResetData();
void UpdateLock(blink::WebScreenOrientationLockType);
void ResetLock();
- void UpdateDeviceOrientation(blink::WebScreenOrientationType);
+ void UpdateDeviceOrientation(
+ RenderView* render_view,
+ blink::WebScreenOrientationType);
private:
virtual ~MockScreenOrientationController();
@@ -36,6 +42,10 @@ class MockScreenOrientationController
void UpdateScreenOrientation(blink::WebScreenOrientationType);
bool IsOrientationAllowedByCurrentLock(blink::WebScreenOrientationType);
blink::WebScreenOrientationType SuitableOrientationForCurrentLock();
+ RenderViewImpl* render_view_impl() const;
+
+ // RenderViewObserver
+ virtual void OnDestruct() OVERRIDE;
blink::WebScreenOrientationLockType current_lock_;
blink::WebScreenOrientationType device_orientation_;
diff --git a/content/test/layouttest_support.cc b/content/test/layouttest_support.cc
index 9e6433b..0113127 100644
--- a/content/test/layouttest_support.cc
+++ b/content/test/layouttest_support.cc
@@ -104,11 +104,8 @@ void SetMockDeviceOrientationData(const WebDeviceOrientationData& data) {
void SetMockScreenOrientation(
RenderView* render_view,
const blink::WebScreenOrientationType& orientation) {
- static_cast<RenderViewImpl*>(render_view)
- ->SetScreenOrientationForTesting(orientation);
- // FIXME(ostap): Remove this when blink side gets updated.
RendererWebKitPlatformSupportImpl::
- SetMockScreenOrientationForTesting(orientation);
+ SetMockScreenOrientationForTesting(render_view, orientation);
}
void ResetMockScreenOrientation()