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

Unified Diff: chrome/browser/extensions/api/tabs/windows_util.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: Disable focus event tests on MacOSX Created 5 years, 5 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
index 0e2ead5b3e8b9c70018413ae476d90e05c3c2f49..9b2e8c0f3f63fe7883d544516c4360fac23f2f8c 100644
--- a/chrome/browser/extensions/api/tabs/windows_util.cc
+++ b/chrome/browser/extensions/api/tabs/windows_util.cc
@@ -2,24 +2,77 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <string>
+#include <vector>
+
#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/chrome_extension_function.h"
#include "chrome/browser/extensions/chrome_extension_function_details.h"
+#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/extensions/window_controller.h"
#include "chrome/browser/extensions/window_controller_list.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/common/extensions/api/windows.h"
#include "extensions/browser/extension_function.h"
#include "extensions/browser/extension_function_dispatcher.h"
#include "extensions/common/constants.h"
#include "extensions/common/error_utils.h"
+#include "extensions/common/extension.h"
+
+namespace keys = extensions::tabs_constants;
+namespace windows = extensions::api::windows;
namespace windows_util {
+namespace {
+
+extensions::WindowTypeFilter CreateTypeFilter(
+ int length,
+ const windows::WindowType types[]) {
+ extensions::WindowTypeFilter filter;
+ for (int i = 0; i < length; i++)
+ filter.push_back(types[i]);
+ return filter;
+}
+
+} // namespace
+
+const extensions::WindowTypeFilter& GetDefaultWindowTypeFilters() {
+ static const windows::WindowType types[] = {windows::WINDOW_TYPE_NORMAL,
+ windows::WINDOW_TYPE_PANEL,
+ windows::WINDOW_TYPE_POPUP};
not at google - send to devlin 2015/07/31 21:48:03 There are so few of these, you could model it as a
llandwerlin-old 2015/08/03 10:11:54 Switching to a bitmask.
+ CR_DEFINE_STATIC_LOCAL(extensions::WindowTypeFilter, filter,
+ (CreateTypeFilter(arraysize(types), types)));
+ return filter;
+}
+
+const extensions::WindowTypeFilter& GetNoWindowTypeFilters() {
not at google - send to devlin 2015/07/31 21:48:03 I don't understand this naming... looks like it ma
llandwerlin-old 2015/08/03 10:11:54 Done.
+ static const windows::WindowType types[] = {
+ windows::WINDOW_TYPE_APP, windows::WINDOW_TYPE_DEVTOOLS,
+ windows::WINDOW_TYPE_NORMAL, windows::WINDOW_TYPE_PANEL,
+ windows::WINDOW_TYPE_POPUP};
+ CR_DEFINE_STATIC_LOCAL(extensions::WindowTypeFilter, filter,
+ (CreateTypeFilter(arraysize(types), types)));
+ return filter;
+}
+
+bool WindowMatchesTypeFilter(const extensions::WindowController* controller,
+ const extensions::WindowTypeFilter& filters) {
+ int window_type = extensions::api::windows::ParseWindowType(
not at google - send to devlin 2015/07/31 21:48:03 this should be a WindowType not an int.
llandwerlin-old 2015/08/03 10:11:54 Done.
+ controller->GetWindowTypeText());
+ for (const auto& iter : filters) {
+ if (window_type == iter)
+ return true;
+ }
+ return false;
+}
+
bool GetWindowFromWindowID(UIThreadExtensionFunction* function,
int window_id,
+ const extensions::WindowTypeFilter& type_filter,
extensions::WindowController** controller) {
if (window_id == extension_misc::kCurrentWindowId) {
extensions::WindowController* extension_window_controller =
@@ -38,7 +91,8 @@ bool GetWindowFromWindowID(UIThreadExtensionFunction* function,
}
} else {
*controller = extensions::WindowControllerList::GetInstance()
- ->FindWindowForFunctionById(function, window_id);
+ ->FindWindowForFunctionByIdWithFilter(function, window_id,
+ type_filter);
if (!(*controller)) {
function->SetError(extensions::ErrorUtils::FormatErrorMessage(
extensions::tabs_constants::kWindowNotFoundError,
@@ -49,12 +103,30 @@ bool GetWindowFromWindowID(UIThreadExtensionFunction* function,
return true;
}
+bool ExtensionCanOperateOnWindow(
+ const extensions::Extension* extension,
+ content::BrowserContext* browser_context,
+ const extensions::WindowController* controller,
+ const extensions::WindowTypeFilter& type_filter) {
+ if (!WindowMatchesTypeFilter(controller, type_filter))
+ return false;
+
+ if (browser_context == controller->profile())
+ return true;
+
+ if (!extensions::util::CanCrossIncognito(extension, browser_context))
not at google - send to devlin 2015/07/31 21:48:03 The other implementation uses function->include_in
llandwerlin-old 2015/08/03 10:11:54 It looks like the remaining of a previous iteratio
+ return false;
+
+ Profile* profile = Profile::FromBrowserContext(browser_context);
+ return profile->HasOffTheRecordProfile() &&
+ profile->GetOffTheRecordProfile() == controller->profile();
+}
+
bool CanOperateOnWindow(const UIThreadExtensionFunction* function,
- const extensions::WindowController* controller) {
- if (function->extension() != NULL &&
- !controller->IsVisibleToExtension(function->extension())) {
+ const extensions::WindowController* controller,
+ const extensions::WindowTypeFilter& type_filter) {
+ if (!WindowMatchesTypeFilter(controller, type_filter))
return false;
- }
if (function->browser_context() == controller->profile())
return true;

Powered by Google App Engine
This is Rietveld 408576698