Commit 7e17239b authored by khmel@google.com's avatar khmel@google.com Committed by Commit Bot

arc: Prevent crash from attempt do download some document.

This prevents crash when user tries to download pdf document from
Play Store ToS.

Test: Manually
Bug: b:64117707
Change-Id: I965a760b0bdef2c1167a8007822ed7c9a2b353c6
Reviewed-on: https://chromium-review.googlesource.com/1009111
Commit-Queue: Yury Khmel <khmel@google.com>
Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#551086}
parent 03640fa2
......@@ -22,6 +22,7 @@
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_view_host.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/sessions/session_tab_helper.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
......@@ -39,6 +40,12 @@
#include "ui/shell_dialogs/selected_file_info.h"
#include "ui/views/widget/widget.h"
#if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/login/ui/login_display_host.h"
#include "chrome/browser/chromeos/login/ui/webui_login_view.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#endif
using extensions::AppWindow;
using content::BrowserThread;
......@@ -93,6 +100,21 @@ scoped_refptr<SelectFileDialogExtension> PendingDialog::Find(
return it->second;
}
#if defined(OS_CHROMEOS)
// Return the Chrome OS WebUI login WebContents, if applicable.
content::WebContents* GetLoginWebContents() {
chromeos::LoginDisplayHost* const login_display_host =
chromeos::LoginDisplayHost::default_host();
if (!login_display_host)
return nullptr;
chromeos::WebUILoginView* const view =
login_display_host->GetWebUILoginView();
if (!view)
return nullptr;
return view->GetWebContents();
}
#endif
// Given |owner_window| finds corresponding |base_window|, it's associated
// |web_contents| and |profile|.
void FindRuntimeContext(gfx::NativeWindow owner_window,
......@@ -138,7 +160,13 @@ void FindRuntimeContext(gfx::NativeWindow owner_window,
if (chrome::IsRunningInForcedAppMode() && !(*web_contents))
*web_contents = chromeos::LoginWebDialog::GetCurrentWebContents();
CHECK(web_contents);
#if defined(OS_CHROMEOS)
// Check for a WebContents used for the Chrome OS WebUI login flow.
if (!*web_contents)
*web_contents = GetLoginWebContents();
#endif
CHECK(*web_contents);
}
} // namespace
......@@ -332,6 +360,14 @@ void SelectFileDialogExtension::SelectFileImpl(
profile_ = Profile::FromBrowserContext(web_contents->GetBrowserContext());
CHECK(profile_);
#if defined(OS_CHROMEOS)
// Handle the case when |web_contents| is associated with Default profile.
if (chromeos::ProfileHelper::IsSigninProfile(profile_)) {
profile_ = ProfileManager::GetActiveUserProfile();
CHECK(profile_);
}
#endif
// 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);
......
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