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 24, 2017
1 parent 6ff739a commit db08d69
Showing 1 changed file with 33 additions and 10 deletions.
43 changes: 33 additions & 10 deletions atom/browser/api/atom_api_web_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,17 @@ void WebContents::AddNewContents(content::WebContents* source,
user_gesture = true;
}

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 +2585,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 @@ -2612,32 +2626,41 @@ void WebContents::OnTabCreated(const mate::Dictionary& options,
auto api_window =
mate::TrackableObject<Window>::FromWeakMapID(isolate(), window_id);
if (api_window) {
if (opener_tab_id != TabStripModel::kNoTab ||
index == TabStripModel::kNoTab) {
tab_strip = api_window->window()->browser()->tab_strip_model();
index = owner_window()->browser()->tab_strip_model()->
order_controller()->DetermineInsertionIndex(
ui::PAGE_TRANSITION_LINK,
active ? TabStripModel::ADD_ACTIVE : TabStripModel::ADD_NONE);
}
// 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);
if (!tab_strip &&
(opener_tab_id != TabStripModel::kNoTab ||
index == TabStripModel::kNoTab)) {
tab_strip = owner_window()->browser()->tab_strip_model();
index = owner_window()->browser()->tab_strip_model()->
order_controller()->DetermineInsertionIndex(
ui::PAGE_TRANSITION_LINK,
active ? TabStripModel::ADD_ACTIVE : TabStripModel::ADD_NONE);
}

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 db08d69

Please sign in to comment.