| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef EXTENSIONS_COMMON_EVENT_FILTERING_INFO_H_ | 5 #ifndef EXTENSIONS_COMMON_EVENT_FILTERING_INFO_H_ |
| 6 #define EXTENSIONS_COMMON_EVENT_FILTERING_INFO_H_ | 6 #define EXTENSIONS_COMMON_EVENT_FILTERING_INFO_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> |
| 9 | 10 |
| 10 #include "base/optional.h" | 11 #include "base/optional.h" |
| 11 #include "url/gurl.h" | 12 #include "url/gurl.h" |
| 12 | 13 |
| 13 namespace base { | |
| 14 class DictionaryValue; | |
| 15 } | |
| 16 | |
| 17 namespace extensions { | 14 namespace extensions { |
| 18 | 15 |
| 19 // Extra information about an event that is used in event filtering. | 16 // Extra information about an event that is used in event filtering. |
| 20 // | 17 // |
| 21 // This is the information that is matched against criteria specified in JS | 18 // This is the information that is matched against criteria specified in JS |
| 22 // extension event listeners. Eg: | 19 // extension event listeners. Eg: |
| 23 // | 20 // |
| 24 // chrome.someApi.onSomeEvent.addListener(cb, | 21 // chrome.someApi.onSomeEvent.addListener(cb, |
| 25 // {url: [{hostSuffix: 'google.com'}], | 22 // {url: [{hostSuffix: 'google.com'}], |
| 26 // tabId: 1}); | 23 // tabId: 1}); |
| 27 struct EventFilteringInfo { | 24 struct EventFilteringInfo { |
| 28 public: | 25 public: |
| 29 EventFilteringInfo(); | 26 EventFilteringInfo(); |
| 30 explicit EventFilteringInfo(const base::DictionaryValue& dict); | |
| 31 EventFilteringInfo(const EventFilteringInfo& other); | 27 EventFilteringInfo(const EventFilteringInfo& other); |
| 32 ~EventFilteringInfo(); | 28 ~EventFilteringInfo(); |
| 33 | 29 |
| 34 base::Optional<GURL> url; | 30 base::Optional<GURL> url; |
| 35 base::Optional<std::string> service_type; | 31 base::Optional<std::string> service_type; |
| 36 base::Optional<int> instance_id; | 32 base::Optional<int> instance_id; |
| 37 | 33 |
| 38 // Note: window type & visible are Chrome concepts, so arguably | 34 // Note: window type & visible are Chrome concepts, so arguably |
| 39 // doesn't belong in the extensions module. If the number of Chrome | 35 // doesn't belong in the extensions module. If the number of Chrome |
| 40 // concept grows, consider a delegation model with a | 36 // concept grows, consider a delegation model with a |
| 41 // ChromeEventFilteringInfo class. | 37 // ChromeEventFilteringInfo class. |
| 42 base::Optional<std::string> window_type; | 38 base::Optional<std::string> window_type; |
| 43 | 39 |
| 44 // By default events related to windows are filtered based on the | 40 // By default events related to windows are filtered based on the |
| 45 // listener's extension. This parameter will be set if the listener | 41 // listener's extension. This parameter will be set if the listener |
| 46 // didn't set any filter on window types. | 42 // didn't set any filter on window types. |
| 47 base::Optional<bool> window_exposed_by_default; | 43 base::Optional<bool> window_exposed_by_default; |
| 48 | 44 |
| 49 std::unique_ptr<base::DictionaryValue> AsValue() const; | 45 bool is_empty() const { |
| 46 return !url && !service_type && !instance_id && !window_type && |
| 47 !window_exposed_by_default; |
| 48 } |
| 50 }; | 49 }; |
| 51 | 50 |
| 52 } // namespace extensions | 51 } // namespace extensions |
| 53 | 52 |
| 54 #endif // EXTENSIONS_COMMON_EVENT_FILTERING_INFO_H_ | 53 #endif // EXTENSIONS_COMMON_EVENT_FILTERING_INFO_H_ |
| OLD | NEW |