1a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved. 2a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 3a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// found in the LICENSE file. 4a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 5a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#ifndef CONTENT_BROWSER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_PROVIDER_ANDROID_H_ 6a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#define CONTENT_BROWSER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_PROVIDER_ANDROID_H_ 7a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 85f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include <jni.h> 95f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 10a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "base/compiler_specific.h" 111320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "content/public/browser/screen_orientation_provider.h" 12116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "content/public/browser/web_contents_observer.h" 13a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 14a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)namespace content { 15a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 161320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass ScreenOrientationDispatcherHost; 17116680a4aac90f2aa7413d9095a592090648e557Ben Murdochclass WebContentsImpl; 18116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 19116680a4aac90f2aa7413d9095a592090648e557Ben Murdochclass ScreenOrientationProviderAndroid : public ScreenOrientationProvider, 20116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch public WebContentsObserver { 21a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) public: 22116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch explicit ScreenOrientationProviderAndroid( 23116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch ScreenOrientationDispatcherHost* dispatcher, 24116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch WebContents* web_contents); 25a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 26a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) static bool Register(JNIEnv* env); 27a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 28a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // ScreenOrientationProvider 29116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual void LockOrientation(int request_id, 30116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch blink::WebScreenOrientationLockType) OVERRIDE; 31a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual void UnlockOrientation() OVERRIDE; 32116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual void OnOrientationChange() OVERRIDE; 33116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 34116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // WebContentsObserver 35116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual void DidToggleFullscreenModeForTab(bool entered_fullscreen) OVERRIDE; 36a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 376e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // Ask the ScreenOrientationListener (Java) to start accurately listening to 386e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // the screen orientation. It keep track of the number of start request if it 396e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // is already running an accurate listening. 406e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) static void StartAccurateListening(); 416e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 426e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // Ask the ScreenOrientationListener (Java) to stop accurately listening to 436e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // the screen orientation. It will actually stop only if the number of stop 446e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // requests matches the number of start requests. 456e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) static void StopAccurateListening(); 466e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 47a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) private: 48116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch WebContentsImpl* web_contents_impl(); 49116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 50116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // Whether the passed |lock| matches the current orientation. In other words, 51116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // whether the orientation will need to change to match the |lock|. 52116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch bool LockMatchesCurrentOrientation(blink::WebScreenOrientationLockType lock); 53116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 54116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // Returns the lock type that should be associated with 'natural' lock. 55116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // Returns WebScreenOrientationLockDefault if the natural lock type can't be 56116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // found. 57116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch blink::WebScreenOrientationLockType GetNaturalLockType() const; 58116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 59a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual ~ScreenOrientationProviderAndroid(); 60a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 61116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // ScreenOrientationDispatcherHost owns ScreenOrientationProvider so 62116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // dispatcher_ should not point to an invalid memory. 63116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch ScreenOrientationDispatcherHost* dispatcher_; 64116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 65116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // Whether the ScreenOrientationProvider currently has a lock applied. 66116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch bool lock_applied_; 67116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 68116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch struct LockInformation { 69116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch LockInformation(int request_id, blink::WebScreenOrientationLockType lock); 70116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch int request_id; 71116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch blink::WebScreenOrientationLockType lock; 72116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch }; 73116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch LockInformation* pending_lock_; 74116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 75a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(ScreenOrientationProviderAndroid); 76a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}; 77a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 78a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} // namespace content 79a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 80a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#endif // CONTENT_BROWSER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_PROVIDER_ANDROID_H_ 81