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

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

Issue 1099553002: extensions: windows: list all windows from the current profile (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix bitmask issue Created 5 years, 4 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/window_controller_list.h" 5 #include "chrome/browser/extensions/window_controller_list.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "chrome/browser/extensions/api/tabs/windows_util.h" 9 #include "chrome/browser/extensions/api/tabs/windows_util.h"
10 #include "chrome/browser/extensions/chrome_extension_function_details.h" 10 #include "chrome/browser/extensions/chrome_extension_function_details.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 void WindowControllerList::AddObserver(WindowControllerListObserver* observer) { 48 void WindowControllerList::AddObserver(WindowControllerListObserver* observer) {
49 observers_.AddObserver(observer); 49 observers_.AddObserver(observer);
50 } 50 }
51 51
52 void WindowControllerList::RemoveObserver( 52 void WindowControllerList::RemoveObserver(
53 WindowControllerListObserver* observer) { 53 WindowControllerListObserver* observer) {
54 observers_.RemoveObserver(observer); 54 observers_.RemoveObserver(observer);
55 } 55 }
56 56
57 WindowController* WindowControllerList::FindWindowById(int id) const { 57 WindowController* WindowControllerList::FindWindowById(int id) const {
58 return FindWindowByIdWithFilter(id,
59 windows_util::GetDefaultWindowTypeFilter());
60 }
61
62 WindowController* WindowControllerList::FindWindowByIdWithFilter(
63 int id,
64 WindowTypeFilter filter) const {
58 for (ControllerList::const_iterator iter = windows().begin(); 65 for (ControllerList::const_iterator iter = windows().begin();
59 iter != windows().end(); ++iter) { 66 iter != windows().end(); ++iter) {
60 if ((*iter)->GetWindowId() == id) 67 if ((*iter)->GetWindowId() == id &&
68 windows_util::WindowMatchesTypeFilter(*iter, filter))
61 return *iter; 69 return *iter;
62 } 70 }
63 return NULL; 71 return nullptr;
64 } 72 }
65 73
66 WindowController* WindowControllerList::FindWindowForFunctionById( 74 WindowController* WindowControllerList::FindWindowForFunctionById(
67 const UIThreadExtensionFunction* function, 75 const UIThreadExtensionFunction* function,
68 int id) const { 76 int id) const {
69 WindowController* controller = FindWindowById(id); 77 return FindWindowForFunctionByIdWithFilter(
70 if (controller && windows_util::CanOperateOnWindow(function, controller)) 78 function, id, windows_util::GetDefaultWindowTypeFilter());
79 }
80
81 WindowController* WindowControllerList::FindWindowForFunctionByIdWithFilter(
82 const UIThreadExtensionFunction* function,
83 int id,
84 WindowTypeFilter filter) const {
85 WindowController* controller = FindWindowByIdWithFilter(id, filter);
86 if (controller &&
87 windows_util::CanOperateOnWindow(function, controller, filter))
71 return controller; 88 return controller;
72 return NULL; 89 return nullptr;
73 } 90 }
74 91
75 WindowController* WindowControllerList::CurrentWindowForFunction( 92 WindowController* WindowControllerList::CurrentWindowForFunction(
76 const UIThreadExtensionFunction* function) const { 93 const UIThreadExtensionFunction* function) const {
77 WindowController* result = NULL; 94 return CurrentWindowForFunctionWithFilter(
95 function, windows_util::GetDefaultWindowTypeFilter());
96 }
97
98 WindowController* WindowControllerList::CurrentWindowForFunctionWithFilter(
99 const UIThreadExtensionFunction* function,
100 WindowTypeFilter filter) const {
101 WindowController* result = nullptr;
78 // Returns either the focused window (if any), or the last window in the list. 102 // Returns either the focused window (if any), or the last window in the list.
79 for (ControllerList::const_iterator iter = windows().begin(); 103 for (ControllerList::const_iterator iter = windows().begin();
80 iter != windows().end(); ++iter) { 104 iter != windows().end(); ++iter) {
81 if (windows_util::CanOperateOnWindow(function, *iter)) { 105 if (windows_util::CanOperateOnWindow(function, *iter, filter)) {
82 result = *iter; 106 result = *iter;
83 if (result->window()->IsActive()) 107 if (result->window()->IsActive())
84 break; // use focused window 108 break; // use focused window
85 } 109 }
86 } 110 }
87 return result; 111 return result;
88 } 112 }
89 113
90 } // namespace extensions 114 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698