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_helper.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 bool GetWindowFromWindowID(UIThreadExtensionFunction* function, |
| 16 int window_id, |
| 17 extensions::WindowController** controller) { |
| 18 if (window_id == extension_misc::kCurrentWindowId) { |
| 19 extensions::WindowController* extension_window_controller = |
| 20 function->dispatcher()->delegate()->GetExtensionWindowController(); |
| 21 // If there is a window controller associated with this extension, use that. |
| 22 if (extension_window_controller) { |
| 23 *controller = extension_window_controller; |
| 24 } else { |
| 25 // Otherwise get the focused or most recently added window. |
| 26 *controller = extensions::WindowControllerList::GetInstance()-> |
| 27 CurrentWindowForFunction(function); |
| 28 } |
| 29 if (!(*controller)) { |
| 30 function->SetError(extensions::tabs_constants::kNoCurrentWindowError); |
| 31 return false; |
| 32 } |
| 33 } else { |
| 34 *controller = extensions::WindowControllerList::GetInstance()-> |
| 35 FindWindowForFunctionById(function, window_id); |
| 36 if (!(*controller)) { |
| 37 function->SetError(extensions::ErrorUtils::FormatErrorMessage( |
| 38 extensions::tabs_constants::kWindowNotFoundError, |
| 39 base::IntToString(window_id))); |
| 40 return false; |
| 41 } |
| 42 } |
| 43 return true; |
| 44 } |
OLD | NEW |