| Index: chrome/browser/extensions/extension_window_list.cc
|
| diff --git a/chrome/browser/extensions/extension_window_list.cc b/chrome/browser/extensions/extension_window_list.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..2dd8fe9b0331fc77b9a7ab4c7049a34d76d8f890
|
| --- /dev/null
|
| +++ b/chrome/browser/extensions/extension_window_list.cc
|
| @@ -0,0 +1,77 @@
|
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/extensions/extension_window_list.h"
|
| +
|
| +#include <algorithm>
|
| +
|
| +#include "chrome/browser/extensions/extension_window_controller.h"
|
| +#include "chrome/browser/sessions/session_id.h"
|
| +#include "chrome/browser/ui/base_window.h"
|
| +
|
| +///////////////////////////////////////////////////////////////////////////////
|
| +// ExtensionWindowList
|
| +
|
| +// static
|
| +ExtensionWindowList* ExtensionWindowList::GetInstance() {
|
| + return Singleton<ExtensionWindowList>::get();
|
| +}
|
| +
|
| +ExtensionWindowList::ExtensionWindowList() {
|
| +}
|
| +
|
| +void ExtensionWindowList::AddExtensionWindow(
|
| + ExtensionWindowController* window) {
|
| + windows_.push_back(window);
|
| +}
|
| +
|
| +void ExtensionWindowList::RemoveExtensionWindow(
|
| + ExtensionWindowController* window) {
|
| + WindowList::iterator iter = std::find(
|
| + windows_.begin(), windows_.end(), window);
|
| + if (iter != windows_.end())
|
| + windows_.erase(iter);
|
| +}
|
| +
|
| +ExtensionWindowController* ExtensionWindowList::FindWindowById(
|
| + Profile* profile,
|
| + bool include_incognito,
|
| + int id) const {
|
| + for (WindowList::const_iterator iter = windows().begin();
|
| + iter != windows().end(); ++iter) {
|
| + if ((*iter)->MatchesProfile(profile, include_incognito)) {
|
| + if ((*iter)->GetSessionId().id() == id)
|
| + return *iter;
|
| + }
|
| + }
|
| + return NULL;
|
| +}
|
| +
|
| +ExtensionWindowController* ExtensionWindowList::CurrentWindow(
|
| + Profile* profile,
|
| + bool include_incognito) const {
|
| + ExtensionWindowController* result = NULL;
|
| + // Returns either the focused window (if any), or the last window in the list.
|
| + for (WindowList::const_iterator iter = windows().begin();
|
| + iter != windows().end(); ++iter) {
|
| + if ((*iter)->MatchesProfile(profile, include_incognito)) {
|
| + result = *iter;
|
| + if (result->window()->IsActive())
|
| + break; // use focused window
|
| + }
|
| + }
|
| + return result;
|
| +}
|
| +
|
| +ExtensionWindowController* ExtensionWindowList::FocusedWindow(
|
| + Profile* profile,
|
| + bool include_incognito) const {
|
| + for (WindowList::const_iterator iter = windows().begin();
|
| + iter != windows().end(); ++iter) {
|
| + if ((*iter)->MatchesProfile(profile, include_incognito) &&
|
| + (*iter)->window()->IsActive())
|
| + return *iter;
|
| + }
|
| + return NULL;
|
| +}
|
|
|