| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 5 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> |
| 9 #include <string> | 10 #include <string> |
| 10 | 11 |
| 11 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 12 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 13 #include "chrome/app/chrome_command_ids.h" | 14 #include "chrome/app/chrome_command_ids.h" |
| 14 #include "chrome/browser/browser_shutdown.h" | 15 #include "chrome/browser/browser_shutdown.h" |
| 15 #include "chrome/browser/defaults.h" | 16 #include "chrome/browser/defaults.h" |
| 16 #include "chrome/browser/extensions/tab_helper.h" | 17 #include "chrome/browser/extensions/tab_helper.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" | 19 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" |
| (...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 return i; | 592 return i; |
| 592 } | 593 } |
| 593 return kNoTab; | 594 return kNoTab; |
| 594 } | 595 } |
| 595 | 596 |
| 596 int TabStripModel::GetIndexOfLastWebContentsOpenedBy(const WebContents* opener, | 597 int TabStripModel::GetIndexOfLastWebContentsOpenedBy(const WebContents* opener, |
| 597 int start_index) const { | 598 int start_index) const { |
| 598 DCHECK(opener); | 599 DCHECK(opener); |
| 599 DCHECK(ContainsIndex(start_index)); | 600 DCHECK(ContainsIndex(start_index)); |
| 600 | 601 |
| 601 for (int i = contents_data_.size() - 1; i > start_index; --i) { | 602 std::set<const WebContents*> opener_and_descendants; |
| 602 if (contents_data_[i]->opener() == opener) | 603 opener_and_descendants.insert(opener); |
| 603 return i; | 604 int last_index = kNoTab; |
| 605 |
| 606 for (int i = start_index + 1; i < count(); ++i) { |
| 607 // Test opened by transitively, i.e. include tabs opened by tabs opened by |
| 608 // opener, etc. Stop when we find the first non-descendant. |
| 609 if (!opener_and_descendants.count(contents_data_[i]->opener())) |
| 610 break; |
| 611 opener_and_descendants.insert(contents_data_[i]->web_contents()); |
| 612 last_index = i; |
| 604 } | 613 } |
| 605 return kNoTab; | 614 return last_index; |
| 606 } | 615 } |
| 607 | 616 |
| 608 void TabStripModel::TabNavigating(WebContents* contents, | 617 void TabStripModel::TabNavigating(WebContents* contents, |
| 609 ui::PageTransition transition) { | 618 ui::PageTransition transition) { |
| 610 if (ShouldForgetOpenersForTransition(transition)) { | 619 if (ShouldForgetOpenersForTransition(transition)) { |
| 611 // Don't forget the openers if this tab is a New Tab page opened at the | 620 // Don't forget the openers if this tab is a New Tab page opened at the |
| 612 // end of the TabStrip (e.g. by pressing Ctrl+T). Give the user one | 621 // end of the TabStrip (e.g. by pressing Ctrl+T). Give the user one |
| 613 // navigation of one of these transition types before resetting the | 622 // navigation of one of these transition types before resetting the |
| 614 // opener relationships (this allows for the use case of opening a new | 623 // opener relationships (this allows for the use case of opening a new |
| 615 // tab to do a quick look-up of something while viewing a tab earlier in | 624 // tab to do a quick look-up of something while viewing a tab earlier in |
| (...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1429 void TabStripModel::ForgetOpenersAndGroupsReferencing( | 1438 void TabStripModel::ForgetOpenersAndGroupsReferencing( |
| 1430 const WebContents* tab) { | 1439 const WebContents* tab) { |
| 1431 for (WebContentsDataVector::const_iterator i = contents_data_.begin(); | 1440 for (WebContentsDataVector::const_iterator i = contents_data_.begin(); |
| 1432 i != contents_data_.end(); ++i) { | 1441 i != contents_data_.end(); ++i) { |
| 1433 if ((*i)->group() == tab) | 1442 if ((*i)->group() == tab) |
| 1434 (*i)->set_group(NULL); | 1443 (*i)->set_group(NULL); |
| 1435 if ((*i)->opener() == tab) | 1444 if ((*i)->opener() == tab) |
| 1436 (*i)->set_opener(NULL); | 1445 (*i)->set_opener(NULL); |
| 1437 } | 1446 } |
| 1438 } | 1447 } |
| OLD | NEW |