1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/browser/screen_orientation/screen_orientation_dispatcher_host.h"
7 #include "content/browser/screen_orientation/screen_orientation_provider.h"
8 #include "content/common/screen_orientation_messages.h"
9 #include "content/public/browser/render_frame_host.h"
10 #include "content/public/browser/web_contents.h"
14 ScreenOrientationDispatcherHost::ScreenOrientationDispatcherHost(
15 WebContents* web_contents)
16 : WebContentsObserver(web_contents) {
18 provider_.reset(CreateProvider());
21 ScreenOrientationDispatcherHost::~ScreenOrientationDispatcherHost() {
24 bool ScreenOrientationDispatcherHost::OnMessageReceived(
25 const IPC::Message& message,
26 RenderFrameHost* render_frame_host) {
29 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(ScreenOrientationDispatcherHost, message,
31 IPC_MESSAGE_HANDLER(ScreenOrientationHostMsg_LockRequest, OnLockRequest)
32 IPC_MESSAGE_HANDLER(ScreenOrientationHostMsg_Unlock, OnUnlockRequest)
33 IPC_MESSAGE_UNHANDLED(handled = false)
39 void ScreenOrientationDispatcherHost::OnOrientationChange(
40 blink::WebScreenOrientationType orientation) {
41 Send(new ScreenOrientationMsg_OrientationChange(orientation));
44 void ScreenOrientationDispatcherHost::SetProviderForTests(
45 ScreenOrientationProvider* provider) {
46 provider_.reset(provider);
49 void ScreenOrientationDispatcherHost::OnLockRequest(
50 RenderFrameHost* render_frame_host,
51 blink::WebScreenOrientationLockType orientation,
54 render_frame_host->Send(new ScreenOrientationMsg_LockError(
55 render_frame_host->GetRoutingID(),
57 blink::WebLockOrientationCallback::ErrorTypeNotAvailable));
61 // TODO(mlamouri): pass real values.
62 render_frame_host->Send(new ScreenOrientationMsg_LockSuccess(
63 render_frame_host->GetRoutingID(),
66 blink::WebScreenOrientationPortraitPrimary));
67 provider_->LockOrientation(orientation);
70 void ScreenOrientationDispatcherHost::OnUnlockRequest(
71 RenderFrameHost* render_frame_host) {
75 provider_->UnlockOrientation();
78 #if !defined(OS_ANDROID)
80 ScreenOrientationProvider* ScreenOrientationDispatcherHost::CreateProvider() {
85 } // namespace content