diff options
author | lionel.g.landwerlin <lionel.g.landwerlin@intel.com> | 2015-08-05 17:04:10 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-08-06 00:04:39 +0000 |
commit | 56b2a727992f8caf2141f89bf0073793f5cbe3d8 (patch) | |
tree | 7b5e2e7b355bbac1bb4de5c3d8c5281386fe731c /extensions/common/event_matcher.cc | |
parent | 123ef4fe9ba98342fcb6bd6f5437a10592d0ed2f (diff) | |
download | chromium_src-56b2a727992f8caf2141f89bf0073793f5cbe3d8.zip chromium_src-56b2a727992f8caf2141f89bf0073793f5cbe3d8.tar.gz chromium_src-56b2a727992f8caf2141f89bf0073793f5cbe3d8.tar.bz2 |
extensions: windows: list all windows from the current profile
This change allows extensions to get access to a broader set of
chromium windows (namely windows created by other
applications/extensions) as long as they belong to the same profile.
BUG=394341
TEST=browser_tests --gtest_filter=ExtensionTabsTest.*
Review URL: https://codereview.chromium.org/1099553002
Cr-Commit-Position: refs/heads/master@{#342016}
Diffstat (limited to 'extensions/common/event_matcher.cc')
-rw-r--r-- | extensions/common/event_matcher.cc | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/extensions/common/event_matcher.cc b/extensions/common/event_matcher.cc index 8ae022a..0071111 100644 --- a/extensions/common/event_matcher.cc +++ b/extensions/common/event_matcher.cc @@ -2,12 +2,17 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/callback.h" + #include "extensions/common/event_matcher.h" #include "extensions/common/event_filtering_info.h" namespace { const char kUrlFiltersKey[] = "url"; +const char kWindowTypesKey[] = "windowTypes"; + +const char* const kDefaultWindowTypes[] = {"normal", "panel", "popup"}; } namespace extensions { @@ -29,20 +34,30 @@ bool EventMatcher::MatchNonURLCriteria( return event_info.instance_id() == GetInstanceID(); } + if (event_info.has_window_type()) { + for (int i = 0; i < GetWindowTypeCount(); i++) { + std::string window_type; + if (GetWindowType(i, &window_type) && + window_type == event_info.window_type()) + return true; + } + return false; + } + const std::string& service_type_filter = GetServiceTypeFilter(); return service_type_filter.empty() || service_type_filter == event_info.service_type(); } int EventMatcher::GetURLFilterCount() const { - base::ListValue* url_filters = NULL; + base::ListValue* url_filters = nullptr; if (filter_->GetList(kUrlFiltersKey, &url_filters)) return url_filters->GetSize(); return 0; } bool EventMatcher::GetURLFilter(int i, base::DictionaryValue** url_filter_out) { - base::ListValue* url_filters = NULL; + base::ListValue* url_filters = nullptr; if (filter_->GetList(kUrlFiltersKey, &url_filters)) { return url_filters->GetDictionary(i, url_filter_out); } @@ -65,6 +80,25 @@ int EventMatcher::GetInstanceID() const { return instance_id; } +int EventMatcher::GetWindowTypeCount() const { + base::ListValue* window_type_filters = nullptr; + if (filter_->GetList(kWindowTypesKey, &window_type_filters)) + return window_type_filters->GetSize(); + return arraysize(kDefaultWindowTypes); +} + +bool EventMatcher::GetWindowType(int i, std::string* window_type_out) const { + base::ListValue* window_types = nullptr; + if (filter_->GetList(kWindowTypesKey, &window_types)) { + return window_types->GetString(i, window_type_out); + } + if (i >= 0 && i < static_cast<int>(arraysize(kDefaultWindowTypes))) { + *window_type_out = kDefaultWindowTypes[i]; + return true; + } + return false; +} + int EventMatcher::GetRoutingID() const { return routing_id_; } |