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 | 37 |
39 layout_test_notification_manager_.reset( | 38 layout_test_notification_manager_.reset( |
40 new LayoutTestNotificationManager()); | 39 new LayoutTestNotificationManager()); |
41 | 40 |
(...skipping 21 matching lines...) Expand all Loading... |
63 BrowserContext::GetDefaultStoragePartition(browser_context()); | 62 BrowserContext::GetDefaultStoragePartition(browser_context()); |
64 host->AddFilter(new LayoutTestMessageFilter( | 63 host->AddFilter(new LayoutTestMessageFilter( |
65 host->GetID(), | 64 host->GetID(), |
66 partition->GetDatabaseTracker(), | 65 partition->GetDatabaseTracker(), |
67 partition->GetQuotaManager(), | 66 partition->GetQuotaManager(), |
68 partition->GetURLRequestContext())); | 67 partition->GetURLRequestContext())); |
69 | 68 |
70 host->Send(new ShellViewMsg_SetWebKitSourceDir(GetWebKitRootDirFilePath())); | 69 host->Send(new ShellViewMsg_SetWebKitSourceDir(GetWebKitRootDirFilePath())); |
71 } | 70 } |
72 | 71 |
73 void LayoutTestContentBrowserClient::RequestDesktopNotificationPermission( | 72 void LayoutTestContentBrowserClient::RequestPermission( |
74 const GURL& source_origin, | 73 PermissionType permission, |
75 RenderFrameHost* render_frame_host, | 74 WebContents* web_contents, |
76 const base::Callback<void(blink::WebNotificationPermission)>& callback) { | 75 int bridge_id, |
77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 76 const GURL& requesting_frame, |
78 BrowserThread::PostTask(BrowserThread::IO, | 77 bool user_gesture, |
79 FROM_HERE, | 78 const base::Callback<void(bool)>& result_callback) { |
80 base::Bind(&RequestDesktopNotificationPermissionOnIO, | 79 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
81 source_origin, | 80 if (permission == content::PERMISSION_NOTIFICATIONS) { |
82 render_frame_host, | 81 BrowserThread::PostTask( |
83 callback)); | 82 BrowserThread::IO, |
| 83 FROM_HERE, |
| 84 base::Bind(&RequestDesktopNotificationPermissionOnIO, |
| 85 requesting_frame, |
| 86 result_callback)); |
| 87 return; |
| 88 } |
| 89 ShellContentBrowserClient::RequestPermission(permission, |
| 90 web_contents, |
| 91 bridge_id, |
| 92 requesting_frame, |
| 93 user_gesture, |
| 94 result_callback); |
84 } | 95 } |
85 | 96 |
86 blink::WebNotificationPermission | 97 blink::WebNotificationPermission |
87 LayoutTestContentBrowserClient::CheckDesktopNotificationPermission( | 98 LayoutTestContentBrowserClient::CheckDesktopNotificationPermission( |
88 const GURL& source_url, | 99 const GURL& source_url, |
89 ResourceContext* context, | 100 ResourceContext* context, |
90 int render_process_id) { | 101 int render_process_id) { |
91 LayoutTestNotificationManager* manager = GetLayoutTestNotificationManager(); | 102 LayoutTestNotificationManager* manager = GetLayoutTestNotificationManager(); |
92 if (manager) | 103 if (manager) |
93 return manager->CheckPermission(source_url); | 104 return manager->CheckPermission(source_url); |
94 | 105 |
95 return blink::WebNotificationPermissionAllowed; | 106 return blink::WebNotificationPermissionAllowed; |
96 } | 107 } |
97 | 108 |
98 void LayoutTestContentBrowserClient::ShowDesktopNotification( | 109 void LayoutTestContentBrowserClient::ShowDesktopNotification( |
99 const ShowDesktopNotificationHostMsgParams& params, | 110 const ShowDesktopNotificationHostMsgParams& params, |
100 RenderFrameHost* render_frame_host, | 111 RenderFrameHost* render_frame_host, |
101 scoped_ptr<DesktopNotificationDelegate> delegate, | 112 scoped_ptr<DesktopNotificationDelegate> delegate, |
102 base::Closure* cancel_callback) { | 113 base::Closure* cancel_callback) { |
103 if (auto* manager = GetLayoutTestNotificationManager()) | 114 if (auto* manager = GetLayoutTestNotificationManager()) |
104 manager->Show(params, delegate.Pass(), cancel_callback); | 115 manager->Show(params, delegate.Pass(), cancel_callback); |
105 } | 116 } |
106 | 117 |
107 } // namespace content | 118 } // namespace content |
OLD | NEW |