Skip to content
This repository has been archived by the owner on Jan 4, 2019. It is now read-only.

Commit

Permalink
Get native window reference manually if it's not found in user data (…
Browse files Browse the repository at this point in the history
…as a result of losing a race condition)

Fixes brave/browser-laptop#14409

Auditors: @bridiver
  • Loading branch information
bsclifton committed Jul 30, 2018
1 parent a508cf5 commit 4504af1
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion atom/browser/atom_download_manager_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <utility>
#include <vector>

#include "atom/browser/extensions/tab_helper.h"
#include "atom/browser/native_window.h"
#include "base/bind.h"
#include "base/files/file_util.h"
Expand All @@ -19,6 +20,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/safe_browsing/download_protection/download_protection_util.h"
#include "chrome/browser/safe_browsing/safe_browsing_service.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/safe_browsing/file_type_policies.h"
#include "components/prefs/pref_service.h"
Expand Down Expand Up @@ -63,7 +65,19 @@ NativeWindow* GetNativeWindowFromWebContents(
content::WebContents* web_contents) {
DCHECK(web_contents);
auto relay = NativeWindowRelay::FromWebContents(web_contents);
return relay ? relay->window.get() : nullptr;
if (relay)
return relay->window.get();

auto helper =
extensions::TabHelper::FromWebContents(web_contents);
if (!helper)
return nullptr;

auto browser = helper->browser();
if (!browser)
return nullptr;

return static_cast<NativeWindow*>(browser->window());
}

// Blank newtab on download should be closed after starting download.
Expand Down

1 comment on commit 4504af1

@bridiver
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the comment on this commit message is not really correct. This gets the native window from the tab strip for tabs that are not currently attached. The race condition was in b-l, not here. We actually don't even need the original code to get it from the NativeWindowRelay, but I left it anyway

Please sign in to comment.