OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 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/api/tabs/windows_util.h" | |
6 | |
7 #include "base/strings/string_number_conversions.h" | |
8 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" | |
9 #include "chrome/browser/extensions/extension_function.h" | |
10 #include "chrome/browser/extensions/extension_function_dispatcher.h" | |
11 #include "chrome/browser/extensions/window_controller.h" | |
12 #include "chrome/browser/extensions/window_controller_list.h" | |
13 #include "extensions/common/error_utils.h" | |
14 | |
15 namespace windows_util { | |
16 | |
not at google - send to devlin
2013/08/15 20:16:24
comment here would be nice
Kristen Dwan
2013/08/16 22:03:06
put one in header.
| |
17 bool GetWindowFromWindowID(UIThreadExtensionFunction* function, | |
18 int window_id, | |
19 extensions::WindowController** controller) { | |
20 if (window_id == extension_misc::kCurrentWindowId) { | |
21 extensions::WindowController* extension_window_controller = | |
22 function->dispatcher()->delegate()->GetExtensionWindowController(); | |
23 // If there is a window controller associated with this extension, use that. | |
24 if (extension_window_controller) { | |
25 *controller = extension_window_controller; | |
26 } else { | |
27 // Otherwise get the focused or most recently added window. | |
28 *controller = extensions::WindowControllerList::GetInstance()-> | |
29 CurrentWindowForFunction(function); | |
30 } | |
31 if (!(*controller)) { | |
32 function->SetError(extensions::tabs_constants::kNoCurrentWindowError); | |
33 return false; | |
34 } | |
35 } else { | |
36 *controller = extensions::WindowControllerList::GetInstance()-> | |
37 FindWindowForFunctionById(function, window_id); | |
38 if (!(*controller)) { | |
39 function->SetError(extensions::ErrorUtils::FormatErrorMessage( | |
40 extensions::tabs_constants::kWindowNotFoundError, | |
41 base::IntToString(window_id))); | |
42 return false; | |
43 } | |
44 } | |
45 return true; | |
46 } | |
47 | |
48 } // namespace windows_util | |
OLD | NEW |