| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/screen_orientation/screen_orientation_dispatcher_host.
h" | 5 #include "content/browser/screen_orientation/screen_orientation_dispatcher_host_
impl.h" |
| 6 | 6 |
| 7 #include "content/browser/screen_orientation/screen_orientation_provider.h" | |
| 8 #include "content/common/screen_orientation_messages.h" | 7 #include "content/common/screen_orientation_messages.h" |
| 9 #include "content/public/browser/render_frame_host.h" | 8 #include "content/public/browser/render_frame_host.h" |
| 10 #include "content/public/browser/render_process_host.h" | 9 #include "content/public/browser/render_process_host.h" |
| 11 #include "content/public/browser/render_view_host.h" | 10 #include "content/public/browser/render_view_host.h" |
| 12 #include "content/public/browser/render_widget_host.h" | 11 #include "content/public/browser/render_widget_host.h" |
| 12 #include "content/public/browser/screen_orientation_provider.h" |
| 13 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
| 14 #include "third_party/WebKit/public/platform/WebScreenInfo.h" | 14 #include "third_party/WebKit/public/platform/WebScreenInfo.h" |
| 15 | 15 |
| 16 namespace content { | 16 namespace content { |
| 17 | 17 |
| 18 ScreenOrientationDispatcherHost::LockInformation::LockInformation( | 18 ScreenOrientationDispatcherHostImpl::LockInformation::LockInformation( |
| 19 int request_id, int process_id, int routing_id) | 19 int request_id, int process_id, int routing_id) |
| 20 : request_id(request_id), | 20 : request_id(request_id), |
| 21 process_id(process_id), | 21 process_id(process_id), |
| 22 routing_id(routing_id) { | 22 routing_id(routing_id) { |
| 23 } | 23 } |
| 24 | 24 |
| 25 ScreenOrientationDispatcherHost::ScreenOrientationDispatcherHost( | 25 ScreenOrientationDispatcherHostImpl::ScreenOrientationDispatcherHostImpl( |
| 26 WebContents* web_contents) | 26 WebContents* web_contents) |
| 27 : WebContentsObserver(web_contents), | 27 : WebContentsObserver(web_contents), |
| 28 current_lock_(NULL) { | 28 current_lock_(NULL) { |
| 29 provider_.reset(ScreenOrientationProvider::Create(this, web_contents)); | 29 provider_.reset(ScreenOrientationProvider::Create(this, web_contents)); |
| 30 } | 30 } |
| 31 | 31 |
| 32 ScreenOrientationDispatcherHost::~ScreenOrientationDispatcherHost() { | 32 ScreenOrientationDispatcherHostImpl::~ScreenOrientationDispatcherHostImpl() { |
| 33 ResetCurrentLock(); | 33 ResetCurrentLock(); |
| 34 } | 34 } |
| 35 | 35 |
| 36 void ScreenOrientationDispatcherHost::ResetCurrentLock() { | 36 void ScreenOrientationDispatcherHostImpl::ResetCurrentLock() { |
| 37 if (current_lock_) { | 37 if (current_lock_) { |
| 38 delete current_lock_; | 38 delete current_lock_; |
| 39 current_lock_ = 0; | 39 current_lock_ = 0; |
| 40 } | 40 } |
| 41 } | 41 } |
| 42 | 42 |
| 43 bool ScreenOrientationDispatcherHost::OnMessageReceived( | 43 bool ScreenOrientationDispatcherHostImpl::OnMessageReceived( |
| 44 const IPC::Message& message, | 44 const IPC::Message& message, |
| 45 RenderFrameHost* render_frame_host) { | 45 RenderFrameHost* render_frame_host) { |
| 46 bool handled = true; | 46 bool handled = true; |
| 47 | 47 |
| 48 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(ScreenOrientationDispatcherHost, message, | 48 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(ScreenOrientationDispatcherHostImpl, message, |
| 49 render_frame_host) | 49 render_frame_host) |
| 50 IPC_MESSAGE_HANDLER(ScreenOrientationHostMsg_LockRequest, OnLockRequest) | 50 IPC_MESSAGE_HANDLER(ScreenOrientationHostMsg_LockRequest, OnLockRequest) |
| 51 IPC_MESSAGE_HANDLER(ScreenOrientationHostMsg_Unlock, OnUnlockRequest) | 51 IPC_MESSAGE_HANDLER(ScreenOrientationHostMsg_Unlock, OnUnlockRequest) |
| 52 IPC_MESSAGE_UNHANDLED(handled = false) | 52 IPC_MESSAGE_UNHANDLED(handled = false) |
| 53 IPC_END_MESSAGE_MAP() | 53 IPC_END_MESSAGE_MAP() |
| 54 | 54 |
| 55 return handled; | 55 return handled; |
| 56 } | 56 } |
| 57 | 57 |
| 58 RenderFrameHost* | 58 RenderFrameHost* |
| 59 ScreenOrientationDispatcherHost::GetRenderFrameHostForRequestID( | 59 ScreenOrientationDispatcherHostImpl::GetRenderFrameHostForRequestID( |
| 60 int request_id) { | 60 int request_id) { |
| 61 if (!current_lock_ || current_lock_->request_id != request_id) | 61 if (!current_lock_ || current_lock_->request_id != request_id) |
| 62 return NULL; | 62 return NULL; |
| 63 | 63 |
| 64 return RenderFrameHost::FromID(current_lock_->process_id, | 64 return RenderFrameHost::FromID(current_lock_->process_id, |
| 65 current_lock_->routing_id); | 65 current_lock_->routing_id); |
| 66 } | 66 } |
| 67 | 67 |
| 68 void ScreenOrientationDispatcherHost::NotifyLockSuccess(int request_id) { | 68 void ScreenOrientationDispatcherHostImpl::NotifyLockSuccess(int request_id) { |
| 69 RenderFrameHost* render_frame_host = | 69 RenderFrameHost* render_frame_host = |
| 70 GetRenderFrameHostForRequestID(request_id); | 70 GetRenderFrameHostForRequestID(request_id); |
| 71 if (!render_frame_host) | 71 if (!render_frame_host) |
| 72 return; | 72 return; |
| 73 | 73 |
| 74 render_frame_host->Send(new ScreenOrientationMsg_LockSuccess( | 74 render_frame_host->Send(new ScreenOrientationMsg_LockSuccess( |
| 75 render_frame_host->GetRoutingID(), request_id)); | 75 render_frame_host->GetRoutingID(), request_id)); |
| 76 ResetCurrentLock(); | 76 ResetCurrentLock(); |
| 77 } | 77 } |
| 78 | 78 |
| 79 void ScreenOrientationDispatcherHost::NotifyLockError( | 79 void ScreenOrientationDispatcherHostImpl::NotifyLockError( |
| 80 int request_id, blink::WebLockOrientationError error) { | 80 int request_id, blink::WebLockOrientationError error) { |
| 81 RenderFrameHost* render_frame_host = | 81 RenderFrameHost* render_frame_host = |
| 82 GetRenderFrameHostForRequestID(request_id); | 82 GetRenderFrameHostForRequestID(request_id); |
| 83 if (!render_frame_host) | 83 if (!render_frame_host) |
| 84 return; | 84 return; |
| 85 | 85 |
| 86 NotifyLockError(request_id, render_frame_host, error); | 86 NotifyLockError(request_id, render_frame_host, error); |
| 87 } | 87 } |
| 88 | 88 |
| 89 void ScreenOrientationDispatcherHost::NotifyLockError( | 89 void ScreenOrientationDispatcherHostImpl::NotifyLockError( |
| 90 int request_id, | 90 int request_id, |
| 91 RenderFrameHost* render_frame_host, | 91 RenderFrameHost* render_frame_host, |
| 92 blink::WebLockOrientationError error) { | 92 blink::WebLockOrientationError error) { |
| 93 render_frame_host->Send(new ScreenOrientationMsg_LockError( | 93 render_frame_host->Send(new ScreenOrientationMsg_LockError( |
| 94 render_frame_host->GetRoutingID(), request_id, error)); | 94 render_frame_host->GetRoutingID(), request_id, error)); |
| 95 ResetCurrentLock(); | 95 ResetCurrentLock(); |
| 96 } | 96 } |
| 97 | 97 |
| 98 void ScreenOrientationDispatcherHost::OnOrientationChange() { | 98 void ScreenOrientationDispatcherHostImpl::OnOrientationChange() { |
| 99 if (provider_) | 99 if (provider_) |
| 100 provider_->OnOrientationChange(); | 100 provider_->OnOrientationChange(); |
| 101 } | 101 } |
| 102 | 102 |
| 103 void ScreenOrientationDispatcherHost::OnLockRequest( | 103 void ScreenOrientationDispatcherHostImpl::OnLockRequest( |
| 104 RenderFrameHost* render_frame_host, | 104 RenderFrameHost* render_frame_host, |
| 105 blink::WebScreenOrientationLockType orientation, | 105 blink::WebScreenOrientationLockType orientation, |
| 106 int request_id) { | 106 int request_id) { |
| 107 if (current_lock_) { | 107 if (current_lock_) { |
| 108 NotifyLockError(current_lock_->request_id, render_frame_host, | 108 NotifyLockError(current_lock_->request_id, render_frame_host, |
| 109 blink::WebLockOrientationErrorCanceled); | 109 blink::WebLockOrientationErrorCanceled); |
| 110 } | 110 } |
| 111 | 111 |
| 112 if (!provider_) { | 112 if (!provider_) { |
| 113 NotifyLockError(request_id, render_frame_host, | 113 NotifyLockError(request_id, render_frame_host, |
| 114 blink::WebLockOrientationErrorNotAvailable); | 114 blink::WebLockOrientationErrorNotAvailable); |
| 115 return; | 115 return; |
| 116 } | 116 } |
| 117 | 117 |
| 118 current_lock_ = new LockInformation(request_id, | 118 current_lock_ = new LockInformation(request_id, |
| 119 render_frame_host->GetProcess()->GetID(), | 119 render_frame_host->GetProcess()->GetID(), |
| 120 render_frame_host->GetRoutingID()); | 120 render_frame_host->GetRoutingID()); |
| 121 | 121 |
| 122 provider_->LockOrientation(request_id, orientation); | 122 provider_->LockOrientation(request_id, orientation); |
| 123 } | 123 } |
| 124 | 124 |
| 125 void ScreenOrientationDispatcherHost::OnUnlockRequest( | 125 void ScreenOrientationDispatcherHostImpl::OnUnlockRequest( |
| 126 RenderFrameHost* render_frame_host) { | 126 RenderFrameHost* render_frame_host) { |
| 127 if (current_lock_) { | 127 if (current_lock_) { |
| 128 NotifyLockError(current_lock_->request_id, render_frame_host, | 128 NotifyLockError(current_lock_->request_id, render_frame_host, |
| 129 blink::WebLockOrientationErrorCanceled); | 129 blink::WebLockOrientationErrorCanceled); |
| 130 } | 130 } |
| 131 | 131 |
| 132 if (!provider_) | 132 if (!provider_) |
| 133 return; | 133 return; |
| 134 | 134 |
| 135 provider_->UnlockOrientation(); | 135 provider_->UnlockOrientation(); |
| 136 } | 136 } |
| 137 | 137 |
| 138 } // namespace content | 138 } // namespace content |
| OLD | NEW |