Chromium Code Reviews| OLD | NEW |
|---|---|
| (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/wake_lock/wake_lock_dispatcher_host.h" | |
| 6 | |
| 7 #include "content/browser/renderer_host/render_view_host_impl.h" | |
| 8 #include "content/common/wake_lock_messages.h" | |
| 9 #include "content/public/browser/web_contents.h" | |
| 10 | |
| 11 namespace content { | |
| 12 | |
| 13 WakeLockDispatcherHost::WakeLockDispatcherHost( | |
| 14 WebContents* web_contents) | |
| 15 : WebContentsObserver(web_contents) { | |
| 16 } | |
| 17 | |
| 18 WakeLockDispatcherHost::~WakeLockDispatcherHost() { | |
| 19 } | |
| 20 | |
| 21 bool WakeLockDispatcherHost::OnMessageReceived( | |
| 22 const IPC::Message& message) { | |
| 23 bool handled = true; | |
| 24 | |
| 25 IPC_BEGIN_MESSAGE_MAP(WakeLockDispatcherHost, message) | |
| 26 IPC_MESSAGE_HANDLER(WakeLockViewHostMsg_RequestLock, OnRequestWakeLock) | |
| 27 IPC_MESSAGE_HANDLER(WakeLockViewHostMsg_RequestUnlock, OnRequestWakeUnlock) | |
| 28 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 29 IPC_END_MESSAGE_MAP() | |
| 30 | |
| 31 return handled; | |
| 32 } | |
| 33 | |
| 34 void WakeLockDispatcherHost::OnRequestWakeLock( | |
| 35 const blink::WakeLockRequestInfo& info, | |
| 36 const GURL&) { | |
| 37 // TODO(redchenko): Get permission (infobar). | |
| 38 SendWakeLockPermissionResponse(info, false); | |
| 39 } | |
| 40 | |
| 41 void WakeLockDispatcherHost::OnRequestWakeUnlock( | |
| 42 const blink::WakeLockRequestInfo& info) { | |
| 43 if (RenderViewHost* host = web_contents()->GetRenderViewHost()) { | |
| 44 const int routed_id = host->GetRoutingID(); | |
| 45 // TODO(redchenko): Request to WakeLockManager for real unlock resource | |
| 46 const bool isUnlocked = true; | |
| 47 if (isUnlocked) { | |
| 48 host->Send(new WakeLockViewMsg_UnlockedSuccessful( | |
| 49 routed_id, info.requestId)); | |
| 50 } else { | |
| 51 host->Send(new WakeLockViewMsg_UnlockedFailed( | |
| 52 routed_id, info.requestId)); | |
| 53 } | |
| 54 } | |
| 55 } | |
| 56 | |
| 57 void WakeLockDispatcherHost::SendWakeLockPermissionResponse( | |
| 58 const blink::WakeLockRequestInfo& info, | |
| 59 bool allowed) { | |
| 60 if (RenderViewHost* host = web_contents()->GetRenderViewHost()) { | |
| 61 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
| |
| 62 if (allowed) { | |
| 63 host->Send(new WakeLockViewMsg_LockedSuccessful( | |
| 64 routed_id, info.requestId)); | |
| 65 } else { | |
| 66 host->Send(new WakeLockViewMsg_LockedFailed( | |
| 67 routed_id, info.requestId)); | |
| 68 } | |
| 69 } | |
| 70 } | |
| 71 } // namespace content | |
| OLD | NEW |