Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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.h" | 5 #include "chrome/browser/ui/browser.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 1562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1573 DCHECK(source); | 1573 DCHECK(source); |
| 1574 chrome::ViewSource(this, source, frame_url, frame_page_state); | 1574 chrome::ViewSource(this, source, frame_url, frame_page_state); |
| 1575 } | 1575 } |
| 1576 | 1576 |
| 1577 void Browser::ShowRepostFormWarningDialog(WebContents* source) { | 1577 void Browser::ShowRepostFormWarningDialog(WebContents* source) { |
| 1578 TabModalConfirmDialog::Create(new RepostFormWarningController(source), | 1578 TabModalConfirmDialog::Create(new RepostFormWarningController(source), |
| 1579 source); | 1579 source); |
| 1580 } | 1580 } |
| 1581 | 1581 |
| 1582 bool Browser::ShouldCreateWebContents( | 1582 bool Browser::ShouldCreateWebContents( |
| 1583 WebContents* web_contents, | 1583 content::WebContents* web_contents, |
| 1584 content::SiteInstance* source_site_instance, | |
| 1584 int32_t route_id, | 1585 int32_t route_id, |
| 1585 int32_t main_frame_route_id, | 1586 int32_t main_frame_route_id, |
| 1586 int32_t main_frame_widget_route_id, | 1587 int32_t main_frame_widget_route_id, |
| 1587 WindowContainerType window_container_type, | 1588 WindowContainerType window_container_type, |
| 1589 const GURL& opener_url, | |
| 1588 const std::string& frame_name, | 1590 const std::string& frame_name, |
| 1589 const GURL& target_url, | 1591 const GURL& target_url, |
| 1590 const std::string& partition_id, | 1592 const std::string& partition_id, |
| 1591 content::SessionStorageNamespace* session_storage_namespace) { | 1593 content::SessionStorageNamespace* session_storage_namespace) { |
| 1592 if (window_container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) { | 1594 if (window_container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) { |
| 1593 // If a BackgroundContents is created, suppress the normal WebContents. | 1595 // If a BackgroundContents is created, suppress the normal WebContents. |
| 1594 return !MaybeCreateBackgroundContents( | 1596 return !MaybeCreateBackgroundContents( |
| 1595 route_id, main_frame_route_id, main_frame_widget_route_id, web_contents, | 1597 source_site_instance, opener_url, route_id, main_frame_route_id, |
| 1596 frame_name, target_url, partition_id, session_storage_namespace); | 1598 main_frame_widget_route_id, frame_name, target_url, partition_id, |
| 1599 session_storage_namespace); | |
| 1597 } | 1600 } |
| 1598 | 1601 |
| 1599 return true; | 1602 return true; |
| 1600 } | 1603 } |
| 1601 | 1604 |
| 1602 void Browser::WebContentsCreated(WebContents* source_contents, | 1605 void Browser::WebContentsCreated(WebContents* source_contents, |
| 1603 int opener_render_process_id, | 1606 int opener_render_process_id, |
| 1604 int opener_render_frame_id, | 1607 int opener_render_frame_id, |
| 1605 const std::string& frame_name, | 1608 const std::string& frame_name, |
| 1606 const GURL& target_url, | 1609 const GURL& target_url, |
| (...skipping 905 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2512 // Windows and GTK remove the browser controls in fullscreen, but Mac and Ash | 2515 // Windows and GTK remove the browser controls in fullscreen, but Mac and Ash |
| 2513 // keep the controls in a slide-down panel. | 2516 // keep the controls in a slide-down panel. |
| 2514 return window_ && window_->ShouldHideUIForFullscreen(); | 2517 return window_ && window_->ShouldHideUIForFullscreen(); |
| 2515 } | 2518 } |
| 2516 | 2519 |
| 2517 bool Browser::ShouldStartShutdown() const { | 2520 bool Browser::ShouldStartShutdown() const { |
| 2518 return BrowserList::GetInstance()->size() <= 1; | 2521 return BrowserList::GetInstance()->size() <= 1; |
| 2519 } | 2522 } |
| 2520 | 2523 |
| 2521 bool Browser::MaybeCreateBackgroundContents( | 2524 bool Browser::MaybeCreateBackgroundContents( |
| 2525 content::SiteInstance* site_instance, | |
| 2526 const GURL& opener_url, | |
| 2522 int32_t route_id, | 2527 int32_t route_id, |
| 2523 int32_t main_frame_route_id, | 2528 int32_t main_frame_route_id, |
| 2524 int32_t main_frame_widget_route_id, | 2529 int32_t main_frame_widget_route_id, |
| 2525 WebContents* opener_web_contents, | |
| 2526 const std::string& frame_name, | 2530 const std::string& frame_name, |
| 2527 const GURL& target_url, | 2531 const GURL& target_url, |
| 2528 const std::string& partition_id, | 2532 const std::string& partition_id, |
| 2529 content::SessionStorageNamespace* session_storage_namespace) { | 2533 content::SessionStorageNamespace* session_storage_namespace) { |
| 2530 GURL opener_url = opener_web_contents->GetURL(); | |
|
Charlie Reis
2016/11/23 06:59:48
Yuck! Thanks for fixing this.
ncarter (slow)
2016/11/24 00:00:05
Acknowledged.
| |
| 2531 ExtensionService* extensions_service = | 2534 ExtensionService* extensions_service = |
| 2532 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 2535 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
| 2533 | 2536 |
| 2534 if (!opener_url.is_valid() || | 2537 if (!opener_url.is_valid() || frame_name.empty() || !extensions_service || |
| 2535 frame_name.empty() || | |
| 2536 !extensions_service || | |
| 2537 !extensions_service->is_ready()) | 2538 !extensions_service->is_ready()) |
| 2538 return false; | 2539 return false; |
| 2539 | 2540 |
| 2540 // Only hosted apps have web extents, so this ensures that only hosted apps | 2541 // Only hosted apps have web extents, so this ensures that only hosted apps |
| 2541 // can create BackgroundContents. We don't have to check for background | 2542 // can create BackgroundContents. We don't have to check for background |
| 2542 // permission as that is checked in RenderMessageFilter when the CreateWindow | 2543 // permission as that is checked in RenderMessageFilter when the CreateWindow |
| 2543 // message is processed. | 2544 // message is processed. |
| 2544 const Extension* extension = extensions::ExtensionRegistry::Get(profile_) | 2545 const Extension* extension = extensions::ExtensionRegistry::Get(profile_) |
| 2545 ->enabled_extensions() | 2546 ->enabled_extensions() |
| 2546 .GetHostedAppByURL(opener_url); | 2547 .GetHostedAppByURL(opener_url); |
| 2547 if (!extension) | 2548 if (!extension) |
| 2548 return false; | 2549 return false; |
| 2549 | 2550 |
| 2550 // No BackgroundContents allowed if BackgroundContentsService doesn't exist. | 2551 // No BackgroundContents allowed if BackgroundContentsService doesn't exist. |
| 2551 BackgroundContentsService* service = | 2552 BackgroundContentsService* service = |
| 2552 BackgroundContentsServiceFactory::GetForProfile(profile_); | 2553 BackgroundContentsServiceFactory::GetForProfile(profile_); |
| 2553 if (!service) | 2554 if (!service) |
| 2554 return false; | 2555 return false; |
| 2555 | 2556 |
| 2556 // Ensure that we're trying to open this from the extension's process. | 2557 // Ensure that we're trying to open this from the extension's process. |
| 2557 SiteInstance* opener_site_instance = opener_web_contents->GetSiteInstance(); | |
|
Charlie Reis
2016/11/23 06:59:48
And this!
ncarter (slow)
2016/11/24 00:00:05
Done.
| |
| 2558 extensions::ProcessMap* process_map = extensions::ProcessMap::Get(profile_); | 2558 extensions::ProcessMap* process_map = extensions::ProcessMap::Get(profile_); |
| 2559 if (!opener_site_instance->GetProcess() || | 2559 if (!site_instance->GetProcess() || |
| 2560 !process_map->Contains( | 2560 !process_map->Contains(extension->id(), |
| 2561 extension->id(), opener_site_instance->GetProcess()->GetID())) { | 2561 site_instance->GetProcess()->GetID())) { |
| 2562 return false; | 2562 return false; |
| 2563 } | 2563 } |
| 2564 | 2564 |
| 2565 // Only allow a single background contents per app. | 2565 // Only allow a single background contents per app. |
| 2566 bool allow_js_access = extensions::BackgroundInfo::AllowJSAccess(extension); | 2566 bool allow_js_access = extensions::BackgroundInfo::AllowJSAccess(extension); |
| 2567 BackgroundContents* existing = | 2567 BackgroundContents* existing = |
| 2568 service->GetAppBackgroundContents(base::ASCIIToUTF16(extension->id())); | 2568 service->GetAppBackgroundContents(base::ASCIIToUTF16(extension->id())); |
| 2569 if (existing) { | 2569 if (existing) { |
| 2570 // For non-scriptable background contents, ignore the request altogether, | 2570 // For non-scriptable background contents, ignore the request altogether, |
| 2571 // (returning true, so that a regular WebContents isn't created either). | 2571 // (returning true, so that a regular WebContents isn't created either). |
| 2572 if (!allow_js_access) | 2572 if (!allow_js_access) |
| 2573 return true; | 2573 return true; |
| 2574 // For scriptable background pages, if one already exists, close it (even | 2574 // For scriptable background pages, if one already exists, close it (even |
| 2575 // if it was specified in the manifest). | 2575 // if it was specified in the manifest). |
| 2576 delete existing; | 2576 delete existing; |
| 2577 } | 2577 } |
| 2578 | 2578 |
| 2579 // If script access is not allowed, create the the background contents in a | 2579 // Passed all the checks, so this should be created as a BackgroundContents. |
| 2580 // new SiteInstance, so that a separate process is used. | 2580 BackgroundContents* contents = nullptr; |
| 2581 scoped_refptr<content::SiteInstance> site_instance = | 2581 if (allow_js_access) { |
| 2582 allow_js_access ? | 2582 contents = service->CreateBackgroundContents( |
| 2583 opener_site_instance : | 2583 site_instance, route_id, main_frame_route_id, |
| 2584 content::SiteInstance::Create(opener_web_contents->GetBrowserContext()); | 2584 main_frame_widget_route_id, profile_, frame_name, |
| 2585 base::ASCIIToUTF16(extension->id()), partition_id, | |
| 2586 session_storage_namespace); | |
| 2587 } else { | |
| 2588 // If script access is not allowed, create the the background contents in a | |
| 2589 // new SiteInstance, so that a separate process is used. We must not use any | |
| 2590 // of the passed-in routing IDs, as they are objects in the opener's | |
| 2591 // process. | |
| 2592 contents = service->CreateBackgroundContents( | |
| 2593 content::SiteInstance::Create(site_instance->GetBrowserContext()), | |
| 2594 MSG_ROUTING_NONE, MSG_ROUTING_NONE, MSG_ROUTING_NONE, profile_, | |
| 2595 frame_name, base::ASCIIToUTF16(extension->id()), partition_id, | |
| 2596 session_storage_namespace); | |
| 2585 | 2597 |
| 2586 // Passed all the checks, so this should be created as a BackgroundContents. | 2598 // When a separate process is used, the original renderer cannot access the |
| 2587 BackgroundContents* contents = service->CreateBackgroundContents( | 2599 // new window later, thus we need to navigate the window now. |
| 2588 site_instance.get(), route_id, main_frame_route_id, | 2600 if (contents) { |
| 2589 main_frame_widget_route_id, profile_, frame_name, | 2601 contents->web_contents()->GetController().LoadURL( |
| 2590 base::ASCIIToUTF16(extension->id()), partition_id, | 2602 target_url, content::Referrer(), ui::PAGE_TRANSITION_LINK, |
| 2591 session_storage_namespace); | 2603 std::string()); // No extra headers. |
| 2592 | 2604 } |
| 2593 // When a separate process is used, the original renderer cannot access the | |
| 2594 // new window later, thus we need to navigate the window now. | |
| 2595 if (contents && !allow_js_access) { | |
| 2596 contents->web_contents()->GetController().LoadURL( | |
| 2597 target_url, | |
| 2598 content::Referrer(), | |
| 2599 ui::PAGE_TRANSITION_LINK, | |
| 2600 std::string()); // No extra headers. | |
| 2601 } | 2605 } |
| 2602 | 2606 |
| 2603 return contents != NULL; | 2607 return contents != NULL; |
| 2604 } | 2608 } |
| OLD | NEW |