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 #include "extensions/common/event_filtering_info.h" | 5 #include "extensions/common/event_filtering_info.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 | 12 |
13 namespace extensions { | 13 namespace extensions { |
14 | 14 |
| 15 namespace { |
| 16 |
| 17 const char kInstanceId[] = "instanceId"; |
| 18 const char kServiceType[] = "serviceType"; |
| 19 const char kWindowType[] = "windowType"; |
| 20 const char kWindowExposedByDefault[] = "windowExposedByDefault"; |
| 21 |
| 22 } |
| 23 |
15 EventFilteringInfo::EventFilteringInfo() | 24 EventFilteringInfo::EventFilteringInfo() |
16 : has_url_(false), | 25 : has_url_(false), |
17 has_instance_id_(false), | 26 has_instance_id_(false), |
18 instance_id_(0), | 27 instance_id_(0), |
19 has_window_type_(false), | 28 has_window_type_(false), |
20 has_window_exposed_by_default_(false) {} | 29 has_window_exposed_by_default_(false) {} |
21 | 30 |
| 31 EventFilteringInfo::EventFilteringInfo(const base::DictionaryValue& dict) |
| 32 : EventFilteringInfo() { |
| 33 std::string url; |
| 34 if (dict.GetString("url", &url)) { |
| 35 GURL maybe_url(url); |
| 36 if (maybe_url.is_valid()) { |
| 37 has_url_ = true; |
| 38 url_.Swap(&maybe_url); |
| 39 } |
| 40 } |
| 41 |
| 42 has_instance_id_ = dict.GetInteger(kInstanceId, &instance_id_); |
| 43 dict.GetString(kServiceType, &service_type_); |
| 44 has_window_type_ = dict.GetString(kWindowType, &window_type_); |
| 45 has_window_exposed_by_default_ = |
| 46 dict.GetBoolean(kWindowExposedByDefault, &window_exposed_by_default_); |
| 47 } |
| 48 |
22 EventFilteringInfo::EventFilteringInfo(const EventFilteringInfo& other) = | 49 EventFilteringInfo::EventFilteringInfo(const EventFilteringInfo& other) = |
23 default; | 50 default; |
24 | 51 |
25 EventFilteringInfo::~EventFilteringInfo() { | 52 EventFilteringInfo::~EventFilteringInfo() { |
26 } | 53 } |
27 | 54 |
28 void EventFilteringInfo::SetWindowType(const std::string& window_type) { | 55 void EventFilteringInfo::SetWindowType(const std::string& window_type) { |
29 window_type_ = window_type; | 56 window_type_ = window_type; |
30 has_window_type_ = true; | 57 has_window_type_ = true; |
31 } | 58 } |
(...skipping 12 matching lines...) Expand all Loading... |
44 instance_id_ = instance_id; | 71 instance_id_ = instance_id; |
45 has_instance_id_ = true; | 72 has_instance_id_ = true; |
46 } | 73 } |
47 | 74 |
48 std::unique_ptr<base::DictionaryValue> EventFilteringInfo::AsValue() const { | 75 std::unique_ptr<base::DictionaryValue> EventFilteringInfo::AsValue() const { |
49 auto result = base::MakeUnique<base::DictionaryValue>(); | 76 auto result = base::MakeUnique<base::DictionaryValue>(); |
50 if (has_url_) | 77 if (has_url_) |
51 result->SetString("url", url_.spec()); | 78 result->SetString("url", url_.spec()); |
52 | 79 |
53 if (has_instance_id_) | 80 if (has_instance_id_) |
54 result->SetInteger("instanceId", instance_id_); | 81 result->SetInteger(kInstanceId, instance_id_); |
55 | 82 |
56 if (!service_type_.empty()) | 83 if (!service_type_.empty()) |
57 result->SetString("serviceType", service_type_); | 84 result->SetString(kServiceType, service_type_); |
58 | 85 |
59 if (has_window_type_) | 86 if (has_window_type_) |
60 result->SetString("windowType", window_type_); | 87 result->SetString(kWindowType, window_type_); |
61 | 88 |
62 if (has_window_exposed_by_default_) | 89 if (has_window_exposed_by_default_) |
63 result->SetBoolean("windowExposedByDefault", window_exposed_by_default_); | 90 result->SetBoolean(kWindowExposedByDefault, window_exposed_by_default_); |
64 | 91 |
65 return result; | 92 return result; |
66 } | 93 } |
67 | 94 |
68 } // namespace extensions | 95 } // namespace extensions |
OLD | NEW |