Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: chrome/browser/extensions/extension_window_list.cc

Issue 9428018: Create BaseWindow and ExtensionWindowWrapper for extension API access to Panels (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Address comments. Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/extensions/extension_window_controller.h"
10 #include "chrome/browser/sessions/session_id.h"
11 #include "chrome/browser/ui/base_window.h"
12
13 ///////////////////////////////////////////////////////////////////////////////
14 // ExtensionWindowList
15
16 // static
17 ExtensionWindowList* ExtensionWindowList::GetInstance() {
18 return Singleton<ExtensionWindowList>::get();
19 }
20
21 ExtensionWindowList::ExtensionWindowList() {
22 }
23
24 void ExtensionWindowList::AddExtensionWindow(
25 ExtensionWindowController* window) {
26 windows_.push_back(window);
27 }
28
29 void ExtensionWindowList::RemoveExtensionWindow(
30 ExtensionWindowController* window) {
31 WindowList::iterator iter = std::find(
32 windows_.begin(), windows_.end(), window);
33 if (iter != windows_.end())
34 windows_.erase(iter);
35 }
36
37 ExtensionWindowController* ExtensionWindowList::FindWindowById(
38 Profile* profile,
39 bool include_incognito,
40 int id) const {
41 for (WindowList::const_iterator iter = windows().begin();
42 iter != windows().end(); ++iter) {
43 if ((*iter)->MatchesProfile(profile, include_incognito)) {
44 if ((*iter)->GetSessionId().id() == id)
45 return *iter;
46 }
47 }
48 return NULL;
49 }
50
51 ExtensionWindowController* ExtensionWindowList::CurrentWindow(
52 Profile* profile,
53 bool include_incognito) const {
54 ExtensionWindowController* result = NULL;
55 // Returns either the focused window (if any), or the last window in the list.
56 for (WindowList::const_iterator iter = windows().begin();
57 iter != windows().end(); ++iter) {
58 if ((*iter)->MatchesProfile(profile, include_incognito)) {
59 result = *iter;
60 if (result->window()->IsActive())
61 break; // use focused window
62 }
63 }
64 return result;
65 }
66
67 ExtensionWindowController* ExtensionWindowList::FocusedWindow(
68 Profile* profile,
69 bool include_incognito) const {
70 for (WindowList::const_iterator iter = windows().begin();
71 iter != windows().end(); ++iter) {
72 if ((*iter)->MatchesProfile(profile, include_incognito) &&
73 (*iter)->window()->IsActive())
74 return *iter;
75 }
76 return NULL;
77 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698