OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/browser/service_worker/service_worker_client_utils.h" | 5 #include "content/browser/service_worker/service_worker_client_utils.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <tuple> | 8 #include <tuple> |
9 | 9 |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 // explicitly activate the window, which brings Chrome to the front. | 169 // explicitly activate the window, which brings Chrome to the front. |
170 static_cast<WebContentsImpl*>(web_contents)->Activate(); | 170 static_cast<WebContentsImpl*>(web_contents)->Activate(); |
171 | 171 |
172 RenderFrameHostImpl* rfhi = | 172 RenderFrameHostImpl* rfhi = |
173 static_cast<RenderFrameHostImpl*>(web_contents->GetMainFrame()); | 173 static_cast<RenderFrameHostImpl*>(web_contents->GetMainFrame()); |
174 new OpenURLObserver(web_contents, | 174 new OpenURLObserver(web_contents, |
175 rfhi->frame_tree_node()->frame_tree_node_id(), callback); | 175 rfhi->frame_tree_node()->frame_tree_node_id(), callback); |
176 } | 176 } |
177 | 177 |
178 void OpenWindowOnUI( | 178 void OpenWindowOnUI( |
| 179 const GURL& redirect_url, |
179 const GURL& url, | 180 const GURL& url, |
180 const GURL& script_url, | 181 const GURL& script_url, |
181 int worker_process_id, | 182 int worker_process_id, |
182 const scoped_refptr<ServiceWorkerContextWrapper>& context_wrapper, | 183 const scoped_refptr<ServiceWorkerContextWrapper>& context_wrapper, |
183 const OpenURLCallback& callback) { | 184 const OpenURLCallback& callback) { |
184 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 185 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
185 | 186 |
186 BrowserContext* browser_context = | 187 BrowserContext* browser_context = |
187 context_wrapper->storage_partition() | 188 context_wrapper->storage_partition() |
188 ? context_wrapper->storage_partition()->browser_context() | 189 ? context_wrapper->storage_partition()->browser_context() |
189 : nullptr; | 190 : nullptr; |
190 // We are shutting down. | 191 // We are shutting down. |
191 if (!browser_context) | 192 if (!browser_context) |
192 return; | 193 return; |
193 | 194 |
194 RenderProcessHost* render_process_host = | 195 RenderProcessHost* render_process_host = |
195 RenderProcessHost::FromID(worker_process_id); | 196 RenderProcessHost::FromID(worker_process_id); |
196 if (render_process_host->IsForGuestsOnly()) { | 197 if (render_process_host->IsForGuestsOnly()) { |
197 BrowserThread::PostTask( | 198 BrowserThread::PostTask( |
198 BrowserThread::IO, FROM_HERE, | 199 BrowserThread::IO, FROM_HERE, |
199 base::Bind(callback, ChildProcessHost::kInvalidUniqueID, | 200 base::Bind(callback, ChildProcessHost::kInvalidUniqueID, |
200 MSG_ROUTING_NONE)); | 201 MSG_ROUTING_NONE)); |
201 return; | 202 return; |
202 } | 203 } |
203 | 204 |
204 OpenURLParams params( | 205 OpenURLParams params( |
205 url, | 206 url, |
206 Referrer::SanitizeForRequest( | 207 Referrer::SanitizeForRequest( |
207 url, Referrer(script_url, blink::kWebReferrerPolicyDefault)), | 208 url, Referrer(script_url, blink::kWebReferrerPolicyDefault)), |
208 WindowOpenDisposition::NEW_FOREGROUND_TAB, | 209 redirect_url.is_valid() ? WindowOpenDisposition::NEW_POPUP |
| 210 : WindowOpenDisposition::NEW_FOREGROUND_TAB, |
209 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, true /* is_renderer_initiated */); | 211 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, true /* is_renderer_initiated */); |
210 | 212 |
| 213 if (redirect_url.is_valid()) { |
| 214 params.redirect_chain.emplace_back(redirect_url); |
| 215 } |
| 216 |
211 GetContentClient()->browser()->OpenURL(browser_context, params, | 217 GetContentClient()->browser()->OpenURL(browser_context, params, |
212 base::Bind(&DidOpenURLOnUI, callback)); | 218 base::Bind(&DidOpenURLOnUI, callback)); |
213 } | 219 } |
214 | 220 |
215 void NavigateClientOnUI(const GURL& url, | 221 void NavigateClientOnUI(const GURL& url, |
216 const GURL& script_url, | 222 const GURL& script_url, |
217 int process_id, | 223 int process_id, |
218 int frame_id, | 224 int frame_id, |
219 const OpenURLCallback& callback) { | 225 const OpenURLCallback& callback) { |
220 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 226 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 433 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
428 DCHECK_EQ(blink::kWebServiceWorkerClientTypeWindow, | 434 DCHECK_EQ(blink::kWebServiceWorkerClientTypeWindow, |
429 provider_host->client_type()); | 435 provider_host->client_type()); |
430 BrowserThread::PostTaskAndReplyWithResult( | 436 BrowserThread::PostTaskAndReplyWithResult( |
431 BrowserThread::UI, FROM_HERE, | 437 BrowserThread::UI, FROM_HERE, |
432 base::Bind(&FocusOnUI, provider_host->process_id(), | 438 base::Bind(&FocusOnUI, provider_host->process_id(), |
433 provider_host->frame_id(), provider_host->client_uuid()), | 439 provider_host->frame_id(), provider_host->client_uuid()), |
434 callback); | 440 callback); |
435 } | 441 } |
436 | 442 |
437 void OpenWindow(const GURL& url, | 443 void OpenWindow(const GURL& redirect_url, |
| 444 const GURL& url, |
438 const GURL& script_url, | 445 const GURL& script_url, |
439 int worker_process_id, | 446 int worker_process_id, |
440 const base::WeakPtr<ServiceWorkerContextCore>& context, | 447 const base::WeakPtr<ServiceWorkerContextCore>& context, |
441 const NavigationCallback& callback) { | 448 const NavigationCallback& callback) { |
442 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 449 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
443 BrowserThread::PostTask( | 450 BrowserThread::PostTask( |
444 BrowserThread::UI, FROM_HERE, | 451 BrowserThread::UI, FROM_HERE, |
445 base::Bind( | 452 base::Bind( |
446 &OpenWindowOnUI, url, script_url, worker_process_id, | 453 &OpenWindowOnUI, redirect_url, url, script_url, worker_process_id, |
447 make_scoped_refptr(context->wrapper()), | 454 make_scoped_refptr(context->wrapper()), |
448 base::Bind(&DidNavigate, context, script_url.GetOrigin(), callback))); | 455 base::Bind(&DidNavigate, context, script_url.GetOrigin(), callback))); |
449 } | 456 } |
450 | 457 |
451 void NavigateClient(const GURL& url, | 458 void NavigateClient(const GURL& url, |
452 const GURL& script_url, | 459 const GURL& script_url, |
453 int process_id, | 460 int process_id, |
454 int frame_id, | 461 int frame_id, |
455 const base::WeakPtr<ServiceWorkerContextCore>& context, | 462 const base::WeakPtr<ServiceWorkerContextCore>& context, |
456 const NavigationCallback& callback) { | 463 const NavigationCallback& callback) { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 GetWindowClients(controller, options, callback); | 514 GetWindowClients(controller, options, callback); |
508 return; | 515 return; |
509 } | 516 } |
510 | 517 |
511 GetNonWindowClients(controller, options, &clients); | 518 GetNonWindowClients(controller, options, &clients); |
512 DidGetClients(callback, &clients); | 519 DidGetClients(callback, &clients); |
513 } | 520 } |
514 | 521 |
515 } // namespace service_worker_client_utils | 522 } // namespace service_worker_client_utils |
516 } // namespace content | 523 } // namespace content |
OLD | NEW |