| 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..5bc6f16ab639948170dd328148341b5d93af70e8
|
| --- /dev/null
|
| +++ b/content/browser/wake_lock/wake_lock_dispatcher_host.cc
|
| @@ -0,0 +1,86 @@
|
| +// Copyright (c) 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 "base/bind.h"
|
| +#include "content/browser/renderer_host/render_view_host_impl.h"
|
| +#include "content/browser/wake_lock/wake_lock_manager.h"
|
| +#include "content/browser/wake_lock/wake_lock_web_contents_observer.h"
|
| +#include "content/common/wake_lock_messages.h"
|
| +#include "content/public/browser/wake_lock_permission_context.h"
|
| +
|
| +namespace content {
|
| +
|
| +void SendWakeLockPermissionResponse(int render_process_id,
|
| + int routed_id,
|
| + bool allowed) {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| + RenderViewHostImpl* render_view_host =
|
| + RenderViewHostImpl::FromID(render_process_id, routed_id);
|
| + if (!render_view_host)
|
| + return;
|
| + if (allowed) {
|
| + WakeLockManager::GetInstance()->createWebContentsObserver(
|
| + render_process_id, routed_id);
|
| + WakeLockManager::GetInstance()->createScreenLock(
|
| + render_process_id, routed_id);
|
| + render_view_host->Send(
|
| + new WakeLockScreenViewMsg_LockedSuccessful(routed_id));
|
| + } else {
|
| + render_view_host->Send(
|
| + new WakeLockScreenViewMsg_LockedFailed(routed_id));
|
| + }
|
| +}
|
| +
|
| +WakeLockDispatcherHost::WakeLockDispatcherHost(
|
| + int render_process_id, WakeLockPermissionContext* wakelock_context)
|
| + : content::BrowserMessageFilter(WakeLockMsgStart),
|
| + render_process_id_(render_process_id),
|
| + wakelock_permission_context_(wakelock_context) {
|
| +}
|
| +
|
| +WakeLockDispatcherHost::~WakeLockDispatcherHost() {
|
| +}
|
| +
|
| +bool WakeLockDispatcherHost::OnMessageReceived(const IPC::Message& message) {
|
| + bool handled = true;
|
| + IPC_BEGIN_MESSAGE_MAP(WakeLockDispatcherHost, message)
|
| + static_cast<void>(param__);
|
| + IPC_MESSAGE_HANDLER_GENERIC(WakeLockScreenViewHostMsg_RequestLock,
|
| + OnRequestWakeLockScreen(message.routing_id()))
|
| + IPC_MESSAGE_HANDLER_GENERIC(WakeLockScreenViewHostMsg_RequestUnlock,
|
| + OnRequestWakeUnlockScreen(message.routing_id()))
|
| + IPC_MESSAGE_UNHANDLED(handled = false)
|
| + IPC_END_MESSAGE_MAP()
|
| + return handled;
|
| +}
|
| +
|
| +void WakeLockDispatcherHost::OnRequestWakeLockScreen(int routed_id) {
|
| + GURL requesting_frame;
|
| + if (wakelock_permission_context_.get()) {
|
| + wakelock_permission_context_->RequestWakeLockPermission(
|
| + render_process_id_,
|
| + routed_id,
|
| + requesting_frame,
|
| + base::Bind(&SendWakeLockPermissionResponse,
|
| + render_process_id_,
|
| + routed_id));
|
| + } else {
|
| + BrowserThread::PostTask(
|
| + BrowserThread::UI, FROM_HERE,
|
| + base::Bind(&SendWakeLockPermissionResponse, render_process_id_,
|
| + routed_id, true));
|
| + }
|
| +}
|
| +
|
| +void WakeLockDispatcherHost::OnRequestWakeUnlockScreen(int routed_id) {
|
| + bool isUnlocked = WakeLockManager::GetInstance()->releaseScreenLock(
|
| + render_process_id_, routed_id);
|
| + if (isUnlocked)
|
| + Send(new WakeLockScreenViewMsg_UnlockedSuccessful(routed_id));
|
| + else
|
| + Send(new WakeLockScreenViewMsg_UnlockedFailed(routed_id));
|
| +}
|
| +}
|
|
|