OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/tabs/tab_strip_model.h" | 5 #include "chrome/browser/tabs/tab_strip_model.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "chrome/common/url_constants.h" | 27 #include "chrome/common/url_constants.h" |
28 #include "content/browser/tab_contents/tab_contents.h" | 28 #include "content/browser/tab_contents/tab_contents.h" |
29 #include "content/browser/tab_contents/tab_contents_view.h" | 29 #include "content/browser/tab_contents/tab_contents_view.h" |
30 #include "content/public/browser/navigation_controller.h" | 30 #include "content/public/browser/navigation_controller.h" |
31 #include "content/public/browser/navigation_entry.h" | 31 #include "content/public/browser/navigation_entry.h" |
32 #include "content/public/browser/notification_service.h" | 32 #include "content/public/browser/notification_service.h" |
33 #include "content/public/browser/render_process_host.h" | 33 #include "content/public/browser/render_process_host.h" |
34 #include "content/public/browser/user_metrics.h" | 34 #include "content/public/browser/user_metrics.h" |
35 #include "content/public/browser/web_contents_delegate.h" | 35 #include "content/public/browser/web_contents_delegate.h" |
36 | 36 |
| 37 using content::NavigationController; |
37 using content::NavigationEntry; | 38 using content::NavigationEntry; |
38 using content::UserMetricsAction; | 39 using content::UserMetricsAction; |
39 using content::WebContents; | 40 using content::WebContents; |
40 | 41 |
41 namespace { | 42 namespace { |
42 | 43 |
43 // Returns true if the specified transition is one of the types that cause the | 44 // Returns true if the specified transition is one of the types that cause the |
44 // opener relationships for the tab in which the transition occured to be | 45 // opener relationships for the tab in which the transition occured to be |
45 // forgotten. This is generally any navigation that isn't a link click (i.e. | 46 // forgotten. This is generally any navigation that isn't a link click (i.e. |
46 // any navigation that can be considered to be the start of a new task distinct | 47 // any navigation that can be considered to be the start of a new task distinct |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 int index = 0; | 382 int index = 0; |
382 TabContentsDataVector::const_iterator iter = contents_data_.begin(); | 383 TabContentsDataVector::const_iterator iter = contents_data_.begin(); |
383 for (; iter != contents_data_.end(); ++iter, ++index) { | 384 for (; iter != contents_data_.end(); ++iter, ++index) { |
384 if ((*iter)->contents->tab_contents() == contents) | 385 if ((*iter)->contents->tab_contents() == contents) |
385 return index; | 386 return index; |
386 } | 387 } |
387 return kNoTab; | 388 return kNoTab; |
388 } | 389 } |
389 | 390 |
390 int TabStripModel::GetIndexOfController( | 391 int TabStripModel::GetIndexOfController( |
391 const content::NavigationController* controller) const { | 392 const NavigationController* controller) const { |
392 int index = 0; | 393 int index = 0; |
393 TabContentsDataVector::const_iterator iter = contents_data_.begin(); | 394 TabContentsDataVector::const_iterator iter = contents_data_.begin(); |
394 for (; iter != contents_data_.end(); ++iter, ++index) { | 395 for (; iter != contents_data_.end(); ++iter, ++index) { |
395 if (&(*iter)->contents->tab_contents()->GetController() == controller) | 396 if (&(*iter)->contents->tab_contents()->GetController() == controller) |
396 return index; | 397 return index; |
397 } | 398 } |
398 return kNoTab; | 399 return kNoTab; |
399 } | 400 } |
400 | 401 |
401 void TabStripModel::UpdateTabContentsStateAt(int index, | 402 void TabStripModel::UpdateTabContentsStateAt(int index, |
(...skipping 23 matching lines...) Expand all Loading... |
425 | 426 |
426 bool TabStripModel::TabsAreLoading() const { | 427 bool TabStripModel::TabsAreLoading() const { |
427 TabContentsDataVector::const_iterator iter = contents_data_.begin(); | 428 TabContentsDataVector::const_iterator iter = contents_data_.begin(); |
428 for (; iter != contents_data_.end(); ++iter) { | 429 for (; iter != contents_data_.end(); ++iter) { |
429 if ((*iter)->contents->tab_contents()->IsLoading()) | 430 if ((*iter)->contents->tab_contents()->IsLoading()) |
430 return true; | 431 return true; |
431 } | 432 } |
432 return false; | 433 return false; |
433 } | 434 } |
434 | 435 |
435 content::NavigationController* TabStripModel::GetOpenerOfTabContentsAt( | 436 NavigationController* TabStripModel::GetOpenerOfTabContentsAt(int index) { |
436 int index) { | |
437 DCHECK(ContainsIndex(index)); | 437 DCHECK(ContainsIndex(index)); |
438 return contents_data_.at(index)->opener; | 438 return contents_data_.at(index)->opener; |
439 } | 439 } |
440 | 440 |
441 int TabStripModel::GetIndexOfNextTabContentsOpenedBy( | 441 int TabStripModel::GetIndexOfNextTabContentsOpenedBy( |
442 const content::NavigationController* opener, | 442 const NavigationController* opener, |
443 int start_index, | 443 int start_index, |
444 bool use_group) const { | 444 bool use_group) const { |
445 DCHECK(opener); | 445 DCHECK(opener); |
446 DCHECK(ContainsIndex(start_index)); | 446 DCHECK(ContainsIndex(start_index)); |
447 | 447 |
448 // Check tabs after start_index first. | 448 // Check tabs after start_index first. |
449 for (int i = start_index + 1; i < count(); ++i) { | 449 for (int i = start_index + 1; i < count(); ++i) { |
450 if (OpenerMatches(contents_data_[i], opener, use_group)) | 450 if (OpenerMatches(contents_data_[i], opener, use_group)) |
451 return i; | 451 return i; |
452 } | 452 } |
453 // Then check tabs before start_index, iterating backwards. | 453 // Then check tabs before start_index, iterating backwards. |
454 for (int i = start_index - 1; i >= 0; --i) { | 454 for (int i = start_index - 1; i >= 0; --i) { |
455 if (OpenerMatches(contents_data_[i], opener, use_group)) | 455 if (OpenerMatches(contents_data_[i], opener, use_group)) |
456 return i; | 456 return i; |
457 } | 457 } |
458 return kNoTab; | 458 return kNoTab; |
459 } | 459 } |
460 | 460 |
461 int TabStripModel::GetIndexOfFirstTabContentsOpenedBy( | 461 int TabStripModel::GetIndexOfFirstTabContentsOpenedBy( |
462 const content::NavigationController* opener, | 462 const NavigationController* opener, int start_index) const { |
463 int start_index) const { | |
464 DCHECK(opener); | 463 DCHECK(opener); |
465 DCHECK(ContainsIndex(start_index)); | 464 DCHECK(ContainsIndex(start_index)); |
466 | 465 |
467 for (int i = 0; i < start_index; ++i) { | 466 for (int i = 0; i < start_index; ++i) { |
468 if (contents_data_[i]->opener == opener) | 467 if (contents_data_[i]->opener == opener) |
469 return i; | 468 return i; |
470 } | 469 } |
471 return kNoTab; | 470 return kNoTab; |
472 } | 471 } |
473 | 472 |
474 int TabStripModel::GetIndexOfLastTabContentsOpenedBy( | 473 int TabStripModel::GetIndexOfLastTabContentsOpenedBy( |
475 const content::NavigationController* opener, int start_index) const { | 474 const NavigationController* opener, int start_index) const { |
476 DCHECK(opener); | 475 DCHECK(opener); |
477 DCHECK(ContainsIndex(start_index)); | 476 DCHECK(ContainsIndex(start_index)); |
478 | 477 |
479 TabContentsDataVector::const_iterator end = | 478 TabContentsDataVector::const_iterator end = |
480 contents_data_.begin() + start_index; | 479 contents_data_.begin() + start_index; |
481 TabContentsDataVector::const_iterator iter = contents_data_.end(); | 480 TabContentsDataVector::const_iterator iter = contents_data_.end(); |
482 TabContentsDataVector::const_iterator next; | 481 TabContentsDataVector::const_iterator next; |
483 for (; iter != end; --iter) { | 482 for (; iter != end; --iter) { |
484 next = iter - 1; | 483 next = iter - 1; |
485 if (next == end) | 484 if (next == end) |
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1085 for (int i = 0; i < count(); ++i) { | 1084 for (int i = 0; i < count(); ++i) { |
1086 if (i == index) | 1085 if (i == index) |
1087 continue; | 1086 continue; |
1088 if (GetTabContentsAt(i)->tab_contents()->GetURL().host() == domain) | 1087 if (GetTabContentsAt(i)->tab_contents()->GetURL().host() == domain) |
1089 indices->push_back(i); | 1088 indices->push_back(i); |
1090 } | 1089 } |
1091 } | 1090 } |
1092 | 1091 |
1093 void TabStripModel::GetIndicesWithSameOpener(int index, | 1092 void TabStripModel::GetIndicesWithSameOpener(int index, |
1094 std::vector<int>* indices) { | 1093 std::vector<int>* indices) { |
1095 content::NavigationController* opener = contents_data_[index]->group; | 1094 NavigationController* opener = contents_data_[index]->group; |
1096 if (!opener) { | 1095 if (!opener) { |
1097 // If there is no group, find all tabs with the selected tab as the opener. | 1096 // If there is no group, find all tabs with the selected tab as the opener. |
1098 opener = &(GetTabContentsAt(index)->tab_contents()->GetController()); | 1097 opener = &(GetTabContentsAt(index)->tab_contents()->GetController()); |
1099 if (!opener) | 1098 if (!opener) |
1100 return; | 1099 return; |
1101 } | 1100 } |
1102 for (int i = 0; i < count(); ++i) { | 1101 for (int i = 0; i < count(); ++i) { |
1103 if (i == index) | 1102 if (i == index) |
1104 continue; | 1103 continue; |
1105 if (contents_data_[i]->group == opener || | 1104 if (contents_data_[i]->group == opener || |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1314 MoveTabContentsAt(selection_model_.selected_indices()[tab_index], | 1313 MoveTabContentsAt(selection_model_.selected_indices()[tab_index], |
1315 target_index, false); | 1314 target_index, false); |
1316 } | 1315 } |
1317 tab_index++; | 1316 tab_index++; |
1318 target_index++; | 1317 target_index++; |
1319 } | 1318 } |
1320 } | 1319 } |
1321 | 1320 |
1322 // static | 1321 // static |
1323 bool TabStripModel::OpenerMatches(const TabContentsData* data, | 1322 bool TabStripModel::OpenerMatches(const TabContentsData* data, |
1324 const content::NavigationController* opener, | 1323 const NavigationController* opener, |
1325 bool use_group) { | 1324 bool use_group) { |
1326 return data->opener == opener || (use_group && data->group == opener); | 1325 return data->opener == opener || (use_group && data->group == opener); |
1327 } | 1326 } |
1328 | 1327 |
1329 void TabStripModel::ForgetOpenersAndGroupsReferencing( | 1328 void TabStripModel::ForgetOpenersAndGroupsReferencing( |
1330 const content::NavigationController* tab) { | 1329 const NavigationController* tab) { |
1331 for (TabContentsDataVector::const_iterator i = contents_data_.begin(); | 1330 for (TabContentsDataVector::const_iterator i = contents_data_.begin(); |
1332 i != contents_data_.end(); ++i) { | 1331 i != contents_data_.end(); ++i) { |
1333 if ((*i)->group == tab) | 1332 if ((*i)->group == tab) |
1334 (*i)->group = NULL; | 1333 (*i)->group = NULL; |
1335 if ((*i)->opener == tab) | 1334 if ((*i)->opener == tab) |
1336 (*i)->opener = NULL; | 1335 (*i)->opener = NULL; |
1337 } | 1336 } |
1338 } | 1337 } |
OLD | NEW |