Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / extensions / common / event_filtering_info.cc
blobfe9ef29c6dda9170d1f07792b4f674df18957743
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 #include "extensions/common/event_filtering_info.h"
7 #include "base/json/json_writer.h"
8 #include "base/values.h"
10 namespace extensions {
12 EventFilteringInfo::EventFilteringInfo()
13 : has_url_(false),
14 has_instance_id_(false),
15 instance_id_(0),
16 has_window_type_(false),
17 has_window_exposed_by_default_(false) {}
19 EventFilteringInfo::~EventFilteringInfo() {
22 void EventFilteringInfo::SetWindowType(const std::string& window_type) {
23 window_type_ = window_type;
24 has_window_type_ = true;
27 void EventFilteringInfo::SetWindowExposedByDefault(const bool exposed) {
28 window_exposed_by_default_ = exposed;
29 has_window_exposed_by_default_ = true;
32 void EventFilteringInfo::SetURL(const GURL& url) {
33 url_ = url;
34 has_url_ = true;
37 void EventFilteringInfo::SetInstanceID(int instance_id) {
38 instance_id_ = instance_id;
39 has_instance_id_ = true;
42 scoped_ptr<base::Value> EventFilteringInfo::AsValue() const {
43 if (IsEmpty())
44 return base::Value::CreateNullValue();
46 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue);
47 if (has_url_)
48 result->SetString("url", url_.spec());
50 if (has_instance_id_)
51 result->SetInteger("instanceId", instance_id_);
53 if (!service_type_.empty())
54 result->SetString("serviceType", service_type_);
56 if (has_window_type_)
57 result->SetString("windowType", window_type_);
59 if (has_window_exposed_by_default_)
60 result->SetBoolean("windowExposedByDefault", window_exposed_by_default_);
62 return result.Pass();
65 bool EventFilteringInfo::IsEmpty() const {
66 return !has_window_type_ && !has_url_ && service_type_.empty() &&
67 !has_instance_id_ && !has_window_exposed_by_default_;
70 } // namespace extensions