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

Commit

Permalink
Set the opener's tabId on tab creation
Browse files Browse the repository at this point in the history
  • Loading branch information
bsclifton committed Jun 13, 2017
1 parent 5e013b2 commit f704abe
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions atom/browser/api/atom_api_web_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2556,6 +2556,7 @@ void WebContents::OnTabCreated(const mate::Dictionary& options,
content::WebContents* source = nullptr;
if (opener_tab_id != -1) {
source = extensions::TabHelper::GetTabById(opener_tab_id);
tab_helper->SetOpener(opener_tab_id);
}
if (!source)
source = web_contents();
Expand Down
6 changes: 6 additions & 0 deletions atom/browser/extensions/tab_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ TabHelper::TabHelper(content::WebContents* contents)
active_(false),
is_placeholder_(false),
window_closing_(false),
opener_tab_id_(TabStripModel::kNoTab),
browser_(nullptr) {
SessionTabHelper::CreateForWebContents(contents);
SetWindowId(-1);
Expand Down Expand Up @@ -210,6 +211,7 @@ void TabHelper::DidAttach() {
browser_->tab_strip_model()->ActivateTabAt(get_tab_strip_index(), true);
active_ = false;
}

if (is_placeholder()) {
guest()->SetCanRunInDetachedState(false);
if (!pinned_ && !IsDiscarded()) {
Expand Down Expand Up @@ -497,6 +499,10 @@ void TabHelper::SetTabValues(const base::DictionaryValue& values) {
values_->MergeDictionary(&values);
}

void TabHelper::SetOpener(int openerTabId) {
opener_tab_id_ = openerTabId;
}

void TabHelper::RenderViewCreated(content::RenderViewHost* render_view_host) {
render_view_map_[session_id()] = std::make_pair(
render_view_host->GetProcess()->GetID(),
Expand Down
5 changes: 5 additions & 0 deletions atom/browser/extensions/tab_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ class TabHelper : public content::WebContentsObserver,
return values_.get();
}

void SetOpener(int openerTabId);

bool ExecuteScriptInTab(mate::Arguments* args);

ScriptExecutor* script_executor() const {
Expand All @@ -125,6 +127,8 @@ class TabHelper : public content::WebContentsObserver,
void SetPlaceholder(bool is_placeholder);
bool is_placeholder() const { return is_placeholder_; }

int opener_tab_id() const { return opener_tab_id_; }

// If the specified WebContents has a TabHelper (probably because it
// was used as the contents of a tab), returns a tab id. This value is
// immutable for a given tab. It will be unique across Chrome within the
Expand Down Expand Up @@ -197,6 +201,7 @@ class TabHelper : public content::WebContentsObserver,
bool active_;
bool is_placeholder_;
bool window_closing_;
int opener_tab_id_;

Browser* browser_;

Expand Down
7 changes: 2 additions & 5 deletions chromium_src/chrome/browser/extensions/extension_tab_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,8 @@ std::unique_ptr<api::tabs::Tab> ExtensionTabUtil::CreateTabObject(
if (entry && entry->GetFavicon().valid)
tab_object->fav_icon_url.reset(
new std::string(entry->GetFavicon().url.spec()));
if (tab_strip) {
WebContents* opener = tab_strip->GetOpenerOfWebContentsAt(tab_index);
if (opener)
tab_object->opener_tab_id.reset(new int(GetTabIdForExtensions(opener)));
}

tab_object->opener_tab_id.reset(new int(tab_helper->opener_tab_id()));

return tab_object;
}
Expand Down

0 comments on commit f704abe

Please sign in to comment.