OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <string> |
| 6 #include <vector> |
| 7 |
5 #include "chrome/browser/extensions/api/tabs/windows_util.h" | 8 #include "chrome/browser/extensions/api/tabs/windows_util.h" |
6 | 9 |
7 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
8 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" | 11 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
9 #include "chrome/browser/extensions/chrome_extension_function.h" | 12 #include "chrome/browser/extensions/chrome_extension_function.h" |
10 #include "chrome/browser/extensions/chrome_extension_function_details.h" | 13 #include "chrome/browser/extensions/chrome_extension_function_details.h" |
| 14 #include "chrome/browser/extensions/extension_util.h" |
11 #include "chrome/browser/extensions/window_controller.h" | 15 #include "chrome/browser/extensions/window_controller.h" |
12 #include "chrome/browser/extensions/window_controller_list.h" | 16 #include "chrome/browser/extensions/window_controller_list.h" |
13 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
14 #include "extensions/browser/extension_function.h" | 18 #include "extensions/browser/extension_function.h" |
15 #include "extensions/browser/extension_function_dispatcher.h" | 19 #include "extensions/browser/extension_function_dispatcher.h" |
16 #include "extensions/common/constants.h" | 20 #include "extensions/common/constants.h" |
17 #include "extensions/common/error_utils.h" | 21 #include "extensions/common/error_utils.h" |
| 22 #include "extensions/common/extension.h" |
18 | 23 |
19 namespace windows_util { | 24 namespace windows_util { |
20 | 25 |
21 bool GetWindowFromWindowID(UIThreadExtensionFunction* function, | 26 bool GetWindowFromWindowID(UIThreadExtensionFunction* function, |
22 int window_id, | 27 int window_id, |
| 28 extensions::WindowController::TypeFilter filter, |
23 extensions::WindowController** controller) { | 29 extensions::WindowController** controller) { |
24 if (window_id == extension_misc::kCurrentWindowId) { | 30 if (window_id == extension_misc::kCurrentWindowId) { |
25 extensions::WindowController* extension_window_controller = | 31 extensions::WindowController* extension_window_controller = |
26 function->dispatcher()->GetExtensionWindowController(); | 32 function->dispatcher()->GetExtensionWindowController(); |
27 // If there is a window controller associated with this extension, use that. | 33 // If there is a window controller associated with this extension, use that. |
28 if (extension_window_controller) { | 34 if (extension_window_controller) { |
29 *controller = extension_window_controller; | 35 *controller = extension_window_controller; |
30 } else { | 36 } else { |
31 // Otherwise get the focused or most recently added window. | 37 // Otherwise get the focused or most recently added window. |
32 *controller = extensions::WindowControllerList::GetInstance() | 38 *controller = extensions::WindowControllerList::GetInstance() |
33 ->CurrentWindowForFunction(function); | 39 ->CurrentWindowForFunction(function); |
34 } | 40 } |
35 if (!(*controller)) { | 41 if (!(*controller)) { |
36 function->SetError(extensions::tabs_constants::kNoCurrentWindowError); | 42 function->SetError(extensions::tabs_constants::kNoCurrentWindowError); |
37 return false; | 43 return false; |
38 } | 44 } |
39 } else { | 45 } else { |
40 *controller = extensions::WindowControllerList::GetInstance() | 46 *controller = |
41 ->FindWindowForFunctionById(function, window_id); | 47 extensions::WindowControllerList::GetInstance() |
| 48 ->FindWindowForFunctionByIdWithFilter(function, window_id, filter); |
42 if (!(*controller)) { | 49 if (!(*controller)) { |
43 function->SetError(extensions::ErrorUtils::FormatErrorMessage( | 50 function->SetError(extensions::ErrorUtils::FormatErrorMessage( |
44 extensions::tabs_constants::kWindowNotFoundError, | 51 extensions::tabs_constants::kWindowNotFoundError, |
45 base::IntToString(window_id))); | 52 base::IntToString(window_id))); |
46 return false; | 53 return false; |
47 } | 54 } |
48 } | 55 } |
49 return true; | 56 return true; |
50 } | 57 } |
51 | 58 |
52 bool CanOperateOnWindow(const UIThreadExtensionFunction* function, | 59 bool CanOperateOnWindow(const UIThreadExtensionFunction* function, |
53 const extensions::WindowController* controller) { | 60 const extensions::WindowController* controller, |
54 if (function->extension() != NULL && | 61 extensions::WindowController::TypeFilter filter) { |
55 !controller->IsVisibleToExtension(function->extension())) { | 62 if (!controller->MatchesFilter(filter)) |
56 return false; | 63 return false; |
57 } | |
58 | 64 |
59 if (function->browser_context() == controller->profile()) | 65 if (function->browser_context() == controller->profile()) |
60 return true; | 66 return true; |
61 | 67 |
62 if (!function->include_incognito()) | 68 if (!function->include_incognito()) |
63 return false; | 69 return false; |
64 | 70 |
65 Profile* profile = Profile::FromBrowserContext(function->browser_context()); | 71 Profile* profile = Profile::FromBrowserContext(function->browser_context()); |
66 return profile->HasOffTheRecordProfile() && | 72 return profile->HasOffTheRecordProfile() && |
67 profile->GetOffTheRecordProfile() == controller->profile(); | 73 profile->GetOffTheRecordProfile() == controller->profile(); |
68 } | 74 } |
69 | 75 |
70 } // namespace windows_util | 76 } // namespace windows_util |
OLD | NEW |