Chromium Code Reviews| 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/shell/browser/layout_test/layout_test_content_browser_client.h " | 5 #include "content/shell/browser/layout_test/layout_test_content_browser_client.h " |
| 6 | 6 |
| 7 #include "content/public/browser/browser_context.h" | 7 #include "content/public/browser/browser_context.h" |
| 8 #include "content/public/browser/browser_thread.h" | 8 #include "content/public/browser/browser_thread.h" |
| 9 #include "content/public/browser/render_process_host.h" | 9 #include "content/public/browser/render_process_host.h" |
| 10 #include "content/public/browser/storage_partition.h" | 10 #include "content/public/browser/storage_partition.h" |
| 11 #include "content/shell/browser/layout_test/layout_test_message_filter.h" | 11 #include "content/shell/browser/layout_test/layout_test_message_filter.h" |
| 12 #include "content/shell/browser/layout_test/layout_test_notification_manager.h" | 12 #include "content/shell/browser/layout_test/layout_test_notification_manager.h" |
| 13 #include "content/shell/browser/shell_browser_context.h" | 13 #include "content/shell/browser/shell_browser_context.h" |
| 14 #include "content/shell/common/shell_messages.h" | 14 #include "content/shell/common/shell_messages.h" |
| 15 #include "content/shell/common/webkit_test_helpers.h" | 15 #include "content/shell/common/webkit_test_helpers.h" |
| 16 | 16 |
| 17 namespace content { | 17 namespace content { |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 LayoutTestContentBrowserClient* g_layout_test_browser_client; | 20 LayoutTestContentBrowserClient* g_layout_test_browser_client; |
| 21 | 21 |
| 22 void RequestDesktopNotificationPermissionOnIO( | 22 void RequestDesktopNotificationPermissionOnIO( |
| 23 const GURL& source_origin, | 23 const GURL& source_origin, |
| 24 RenderFrameHost* render_frame_host, | 24 const base::Callback<void(bool)>& callback) { |
| 25 const base::Callback<void(blink::WebNotificationPermission)>& callback) { | |
| 26 LayoutTestNotificationManager* manager = | 25 LayoutTestNotificationManager* manager = |
| 27 LayoutTestContentBrowserClient::Get()->GetLayoutTestNotificationManager(); | 26 LayoutTestContentBrowserClient::Get()->GetLayoutTestNotificationManager(); |
| 28 if (manager) | 27 if (manager) |
| 29 manager->RequestPermission(source_origin, callback); | 28 manager->RequestPermission(source_origin, callback); |
| 30 else | 29 else |
| 31 callback.Run(blink::WebNotificationPermissionAllowed); | 30 callback.Run(true); |
| 32 } | 31 } |
| 33 | 32 |
| 34 } // namespace | 33 } // namespace |
| 35 | 34 |
| 36 LayoutTestContentBrowserClient::LayoutTestContentBrowserClient() { | 35 LayoutTestContentBrowserClient::LayoutTestContentBrowserClient() { |
| 37 DCHECK(!g_layout_test_browser_client); | 36 DCHECK(!g_layout_test_browser_client); |
| 38 g_layout_test_browser_client = this; | 37 g_layout_test_browser_client = this; |
| 39 } | 38 } |
| 40 | 39 |
| 41 LayoutTestContentBrowserClient::~LayoutTestContentBrowserClient() { | 40 LayoutTestContentBrowserClient::~LayoutTestContentBrowserClient() { |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 65 BrowserContext::GetDefaultStoragePartition(browser_context()); | 64 BrowserContext::GetDefaultStoragePartition(browser_context()); |
| 66 host->AddFilter(new LayoutTestMessageFilter( | 65 host->AddFilter(new LayoutTestMessageFilter( |
| 67 host->GetID(), | 66 host->GetID(), |
| 68 partition->GetDatabaseTracker(), | 67 partition->GetDatabaseTracker(), |
| 69 partition->GetQuotaManager(), | 68 partition->GetQuotaManager(), |
| 70 partition->GetURLRequestContext())); | 69 partition->GetURLRequestContext())); |
| 71 | 70 |
| 72 host->Send(new ShellViewMsg_SetWebKitSourceDir(GetWebKitRootDirFilePath())); | 71 host->Send(new ShellViewMsg_SetWebKitSourceDir(GetWebKitRootDirFilePath())); |
| 73 } | 72 } |
| 74 | 73 |
| 75 void LayoutTestContentBrowserClient::RequestDesktopNotificationPermission( | 74 void LayoutTestContentBrowserClient::RequestPermission( |
| 76 const GURL& source_origin, | 75 PermissionType permission, |
| 77 RenderFrameHost* render_frame_host, | 76 WebContents* web_contents, |
| 78 const base::Callback<void(blink::WebNotificationPermission)>& callback) { | 77 int bridge_id, |
| 79 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 78 const GURL& requesting_frame, |
| 80 BrowserThread::PostTask(BrowserThread::IO, | 79 bool user_gesture, |
| 81 FROM_HERE, | 80 const base::Callback<void(bool)>& result_callback) { |
| 82 base::Bind(&RequestDesktopNotificationPermissionOnIO, | 81 if (permission == content::PERMISSION_NOTIFICATIONS) { |
| 83 source_origin, | 82 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
|
Peter Beverloo
2014/10/24 14:37:28
Lift this DCHECK up one level higher please. It'd
Miguel Garcia
2014/10/24 16:05:32
Done.
| |
| 84 render_frame_host, | 83 BrowserThread::PostTask( |
| 85 callback)); | 84 BrowserThread::IO, |
| 85 FROM_HERE, | |
| 86 base::Bind(&RequestDesktopNotificationPermissionOnIO, | |
| 87 requesting_frame, | |
| 88 result_callback)); | |
| 89 return; | |
| 90 } | |
| 91 ShellContentBrowserClient::RequestPermission(permission, | |
| 92 web_contents, | |
| 93 bridge_id, | |
| 94 requesting_frame, | |
| 95 user_gesture, | |
| 96 result_callback); | |
| 86 } | 97 } |
| 87 | 98 |
| 88 blink::WebNotificationPermission | 99 blink::WebNotificationPermission |
| 89 LayoutTestContentBrowserClient::CheckDesktopNotificationPermission( | 100 LayoutTestContentBrowserClient::CheckDesktopNotificationPermission( |
| 90 const GURL& source_url, | 101 const GURL& source_url, |
| 91 ResourceContext* context, | 102 ResourceContext* context, |
| 92 int render_process_id) { | 103 int render_process_id) { |
| 93 LayoutTestNotificationManager* manager = GetLayoutTestNotificationManager(); | 104 LayoutTestNotificationManager* manager = GetLayoutTestNotificationManager(); |
| 94 if (manager) | 105 if (manager) |
| 95 return manager->CheckPermission(source_url); | 106 return manager->CheckPermission(source_url); |
| 96 | 107 |
| 97 return blink::WebNotificationPermissionAllowed; | 108 return blink::WebNotificationPermissionAllowed; |
| 98 } | 109 } |
| 99 | 110 |
| 100 } // namespace content | 111 } // namespace content |
| OLD | NEW |