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

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

Issue 2391883006: Mojo-ify implementation of screen orientation locking/unlocking. (Closed)
Patch Set: Ensure correct ordering between ViewMsg_Resize and screen orientation messages Created 4 years, 2 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_ impl.h"
6
7 #include "content/common/screen_orientation_messages.h"
8 #include "content/public/browser/navigation_details.h"
9 #include "content/public/browser/render_frame_host.h"
10 #include "content/public/browser/render_process_host.h"
11 #include "content/public/browser/render_view_host.h"
12 #include "content/public/browser/render_widget_host.h"
13 #include "content/public/browser/screen_orientation_provider.h"
14 #include "content/public/browser/web_contents.h"
15
16 namespace content {
17
18 ScreenOrientationDispatcherHostImpl::LockInformation::LockInformation(
19 int request_id, int process_id, int routing_id)
20 : request_id(request_id),
21 process_id(process_id),
22 routing_id(routing_id) {
23 }
24
25 ScreenOrientationDispatcherHostImpl::ScreenOrientationDispatcherHostImpl(
26 WebContents* web_contents)
27 : WebContentsObserver(web_contents),
28 current_lock_(NULL) {
29 provider_.reset(new ScreenOrientationProvider(this, web_contents));
30 }
31
32 ScreenOrientationDispatcherHostImpl::~ScreenOrientationDispatcherHostImpl() {
33 ResetCurrentLock();
34 }
35
36 void ScreenOrientationDispatcherHostImpl::ResetCurrentLock() {
37 if (current_lock_) {
38 delete current_lock_;
39 current_lock_ = 0;
40 }
41 }
42
43 bool ScreenOrientationDispatcherHostImpl::OnMessageReceived(
44 const IPC::Message& message,
45 RenderFrameHost* render_frame_host) {
46 bool handled = true;
47
48 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(ScreenOrientationDispatcherHostImpl, message,
49 render_frame_host)
50 IPC_MESSAGE_HANDLER(ScreenOrientationHostMsg_LockRequest, OnLockRequest)
51 IPC_MESSAGE_HANDLER(ScreenOrientationHostMsg_Unlock, OnUnlockRequest)
52 IPC_MESSAGE_UNHANDLED(handled = false)
53 IPC_END_MESSAGE_MAP()
54
55 return handled;
56 }
57
58 void ScreenOrientationDispatcherHostImpl::DidNavigateMainFrame(
59 const LoadCommittedDetails& details, const FrameNavigateParams& params) {
60 if (!provider_ || details.is_in_page)
blundell 2016/10/21 18:16:31 It seems like this logic is missing from the new i
lunalu1 2016/10/24 16:57:36 Done.
61 return;
62 provider_->UnlockOrientation();
63 }
64
65 RenderFrameHost*
66 ScreenOrientationDispatcherHostImpl::GetRenderFrameHostForRequestID(
67 int request_id) {
68 if (!current_lock_ || current_lock_->request_id != request_id)
69 return NULL;
70
71 return RenderFrameHost::FromID(current_lock_->process_id,
72 current_lock_->routing_id);
73 }
74
75 void ScreenOrientationDispatcherHostImpl::NotifyLockSuccess(int request_id) {
76 RenderFrameHost* render_frame_host =
77 GetRenderFrameHostForRequestID(request_id);
78 if (!render_frame_host)
79 return;
80
81 render_frame_host->Send(new ScreenOrientationMsg_LockSuccess(
82 render_frame_host->GetRoutingID(), request_id));
83 ResetCurrentLock();
84 }
85
86 void ScreenOrientationDispatcherHostImpl::NotifyLockError(
87 int request_id, blink::WebLockOrientationError error) {
88 RenderFrameHost* render_frame_host =
89 GetRenderFrameHostForRequestID(request_id);
90 if (!render_frame_host)
91 return;
92
93 NotifyLockError(request_id, render_frame_host, error);
94 }
95
96 void ScreenOrientationDispatcherHostImpl::NotifyLockError(
97 int request_id,
98 RenderFrameHost* render_frame_host,
99 blink::WebLockOrientationError error) {
100 render_frame_host->Send(new ScreenOrientationMsg_LockError(
101 render_frame_host->GetRoutingID(), request_id, error));
102 ResetCurrentLock();
103 }
104
105 void ScreenOrientationDispatcherHostImpl::OnOrientationChange() {
106 if (provider_)
107 provider_->OnOrientationChange();
108 }
109
110 void ScreenOrientationDispatcherHostImpl::OnLockRequest(
111 RenderFrameHost* render_frame_host,
112 blink::WebScreenOrientationLockType orientation,
113 int request_id) {
114 if (current_lock_) {
115 NotifyLockError(current_lock_->request_id, render_frame_host,
116 blink::WebLockOrientationErrorCanceled);
117 }
118
119 if (!provider_) {
120 NotifyLockError(request_id, render_frame_host,
121 blink::WebLockOrientationErrorNotAvailable);
122 return;
123 }
124
125 current_lock_ = new LockInformation(request_id,
126 render_frame_host->GetProcess()->GetID(),
127 render_frame_host->GetRoutingID());
128
129 provider_->LockOrientation(request_id, orientation);
130 }
131
132 void ScreenOrientationDispatcherHostImpl::OnUnlockRequest(
133 RenderFrameHost* render_frame_host) {
134 if (current_lock_) {
135 NotifyLockError(current_lock_->request_id, render_frame_host,
136 blink::WebLockOrientationErrorCanceled);
137 }
138
139 if (!provider_)
140 return;
141
142 provider_->UnlockOrientation();
143 }
144
145 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698