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

Commit

Permalink
Determine next index in all cases
Browse files Browse the repository at this point in the history
  • Loading branch information
bbondy committed Aug 25, 2017
1 parent 6ff739a commit ead7260
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions atom/browser/api/atom_api_web_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,20 @@ void WebContents::AddNewContents(content::WebContents* source,
user_gesture = true;
}

if (disposition != WindowOpenDisposition::NEW_WINDOW &&
disposition != WindowOpenDisposition::NEW_POPUP) {
auto tab_helper = extensions::TabHelper::FromWebContents(new_contents);
if (tab_helper->get_index() == TabStripModel::kNoTab) {
int index =
owner_window()->browser()->tab_strip_model()->order_controller()->
DetermineInsertionIndex(ui::PAGE_TRANSITION_LINK,
tab_helper->is_active() ?
TabStripModel::ADD_ACTIVE :
TabStripModel::ADD_NONE);
tab_helper->SetTabIndex(index);
}
}

node::Environment* env = node::Environment::GetCurrent(isolate());
if (!env) {
return;
Expand Down Expand Up @@ -2574,6 +2588,9 @@ void WebContents::OnTabCreated(const mate::Dictionary& options,
tab_helper->SetAutoDiscardable(autoDiscardable);
}

int opener_tab_id = TabStripModel::kNoTab;
options.Get("openerTabId", &opener_tab_id);

bool discarded = false;
if (options.Get("discarded", &discarded) && discarded && !active) {
std::string url;
Expand Down Expand Up @@ -2615,29 +2632,20 @@ void WebContents::OnTabCreated(const mate::Dictionary& options,
// TODO(bridiver) - combine these two methods
tab_helper->SetWindowId(window_id);
tab_helper->SetBrowser(api_window->window()->browser());
tab_strip = api_window->window()->browser()->tab_strip_model();
}
}

int opener_tab_id = TabStripModel::kNoTab;
options.Get("openerTabId", &opener_tab_id);

content::WebContents* source = nullptr;
if (opener_tab_id != TabStripModel::kNoTab) {
source = extensions::TabHelper::GetTabById(opener_tab_id);
tab_helper->SetOpener(opener_tab_id);
if (!tab_strip) {
tab_strip = owner_window()->browser()->tab_strip_model();
}
int index = tab_strip->order_controller()->
DetermineInsertionIndex(ui::PAGE_TRANSITION_LINK,
active ? TabStripModel::ADD_ACTIVE : TabStripModel::ADD_NONE);
tab_helper->SetTabIndex(index);
}

if (!source)
source = web_contents();

tab_helper->SetTabIndex(index);

bool was_blocked = false;
AddNewContents(source,
tab,
Expand Down

0 comments on commit ead7260

Please sign in to comment.