Upstreaming browser/ui/uikit_ui_util from iOS.
[chromium-blink-merge.git] / extensions / common / event_filtering_info.cc
blobc585de97496713dc704ba0aa9794c8c011dc2fb8
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) {}
18 EventFilteringInfo::~EventFilteringInfo() {
21 void EventFilteringInfo::SetWindowType(const std::string& window_type) {
22 window_type_ = window_type;
23 has_window_type_ = true;
26 void EventFilteringInfo::SetURL(const GURL& url) {
27 url_ = url;
28 has_url_ = true;
31 void EventFilteringInfo::SetInstanceID(int instance_id) {
32 instance_id_ = instance_id;
33 has_instance_id_ = true;
36 scoped_ptr<base::Value> EventFilteringInfo::AsValue() const {
37 if (IsEmpty())
38 return base::Value::CreateNullValue();
40 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue);
41 if (has_url_)
42 result->SetString("url", url_.spec());
44 if (has_instance_id_)
45 result->SetInteger("instanceId", instance_id_);
47 if (!service_type_.empty())
48 result->SetString("serviceType", service_type_);
50 if (has_window_type_)
51 result->SetString("windowType", window_type_);
53 return result.Pass();
56 bool EventFilteringInfo::IsEmpty() const {
57 return !has_window_type_ && !has_url_ && service_type_.empty() &&
58 !has_instance_id_;
61 } // namespace extensions