Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: content/browser/screen_orientation/screen_orientation_dispatcher_host.cc

Issue 150153004: [WIP] Add Chromium-side support for the Screen Orientation API (Closed) Base URL: https://git.chromium.org/chromium/src.git@master
Patch Set: Updated by review comments. Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "content/browser/screen_orientation/screen_orientation_dispatcher_host. h"
6
7 #include "content/common/view_messages.h"
8 #include "content/port/browser/screen_orientation_provider.h"
9 #include "content/public/browser/content_browser_client.h"
10 #include "content/public/common/content_client.h"
11
12 namespace content {
13
14 ScreenOrientationDispatcherHost::ScreenOrientationDispatcherHost()
15 : orientation_lock_(0) {
16 provider_.reset(
17 GetContentClient()->browser()->OverrideScreenOrientationProvider());
18 if (!provider_.get())
19 provider_.reset(CreateProvider());
20 }
21
22 ScreenOrientationDispatcherHost::~ScreenOrientationDispatcherHost() {
23 }
24
25 bool ScreenOrientationDispatcherHost::OnMessageReceived(
26 const IPC::Message& message,
27 bool* message_was_ok) {
28 bool handled = true;
29 IPC_BEGIN_MESSAGE_MAP_EX(ScreenOrientationDispatcherHost,
30 message,
31 *message_was_ok)
32 IPC_MESSAGE_HANDLER(ViewHostMsg_LockScreenOrientation, OnLockOrientation)
33 IPC_MESSAGE_HANDLER(ViewHostMsg_UnlockScreenOrientation,
34 OnUnlockOrientation)
35 IPC_MESSAGE_UNHANDLED(handled = false)
36 IPC_END_MESSAGE_MAP_EX()
37 return handled;
38 }
39
40 void ScreenOrientationDispatcherHost::OnLockOrientation(unsigned char lock,
41 bool* result) {
42 if (!provider_.get())
43 return;
44
45 orientation_lock_ =
46 static_cast<ScreenOrientationProvider::Orientations>(lock);
47
48 assert((orientation_lock_ & ScreenOrientationProvider::OrientationAny) == 0);
49
50 // Is it legal to provide empty lock?
51 assert(orientation_lock_);
52
53 *result = provider_->LockOrientation(orientation_lock_);
54 }
55
56 void ScreenOrientationDispatcherHost::OnUnlockOrientation() {
57 if (!provider_.get())
58 return;
59
60 provider_->UnlockOrientation();
61 orientation_lock_ = 0;
62 }
63
64 #if !defined(OS_ANDROID)
65 // static
66 ScreenOrientationProvider* ScreenOrientationDispatcherHost::CreateProvider() {
67 return NULL;
68 }
69 #endif
70 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698