OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/ui/browser_navigator.h" | 5 #include "chrome/browser/ui/browser_navigator.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 19 matching lines...) Expand all Loading... | |
30 #include "chrome/browser/ui/singleton_tabs.h" | 30 #include "chrome/browser/ui/singleton_tabs.h" |
31 #include "chrome/browser/ui/status_bubble.h" | 31 #include "chrome/browser/ui/status_bubble.h" |
32 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 32 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
33 #include "chrome/browser/web_applications/web_app.h" | 33 #include "chrome/browser/web_applications/web_app.h" |
34 #include "chrome/common/extensions/extension.h" | 34 #include "chrome/common/extensions/extension.h" |
35 #include "chrome/common/pref_names.h" | 35 #include "chrome/common/pref_names.h" |
36 #include "chrome/common/url_constants.h" | 36 #include "chrome/common/url_constants.h" |
37 #include "content/public/browser/browser_url_handler.h" | 37 #include "content/public/browser/browser_url_handler.h" |
38 #include "content/public/browser/notification_service.h" | 38 #include "content/public/browser/notification_service.h" |
39 #include "content/public/browser/render_view_host.h" | 39 #include "content/public/browser/render_view_host.h" |
40 #include "content/public/browser/site_instance.h" | |
40 #include "content/public/browser/web_contents.h" | 41 #include "content/public/browser/web_contents.h" |
41 #include "content/public/browser/web_contents_view.h" | 42 #include "content/public/browser/web_contents_view.h" |
42 | 43 |
43 #if defined(USE_AURA) | 44 #if defined(USE_AURA) |
44 #include "ui/aura/window.h" | 45 #include "ui/aura/window.h" |
45 #endif | 46 #endif |
46 | 47 |
47 using content::GlobalRequestID; | 48 using content::GlobalRequestID; |
48 using content::WebContents; | 49 using content::WebContents; |
49 | 50 |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
310 chrome::NavigateParams* params_; | 311 chrome::NavigateParams* params_; |
311 scoped_ptr<WebContents> target_contents_owner_; | 312 scoped_ptr<WebContents> target_contents_owner_; |
312 DISALLOW_COPY_AND_ASSIGN(ScopedTargetContentsOwner); | 313 DISALLOW_COPY_AND_ASSIGN(ScopedTargetContentsOwner); |
313 }; | 314 }; |
314 | 315 |
315 content::WebContents* CreateTargetContents(const chrome::NavigateParams& params, | 316 content::WebContents* CreateTargetContents(const chrome::NavigateParams& params, |
316 const GURL& url) { | 317 const GURL& url) { |
317 WebContents::CreateParams create_params( | 318 WebContents::CreateParams create_params( |
318 params.browser->profile(), | 319 params.browser->profile(), |
319 tab_util::GetSiteInstanceForNewTab(params.browser->profile(), url)); | 320 tab_util::GetSiteInstanceForNewTab(params.browser->profile(), url)); |
321 | |
322 // If we want to set the opener, we need to use the same SiteInstance. | |
Charlie Reis
2013/07/30 01:26:30
I'm skeptical about this, since it shouldn't alway
jochen (gone - plz use gerrit)
2013/07/30 14:50:39
The popup needs to be in the same process as the o
Charlie Reis
2013/07/31 17:16:16
That's not true. Creating opener RVHs allows it t
| |
323 if (params.source_contents && params.should_set_opener) | |
324 create_params.site_instance = params.source_contents->GetSiteInstance(); | |
320 if (params.source_contents) { | 325 if (params.source_contents) { |
321 create_params.initial_size = | 326 create_params.initial_size = |
322 params.source_contents->GetView()->GetContainerSize(); | 327 params.source_contents->GetView()->GetContainerSize(); |
323 } | 328 } |
329 if (params.source_contents && params.should_copy_session_storage_namespace) { | |
330 // To clone the session storage namespace, we need a site instance. | |
331 if (!create_params.site_instance) { | |
332 create_params.site_instance = | |
333 content::SiteInstance::CreateForURL(params.browser->profile(), url); | |
334 } | |
335 } | |
324 #if defined(USE_AURA) | 336 #if defined(USE_AURA) |
325 if (params.browser->window() && | 337 if (params.browser->window() && |
326 params.browser->window()->GetNativeWindow()) { | 338 params.browser->window()->GetNativeWindow()) { |
327 create_params.context = | 339 create_params.context = |
328 params.browser->window()->GetNativeWindow(); | 340 params.browser->window()->GetNativeWindow(); |
329 } | 341 } |
330 #endif | 342 #endif |
343 WebContents* target_contents; | |
344 if (params.source_contents && | |
345 (params.should_set_opener || | |
346 params.should_copy_session_storage_namespace)) { | |
347 DCHECK(!params.should_set_opener || | |
Bernhard Bauer
2013/07/30 08:34:50
Wait, you have here
if (a || b) {
DCHECK(!a
| |
348 params.should_copy_session_storage_namespace); | |
349 target_contents = WebContents::CreateWithOpener( | |
350 create_params, params.source_contents, params.should_set_opener); | |
351 } else { | |
352 target_contents = WebContents::Create(create_params); | |
353 } | |
331 | 354 |
332 content::WebContents* target_contents = WebContents::Create(create_params); | |
333 // New tabs can have WebUI URLs that will make calls back to arbitrary | 355 // New tabs can have WebUI URLs that will make calls back to arbitrary |
334 // tab helpers, so the entire set of tab helpers needs to be set up | 356 // tab helpers, so the entire set of tab helpers needs to be set up |
335 // immediately. | 357 // immediately. |
336 BrowserNavigatorWebContentsAdoption::AttachTabHelpers(target_contents); | 358 BrowserNavigatorWebContentsAdoption::AttachTabHelpers(target_contents); |
337 extensions::TabHelper::FromWebContents(target_contents)-> | 359 extensions::TabHelper::FromWebContents(target_contents)-> |
338 SetExtensionAppById(params.extension_app_id); | 360 SetExtensionAppById(params.extension_app_id); |
339 // TODO(sky): Figure out why this is needed. Without it we seem to get | 361 // TODO(sky): Figure out why this is needed. Without it we seem to get |
340 // failures in startup tests. | 362 // failures in startup tests. |
341 // By default, content believes it is not hidden. When adding contents | 363 // By default, content believes it is not hidden. When adding contents |
342 // in the background, tell it that it's hidden. | 364 // in the background, tell it that it's hidden. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
386 is_renderer_initiated(false), | 408 is_renderer_initiated(false), |
387 tabstrip_index(-1), | 409 tabstrip_index(-1), |
388 tabstrip_add_types(TabStripModel::ADD_ACTIVE), | 410 tabstrip_add_types(TabStripModel::ADD_ACTIVE), |
389 window_action(NO_ACTION), | 411 window_action(NO_ACTION), |
390 user_gesture(true), | 412 user_gesture(true), |
391 path_behavior(RESPECT), | 413 path_behavior(RESPECT), |
392 ref_behavior(IGNORE_REF), | 414 ref_behavior(IGNORE_REF), |
393 browser(a_browser), | 415 browser(a_browser), |
394 initiating_profile(NULL), | 416 initiating_profile(NULL), |
395 host_desktop_type(GetHostDesktop(a_browser)), | 417 host_desktop_type(GetHostDesktop(a_browser)), |
396 should_replace_current_entry(false) { | 418 should_replace_current_entry(false), |
419 should_copy_session_storage_namespace(false), | |
420 should_set_opener(false) { | |
397 } | 421 } |
398 | 422 |
399 NavigateParams::NavigateParams(Browser* a_browser, | 423 NavigateParams::NavigateParams(Browser* a_browser, |
400 WebContents* a_target_contents) | 424 WebContents* a_target_contents) |
401 : target_contents(a_target_contents), | 425 : target_contents(a_target_contents), |
402 source_contents(NULL), | 426 source_contents(NULL), |
403 disposition(CURRENT_TAB), | 427 disposition(CURRENT_TAB), |
404 transition(content::PAGE_TRANSITION_LINK), | 428 transition(content::PAGE_TRANSITION_LINK), |
405 is_renderer_initiated(false), | 429 is_renderer_initiated(false), |
406 tabstrip_index(-1), | 430 tabstrip_index(-1), |
407 tabstrip_add_types(TabStripModel::ADD_ACTIVE), | 431 tabstrip_add_types(TabStripModel::ADD_ACTIVE), |
408 window_action(NO_ACTION), | 432 window_action(NO_ACTION), |
409 user_gesture(true), | 433 user_gesture(true), |
410 path_behavior(RESPECT), | 434 path_behavior(RESPECT), |
411 ref_behavior(IGNORE_REF), | 435 ref_behavior(IGNORE_REF), |
412 browser(a_browser), | 436 browser(a_browser), |
413 initiating_profile(NULL), | 437 initiating_profile(NULL), |
414 host_desktop_type(GetHostDesktop(a_browser)), | 438 host_desktop_type(GetHostDesktop(a_browser)), |
415 should_replace_current_entry(false) { | 439 should_replace_current_entry(false), |
440 should_copy_session_storage_namespace(false), | |
441 should_set_opener(false) { | |
416 } | 442 } |
417 | 443 |
418 NavigateParams::NavigateParams(Profile* a_profile, | 444 NavigateParams::NavigateParams(Profile* a_profile, |
419 const GURL& a_url, | 445 const GURL& a_url, |
420 content::PageTransition a_transition) | 446 content::PageTransition a_transition) |
421 : url(a_url), | 447 : url(a_url), |
422 target_contents(NULL), | 448 target_contents(NULL), |
423 source_contents(NULL), | 449 source_contents(NULL), |
424 disposition(NEW_FOREGROUND_TAB), | 450 disposition(NEW_FOREGROUND_TAB), |
425 transition(a_transition), | 451 transition(a_transition), |
426 is_renderer_initiated(false), | 452 is_renderer_initiated(false), |
427 tabstrip_index(-1), | 453 tabstrip_index(-1), |
428 tabstrip_add_types(TabStripModel::ADD_ACTIVE), | 454 tabstrip_add_types(TabStripModel::ADD_ACTIVE), |
429 window_action(SHOW_WINDOW), | 455 window_action(SHOW_WINDOW), |
430 user_gesture(true), | 456 user_gesture(true), |
431 path_behavior(RESPECT), | 457 path_behavior(RESPECT), |
432 ref_behavior(IGNORE_REF), | 458 ref_behavior(IGNORE_REF), |
433 browser(NULL), | 459 browser(NULL), |
434 initiating_profile(a_profile), | 460 initiating_profile(a_profile), |
435 host_desktop_type(chrome::GetActiveDesktop()), | 461 host_desktop_type(chrome::GetActiveDesktop()), |
436 should_replace_current_entry(false) { | 462 should_replace_current_entry(false), |
463 should_copy_session_storage_namespace(false), | |
464 should_set_opener(false) { | |
437 } | 465 } |
438 | 466 |
439 NavigateParams::~NavigateParams() {} | 467 NavigateParams::~NavigateParams() {} |
440 | 468 |
441 void FillNavigateParamsFromOpenURLParams(chrome::NavigateParams* nav_params, | 469 void FillNavigateParamsFromOpenURLParams(chrome::NavigateParams* nav_params, |
442 const content::OpenURLParams& params) { | 470 const content::OpenURLParams& params) { |
443 nav_params->referrer = params.referrer; | 471 nav_params->referrer = params.referrer; |
444 nav_params->extra_headers = params.extra_headers; | 472 nav_params->extra_headers = params.extra_headers; |
445 nav_params->disposition = params.disposition; | 473 nav_params->disposition = params.disposition; |
446 nav_params->override_encoding = params.override_encoding; | 474 nav_params->override_encoding = params.override_encoding; |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
670 bool reverse_on_redirect = false; | 698 bool reverse_on_redirect = false; |
671 content::BrowserURLHandler::GetInstance()->RewriteURLIfNecessary( | 699 content::BrowserURLHandler::GetInstance()->RewriteURLIfNecessary( |
672 &rewritten_url, browser_context, &reverse_on_redirect); | 700 &rewritten_url, browser_context, &reverse_on_redirect); |
673 | 701 |
674 // Some URLs are mapped to uber subpages. Do not allow them in incognito. | 702 // Some URLs are mapped to uber subpages. Do not allow them in incognito. |
675 return !(rewritten_url.scheme() == chrome::kChromeUIScheme && | 703 return !(rewritten_url.scheme() == chrome::kChromeUIScheme && |
676 rewritten_url.host() == chrome::kChromeUIUberHost); | 704 rewritten_url.host() == chrome::kChromeUIUberHost); |
677 } | 705 } |
678 | 706 |
679 } // namespace chrome | 707 } // namespace chrome |
OLD | NEW |