Commit 1ec73a4f authored by Satoshi Niwa's avatar Satoshi Niwa Committed by Commit Bot

SelectFileDialogExtension: Obtain Profile from ProfileManager in ChromeOS...

SelectFileDialogExtension: Obtain Profile from ProfileManager in ChromeOS when WebContents is not available.

PROBLEM: Close all browser windows an try opening a SelectFileDialog
from a non-browser window (e.g. ARC app window). Chrome crashes
at https://cs.chromium.org/chromium/src/chrome/browser/ui/views/select_file_dialog_extension.cc?q=CHECK..web_contents$&g=0&l=161

SOLUTION: Use ProfileManager::GetActiveUserProfile() for obtaining
Profile in ChromeOS when WebContents is not available.
WebContents is not essential for creating a dialog (at least in
ChromeOS).

BUG=b:119593284
TEST=Manually open SelectFileDialog from an ARC app after closing all browser windows

Change-Id: Ie3039b9287ad9c8a9d8444e7f7812aedded14b43
Reviewed-on: https://chromium-review.googlesource.com/c/1337144
Commit-Queue: Satoshi Niwa <niwa@chromium.org>
Reviewed-by: default avatarSam McNally <sammc@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609587}
parent abfc03b1
......@@ -157,8 +157,6 @@ void FindRuntimeContext(gfx::NativeWindow owner_window,
if (!*web_contents)
*web_contents = GetLoginWebContents();
#endif
CHECK(*web_contents);
}
} // namespace
......@@ -353,18 +351,18 @@ void SelectFileDialogExtension::SelectFileImpl(
// The web contents to associate the dialog with.
content::WebContents* web_contents = NULL;
FindRuntimeContext(owner_window, &base_window, &web_contents);
CHECK(web_contents);
profile_ = Profile::FromBrowserContext(web_contents->GetBrowserContext());
CHECK(profile_);
if (web_contents)
profile_ = Profile::FromBrowserContext(web_contents->GetBrowserContext());
#if defined(OS_CHROMEOS)
// Handle the case when |web_contents| is associated with Default profile.
if (chromeos::ProfileHelper::IsSigninProfile(profile_)) {
// Handle the cases where |web_contents| is not available or |web_contents| is
// associated with Default profile.
if (!web_contents || chromeos::ProfileHelper::IsSigninProfile(profile_))
profile_ = ProfileManager::GetActiveUserProfile();
CHECK(profile_);
}
#endif
DCHECK(profile_);
// Check if we have another dialog opened for the contents. It's unlikely, but
// possible. In such situation, discard this request.
RoutingID routing_id = GetRoutingIDFromWebContents(web_contents);
......
......@@ -312,7 +312,8 @@ class SelectFileDialogExtensionBrowserTest
listener_->WaitForCalled();
// Dialog no longer believes it is running.
ASSERT_FALSE(dialog_->IsRunning(owning_window));
if (owning_window)
ASSERT_FALSE(dialog_->IsRunning(owning_window));
}
base::ScopedTempDir tmp_dir_;
......@@ -545,3 +546,20 @@ IN_PROC_BROWSER_TEST_F(SelectFileDialogExtensionBrowserTest, FileInputElement) {
// Wait for file dialog's "ready" message.
EXPECT_TRUE(listener.WaitUntilSatisfied());
}
#if defined(OS_CHROMEOS)
IN_PROC_BROWSER_TEST_F(SelectFileDialogExtensionBrowserTest,
OpenDialogWithoutOwningWindow) {
// Open the file dialog with no |owning_window|.
ASSERT_NO_FATAL_FAILURE(OpenDialog(ui::SelectFileDialog::SELECT_OPEN_FILE,
base::FilePath(),
nullptr /* owning_window */, ""));
// Click the "Cancel" button.
CloseDialog(DIALOG_BTN_CANCEL, nullptr /* owning_window */);
// Listener should have been informed of the cancellation.
ASSERT_TRUE(listener_->canceled());
ASSERT_EQ(this, listener_->params());
}
#endif
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