OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/extensions/extension_window_list.h" |
| 6 |
| 7 #include <algorithm> |
| 8 |
| 9 #include "chrome/browser/sessions/session_id.h" |
| 10 #include "chrome/browser/ui/base_window.h" |
| 11 |
| 12 /////////////////////////////////////////////////////////////////////////////// |
| 13 // ExtensionWindowList |
| 14 |
| 15 // static |
| 16 ExtensionWindowList* ExtensionWindowList::GetInstance() { |
| 17 return Singleton<ExtensionWindowList>::get(); |
| 18 } |
| 19 |
| 20 ExtensionWindowList::ExtensionWindowList() { |
| 21 } |
| 22 |
| 23 ExtensionWindowList::~ExtensionWindowList() { |
| 24 } |
| 25 |
| 26 void ExtensionWindowList::AddExtensionWindow( |
| 27 ExtensionWindowController* window) { |
| 28 windows_.push_back(window); |
| 29 } |
| 30 |
| 31 void ExtensionWindowList::RemoveExtensionWindow( |
| 32 ExtensionWindowController* window) { |
| 33 WindowList::iterator iter = std::find( |
| 34 windows_.begin(), windows_.end(), window); |
| 35 if (iter != windows_.end()) |
| 36 windows_.erase(iter); |
| 37 } |
| 38 |
| 39 ExtensionWindowController* ExtensionWindowList::FindWindowById( |
| 40 Profile* profile, |
| 41 ProfileMatchType match_type, |
| 42 int id) const { |
| 43 for (WindowList::const_iterator iter = windows().begin(); |
| 44 iter != windows().end(); ++iter) { |
| 45 if ((*iter)->MatchesProfile(profile, match_type)) { |
| 46 if ((*iter)->GetSessionId().id() == id) |
| 47 return *iter; |
| 48 } |
| 49 } |
| 50 return NULL; |
| 51 } |
| 52 |
| 53 ExtensionWindowController* ExtensionWindowList::CurrentWindow( |
| 54 Profile* profile, |
| 55 ProfileMatchType match_type) const { |
| 56 ExtensionWindowController* result = NULL; |
| 57 // Returns either the focused window (if any), or the last window in the list. |
| 58 for (WindowList::const_iterator iter = windows().begin(); |
| 59 iter != windows().end(); ++iter) { |
| 60 if ((*iter)->MatchesProfile(profile, match_type)) { |
| 61 result = *iter; |
| 62 if (result->window()->IsActive()) |
| 63 break; // use focused window |
| 64 } |
| 65 } |
| 66 return result; |
| 67 } |
OLD | NEW |