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