summaryrefslogtreecommitdiff
blob: c0ae11ff076bc78eb7661e4250fa19478d5a42d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
--- seamonkey-2.53.7/comm/suite/app/profile/suite-prefs.js
+++ seamonkey-2.53.7/comm/suite/app/profile/suite-prefs.js
@@ -225,16 +225,17 @@ pref("browser.tabs.autoHide", false);
 pref("browser.tabs.forceHide", false);
 pref("browser.tabs.closeWindowWithLastTab", true);
 pref("browser.tabs.warnOnClose", true);
 pref("browser.tabs.warnOnCloseOther", true);
 pref("browser.tabs.warnOnOpen", true);
 pref("browser.tabs.maxOpenBeforeWarn", 15);
 pref("browser.tabs.insertRelatedAfterCurrent", true);
 pref("browser.tabs.insertAllTabsAfterCurrent", false);
+pref("browser.tabs.selectOwnerOnClose", true);
 
 // For future use
 pref("browser.tabs.loadBookmarksInBackground", false);
 
 // how many browsers can be saved in the DOM (by the tabbed browser)
 pref("browser.tabs.max_tabs_undo", 3);
 // should popups by saved in the DOM (by the tabbed browser)
 pref("browser.tabs.cache_popups", false);
--- seamonkey-2.53.7/comm/suite/base/content/utilityOverlay.js
+++ seamonkey-2.53.7/comm/suite/base/content/utilityOverlay.js
@@ -1624,21 +1624,23 @@ function openLinkIn(url, where, params)
     // forces tab to be focused
     loadInBackground = true;
     // fall through
   case "tabshifted":
     loadInBackground = !loadInBackground;
     // fall through
   case "tab":
     var browser = w.getBrowser();
+    var owner = loadInBackground ? null : browser.selectedTab;
     var tab = browser.addTab(url, {
                 referrerURI: aReferrerURI,
                 referrerPolicy: aReferrerPolicy,
                 charset: aCharset,
                 postData: aPostData,
+                ownerTab: owner,
                 allowThirdPartyFixup: aAllowThirdPartyFixup,
                 relatedToCurrent: aRelatedToCurrent,
                 allowMixedContent: aAllowMixedContent,
                 noReferrer: aNoReferrer,
                 userContextId: aUserContextId,
                 originPrincipal: aPrincipal,
                 triggeringPrincipal: aTriggeringPrincipal,
               });
--- seamonkey-2.53.7/comm/suite/browser/tabbrowser.xml
+++ seamonkey-2.53.7/comm/suite/browser/tabbrowser.xml
@@ -1151,16 +1151,28 @@
             newBrowser.docShellIsActive = this.mCurrentTab.linkedBrowser.docShellIsActive;
             if (this.mCurrentBrowser) {
               this.mCurrentBrowser.droppedLinkHandler = null;
               this.mCurrentBrowser.docShellIsActive = false;
               this.mCurrentBrowser.removeAttribute("primary");
               this.finder.mListeners.forEach(l => this.mCurrentBrowser.finder.removeResultListener(l));
             }
 
+            var oldTab = this.mCurrentTab;
+
+            // Preview mode should not reset the owner
+            if (!this._previewMode && !oldTab.selected)
+              oldTab.owner = null;
+
+            let lastRelatedTab = this.mLastRelatedIndex ? this.tabs[this.mLastRelatedIndex] : null;
+            if (lastRelatedTab) {
+              if (!lastRelatedTab.selected)
+                lastRelatedTab.owner = null;
+            }
+
             newBrowser.setAttribute("primary", "true");
             this.mCurrentBrowser = newBrowser;
             this.mCurrentTab = this.selectedTab;
             this.mCurrentTab.removeAttribute("unread");
             this.finder.mListeners.forEach(l => this.mCurrentBrowser.finder.addResultListener(l));
 
             var tabListener = this.mTabListeners[this.tabContainer.selectedIndex];
 
@@ -1445,16 +1457,19 @@
                 opener: null,
               };
             }
 
             params.focusNewTab = params.inBackground != null ?
                 !params.inBackground :
                 !Services.prefs.getBoolPref("browser.tabs.loadInBackground");
 
+            if (params.focusNewTab)
+              params.ownerTab = this.selectedTab;
+
             return this.addTab(aURI, params);
          ]]>
         </body>
       </method>
 
       <method name="loadTabs">
         <parameter name="aURIs"/>
         <parameter name="aLoadInBackground"/>
