| 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..a695c4ca165e44ccebbbe4084487c28025cf4c5f 100644
|
| --- a/chrome/browser/extensions/api/tabs/windows_util.cc
|
| +++ b/chrome/browser/extensions/api/tabs/windows_util.cc
|
| @@ -2,24 +2,76 @@
|
| // 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_util {
|
|
|
| +namespace {
|
| +
|
| +std::vector<windows::WindowType> CreateTypeFilter(
|
| + int length,
|
| + const windows::WindowType types[]) {
|
| + std::vector<windows::WindowType> filter;
|
| + for (int i = 0; i < length; i++)
|
| + filter.push_back(types[i]);
|
| + return filter;
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +const std::vector<windows::WindowType>& GetDefaultWindowTypeFilters() {
|
| + static const windows::WindowType types[] = {windows::WINDOW_TYPE_NORMAL,
|
| + windows::WINDOW_TYPE_PANEL,
|
| + windows::WINDOW_TYPE_POPUP};
|
| + CR_DEFINE_STATIC_LOCAL(std::vector<windows::WindowType>, filter,
|
| + (CreateTypeFilter(arraysize(types), types)));
|
| + return filter;
|
| +}
|
| +
|
| +const std::vector<windows::WindowType>& GetNoWindowTypeFilters() {
|
| + 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(std::vector<windows::WindowType>, filter,
|
| + (CreateTypeFilter(arraysize(types), types)));
|
| + return filter;
|
| +}
|
| +
|
| +bool WindowMatchesTypeFilter(const extensions::WindowController* controller,
|
| + const std::vector<windows::WindowType>& filters) {
|
| + int window_type = extensions::api::windows::ParseWindowType(
|
| + controller->GetWindowTypeText());
|
| + for (const auto& iter : filters) {
|
| + if (window_type == iter)
|
| + return true;
|
| + }
|
| + return false;
|
| +}
|
| +
|
| bool GetWindowFromWindowID(UIThreadExtensionFunction* function,
|
| int window_id,
|
| + const std::vector<windows::WindowType>& type_filter,
|
| extensions::WindowController** controller) {
|
| if (window_id == extension_misc::kCurrentWindowId) {
|
| extensions::WindowController* extension_window_controller =
|
| @@ -38,7 +90,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 +102,30 @@ bool GetWindowFromWindowID(UIThreadExtensionFunction* function,
|
| return true;
|
| }
|
|
|
| +bool ExtensionCanOperateOnWindow(
|
| + const extensions::Extension* extension,
|
| + content::BrowserContext* browser_context,
|
| + const extensions::WindowController* controller,
|
| + const std::vector<windows::WindowType>& type_filter) {
|
| + if (!WindowMatchesTypeFilter(controller, type_filter))
|
| + return false;
|
| +
|
| + if (browser_context == controller->profile())
|
| + return true;
|
| +
|
| + if (!extensions::util::CanCrossIncognito(extension, browser_context))
|
| + 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 std::vector<windows::WindowType>& type_filter) {
|
| + if (!WindowMatchesTypeFilter(controller, type_filter))
|
| return false;
|
| - }
|
|
|
| if (function->browser_context() == controller->profile())
|
| return true;
|
|
|