diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index abc53473fc..08f17ede7d 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -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(); diff --git a/atom/browser/extensions/tab_helper.cc b/atom/browser/extensions/tab_helper.cc index df01838ef6..e5e06e0ba0 100644 --- a/atom/browser/extensions/tab_helper.cc +++ b/atom/browser/extensions/tab_helper.cc @@ -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); @@ -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()) { @@ -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(), diff --git a/atom/browser/extensions/tab_helper.h b/atom/browser/extensions/tab_helper.h index 274ab2e928..6d1449ea93 100644 --- a/atom/browser/extensions/tab_helper.h +++ b/atom/browser/extensions/tab_helper.h @@ -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 { @@ -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 @@ -197,6 +201,7 @@ class TabHelper : public content::WebContentsObserver, bool active_; bool is_placeholder_; bool window_closing_; + int opener_tab_id_; Browser* browser_; diff --git a/chromium_src/chrome/browser/extensions/extension_tab_util.cc b/chromium_src/chrome/browser/extensions/extension_tab_util.cc index b8aab4e50c..98ff6d62f2 100644 --- a/chromium_src/chrome/browser/extensions/extension_tab_util.cc +++ b/chromium_src/chrome/browser/extensions/extension_tab_util.cc @@ -183,11 +183,8 @@ std::unique_ptr 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; }