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. 4 5 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" 6 7 #include "base/logging.h" 8 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" 11 TabContentsIterator()12TabContentsIterator::TabContentsIterator() 13 : web_view_index_(-1), 14 cur_(NULL) { 15 // Load the first WebContents into |cur_|. 16 Next(); 17 } 18 Next()19void TabContentsIterator::Next() { 20 // The current WebContents should be valid unless we are at the beginning. 21 DCHECK(cur_ || web_view_index_ == -1) << "Trying to advance past the end"; 22 23 // Update |cur_| to the next WebContents in the list. 24 while (!browser_iterator_.done()) { 25 if (++web_view_index_ >= browser_iterator_->tab_strip_model()->count()) { 26 // Advance to the next Browser in the list. 27 browser_iterator_.Next(); 28 web_view_index_ = -1; 29 continue; 30 } 31 32 content::WebContents* next_tab = browser_iterator_->tab_strip_model() 33 ->GetWebContentsAt(web_view_index_); 34 if (next_tab) { 35 cur_ = next_tab; 36 return; 37 } 38 } 39 // Reached the end. 40 cur_ = NULL; 41 } 42