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

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: nit 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
« no previous file with comments | « chrome/browser/extensions/window_controller_list.h ('k') | chrome/browser/ui/panels/panel.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
11 #include "chrome/browser/extensions/window_controller_list_observer.h" 11 #include "chrome/browser/extensions/window_controller_list_observer.h"
12 #include "chrome/common/extensions/api/windows.h"
12 #include "components/sessions/session_id.h" 13 #include "components/sessions/session_id.h"
13 #include "extensions/browser/extension_function.h" 14 #include "extensions/browser/extension_function.h"
14 #include "ui/base/base_window.h" 15 #include "ui/base/base_window.h"
15 16
16 namespace extensions { 17 namespace extensions {
17 18
18 /////////////////////////////////////////////////////////////////////////////// 19 ///////////////////////////////////////////////////////////////////////////////
19 // WindowControllerList 20 // WindowControllerList
20 21
21 // static 22 // static
(...skipping 26 matching lines...) Expand all
48 void WindowControllerList::AddObserver(WindowControllerListObserver* observer) { 49 void WindowControllerList::AddObserver(WindowControllerListObserver* observer) {
49 observers_.AddObserver(observer); 50 observers_.AddObserver(observer);
50 } 51 }
51 52
52 void WindowControllerList::RemoveObserver( 53 void WindowControllerList::RemoveObserver(
53 WindowControllerListObserver* observer) { 54 WindowControllerListObserver* observer) {
54 observers_.RemoveObserver(observer); 55 observers_.RemoveObserver(observer);
55 } 56 }
56 57
57 WindowController* WindowControllerList::FindWindowById(int id) const { 58 WindowController* WindowControllerList::FindWindowById(int id) const {
59 return FindWindowByIdWithFilter(id,
60 WindowController::GetDefaultWindowFilter());
61 }
62
63 WindowController* WindowControllerList::FindWindowByIdWithFilter(
64 int id,
65 WindowController::TypeFilter filter) const {
58 for (ControllerList::const_iterator iter = windows().begin(); 66 for (ControllerList::const_iterator iter = windows().begin();
59 iter != windows().end(); ++iter) { 67 iter != windows().end(); ++iter) {
60 if ((*iter)->GetWindowId() == id) 68 if ((*iter)->GetWindowId() == id && (*iter)->MatchesFilter(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, WindowController::GetDefaultWindowFilter());
79 }
80
81 WindowController* WindowControllerList::FindWindowForFunctionByIdWithFilter(
82 const UIThreadExtensionFunction* function,
83 int id,
84 WindowController::TypeFilter 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, WindowController::GetDefaultWindowFilter());
96 }
97
98 WindowController* WindowControllerList::CurrentWindowForFunctionWithFilter(
99 const UIThreadExtensionFunction* function,
100 WindowController::TypeFilter 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
« no previous file with comments | « chrome/browser/extensions/window_controller_list.h ('k') | chrome/browser/ui/panels/panel.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698