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 18 matching lines...) Expand all Loading... | |
29 #include "chrome/browser/ui/omnibox/location_bar.h" | 29 #include "chrome/browser/ui/omnibox/location_bar.h" |
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_process_host.h" | |
39 #include "content/public/browser/render_view_host.h" | 40 #include "content/public/browser/render_view_host.h" |
41 #include "content/public/browser/session_storage_namespace.h" | |
42 #include "content/public/browser/site_instance.h" | |
43 #include "content/public/browser/storage_partition.h" | |
40 #include "content/public/browser/web_contents.h" | 44 #include "content/public/browser/web_contents.h" |
41 #include "content/public/browser/web_contents_view.h" | 45 #include "content/public/browser/web_contents_view.h" |
42 | 46 |
43 #if defined(USE_AURA) | 47 #if defined(USE_AURA) |
44 #include "ui/aura/window.h" | 48 #include "ui/aura/window.h" |
45 #endif | 49 #endif |
46 | 50 |
47 using content::GlobalRequestID; | 51 using content::GlobalRequestID; |
48 using content::WebContents; | 52 using content::WebContents; |
49 | 53 |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
242 | 246 |
243 void LoadURLInContents(WebContents* target_contents, | 247 void LoadURLInContents(WebContents* target_contents, |
244 const GURL& url, | 248 const GURL& url, |
245 chrome::NavigateParams* params) { | 249 chrome::NavigateParams* params) { |
246 content::NavigationController::LoadURLParams load_url_params(url); | 250 content::NavigationController::LoadURLParams load_url_params(url); |
247 load_url_params.referrer = params->referrer; | 251 load_url_params.referrer = params->referrer; |
248 load_url_params.transition_type = params->transition; | 252 load_url_params.transition_type = params->transition; |
249 load_url_params.extra_headers = params->extra_headers; | 253 load_url_params.extra_headers = params->extra_headers; |
250 load_url_params.should_replace_current_entry = | 254 load_url_params.should_replace_current_entry = |
251 params->should_replace_current_entry; | 255 params->should_replace_current_entry; |
256 // Even if we only copy the session storage namespace and do not set the | |
257 // opener, we need to use the SiteInstance that was created in | |
258 // CreateTargetContents to make sure we created the SessionStorageNamespace | |
259 // in the right StoragePartition. | |
260 load_url_params.should_stay_in_site_instance = | |
Charlie Reis
2013/07/31 17:16:16
This is incorrect. Setting the opener will not al
jochen (gone - plz use gerrit)
2013/07/31 18:30:52
Removed.
| |
261 params->should_copy_session_storage_namespace || | |
262 params->should_set_opener; | |
252 | 263 |
253 if (params->transferred_global_request_id != GlobalRequestID()) { | 264 if (params->transferred_global_request_id != GlobalRequestID()) { |
254 load_url_params.is_renderer_initiated = params->is_renderer_initiated; | 265 load_url_params.is_renderer_initiated = params->is_renderer_initiated; |
255 load_url_params.transferred_global_request_id = | 266 load_url_params.transferred_global_request_id = |
256 params->transferred_global_request_id; | 267 params->transferred_global_request_id; |
257 } else if (params->is_renderer_initiated) { | 268 } else if (params->is_renderer_initiated) { |
258 load_url_params.is_renderer_initiated = true; | 269 load_url_params.is_renderer_initiated = true; |
259 } | 270 } |
260 target_contents->GetController().LoadURLWithParams(load_url_params); | 271 target_contents->GetController().LoadURLWithParams(load_url_params); |
261 } | 272 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
310 chrome::NavigateParams* params_; | 321 chrome::NavigateParams* params_; |
311 scoped_ptr<WebContents> target_contents_owner_; | 322 scoped_ptr<WebContents> target_contents_owner_; |
312 DISALLOW_COPY_AND_ASSIGN(ScopedTargetContentsOwner); | 323 DISALLOW_COPY_AND_ASSIGN(ScopedTargetContentsOwner); |
313 }; | 324 }; |
314 | 325 |
315 content::WebContents* CreateTargetContents(const chrome::NavigateParams& params, | 326 content::WebContents* CreateTargetContents(const chrome::NavigateParams& params, |
316 const GURL& url) { | 327 const GURL& url) { |
317 WebContents::CreateParams create_params( | 328 WebContents::CreateParams create_params( |
318 params.browser->profile(), | 329 params.browser->profile(), |
319 tab_util::GetSiteInstanceForNewTab(params.browser->profile(), url)); | 330 tab_util::GetSiteInstanceForNewTab(params.browser->profile(), url)); |
331 // In order for window.opener to be accessible, the target contents needs to | |
Charlie Reis
2013/07/31 17:16:16
This reasoning is false. The reason that we creat
jochen (gone - plz use gerrit)
2013/07/31 18:30:52
I removed the SiteInstance related logic as discus
| |
332 // run in the same process as the source contents. | |
333 if (params.source_contents && params.should_set_opener) | |
334 create_params.site_instance = params.source_contents->GetSiteInstance(); | |
320 if (params.source_contents) { | 335 if (params.source_contents) { |
321 create_params.initial_size = | 336 create_params.initial_size = |
322 params.source_contents->GetView()->GetContainerSize(); | 337 params.source_contents->GetView()->GetContainerSize(); |
323 } | 338 } |
324 #if defined(USE_AURA) | 339 #if defined(USE_AURA) |
325 if (params.browser->window() && | 340 if (params.browser->window() && |
326 params.browser->window()->GetNativeWindow()) { | 341 params.browser->window()->GetNativeWindow()) { |
327 create_params.context = | 342 create_params.context = |
328 params.browser->window()->GetNativeWindow(); | 343 params.browser->window()->GetNativeWindow(); |
329 } | 344 } |
330 #endif | 345 #endif |
331 | 346 |
332 content::WebContents* target_contents = WebContents::Create(create_params); | 347 content::SessionStorageNamespaceMap namespace_map; |
348 scoped_refptr<content::SiteInstance> site_instance; | |
349 if (params.source_contents && params.should_copy_session_storage_namespace) { | |
350 Profile* source_profile = Profile::FromBrowserContext( | |
351 params.source_contents->GetBrowserContext()); | |
352 bool is_guest = | |
353 params.source_contents->GetRenderViewHost()->GetProcess()->IsGuest(); | |
354 site_instance = | |
355 !params.should_set_opener && !is_guest | |
356 ? content::SiteInstance::CreateForURL(source_profile, url) | |
357 : params.source_contents->GetSiteInstance(); | |
358 create_params.site_instance = site_instance; | |
359 | |
360 std::string partition_id = source_profile->GetStoragePartitionIdForSite( | |
361 site_instance->GetSiteURL()); | |
362 content::StoragePartition* partition = | |
363 content::BrowserContext::GetStoragePartition(source_profile, | |
364 site_instance); | |
365 content::SessionStorageNamespaceMap::const_iterator old_namespace = | |
366 params.source_contents->GetController().GetSessionStorageNamespaceMap() | |
367 .find(partition_id); | |
368 scoped_refptr<content::SessionStorageNamespace> cloned_namespace = | |
369 content::SessionStorageNamespace::Clone( | |
370 partition->GetDOMStorageContext(), old_namespace->second.get()); | |
371 namespace_map.insert(make_pair(partition_id, cloned_namespace)); | |
372 } | |
373 WebContents* target_contents = WebContents::CreateWithSessionStorage( | |
374 create_params, | |
375 namespace_map, | |
376 params.should_set_opener ? params.source_contents : NULL); | |
377 | |
333 // New tabs can have WebUI URLs that will make calls back to arbitrary | 378 // 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 | 379 // tab helpers, so the entire set of tab helpers needs to be set up |
335 // immediately. | 380 // immediately. |
336 BrowserNavigatorWebContentsAdoption::AttachTabHelpers(target_contents); | 381 BrowserNavigatorWebContentsAdoption::AttachTabHelpers(target_contents); |
337 extensions::TabHelper::FromWebContents(target_contents)-> | 382 extensions::TabHelper::FromWebContents(target_contents)-> |
338 SetExtensionAppById(params.extension_app_id); | 383 SetExtensionAppById(params.extension_app_id); |
339 // TODO(sky): Figure out why this is needed. Without it we seem to get | 384 // TODO(sky): Figure out why this is needed. Without it we seem to get |
340 // failures in startup tests. | 385 // failures in startup tests. |
341 // By default, content believes it is not hidden. When adding contents | 386 // By default, content believes it is not hidden. When adding contents |
342 // in the background, tell it that it's hidden. | 387 // 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), | 431 is_renderer_initiated(false), |
387 tabstrip_index(-1), | 432 tabstrip_index(-1), |
388 tabstrip_add_types(TabStripModel::ADD_ACTIVE), | 433 tabstrip_add_types(TabStripModel::ADD_ACTIVE), |
389 window_action(NO_ACTION), | 434 window_action(NO_ACTION), |
390 user_gesture(true), | 435 user_gesture(true), |
391 path_behavior(RESPECT), | 436 path_behavior(RESPECT), |
392 ref_behavior(IGNORE_REF), | 437 ref_behavior(IGNORE_REF), |
393 browser(a_browser), | 438 browser(a_browser), |
394 initiating_profile(NULL), | 439 initiating_profile(NULL), |
395 host_desktop_type(GetHostDesktop(a_browser)), | 440 host_desktop_type(GetHostDesktop(a_browser)), |
396 should_replace_current_entry(false) { | 441 should_replace_current_entry(false), |
442 should_copy_session_storage_namespace(false), | |
443 should_set_opener(false) { | |
397 } | 444 } |
398 | 445 |
399 NavigateParams::NavigateParams(Browser* a_browser, | 446 NavigateParams::NavigateParams(Browser* a_browser, |
400 WebContents* a_target_contents) | 447 WebContents* a_target_contents) |
401 : target_contents(a_target_contents), | 448 : target_contents(a_target_contents), |
402 source_contents(NULL), | 449 source_contents(NULL), |
403 disposition(CURRENT_TAB), | 450 disposition(CURRENT_TAB), |
404 transition(content::PAGE_TRANSITION_LINK), | 451 transition(content::PAGE_TRANSITION_LINK), |
405 is_renderer_initiated(false), | 452 is_renderer_initiated(false), |
406 tabstrip_index(-1), | 453 tabstrip_index(-1), |
407 tabstrip_add_types(TabStripModel::ADD_ACTIVE), | 454 tabstrip_add_types(TabStripModel::ADD_ACTIVE), |
408 window_action(NO_ACTION), | 455 window_action(NO_ACTION), |
409 user_gesture(true), | 456 user_gesture(true), |
410 path_behavior(RESPECT), | 457 path_behavior(RESPECT), |
411 ref_behavior(IGNORE_REF), | 458 ref_behavior(IGNORE_REF), |
412 browser(a_browser), | 459 browser(a_browser), |
413 initiating_profile(NULL), | 460 initiating_profile(NULL), |
414 host_desktop_type(GetHostDesktop(a_browser)), | 461 host_desktop_type(GetHostDesktop(a_browser)), |
415 should_replace_current_entry(false) { | 462 should_replace_current_entry(false), |
463 should_copy_session_storage_namespace(false), | |
464 should_set_opener(false) { | |
416 } | 465 } |
417 | 466 |
418 NavigateParams::NavigateParams(Profile* a_profile, | 467 NavigateParams::NavigateParams(Profile* a_profile, |
419 const GURL& a_url, | 468 const GURL& a_url, |
420 content::PageTransition a_transition) | 469 content::PageTransition a_transition) |
421 : url(a_url), | 470 : url(a_url), |
422 target_contents(NULL), | 471 target_contents(NULL), |
423 source_contents(NULL), | 472 source_contents(NULL), |
424 disposition(NEW_FOREGROUND_TAB), | 473 disposition(NEW_FOREGROUND_TAB), |
425 transition(a_transition), | 474 transition(a_transition), |
426 is_renderer_initiated(false), | 475 is_renderer_initiated(false), |
427 tabstrip_index(-1), | 476 tabstrip_index(-1), |
428 tabstrip_add_types(TabStripModel::ADD_ACTIVE), | 477 tabstrip_add_types(TabStripModel::ADD_ACTIVE), |
429 window_action(SHOW_WINDOW), | 478 window_action(SHOW_WINDOW), |
430 user_gesture(true), | 479 user_gesture(true), |
431 path_behavior(RESPECT), | 480 path_behavior(RESPECT), |
432 ref_behavior(IGNORE_REF), | 481 ref_behavior(IGNORE_REF), |
433 browser(NULL), | 482 browser(NULL), |
434 initiating_profile(a_profile), | 483 initiating_profile(a_profile), |
435 host_desktop_type(chrome::GetActiveDesktop()), | 484 host_desktop_type(chrome::GetActiveDesktop()), |
436 should_replace_current_entry(false) { | 485 should_replace_current_entry(false), |
486 should_copy_session_storage_namespace(false), | |
487 should_set_opener(false) { | |
437 } | 488 } |
438 | 489 |
439 NavigateParams::~NavigateParams() {} | 490 NavigateParams::~NavigateParams() {} |
440 | 491 |
441 void FillNavigateParamsFromOpenURLParams(chrome::NavigateParams* nav_params, | 492 void FillNavigateParamsFromOpenURLParams(chrome::NavigateParams* nav_params, |
442 const content::OpenURLParams& params) { | 493 const content::OpenURLParams& params) { |
443 nav_params->referrer = params.referrer; | 494 nav_params->referrer = params.referrer; |
444 nav_params->extra_headers = params.extra_headers; | 495 nav_params->extra_headers = params.extra_headers; |
445 nav_params->disposition = params.disposition; | 496 nav_params->disposition = params.disposition; |
446 nav_params->override_encoding = params.override_encoding; | 497 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; | 721 bool reverse_on_redirect = false; |
671 content::BrowserURLHandler::GetInstance()->RewriteURLIfNecessary( | 722 content::BrowserURLHandler::GetInstance()->RewriteURLIfNecessary( |
672 &rewritten_url, browser_context, &reverse_on_redirect); | 723 &rewritten_url, browser_context, &reverse_on_redirect); |
673 | 724 |
674 // Some URLs are mapped to uber subpages. Do not allow them in incognito. | 725 // Some URLs are mapped to uber subpages. Do not allow them in incognito. |
675 return !(rewritten_url.scheme() == chrome::kChromeUIScheme && | 726 return !(rewritten_url.scheme() == chrome::kChromeUIScheme && |
676 rewritten_url.host() == chrome::kChromeUIUberHost); | 727 rewritten_url.host() == chrome::kChromeUIUberHost); |
677 } | 728 } |
678 | 729 |
679 } // namespace chrome | 730 } // namespace chrome |
OLD | NEW |