Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / extensions / common / event_filtering_info.h
blob30581108231f86875099653ed1ceb71fe6e4c727
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.
5 #ifndef EXTENSIONS_COMMON_EVENT_FILTERING_INFO_H_
6 #define EXTENSIONS_COMMON_EVENT_FILTERING_INFO_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "url/gurl.h"
11 namespace base {
12 class Value;
15 namespace extensions {
17 // Extra information about an event that is used in event filtering.
19 // This is the information that is matched against criteria specified in JS
20 // extension event listeners. Eg:
22 // chrome.someApi.onSomeEvent.addListener(cb,
23 // {url: [{hostSuffix: 'google.com'}],
24 // tabId: 1});
25 class EventFilteringInfo {
26 public:
27 EventFilteringInfo();
28 ~EventFilteringInfo();
29 void SetWindowExposedByDefault(bool exposed);
30 void SetWindowType(const std::string& window_type);
31 void SetURL(const GURL& url);
32 void SetInstanceID(int instance_id);
33 void SetServiceType(const std::string& service_type) {
34 service_type_ = service_type;
37 // Note: window type & visible are Chrome concepts, so arguably
38 // doesn't belong in the extensions module. If the number of Chrome
39 // concept grows, consider a delegation model with a
40 // ChromeEventFilteringInfo class.
41 bool has_window_type() const { return has_window_type_; }
42 const std::string& window_type() const { return window_type_; }
44 // By default events related to windows are filtered based on the
45 // listener's extension. This parameter will be set if the listener
46 // didn't set any filter on window types.
47 bool has_window_exposed_by_default() const {
48 return has_window_exposed_by_default_;
50 bool window_exposed_by_default() const { return window_exposed_by_default_; }
52 bool has_url() const { return has_url_; }
53 const GURL& url() const { return url_; }
55 bool has_instance_id() const { return has_instance_id_; }
56 int instance_id() const { return instance_id_; }
58 bool has_service_type() const { return !service_type_.empty(); }
59 const std::string& service_type() const { return service_type_; }
61 scoped_ptr<base::Value> AsValue() const;
62 bool IsEmpty() const;
64 private:
65 bool has_url_;
66 GURL url_;
67 std::string service_type_;
69 bool has_instance_id_;
70 int instance_id_;
72 bool has_window_type_;
73 std::string window_type_;
75 bool has_window_exposed_by_default_;
76 bool window_exposed_by_default_;
78 // Allow implicit copy and assignment.
81 } // namespace extensions
83 #endif // EXTENSIONS_COMMON_EVENT_FILTERING_INFO_H_