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

Unified Diff: chrome/browser/extensions/api/tabs/windows_util.cc

Issue 21022018: Sessions API - previously Session Restore API. Supports restoring currently open foreign windows an… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: delete test. Created 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/tabs/windows_util.cc
diff --git a/chrome/browser/extensions/api/tabs/windows_util.cc b/chrome/browser/extensions/api/tabs/windows_util.cc
new file mode 100644
index 0000000000000000000000000000000000000000..29f43a004f709d09a962847e238dce6b60d10657
--- /dev/null
+++ b/chrome/browser/extensions/api/tabs/windows_util.cc
@@ -0,0 +1,48 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/extensions/api/tabs/windows_util.h"
+
+#include "base/strings/string_number_conversions.h"
+#include "chrome/browser/extensions/api/tabs/tabs_constants.h"
+#include "chrome/browser/extensions/extension_function.h"
+#include "chrome/browser/extensions/extension_function_dispatcher.h"
+#include "chrome/browser/extensions/window_controller.h"
+#include "chrome/browser/extensions/window_controller_list.h"
+#include "extensions/common/error_utils.h"
+
+namespace windows_util {
+
+bool GetWindowFromWindowID(UIThreadExtensionFunction* function,
+ int window_id,
+ extensions::WindowController** controller) {
+ if (window_id == extension_misc::kCurrentWindowId) {
+ extensions::WindowController* extension_window_controller =
+ function->dispatcher()->delegate()->GetExtensionWindowController();
+ // If there is a window controller associated with this extension, use that.
+ if (extension_window_controller) {
+ *controller = extension_window_controller;
+ } else {
+ // Otherwise get the focused or most recently added window.
+ *controller = extensions::WindowControllerList::GetInstance()->
+ CurrentWindowForFunction(function);
+ }
+ if (!(*controller)) {
+ function->SetError(extensions::tabs_constants::kNoCurrentWindowError);
+ return false;
+ }
+ } else {
+ *controller = extensions::WindowControllerList::GetInstance()->
+ FindWindowForFunctionById(function, window_id);
+ if (!(*controller)) {
+ function->SetError(extensions::ErrorUtils::FormatErrorMessage(
+ extensions::tabs_constants::kWindowNotFoundError,
+ base::IntToString(window_id)));
+ return false;
+ }
+ }
+ return true;
+}
+
+} // namespace windows_util
« no previous file with comments | « chrome/browser/extensions/api/tabs/windows_util.h ('k') | chrome/browser/extensions/extension_function_histogram_value.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698