Chromium Code Reviews| 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_wrapper.h" | |
| 6 | |
| 7 #include "chrome/browser/profiles/profile.h" | |
| 8 #include "chrome/browser/sessions/session_id.h" | |
| 9 #include "chrome/browser/ui/base_window.h" | |
| 10 | |
| 11 | |
|
sky
2012/02/22 21:46:25
nit: only one newline.
stevenjb
2012/02/23 02:19:15
Done.
| |
| 12 /////////////////////////////////////////////////////////////////////////////// | |
| 13 // ExtensionWindowWrapper | |
| 14 | |
| 15 ExtensionWindowWrapper::ExtensionWindowWrapper( | |
| 16 BaseWindow* window, Profile* profile) : | |
|
sky
2012/02/22 21:46:25
: on next line.
stevenjb
2012/02/23 02:19:15
Done.
| |
| 17 window_(window), | |
| 18 profile_(profile) { | |
| 19 } | |
| 20 | |
| 21 bool ExtensionWindowWrapper::MatchesProfile( | |
| 22 const Profile* match_profile, bool allow_incognito) const { | |
| 23 return ((profile_ == match_profile) || | |
| 24 (allow_incognito && | |
| 25 (profile_->HasOffTheRecordProfile() && | |
| 26 profile_->GetOffTheRecordProfile() == match_profile))); | |
| 27 } | |
| 28 | |
| 29 | |
| 30 /////////////////////////////////////////////////////////////////////////////// | |
| 31 // ExtensionWindowWrapperList | |
| 32 | |
| 33 // static | |
| 34 ExtensionWindowWrapperList* ExtensionWindowWrapperList::GetInstance() { | |
| 35 return Singleton<ExtensionWindowWrapperList>::get(); | |
| 36 } | |
| 37 | |
| 38 ExtensionWindowWrapperList::ExtensionWindowWrapperList() { | |
| 39 } | |
| 40 | |
| 41 void ExtensionWindowWrapperList::AddExtensionWindow( | |
| 42 ExtensionWindowWrapper* window) { | |
| 43 windows_.push_back(window); | |
| 44 } | |
| 45 | |
| 46 void ExtensionWindowWrapperList::RemoveExtensionWindow( | |
| 47 ExtensionWindowWrapper* window) { | |
| 48 WindowList::iterator iter = std::find( | |
| 49 windows_.begin(), windows_.end(), window); | |
| 50 if (iter != windows_.end()) | |
| 51 windows_.erase(iter); | |
| 52 } | |
| 53 | |
| 54 ExtensionWindowWrapper* ExtensionWindowWrapperList::FindWindowById( | |
| 55 const Profile* profile, bool include_incognito, int id) const { | |
| 56 for (WindowList::const_iterator iter = windows().begin(); | |
| 57 iter != windows().end(); ++iter) { | |
| 58 if ((*iter)->MatchesProfile(profile, include_incognito)) { | |
| 59 if ((*iter)->GetSessionId().id() == id) | |
|
sky
2012/02/22 21:46:25
nit: combine if statements.
stevenjb
2012/02/23 02:19:15
Done.
| |
| 60 return *iter; | |
| 61 } | |
| 62 } | |
| 63 return NULL; | |
| 64 } | |
| 65 | |
| 66 ExtensionWindowWrapper* ExtensionWindowWrapperList::CurrentWindow( | |
| 67 const Profile* profile, bool include_incognito) const { | |
| 68 ExtensionWindowWrapper* result = NULL; | |
| 69 // Returns either the focused window (if any), or the last window in the list. | |
| 70 for (WindowList::const_iterator iter = windows().begin(); | |
| 71 iter != windows().end(); ++iter) { | |
| 72 if ((*iter)->MatchesProfile(profile, include_incognito)) { | |
| 73 result = *iter; | |
| 74 if (result->window()->IsActive()) | |
| 75 break; // use focused window | |
| 76 } | |
| 77 } | |
| 78 return result; | |
| 79 } | |
| 80 | |
| 81 ExtensionWindowWrapper* ExtensionWindowWrapperList::FocusedWindow( | |
| 82 const Profile* profile, bool include_incognito) const { | |
| 83 for (WindowList::const_iterator iter = windows().begin(); | |
| 84 iter != windows().end(); ++iter) { | |
| 85 if ((*iter)->MatchesProfile(profile, include_incognito)) { | |
|
sky
2012/02/22 21:46:25
nit: combine if
stevenjb
2012/02/23 02:19:15
Done.
| |
| 86 if ((*iter)->window()->IsActive()) | |
| 87 return *iter; | |
| 88 } | |
| 89 } | |
| 90 return NULL; | |
| 91 } | |
| OLD | NEW |