diff options
author | tkent@chromium.org <tkent@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-16 01:31:42 +0000 |
---|---|---|
committer | tkent@chromium.org <tkent@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-16 01:31:42 +0000 |
commit | 6f71d7a54374d731ba4f51c07b787340250ec050 (patch) | |
tree | 9d8fcb987348c3ae9651518cfc71aba4f7cd6845 /content/browser | |
parent | 9c9d0b83d2d9d46538f4cf7d3c8b1dabe14401fb (diff) | |
download | chromium_src-6f71d7a54374d731ba4f51c07b787340250ec050.zip chromium_src-6f71d7a54374d731ba4f51c07b787340250ec050.tar.gz chromium_src-6f71d7a54374d731ba4f51c07b787340250ec050.tar.bz2 |
Revert of Properly route screen orientation IPC messages. (https://codereview.chromium.org/327573002/)
Reason for revert:
Broke screen_orientation/lockOrientation-sandboxed-iframe.html
http://test-results.appspot.com/dashboards/flakiness_dashboard.html#group=%40ToT%20Blink&tests=screen_orientation/lockOrientation-sandboxed-iframe.html
Original issue's description:
> 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
TBR=dcheng@chromium.org,jam@chromium.org,mlamouri@chromium.org
NOTREECHECKS=true
NOTRY=true
BUG=162827
Review URL: https://codereview.chromium.org/336153002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@277346 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser')
8 files changed, 86 insertions, 63 deletions
diff --git a/content/browser/android/content_view_core_impl.cc b/content/browser/android/content_view_core_impl.cc index 2335d0a..0fdc058 100644 --- a/content/browser/android/content_view_core_impl.cc +++ b/content/browser/android/content_view_core_impl.cc @@ -1542,6 +1542,38 @@ void ContentViewCoreImpl::SendOrientationChangeEventInternal() { RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); if (rwhv) rwhv->UpdateScreenInfo(GetViewAndroid()); + + // TODO(mlamouri): temporary plumbing for Screen Orientation, this will change + // in the future. The OnResize IPC message sent from UpdateScreenInfo() will + // propagate the information. + blink::WebScreenOrientationType orientation = + blink::WebScreenOrientationPortraitPrimary; + + switch (device_orientation_) { + case 0: + orientation = blink::WebScreenOrientationPortraitPrimary; + break; + case 90: + orientation = blink::WebScreenOrientationLandscapePrimary; + break; + case -90: + orientation = blink::WebScreenOrientationLandscapeSecondary; + break; + case 180: + orientation = blink::WebScreenOrientationPortraitSecondary; + break; + default: + NOTREACHED(); + } + + ScreenOrientationDispatcherHost* sodh = + static_cast<RenderProcessHostImpl*>(web_contents_-> + GetRenderProcessHost())->screen_orientation_dispatcher_host(); + + // sodh can be null if the RenderProcessHost is in the process of being + // destroyed or not yet initialized. + if (sodh) + sodh->OnOrientationChange(orientation); } void ContentViewCoreImpl::ExtractSmartClipData(JNIEnv* env, diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc index de8f5b4..403f885 100644 --- a/content/browser/renderer_host/render_process_host_impl.cc +++ b/content/browser/renderer_host/render_process_host_impl.cc @@ -96,6 +96,7 @@ #include "content/browser/renderer_host/text_input_client_message_filter.h" #include "content/browser/renderer_host/websocket_dispatcher_host.h" #include "content/browser/resolve_proxy_msg_helper.h" +#include "content/browser/screen_orientation/screen_orientation_dispatcher_host.h" #include "content/browser/service_worker/service_worker_context_wrapper.h" #include "content/browser/service_worker/service_worker_dispatcher_host.h" #include "content/browser/shared_worker/shared_worker_message_filter.h" @@ -459,6 +460,7 @@ RenderProcessHostImpl::RenderProcessHostImpl( delayed_cleanup_needed_(false), within_process_died_observer_(false), power_monitor_broadcaster_(this), + screen_orientation_dispatcher_host_(NULL), worker_ref_count_(0), weak_factory_(this) { widget_helper_ = new RenderWidgetHelper(); @@ -882,6 +884,8 @@ void RenderProcessHostImpl::CreateMessageFilters() { AddFilter(new MemoryBenchmarkMessageFilter()); #endif AddFilter(new VibrationMessageFilter()); + screen_orientation_dispatcher_host_ = new ScreenOrientationDispatcherHost(); + AddFilter(screen_orientation_dispatcher_host_); AddFilter(new PushMessagingMessageFilter(GetID())); AddFilter(new BatteryStatusMessageFilter()); } @@ -1500,6 +1504,7 @@ void RenderProcessHostImpl::Cleanup() { channel_.reset(); gpu_message_filter_ = NULL; message_port_message_filter_ = NULL; + screen_orientation_dispatcher_host_ = NULL; RemoveUserData(kSessionStorageHolderKey); // Remove ourself from the list of renderer processes so that we can't be @@ -1913,6 +1918,7 @@ void RenderProcessHostImpl::ProcessDied(bool already_dead) { channel_.reset(); gpu_message_filter_ = NULL; message_port_message_filter_ = NULL; + screen_orientation_dispatcher_host_ = NULL; RemoveUserData(kSessionStorageHolderKey); IDMap<IPC::Listener>::iterator iter(&listeners_); @@ -1977,6 +1983,11 @@ void RenderProcessHostImpl::WebRtcLogMessage(const std::string& message) { } #endif +scoped_refptr<ScreenOrientationDispatcherHost> +RenderProcessHostImpl::screen_orientation_dispatcher_host() const { + return make_scoped_refptr(screen_orientation_dispatcher_host_); +} + void RenderProcessHostImpl::ReleaseOnCloseACK( RenderProcessHost* host, const SessionStorageNamespaceMap& sessions, diff --git a/content/browser/renderer_host/render_process_host_impl.h b/content/browser/renderer_host/render_process_host_impl.h index 32e342d..cd7ec89 100644 --- a/content/browser/renderer_host/render_process_host_impl.h +++ b/content/browser/renderer_host/render_process_host_impl.h @@ -56,6 +56,7 @@ class RenderWidgetHelper; class RenderWidgetHost; class RenderWidgetHostImpl; class RenderWidgetHostViewFrameSubscriber; +class ScreenOrientationDispatcherHost; class StoragePartition; class StoragePartitionImpl; @@ -180,6 +181,9 @@ class CONTENT_EXPORT RenderProcessHostImpl void WebRtcLogMessage(const std::string& message); #endif + scoped_refptr<ScreenOrientationDispatcherHost> + screen_orientation_dispatcher_host() const; + // Used to extend the lifetime of the sessions until the render view // in the renderer is fully closed. This is static because its also called // with mock hosts as input in test cases. @@ -447,6 +451,9 @@ class CONTENT_EXPORT RenderProcessHostImpl WebRtcStopRtpDumpCallback stop_rtp_dump_callback_; #endif + // Message filter and dispatcher for screen orientation. + ScreenOrientationDispatcherHost* screen_orientation_dispatcher_host_; + int worker_ref_count_; // Records the time when the process starts surviving for workers for UMA. diff --git a/content/browser/screen_orientation/screen_orientation_dispatcher_host.cc b/content/browser/screen_orientation/screen_orientation_dispatcher_host.cc index a27890e..3bb494d 100644 --- a/content/browser/screen_orientation/screen_orientation_dispatcher_host.cc +++ b/content/browser/screen_orientation/screen_orientation_dispatcher_host.cc @@ -6,14 +6,11 @@ #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( - WebContents* web_contents) - : WebContentsObserver(web_contents) { +ScreenOrientationDispatcherHost::ScreenOrientationDispatcherHost() + : BrowserMessageFilter(ScreenOrientationMsgStart) { if (!provider_.get()) provider_.reset(CreateProvider()); } @@ -22,13 +19,10 @@ ScreenOrientationDispatcherHost::~ScreenOrientationDispatcherHost() { } bool ScreenOrientationDispatcherHost::OnMessageReceived( - const IPC::Message& message, - RenderFrameHost* render_frame_host) { + const IPC::Message& message) { bool handled = true; - int routing_id = message.routing_id(); - IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(ScreenOrientationDispatcherHost, message, - &routing_id) + IPC_BEGIN_MESSAGE_MAP(ScreenOrientationDispatcherHost, message) IPC_MESSAGE_HANDLER(ScreenOrientationHostMsg_LockRequest, OnLockRequest) IPC_MESSAGE_HANDLER(ScreenOrientationHostMsg_Unlock, OnUnlockRequest) IPC_MESSAGE_UNHANDLED(handled = false) @@ -48,28 +42,24 @@ void ScreenOrientationDispatcherHost::SetProviderForTests( } void ScreenOrientationDispatcherHost::OnLockRequest( - int* routing_id, blink::WebScreenOrientationLockType orientation, int request_id) { if (!provider_) { Send(new ScreenOrientationMsg_LockError( - *routing_id, - request_id, - blink::WebLockOrientationCallback::ErrorTypeNotAvailable)); + request_id, + blink::WebLockOrientationCallback::ErrorTypeNotAvailable)); return; } // TODO(mlamouri): pass real values. Send(new ScreenOrientationMsg_LockSuccess( - *routing_id, - request_id, - 0, - blink::WebScreenOrientationPortraitPrimary)); + request_id, + 0, + blink::WebScreenOrientationPortraitPrimary)); provider_->LockOrientation(orientation); } -void ScreenOrientationDispatcherHost::OnUnlockRequest( - int* routing_id) { +void ScreenOrientationDispatcherHost::OnUnlockRequest() { 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 9f328f6c..363c08c 100644 --- a/content/browser/screen_orientation/screen_orientation_dispatcher_host.h +++ b/content/browser/screen_orientation/screen_orientation_dispatcher_host.h @@ -5,38 +5,36 @@ #ifndef CONTENT_BROWSER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_DISPATCHER_HOST_H_ #define CONTENT_BROWSER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_DISPATCHER_HOST_H_ -#include "content/public/browser/web_contents_observer.h" +#include "content/public/browser/browser_message_filter.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 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. +// ScreenOrientationDispatcherHost is a browser filter for Screen Orientation +// messages and also helps dispatching messages about orientation changes to the +// renderers. class CONTENT_EXPORT ScreenOrientationDispatcherHost - : public WebContentsObserver { + : public BrowserMessageFilter { public: - explicit ScreenOrientationDispatcherHost(WebContents* web_contents); - virtual ~ScreenOrientationDispatcherHost(); + ScreenOrientationDispatcherHost(); - // WebContentsObserver - virtual bool OnMessageReceived(const IPC::Message&, - RenderFrameHost* render_frame_host) OVERRIDE; + // BrowserMessageFilter + virtual bool OnMessageReceived(const IPC::Message&) OVERRIDE; void OnOrientationChange(blink::WebScreenOrientationType orientation); void SetProviderForTests(ScreenOrientationProvider* provider); + protected: + virtual ~ScreenOrientationDispatcherHost(); + private: - void OnLockRequest(int* routing_id, - blink::WebScreenOrientationLockType orientation, + void OnLockRequest(blink::WebScreenOrientationLockType orientation, int request_id); - void OnUnlockRequest(int* routing_id); + void OnUnlockRequest(); 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 index c7a9102..b652413 100644 --- a/content/browser/screen_orientation/screen_orientation_dispatcher_host_unittest.cc +++ b/content/browser/screen_orientation/screen_orientation_dispatcher_host_unittest.cc @@ -2,12 +2,15 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "content/browser/screen_orientation/screen_orientation_dispatcher_host.h" - #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" @@ -50,7 +53,7 @@ class ScreenOrientationDispatcherHostWithSink FINAL : public ScreenOrientationDispatcherHost { public: explicit ScreenOrientationDispatcherHostWithSink(IPC::TestSink* sink) - : ScreenOrientationDispatcherHost(NULL), sink_(sink) {} + : ScreenOrientationDispatcherHost() , sink_(sink) {} virtual bool Send(IPC::Message* message) OVERRIDE { return sink_->Send(message); @@ -65,24 +68,19 @@ class ScreenOrientationDispatcherHostWithSink FINAL : class ScreenOrientationDispatcherHostTest : public testing::Test { protected: virtual ScreenOrientationDispatcherHost* CreateDispatcher() { - return new ScreenOrientationDispatcherHost(NULL); + return new ScreenOrientationDispatcherHost(); } virtual void SetUp() OVERRIDE { provider_ = new MockScreenOrientationProvider(); - dispatcher_.reset(CreateDispatcher()); + dispatcher_ = CreateDispatcher(); dispatcher_->SetProviderForTests(provider_); } - int routing_id() const { - // We return a fake routing_id() in the context of this test. - return 0; - } - // The dispatcher_ owns the provider_ but we still want to access it. MockScreenOrientationProvider* provider_; - scoped_ptr<ScreenOrientationDispatcherHost> dispatcher_; + scoped_refptr<ScreenOrientationDispatcherHost> dispatcher_; }; class ScreenOrientationDispatcherHostWithSinkTest : @@ -125,8 +123,7 @@ TEST_F(ScreenOrientationDispatcherHostWithSinkTest, ProviderLock) { blink::WebScreenOrientationLockType orientation = orientationsToTest[i]; message_was_handled = dispatcher_->OnMessageReceived( - ScreenOrientationHostMsg_LockRequest(routing_id(), orientation, 0), - NULL); + ScreenOrientationHostMsg_LockRequest(orientation, 0)); EXPECT_TRUE(message_was_handled); EXPECT_EQ(orientation, provider_->orientation()); @@ -137,7 +134,7 @@ TEST_F(ScreenOrientationDispatcherHostWithSinkTest, ProviderLock) { // ScreenOrientationProvider. TEST_F(ScreenOrientationDispatcherHostTest, ProviderUnlock) { bool message_was_handled = dispatcher_->OnMessageReceived( - ScreenOrientationHostMsg_Unlock(routing_id()), NULL); + ScreenOrientationHostMsg_Unlock()); EXPECT_TRUE(message_was_handled); EXPECT_TRUE(provider_->unlock_called()); @@ -150,9 +147,7 @@ TEST_F(ScreenOrientationDispatcherHostWithSinkTest, NoProvider_LockError) { const int request_id = 3; dispatcher_->OnMessageReceived(ScreenOrientationHostMsg_LockRequest( - routing_id(), - blink::WebScreenOrientationLockPortraitPrimary, - request_id), NULL); + blink::WebScreenOrientationLockPortraitPrimary, request_id)); EXPECT_EQ(1u, sink().message_count()); @@ -173,9 +168,7 @@ TEST_F(ScreenOrientationDispatcherHostWithSinkTest, NoProvider_LockError) { TEST_F(ScreenOrientationDispatcherHostWithSinkTest, WithProvider_LockSuccess) { const int request_id = 42; dispatcher_->OnMessageReceived(ScreenOrientationHostMsg_LockRequest( - routing_id(), - blink::WebScreenOrientationLockPortraitPrimary, - request_id), NULL); + blink::WebScreenOrientationLockPortraitPrimary, request_id)); EXPECT_EQ(1u, sink().message_count()); diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc index b76a165..9f6ead2 100644 --- a/content/browser/web_contents/web_contents_impl.cc +++ b/content/browser/web_contents/web_contents_impl.cc @@ -45,7 +45,6 @@ #include "content/browser/renderer_host/render_view_host_impl.h" #include "content/browser/renderer_host/render_widget_host_impl.h" #include "content/browser/renderer_host/render_widget_host_view_base.h" -#include "content/browser/screen_orientation/screen_orientation_dispatcher_host.h" #include "content/browser/site_instance_impl.h" #include "content/browser/web_contents/web_contents_view_guest.h" #include "content/browser/webui/generic_handler.h" @@ -1098,9 +1097,6 @@ void WebContentsImpl::Init(const WebContents::CreateParams& params) { geolocation_dispatcher_host_.reset(new GeolocationDispatcherHost(this)); midi_dispatcher_host_.reset(new MidiDispatcherHost(this)); - screen_orientation_dispatcher_host_.reset( - new ScreenOrientationDispatcherHost(this)); - #if defined(OS_ANDROID) date_time_chooser_.reset(new DateTimeChooserAndroid()); #endif diff --git a/content/browser/web_contents/web_contents_impl.h b/content/browser/web_contents/web_contents_impl.h index 40e0fe4..40228db 100644 --- a/content/browser/web_contents/web_contents_impl.h +++ b/content/browser/web_contents/web_contents_impl.h @@ -57,7 +57,6 @@ class RenderViewHostDelegateView; class RenderViewHostImpl; class RenderWidgetHostImpl; class SavePackage; -class ScreenOrientationDispatcherHost; class SiteInstance; class TestWebContents; class WebContentsDelegate; @@ -1135,9 +1134,6 @@ class CONTENT_EXPORT WebContentsImpl scoped_ptr<MidiDispatcherHost> midi_dispatcher_host_; - scoped_ptr<ScreenOrientationDispatcherHost> - screen_orientation_dispatcher_host_; - DISALLOW_COPY_AND_ASSIGN(WebContentsImpl); }; |