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

Commit

Permalink
fixup! LifecycleUnits are now used for tab discarding
Browse files Browse the repository at this point in the history
  • Loading branch information
hferreiro committed May 24, 2018
1 parent 40dc4f9 commit 8868bc4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 59 deletions.
99 changes: 43 additions & 56 deletions atom/browser/api/atom_api_web_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2862,61 +2862,8 @@ void WebContents::OnTabCreated(const mate::Dictionary& options,
}

int window_id = -1;
::Browser *browser = nullptr;
if (options.Get("windowId", &window_id) && window_id != -1) {
if (tab_helper && options.Get("windowId", &window_id) && window_id != -1)
tab_helper->SetWindowId(window_id);
auto api_window =
mate::TrackableObject<Window>::FromWeakMapID(isolate(), window_id);
if (api_window)
browser = api_window->window()->browser();
}
if (!browser) {
browser = owner_window()->browser();
}

// This call needs to happen before both tab_helper->SetAutoDiscardable()
// and tab_helper->Discard() order for the TabLifecycleUnitHolder for this
// tab to be created (which happens when inserting the tab in the
// TabStripModel).
tab_helper->SetBrowser(browser);

bool autoDiscardable = true;
if (tab_helper && options.Get("autoDiscardable", &autoDiscardable)) {
tab_helper->SetAutoDiscardable(autoDiscardable);
}

bool discarded = false;
if (tab_helper && options.Get("discarded", &discarded)
&& discarded && !active) {
std::string url;
if (options.Get("url", &url)) {
std::unique_ptr<content::NavigationEntryImpl> entry =
base::WrapUnique(new content::NavigationEntryImpl);
entry->SetURL(GURL(url));
entry->SetVirtualURL(GURL(url));

std::string title;
if (options.Get("title", &title)) {
entry->SetTitle(base::UTF8ToUTF16(title));
}

std::string favicon_url;
if (options.Get("faviconUrl", &favicon_url) ||
options.Get("favIconUrl", &favicon_url)) {
content::FaviconStatus status;
status.valid = true;
status.url = GURL(favicon_url);
entry->GetFavicon() = status;
}

std::vector<std::unique_ptr<content::NavigationEntry>> entries;
entries.push_back(std::move(entry));
tab->GetController().Restore(entries.size() - 1,
content::RestoreType::CURRENT_SESSION, &entries);
}

tab_helper->Discard();
}

int opener_tab_id = TabStripModel::kNoTab;
if (tab_helper) {
Expand Down Expand Up @@ -2948,10 +2895,50 @@ void WebContents::OnTabCreated(const mate::Dictionary& options,
user_gesture,
&was_blocked);

if (was_blocked)
if (was_blocked) {
callback.Run(nullptr);
else
} else {
bool autoDiscardable = true;
if (tab_helper && options.Get("autoDiscardable", &autoDiscardable)) {
tab_helper->SetAutoDiscardable(autoDiscardable);
}

bool discarded = false;
if (tab_helper && options.Get("discarded", &discarded) && discarded &&
!active) {
std::string url;
if (options.Get("url", &url)) {
std::unique_ptr<content::NavigationEntryImpl> entry =
base::WrapUnique(new content::NavigationEntryImpl);
entry->SetURL(GURL(url));
entry->SetVirtualURL(GURL(url));

std::string title;
if (options.Get("title", &title)) {
entry->SetTitle(base::UTF8ToUTF16(title));
}

std::string favicon_url;
if (options.Get("faviconUrl", &favicon_url) ||
options.Get("favIconUrl", &favicon_url)) {
content::FaviconStatus status;
status.valid = true;
status.url = GURL(favicon_url);
entry->GetFavicon() = status;
}

std::vector<std::unique_ptr<content::NavigationEntry>> entries;
entries.push_back(std::move(entry));
tab->GetController().Restore(entries.size() - 1,
content::RestoreType::CURRENT_SESSION,
&entries);
}

tab_helper->Discard();
}

callback.Run(tab);
}
}

// static
Expand Down
5 changes: 2 additions & 3 deletions atom/browser/extensions/tab_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,8 @@ namespace extensions {

namespace {

resource_coordinator::GuestTabManager* GetTabManager() {
return static_cast<resource_coordinator::GuestTabManager*>(
g_browser_process->GetTabManager());
TabManager* GetTabManager() {
return g_browser_process->GetTabManager();
}

} // namespace
Expand Down

0 comments on commit 8868bc4

Please sign in to comment.