summaryrefslogtreecommitdiffstats
path: root/content/browser/screen_orientation
diff options
context:
space:
mode:
authormlamouri@chromium.org <mlamouri@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-17 14:41:54 +0000
committermlamouri@chromium.org <mlamouri@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-17 14:41:54 +0000
commit01f83f92977e56f76457d9dae167abbfc8d69ee9 (patch)
tree05719c9ede5f5c7c557a1b161a843249bc606de8 /content/browser/screen_orientation
parentad1e23c3f9ed149488e58f0704127612eae5e008 (diff)
downloadchromium_src-01f83f92977e56f76457d9dae167abbfc8d69ee9.zip
chromium_src-01f83f92977e56f76457d9dae167abbfc8d69ee9.tar.gz
chromium_src-01f83f92977e56f76457d9dae167abbfc8d69ee9.tar.bz2
Properly route screen orientation IPC messages.
The messages will now go trough RF/RFH. This is in order to make screen orientation lock Frame specific instead of global to Chromium. The next step is to change the provider accordingly. BUG=162827 Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=277321 Review URL: https://codereview.chromium.org/327573002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@277755 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/screen_orientation')
-rw-r--r--content/browser/screen_orientation/screen_orientation_dispatcher_host.cc33
-rw-r--r--content/browser/screen_orientation/screen_orientation_dispatcher_host.h28
-rw-r--r--content/browser/screen_orientation/screen_orientation_dispatcher_host_unittest.cc184
3 files changed, 36 insertions, 209 deletions
diff --git a/content/browser/screen_orientation/screen_orientation_dispatcher_host.cc b/content/browser/screen_orientation/screen_orientation_dispatcher_host.cc
index 3bb494d..67174d0 100644
--- a/content/browser/screen_orientation/screen_orientation_dispatcher_host.cc
+++ b/content/browser/screen_orientation/screen_orientation_dispatcher_host.cc
@@ -6,11 +6,14 @@
#include "content/browser/screen_orientation/screen_orientation_provider.h"
#include "content/common/screen_orientation_messages.h"
+#include "content/public/browser/render_frame_host.h"
+#include "content/public/browser/web_contents.h"
namespace content {
-ScreenOrientationDispatcherHost::ScreenOrientationDispatcherHost()
- : BrowserMessageFilter(ScreenOrientationMsgStart) {
+ScreenOrientationDispatcherHost::ScreenOrientationDispatcherHost(
+ WebContents* web_contents)
+ : WebContentsObserver(web_contents) {
if (!provider_.get())
provider_.reset(CreateProvider());
}
@@ -19,10 +22,12 @@ ScreenOrientationDispatcherHost::~ScreenOrientationDispatcherHost() {
}
bool ScreenOrientationDispatcherHost::OnMessageReceived(
- const IPC::Message& message) {
+ const IPC::Message& message,
+ RenderFrameHost* render_frame_host) {
bool handled = true;
- IPC_BEGIN_MESSAGE_MAP(ScreenOrientationDispatcherHost, message)
+ IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(ScreenOrientationDispatcherHost, message,
+ render_frame_host)
IPC_MESSAGE_HANDLER(ScreenOrientationHostMsg_LockRequest, OnLockRequest)
IPC_MESSAGE_HANDLER(ScreenOrientationHostMsg_Unlock, OnUnlockRequest)
IPC_MESSAGE_UNHANDLED(handled = false)
@@ -42,24 +47,28 @@ void ScreenOrientationDispatcherHost::SetProviderForTests(
}
void ScreenOrientationDispatcherHost::OnLockRequest(
+ RenderFrameHost* render_frame_host,
blink::WebScreenOrientationLockType orientation,
int request_id) {
if (!provider_) {
- Send(new ScreenOrientationMsg_LockError(
- request_id,
- blink::WebLockOrientationCallback::ErrorTypeNotAvailable));
+ render_frame_host->Send(new ScreenOrientationMsg_LockError(
+ render_frame_host->GetRoutingID(),
+ request_id,
+ blink::WebLockOrientationCallback::ErrorTypeNotAvailable));
return;
}
// TODO(mlamouri): pass real values.
- Send(new ScreenOrientationMsg_LockSuccess(
- request_id,
- 0,
- blink::WebScreenOrientationPortraitPrimary));
+ render_frame_host->Send(new ScreenOrientationMsg_LockSuccess(
+ render_frame_host->GetRoutingID(),
+ request_id,
+ 0,
+ blink::WebScreenOrientationPortraitPrimary));
provider_->LockOrientation(orientation);
}
-void ScreenOrientationDispatcherHost::OnUnlockRequest() {
+void ScreenOrientationDispatcherHost::OnUnlockRequest(
+ RenderFrameHost* render_frame_host) {
if (!provider_.get())
return;
diff --git a/content/browser/screen_orientation/screen_orientation_dispatcher_host.h b/content/browser/screen_orientation/screen_orientation_dispatcher_host.h
index 363c08c..c86854a 100644
--- a/content/browser/screen_orientation/screen_orientation_dispatcher_host.h
+++ b/content/browser/screen_orientation/screen_orientation_dispatcher_host.h
@@ -5,36 +5,38 @@
#ifndef CONTENT_BROWSER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_DISPATCHER_HOST_H_
#define CONTENT_BROWSER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_DISPATCHER_HOST_H_
-#include "content/public/browser/browser_message_filter.h"
+#include "content/public/browser/web_contents_observer.h"
#include "third_party/WebKit/public/platform/WebScreenOrientationLockType.h"
#include "third_party/WebKit/public/platform/WebScreenOrientationType.h"
namespace content {
+class RenderFrameHost;
class ScreenOrientationProvider;
+class WebContents;
-// ScreenOrientationDispatcherHost is a browser filter for Screen Orientation
-// messages and also helps dispatching messages about orientation changes to the
-// renderers.
+// ScreenOrientationDispatcherHost receives lock and unlock requests from the
+// RenderFrames and dispatch them to the ScreenOrientationProvider. It also
+// make sure that the right RenderFrame get replied for each lock request.
class CONTENT_EXPORT ScreenOrientationDispatcherHost
- : public BrowserMessageFilter {
+ : public WebContentsObserver {
public:
- ScreenOrientationDispatcherHost();
+ explicit ScreenOrientationDispatcherHost(WebContents* web_contents);
+ virtual ~ScreenOrientationDispatcherHost();
- // BrowserMessageFilter
- virtual bool OnMessageReceived(const IPC::Message&) OVERRIDE;
+ // WebContentsObserver
+ virtual bool OnMessageReceived(const IPC::Message&,
+ RenderFrameHost* render_frame_host) OVERRIDE;
void OnOrientationChange(blink::WebScreenOrientationType orientation);
void SetProviderForTests(ScreenOrientationProvider* provider);
- protected:
- virtual ~ScreenOrientationDispatcherHost();
-
private:
- void OnLockRequest(blink::WebScreenOrientationLockType orientation,
+ void OnLockRequest(RenderFrameHost* render_frame_host,
+ blink::WebScreenOrientationLockType orientation,
int request_id);
- void OnUnlockRequest();
+ void OnUnlockRequest(RenderFrameHost* render_frame_host);
static ScreenOrientationProvider* CreateProvider();
diff --git a/content/browser/screen_orientation/screen_orientation_dispatcher_host_unittest.cc b/content/browser/screen_orientation/screen_orientation_dispatcher_host_unittest.cc
deleted file mode 100644
index b652413..0000000
--- a/content/browser/screen_orientation/screen_orientation_dispatcher_host_unittest.cc
+++ /dev/null
@@ -1,184 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "base/logging.h"
-#include "base/memory/scoped_ptr.h"
-#include "content/browser/screen_orientation/screen_orientation_dispatcher_host.h"
-#include "content/browser/screen_orientation/screen_orientation_provider.h"
-#include "content/common/screen_orientation_messages.h"
-#include "content/public/browser/browser_context.h"
-#include "content/public/test/mock_render_process_host.h"
-#include "content/public/test/test_browser_context.h"
-#include "content/public/test/test_browser_thread_bundle.h"
-#include "content/public/test/test_utils.h"
-#include "ipc/ipc_test_sink.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace content {
-
-class MockScreenOrientationProvider : public ScreenOrientationProvider {
- public:
- MockScreenOrientationProvider()
- : orientation_(blink::WebScreenOrientationLockPortraitPrimary),
- unlock_called_(false) {}
-
- virtual void LockOrientation(blink::WebScreenOrientationLockType orientation)
- OVERRIDE {
- orientation_ = orientation;
- }
-
- virtual void UnlockOrientation() OVERRIDE {
- unlock_called_ = true;
- }
-
- blink::WebScreenOrientationLockType orientation() const {
- return orientation_;
- }
-
- bool unlock_called() const {
- return unlock_called_;
- }
-
- virtual ~MockScreenOrientationProvider() {}
-
- private:
- blink::WebScreenOrientationLockType orientation_;
- bool unlock_called_;
-
- DISALLOW_COPY_AND_ASSIGN(MockScreenOrientationProvider);
-};
-
-class ScreenOrientationDispatcherHostWithSink FINAL :
- public ScreenOrientationDispatcherHost {
- public:
- explicit ScreenOrientationDispatcherHostWithSink(IPC::TestSink* sink)
- : ScreenOrientationDispatcherHost() , sink_(sink) {}
-
- virtual bool Send(IPC::Message* message) OVERRIDE {
- return sink_->Send(message);
- }
-
- private:
- virtual ~ScreenOrientationDispatcherHostWithSink() { }
-
- IPC::TestSink* sink_;
-};
-
-class ScreenOrientationDispatcherHostTest : public testing::Test {
- protected:
- virtual ScreenOrientationDispatcherHost* CreateDispatcher() {
- return new ScreenOrientationDispatcherHost();
- }
-
- virtual void SetUp() OVERRIDE {
- provider_ = new MockScreenOrientationProvider();
-
- dispatcher_ = CreateDispatcher();
- dispatcher_->SetProviderForTests(provider_);
- }
-
- // The dispatcher_ owns the provider_ but we still want to access it.
- MockScreenOrientationProvider* provider_;
- scoped_refptr<ScreenOrientationDispatcherHost> dispatcher_;
-};
-
-class ScreenOrientationDispatcherHostWithSinkTest :
- public ScreenOrientationDispatcherHostTest {
- protected:
- virtual ScreenOrientationDispatcherHost* CreateDispatcher() OVERRIDE {
- return new ScreenOrientationDispatcherHostWithSink(&sink_);
- }
-
- const IPC::TestSink& sink() const {
- return sink_;
- }
-
- IPC::TestSink sink_;
-};
-
-// Test that when receiving a lock message, it is correctly dispatched to the
-// ScreenOrientationProvider.
-// We don't actually need this to be a *WithSinkTest but otherwise the IPC
-// messages are detected as leaked.
-TEST_F(ScreenOrientationDispatcherHostWithSinkTest, ProviderLock) {
- // If we change this array, update |orientationsToTestCount| below.
- blink::WebScreenOrientationLockType orientationsToTest[] = {
- blink::WebScreenOrientationLockPortraitPrimary,
- blink::WebScreenOrientationLockPortraitSecondary,
- blink::WebScreenOrientationLockLandscapePrimary,
- blink::WebScreenOrientationLockLandscapeSecondary,
- blink::WebScreenOrientationLockPortrait,
- blink::WebScreenOrientationLockLandscapePrimary,
- blink::WebScreenOrientationLockAny
- };
-
- // Unfortunately, initializer list constructor for std::list is not yet
- // something we can use.
- // Keep this in sync with |orientationsToTest|.
- int orientationsToTestCount = 7;
-
- for (int i = 0; i < orientationsToTestCount; ++i) {
- bool message_was_handled = false;
- blink::WebScreenOrientationLockType orientation = orientationsToTest[i];
-
- message_was_handled = dispatcher_->OnMessageReceived(
- ScreenOrientationHostMsg_LockRequest(orientation, 0));
-
- EXPECT_TRUE(message_was_handled);
- EXPECT_EQ(orientation, provider_->orientation());
- }
-}
-
-// Test that when receiving an unlock message, it is correctly dispatched to the
-// ScreenOrientationProvider.
-TEST_F(ScreenOrientationDispatcherHostTest, ProviderUnlock) {
- bool message_was_handled = dispatcher_->OnMessageReceived(
- ScreenOrientationHostMsg_Unlock());
-
- EXPECT_TRUE(message_was_handled);
- EXPECT_TRUE(provider_->unlock_called());
-}
-
-// Test that when there is no provider, a LockRequest fails with the appropriate
-// ErrorType.
-TEST_F(ScreenOrientationDispatcherHostWithSinkTest, NoProvider_LockError) {
- dispatcher_->SetProviderForTests(NULL);
-
- const int request_id = 3;
- dispatcher_->OnMessageReceived(ScreenOrientationHostMsg_LockRequest(
- blink::WebScreenOrientationLockPortraitPrimary, request_id));
-
- EXPECT_EQ(1u, sink().message_count());
-
- const IPC::Message* msg = sink().GetFirstMessageMatching(
- ScreenOrientationMsg_LockError::ID);
- EXPECT_TRUE(msg != NULL);
-
- Tuple2<int, blink::WebLockOrientationCallback::ErrorType> params;
- ScreenOrientationMsg_LockError::Read(msg, &params);
- EXPECT_EQ(request_id, params.a);
- EXPECT_EQ(blink::WebLockOrientationCallback::ErrorTypeNotAvailable, params.b);
-}
-
-// Test that when there is a provider, we always send a success response back to
-// the renderer.
-// TODO(mlamouri): we currently do not test the content of the message because
-// it currently contains dummy values.
-TEST_F(ScreenOrientationDispatcherHostWithSinkTest, WithProvider_LockSuccess) {
- const int request_id = 42;
- dispatcher_->OnMessageReceived(ScreenOrientationHostMsg_LockRequest(
- blink::WebScreenOrientationLockPortraitPrimary, request_id));
-
- EXPECT_EQ(1u, sink().message_count());
-
- const IPC::Message* msg = sink().GetFirstMessageMatching(
- ScreenOrientationMsg_LockSuccess::ID);
- EXPECT_TRUE(msg != NULL);
-
- Tuple3<int, unsigned, blink::WebScreenOrientationType> params;
- ScreenOrientationMsg_LockSuccess::Read(msg, &params);
- EXPECT_EQ(request_id, params.a);
-}
-
-} // namespace content