Commit 2b1b8400 authored by Giovanni Ortuño Urquidi's avatar Giovanni Ortuño Urquidi Committed by Commit Bot

desktop-pwas: Pass opener to new app window

When a website calls window.open() with a URL for which there is a PWA
installed, we cancel the navigation in the newly opened tab and start a
new navigation in a new app window.

This patch plumbs the opener that would have existed in the new tab to
the new app window, so that the new app window can access it.

This only takes care of the child window. The parent window is not yet
able to access the newly opened app window.

Bug: 804881
Change-Id: Ie08c3425b13b4940435e6cf3614a015d61ed10a3
Reviewed-on: https://chromium-review.googlesource.com/906042Reviewed-by: default avatarMatt Giuca <mgiuca@chromium.org>
Reviewed-by: default avatarBen Wells <benwells@chromium.org>
Commit-Queue: Giovanni Ortuño Urquidi <ortuno@chromium.org>
Cr-Commit-Position: refs/heads/master@{#536013}
parent 1dd116fc
...@@ -424,6 +424,7 @@ void BookmarkAppNavigationThrottle::OpenBookmarkApp( ...@@ -424,6 +424,7 @@ void BookmarkAppNavigationThrottle::OpenBookmarkApp(
profile, bookmark_app.get(), extensions::LAUNCH_CONTAINER_WINDOW, profile, bookmark_app.get(), extensions::LAUNCH_CONTAINER_WINDOW,
WindowOpenDisposition::CURRENT_TAB, extensions::SOURCE_URL_HANDLER); WindowOpenDisposition::CURRENT_TAB, extensions::SOURCE_URL_HANDLER);
launch_params.override_url = navigation_handle()->GetURL(); launch_params.override_url = navigation_handle()->GetURL();
launch_params.opener = source->GetOpener();
DVLOG(1) << "Opening app."; DVLOG(1) << "Opening app.";
OpenApplication(launch_params); OpenApplication(launch_params);
......
...@@ -34,7 +34,8 @@ AppLaunchParams::AppLaunchParams(Profile* profile, ...@@ -34,7 +34,8 @@ AppLaunchParams::AppLaunchParams(Profile* profile,
command_line(base::CommandLine::NO_PROGRAM), command_line(base::CommandLine::NO_PROGRAM),
source(source), source(source),
play_store_status(PlayStoreStatus::PLAY_STORE_STATUS_UNKNOWN), play_store_status(PlayStoreStatus::PLAY_STORE_STATUS_UNKNOWN),
display_id(display_id) { display_id(display_id),
opener(nullptr) {
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
// TODO(b/34478891): Remove this from app launch. // TODO(b/34478891): Remove this from app launch.
if (set_playstore_status) { if (set_playstore_status) {
......
...@@ -19,6 +19,10 @@ ...@@ -19,6 +19,10 @@
class Profile; class Profile;
namespace content {
class RenderFrameHost;
}
namespace extensions { namespace extensions {
class Extension; class Extension;
} }
...@@ -78,6 +82,10 @@ struct AppLaunchParams { ...@@ -78,6 +82,10 @@ struct AppLaunchParams {
// display::kInvalidDisplayId means that the display does not exist or is not // display::kInvalidDisplayId means that the display does not exist or is not
// set. // set.
int64_t display_id; int64_t display_id;
// The frame that initiated the open. May be null. If set, the new app will
// have |opener| as its window.opener.
content::RenderFrameHost* opener;
}; };
// Helper to create AppLaunchParams using extensions::GetLaunchContainer with // Helper to create AppLaunchParams using extensions::GetLaunchContainer with
......
...@@ -213,8 +213,12 @@ WebContents* OpenApplicationWindow(const AppLaunchParams& params, ...@@ -213,8 +213,12 @@ WebContents* OpenApplicationWindow(const AppLaunchParams& params,
(extension ? ui::PAGE_TRANSITION_AUTO_BOOKMARK (extension ? ui::PAGE_TRANSITION_AUTO_BOOKMARK
: ui::PAGE_TRANSITION_AUTO_TOPLEVEL); : ui::PAGE_TRANSITION_AUTO_TOPLEVEL);
WebContents* web_contents = NavigateParams nav_params(browser, url, transition);
chrome::AddSelectedTabWithURL(browser, url, transition); nav_params.disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB;
nav_params.opener = params.opener;
Navigate(&nav_params);
WebContents* web_contents = nav_params.target_contents;
web_contents->GetMutableRendererPrefs()->can_accept_load_drops = false; web_contents->GetMutableRendererPrefs()->can_accept_load_drops = false;
web_contents->GetRenderViewHost()->SyncRendererPrefs(); web_contents->GetRenderViewHost()->SyncRendererPrefs();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment