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

Unified Diff: chrome/browser/extensions/extension_window_wrapper.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: 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/extension_window_wrapper.cc
diff --git a/chrome/browser/extensions/extension_window_wrapper.cc b/chrome/browser/extensions/extension_window_wrapper.cc
new file mode 100644
index 0000000000000000000000000000000000000000..298503996a9fd6ec1fce104f79db29f7f4355c23
--- /dev/null
+++ b/chrome/browser/extensions/extension_window_wrapper.cc
@@ -0,0 +1,91 @@
+// 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_wrapper.h"
+
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/sessions/session_id.h"
+#include "chrome/browser/ui/base_window.h"
+
+
sky 2012/02/22 21:46:25 nit: only one newline.
stevenjb 2012/02/23 02:19:15 Done.
+///////////////////////////////////////////////////////////////////////////////
+// ExtensionWindowWrapper
+
+ExtensionWindowWrapper::ExtensionWindowWrapper(
+ BaseWindow* window, Profile* profile) :
sky 2012/02/22 21:46:25 : on next line.
stevenjb 2012/02/23 02:19:15 Done.
+ window_(window),
+ profile_(profile) {
+}
+
+bool ExtensionWindowWrapper::MatchesProfile(
+ const Profile* match_profile, bool allow_incognito) const {
+ return ((profile_ == match_profile) ||
+ (allow_incognito &&
+ (profile_->HasOffTheRecordProfile() &&
+ profile_->GetOffTheRecordProfile() == match_profile)));
+}
+
+
+///////////////////////////////////////////////////////////////////////////////
+// ExtensionWindowWrapperList
+
+// static
+ExtensionWindowWrapperList* ExtensionWindowWrapperList::GetInstance() {
+ return Singleton<ExtensionWindowWrapperList>::get();
+}
+
+ExtensionWindowWrapperList::ExtensionWindowWrapperList() {
+}
+
+void ExtensionWindowWrapperList::AddExtensionWindow(
+ ExtensionWindowWrapper* window) {
+ windows_.push_back(window);
+}
+
+void ExtensionWindowWrapperList::RemoveExtensionWindow(
+ ExtensionWindowWrapper* window) {
+ WindowList::iterator iter = std::find(
+ windows_.begin(), windows_.end(), window);
+ if (iter != windows_.end())
+ windows_.erase(iter);
+}
+
+ExtensionWindowWrapper* ExtensionWindowWrapperList::FindWindowById(
+ const 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)
sky 2012/02/22 21:46:25 nit: combine if statements.
stevenjb 2012/02/23 02:19:15 Done.
+ return *iter;
+ }
+ }
+ return NULL;
+}
+
+ExtensionWindowWrapper* ExtensionWindowWrapperList::CurrentWindow(
+ const Profile* profile, bool include_incognito) const {
+ ExtensionWindowWrapper* 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;
+}
+
+ExtensionWindowWrapper* ExtensionWindowWrapperList::FocusedWindow(
+ const Profile* profile, bool include_incognito) const {
+ for (WindowList::const_iterator iter = windows().begin();
+ iter != windows().end(); ++iter) {
+ if ((*iter)->MatchesProfile(profile, include_incognito)) {
sky 2012/02/22 21:46:25 nit: combine if
stevenjb 2012/02/23 02:19:15 Done.
+ if ((*iter)->window()->IsActive())
+ return *iter;
+ }
+ }
+ return NULL;
+}

Powered by Google App Engine
This is Rietveld 408576698