| Index: content/browser/screen_orientation/screen_orientation_dispatcher_host.cc
|
| diff --git a/content/browser/screen_orientation/screen_orientation_dispatcher_host.cc b/content/browser/screen_orientation/screen_orientation_dispatcher_host.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..fc3f539ed032c7b6cd7f11539594af2f4f39868f
|
| --- /dev/null
|
| +++ b/content/browser/screen_orientation/screen_orientation_dispatcher_host.cc
|
| @@ -0,0 +1,70 @@
|
| +// 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 "content/browser/screen_orientation/screen_orientation_dispatcher_host.h"
|
| +
|
| +#include "content/common/view_messages.h"
|
| +#include "content/port/browser/screen_orientation_provider.h"
|
| +#include "content/public/browser/content_browser_client.h"
|
| +#include "content/public/common/content_client.h"
|
| +
|
| +namespace content {
|
| +
|
| +ScreenOrientationDispatcherHost::ScreenOrientationDispatcherHost()
|
| + : orientation_lock_(0) {
|
| + provider_.reset(
|
| + GetContentClient()->browser()->OverrideScreenOrientationProvider());
|
| + if (!provider_.get())
|
| + provider_.reset(CreateProvider());
|
| +}
|
| +
|
| +ScreenOrientationDispatcherHost::~ScreenOrientationDispatcherHost() {
|
| +}
|
| +
|
| +bool ScreenOrientationDispatcherHost::OnMessageReceived(
|
| + const IPC::Message& message,
|
| + bool* message_was_ok) {
|
| + bool handled = true;
|
| + IPC_BEGIN_MESSAGE_MAP_EX(ScreenOrientationDispatcherHost,
|
| + message,
|
| + *message_was_ok)
|
| + IPC_MESSAGE_HANDLER(ViewHostMsg_LockScreenOrientation, OnLockOrientation)
|
| + IPC_MESSAGE_HANDLER(ViewHostMsg_UnlockScreenOrientation,
|
| + OnUnlockOrientation)
|
| + IPC_MESSAGE_UNHANDLED(handled = false)
|
| + IPC_END_MESSAGE_MAP_EX()
|
| + return handled;
|
| +}
|
| +
|
| +void ScreenOrientationDispatcherHost::OnLockOrientation(unsigned char lock,
|
| + bool* result) {
|
| + if (!provider_.get())
|
| + return;
|
| +
|
| + orientation_lock_ =
|
| + static_cast<ScreenOrientationProvider::Orientations>(lock);
|
| +
|
| + assert((orientation_lock_ & ScreenOrientationProvider::OrientationAny) == 0);
|
| +
|
| + // Is it legal to provide empty lock?
|
| + assert(orientation_lock_);
|
| +
|
| + *result = provider_->LockOrientation(orientation_lock_);
|
| +}
|
| +
|
| +void ScreenOrientationDispatcherHost::OnUnlockOrientation() {
|
| + if (!provider_.get())
|
| + return;
|
| +
|
| + provider_->UnlockOrientation();
|
| + orientation_lock_ = 0;
|
| +}
|
| +
|
| +#if !defined(OS_ANDROID)
|
| +// static
|
| +ScreenOrientationProvider* ScreenOrientationDispatcherHost::CreateProvider() {
|
| + return NULL;
|
| +}
|
| +#endif
|
| +} // namespace content
|
|
|