OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 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 "chrome/browser/wake_lock/chrome_wake_lock_permission_context.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "chrome/browser/infobars/infobar_service.h" |
| 9 #include "chrome/browser/tab_contents/tab_util.h" |
| 10 #include "chrome/browser/wake_lock/wake_lock_infobar_delegate.h" |
| 11 #include "chrome/browser/wake_lock/wake_lock_preference.h" |
| 12 #include "content/public/browser/browser_thread.h" |
| 13 |
| 14 ChromeWakeLockPermissionContext::ChromeWakeLockPermissionContext( |
| 15 Profile* profile) |
| 16 : profile_(profile), |
| 17 shutting_down_(false) { |
| 18 } |
| 19 |
| 20 ChromeWakeLockPermissionContext::~ChromeWakeLockPermissionContext() { |
| 21 } |
| 22 |
| 23 void ChromeWakeLockPermissionContext::RequestWakeLockPermission( |
| 24 int render_process_id, |
| 25 int render_view_id, |
| 26 const GURL& requesting_frame, |
| 27 WakeLockCallback callback) { |
| 28 GURL requesting_frame_origin = requesting_frame.GetOrigin(); |
| 29 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { |
| 30 content::BrowserThread::PostTask( |
| 31 content::BrowserThread::UI, FROM_HERE, |
| 32 base::Bind( |
| 33 &ChromeWakeLockPermissionContext::RequestWakeLockPermission, |
| 34 this, render_process_id, render_view_id, |
| 35 requesting_frame_origin, callback)); |
| 36 return; |
| 37 } |
| 38 |
| 39 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 40 if (shutting_down_) |
| 41 return; |
| 42 |
| 43 content::WebContents* web_contents = |
| 44 tab_util::GetWebContentsByID(render_process_id, render_view_id); |
| 45 GURL embedder = web_contents->GetLastCommittedURL().GetOrigin(); |
| 46 if (!embedder.is_valid()) { |
| 47 callback.Run(false); |
| 48 return; |
| 49 } |
| 50 |
| 51 scoped_ptr<WakeLockPreference> pref = |
| 52 WakeLockPreference::createWakeLockPreference( |
| 53 render_process_id, render_view_id); |
| 54 if (pref->isSavedAllow(embedder.spec())) { |
| 55 callback.Run(pref->isAllowed(embedder.spec())); |
| 56 return; |
| 57 } |
| 58 |
| 59 WakeLockInfoBarDelegate::Create( |
| 60 InfoBarService::FromWebContents(web_contents), |
| 61 render_process_id, |
| 62 render_view_id, |
| 63 callback); |
| 64 } |
| 65 |
| 66 void ChromeWakeLockPermissionContext::ShutdownOnUIThread() { |
| 67 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 68 shutting_down_ = true; |
| 69 } |
OLD | NEW |