@@ -1556,43 +1571,49 @@
         <parameter name="aPostData"/>
         <parameter name="aFocusNewTab"/>
         <parameter name="aAllowThirdPartyFixup"/>
         <body>
           <![CDATA[
             var aTriggeringPrincipal;
             var aReferrerPolicy;
             var aFromExternal;
+            var aOwner;
             var aRelatedToCurrent;
             var aAllowMixedContent;
             var aNoReferrer;
             var aUserContextId;
             var aOriginPrincipal;
             var aOpener;
             if (arguments.length == 2 &&
                 arguments[1] != null &&
                 typeof arguments[1] == "object" &&
                 !(arguments[1] instanceof Ci.nsIURI)) {
               let params = arguments[1];
               aTriggeringPrincipal  = params.triggeringPrincipal;
               aReferrerURI          = params.referrerURI;
               aReferrerPolicy       = params.referrerPolicy;
               aCharset              = params.charset;
               aPostData             = params.postData;
+              aOwner                = params.ownerTab;
               aFocusNewTab          = params.focusNewTab;
               aAllowThirdPartyFixup = params.allowThirdPartyFixup;
               aFromExternal         = params.fromExternal;
               aRelatedToCurrent     = params.relatedToCurrent;
               aAllowMixedContent    = params.allowMixedContent;
               aNoReferrer           = params.noReferrer;
               aUserContextId        = params.userContextId;
               aOriginPrincipal      = params.originPrincipal;
               aOpener               = params.opener;
             }
 
+            // if we're adding tabs, we're past interrupt mode, ditch the owner
+            if (this.mCurrentTab.owner)
+              this.mCurrentTab.owner = null;
+
             this._browsers = null; // invalidate cache
 
             var t = this.referenceTab.cloneNode(true);
 
             var blank = !aURI || aURI == "about:blank";
 
             if (!blank)
               t.setAttribute("label", aURI);
@@ -1640,16 +1661,20 @@
 
             // We start our browsers out as inactive.
             b.docShellIsActive = false;
 
             this.mStrip.collapsed = false;
 
             Services.prefs.setBoolPref("browser.tabs.forceHide", false);
 
+            // If this new tab is owned by another, assert that relationship
+            if (aOwner)
+              t.owner = aOwner;
+
             // wire up a progress listener for the new browser object.
             var position = this.tabs.length - 1;
             var tabListener = this.mTabProgressListener(t, b, blank);
             const filter = Cc["@mozilla.org/appshell/component/browser-status-filter;1"]
                              .createInstance(Ci.nsIWebProgress);
             filter.addProgressListener(tabListener, Ci.nsIWebProgress.NOTIFY_ALL);
             b.webProgress.addProgressListener(filter, Ci.nsIWebProgress.NOTIFY_ALL);
             this.mTabListeners[position] = tabListener;
@@ -1689,16 +1714,20 @@
             // aReferrerURI is null or undefined if the tab is opened from
             // an external application or bookmark, i.e. somewhere other
             // than the current tab.
             if ((aRelatedToCurrent || aReferrerURI ||
                  Services.prefs.getBoolPref("browser.tabs.insertAllTabsAfterCurrent")) &&
                 Services.prefs.getBoolPref("browser.tabs.insertRelatedAfterCurrent")) {
               var lastRelatedIndex = this.mLastRelatedIndex ||
                                      this.tabContainer.selectedIndex;
+              if (this.mLastRelatedIndex)
+                  this.tabs[this.mLastRelatedIndex].owner = null;
+              else
+                  t.owner = this.selectedTab;
               this.moveTabTo(t, ++lastRelatedIndex);
               this.mLastRelatedIndex = lastRelatedIndex;
             }
 
             if (aFocusNewTab) {
               var parentTab = this.selectedTab;
               this.selectedTab = t;
               this.mPreviousTab = parentTab;
@@ -2007,16 +2036,23 @@
             oldBrowser.webProgress.removeProgressListener(filter);
             filter.removeProgressListener(this.mTabListeners[index]);
             this.mTabFilters.splice(index, 1);
             this.mTabListeners.splice(index, 1);
 
             // We are no longer the primary content area
             oldBrowser.removeAttribute("primary");
 
+            // Remove this tab as the owner of any other tabs, since it's going away.
+            for (let tab of this.tabs) {
+              if ("owner" in tab && tab.owner == aTab)
+                // |tab| is a child of the tab we're removing, make it an orphan
+                tab.owner = null;
+            }
+
             // Now select the new tab before nuking the old one.
             var currentIndex = this.tabContainer.selectedIndex;
 
             var newIndex = -1;
             if (currentIndex > index)
               newIndex = currentIndex - 1;
             else if (currentIndex < index)
               newIndex = currentIndex;
@@ -2033,17 +2069,21 @@
             this._browsers = null;
 
             // Clean up before/afterselected attributes before removing the tab
             aTab._selected = false;
             aTab.remove();
 
             // When the current tab is removed select a new tab
             // and fire select events on tabpanels and tabs
-            if (this.mPreviousTab && (aTab == this.mCurrentTab))
+            if (aTab.owner && !aTab.owner.hidden && !aTab.owner.closing &&
+                Services.prefs.getBoolPref("browser.tabs.selectOwnerOnClose")) {
+              this.selectedTab = aTab.owner;
+            }
+            else if (this.mPreviousTab && (aTab == this.mCurrentTab))
               this.selectedTab = this.mPreviousTab;
             else {
               this.tabContainer.selectedIndex = newIndex;
 
               // We need to explicitly clear this, because updateCurrentBrowser
               // doesn't get called for a background tab
               this.mPreviousTab = null;
             }