Chromium Code Reviews| Index: content/browser/wake_lock/wake_lock_dispatcher_host.cc |
| diff --git a/content/browser/wake_lock/wake_lock_dispatcher_host.cc b/content/browser/wake_lock/wake_lock_dispatcher_host.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d314a80e585131ad08af480a7fb5cda31aa31f45 |
| --- /dev/null |
| +++ b/content/browser/wake_lock/wake_lock_dispatcher_host.cc |
| @@ -0,0 +1,71 @@ |
| +// 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/wake_lock/wake_lock_dispatcher_host.h" |
| + |
| +#include "content/browser/renderer_host/render_view_host_impl.h" |
| +#include "content/common/wake_lock_messages.h" |
| +#include "content/public/browser/web_contents.h" |
| + |
| +namespace content { |
| + |
| +WakeLockDispatcherHost::WakeLockDispatcherHost( |
| + WebContents* web_contents) |
| + : WebContentsObserver(web_contents) { |
| +} |
| + |
| +WakeLockDispatcherHost::~WakeLockDispatcherHost() { |
| +} |
| + |
| +bool WakeLockDispatcherHost::OnMessageReceived( |
| + const IPC::Message& message) { |
| + bool handled = true; |
| + |
| + IPC_BEGIN_MESSAGE_MAP(WakeLockDispatcherHost, message) |
| + IPC_MESSAGE_HANDLER(WakeLockViewHostMsg_RequestLock, OnRequestWakeLock) |
| + IPC_MESSAGE_HANDLER(WakeLockViewHostMsg_RequestUnlock, OnRequestWakeUnlock) |
| + IPC_MESSAGE_UNHANDLED(handled = false) |
| + IPC_END_MESSAGE_MAP() |
| + |
| + return handled; |
| +} |
| + |
| +void WakeLockDispatcherHost::OnRequestWakeLock( |
| + const blink::WakeLockRequestInfo& info, |
| + const GURL&) { |
| + // TODO(redchenko): Get permission (infobar). |
| + SendWakeLockPermissionResponse(info, false); |
| +} |
| + |
| +void WakeLockDispatcherHost::OnRequestWakeUnlock( |
| + const blink::WakeLockRequestInfo& info) { |
| + if (RenderViewHost* host = web_contents()->GetRenderViewHost()) { |
| + const int routed_id = host->GetRoutingID(); |
| + // TODO(redchenko): Request to WakeLockManager for real unlock resource |
| + const bool isUnlocked = true; |
| + if (isUnlocked) { |
| + host->Send(new WakeLockViewMsg_UnlockedSuccessful( |
| + routed_id, info.requestId)); |
| + } else { |
| + host->Send(new WakeLockViewMsg_UnlockedFailed( |
| + routed_id, info.requestId)); |
| + } |
| + } |
| +} |
| + |
| +void WakeLockDispatcherHost::SendWakeLockPermissionResponse( |
| + const blink::WakeLockRequestInfo& info, |
| + bool allowed) { |
| + if (RenderViewHost* host = web_contents()->GetRenderViewHost()) { |
| + const int routed_id = host->GetRoutingID(); |
|
mlamouri (slow - plz ping)
2014/09/03 13:20:56
If you use the routing id, shouldn't you use ::OnM
|
| + if (allowed) { |
| + host->Send(new WakeLockViewMsg_LockedSuccessful( |
| + routed_id, info.requestId)); |
| + } else { |
| + host->Send(new WakeLockViewMsg_LockedFailed( |
| + routed_id, info.requestId)); |
| + } |
| + } |
| +} |
| +} // namespace content |