| 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> | |
| 8 | |
| 9 #include "base/json/json_writer.h" | |
| 10 #include "base/memory/ptr_util.h" | |
| 11 #include "base/values.h" | |
| 12 | |
| 13 namespace extensions { | 7 namespace extensions { |
| 14 | 8 |
| 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 | |
| 24 EventFilteringInfo::EventFilteringInfo() {} | 9 EventFilteringInfo::EventFilteringInfo() {} |
| 25 | |
| 26 EventFilteringInfo::EventFilteringInfo(const base::DictionaryValue& dict) | |
| 27 : EventFilteringInfo() { | |
| 28 { | |
| 29 std::string dict_url; | |
| 30 if (dict.GetString("url", &dict_url)) { | |
| 31 GURL maybe_url(dict_url); | |
| 32 if (maybe_url.is_valid()) | |
| 33 url = std::move(maybe_url); | |
| 34 } | |
| 35 } | |
| 36 | |
| 37 { | |
| 38 int dict_instance_id = 0; | |
| 39 if (dict.GetInteger(kInstanceId, &dict_instance_id)) | |
| 40 instance_id = dict_instance_id; | |
| 41 } | |
| 42 | |
| 43 { | |
| 44 std::string dict_service_type; | |
| 45 if (dict.GetString(kServiceType, &dict_service_type)) | |
| 46 service_type = std::move(dict_service_type); | |
| 47 } | |
| 48 | |
| 49 { | |
| 50 std::string dict_window_type; | |
| 51 if (dict.GetString(kWindowType, &dict_window_type)) | |
| 52 window_type = std::move(dict_window_type); | |
| 53 } | |
| 54 | |
| 55 { | |
| 56 bool dict_window_exposed_by_default = false; | |
| 57 if (dict.GetBoolean(kWindowExposedByDefault, | |
| 58 &dict_window_exposed_by_default)) | |
| 59 window_exposed_by_default = dict_window_exposed_by_default; | |
| 60 } | |
| 61 } | |
| 62 | |
| 63 EventFilteringInfo::EventFilteringInfo(const EventFilteringInfo& other) = | 10 EventFilteringInfo::EventFilteringInfo(const EventFilteringInfo& other) = |
| 64 default; | 11 default; |
| 65 | |
| 66 EventFilteringInfo::~EventFilteringInfo() {} | 12 EventFilteringInfo::~EventFilteringInfo() {} |
| 67 | 13 |
| 68 std::unique_ptr<base::DictionaryValue> EventFilteringInfo::AsValue() const { | |
| 69 auto result = base::MakeUnique<base::DictionaryValue>(); | |
| 70 if (url) | |
| 71 result->SetString("url", url->spec()); | |
| 72 | |
| 73 if (instance_id) | |
| 74 result->SetInteger(kInstanceId, *instance_id); | |
| 75 | |
| 76 if (service_type) | |
| 77 result->SetString(kServiceType, *service_type); | |
| 78 | |
| 79 if (window_type) | |
| 80 result->SetString(kWindowType, *window_type); | |
| 81 | |
| 82 if (window_exposed_by_default) | |
| 83 result->SetBoolean(kWindowExposedByDefault, *window_exposed_by_default); | |
| 84 | |
| 85 return result; | |
| 86 } | |
| 87 | |
| 88 } // namespace extensions | 14 } // namespace extensions |
| OLD | NEW |