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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/android/tab_model/tab_model_list.h"
7 #include "chrome/browser/android/tab_android.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/android/tab_model/tab_model.h"
10 #include "chrome/browser/ui/browser_navigator.h"
11 #include "content/public/browser/web_contents.h"
15 // Maintains and gives access to a static list of TabModel instances.
16 static TabModelList::TabModelVector
& tab_models() {
17 CR_DEFINE_STATIC_LOCAL(TabModelList::TabModelVector
,
18 tab_model_vector
, ());
19 return tab_model_vector
;
24 void TabModelList::AddTabModel(TabModel
* tab_model
) {
26 tab_models().push_back(tab_model
);
29 void TabModelList::RemoveTabModel(TabModel
* tab_model
) {
31 TabModelList::iterator remove_tab_model
=
32 std::find(tab_models().begin(), tab_models().end(), tab_model
);
34 if (remove_tab_model
!= tab_models().end())
35 tab_models().erase(remove_tab_model
);
38 void TabModelList::HandlePopupNavigation(chrome::NavigateParams
* params
) {
39 TabAndroid
* tab
= TabAndroid::FromWebContents(params
->source_contents
);
41 // NOTE: If this fails contact dtrainor@.
43 tab
->HandlePopupNavigation(params
);
46 TabModel
* TabModelList::GetTabModelForWebContents(
47 content::WebContents
* web_contents
) {
51 for (TabModelList::const_iterator i
= TabModelList::begin();
52 i
!= TabModelList::end(); ++i
) {
54 for (int index
= 0; index
< model
->GetTabCount(); index
++) {
55 if (web_contents
== model
->GetWebContentsAt(index
))
63 TabModel
* TabModelList::FindTabModelWithId(
64 SessionID::id_type desired_id
) {
65 for (TabModelList::const_iterator i
= TabModelList::begin();
66 i
!= TabModelList::end(); i
++) {
67 if ((*i
)->GetSessionId() == desired_id
)
74 bool TabModelList::IsOffTheRecordSessionActive() {
75 for (TabModelList::const_iterator i
= TabModelList::begin();
76 i
!= TabModelList::end(); i
++) {
77 if ((*i
)->IsOffTheRecord() && (*i
)->GetTabCount() > 0)
84 TabModelList::const_iterator
TabModelList::begin() {
85 return tab_models().begin();
88 TabModelList::const_iterator
TabModelList::end() {
89 return tab_models().end();
92 bool TabModelList::empty() {
93 return tab_models().empty();
96 size_t TabModelList::size() {
97 return tab_models().size();
100 TabModel
* TabModelList::get(size_t index
) {
101 DCHECK_LT(index
, size());
102 return tab_models()[index
];