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 #ifndef CHROME_BROWSER_UI_TAB_CONTENTS_TAB_CONTENTS_ITERATOR_H_
6 #define CHROME_BROWSER_UI_TAB_CONTENTS_TAB_CONTENTS_ITERATOR_H_
10 #include "base/basictypes.h"
11 #include "chrome/browser/ui/browser_iterator.h"
17 // Iterates through all web view hosts in all browser windows. Because the
18 // renderers act asynchronously, getting a host through this interface does
19 // not guarantee that the renderer is ready to go. Doing anything to affect
20 // browser windows or tabs while iterating may cause incorrect behavior.
23 // for (TabContentsIterator iterator; !iterator.done(); iterator.Next()) {
24 // WebContents* cur = *iterator;
26 // iterator->OperationOnWebContents();
29 class TabContentsIterator
{
31 TabContentsIterator();
33 // Returns true if we are past the last Browser.
34 bool done() const { return cur_
== NULL
; }
36 // Returns the Browser instance associated with the current
37 // WebContents. Valid as long as !done().
38 Browser
* browser() const {
39 if (!browser_iterator_
.done())
40 return *browser_iterator_
;
44 // Returns the current WebContents, valid as long as !done().
45 content::WebContents
* operator->() const {
48 content::WebContents
* operator*() const {
52 // Loads the next host into |cur_|. This is designed so that for the initial
53 // call from the constructor, when browser_iterator_ points to the first
54 // Browser and web_view_index_ is -1, it will fill the first host.
58 // Tab index into the current Browser of the current web view.
61 // Current WebContents, or NULL if we're at the end of the list. This
62 // can be extracted given the browser iterator and index, but it's nice to
63 // cache this since the caller may access the current host many times.
64 content::WebContents
* cur_
;
66 // An iterator over all the browsers.
67 chrome::BrowserIterator browser_iterator_
;
69 DISALLOW_COPY_AND_ASSIGN(TabContentsIterator
);
72 #endif // CHROME_BROWSER_UI_TAB_CONTENTS_TAB_CONTENTS_ITERATOR_H_