Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(478)

Side by Side Diff: extensions/common/event_filtering_info.cc

Issue 17419004: <webview>: Add support for filtering extension events by instanceId. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@filter_listener
Patch Set: Correct diff Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/json/json_writer.h" 7 #include "base/json/json_writer.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 9
10 namespace extensions { 10 namespace extensions {
11 11
12 EventFilteringInfo::EventFilteringInfo() 12 EventFilteringInfo::EventFilteringInfo()
13 : has_url_(false) { 13 : has_url_(false),
14 has_instance_id_(false),
15 instance_id_(0) {
14 } 16 }
15 17
16 EventFilteringInfo::~EventFilteringInfo() { 18 EventFilteringInfo::~EventFilteringInfo() {
17 } 19 }
18 20
19 void EventFilteringInfo::SetURL(const GURL& url) { 21 void EventFilteringInfo::SetURL(const GURL& url) {
20 url_ = url; 22 url_ = url;
21 has_url_ = true; 23 has_url_ = true;
22 } 24 }
23 25
26 void EventFilteringInfo::SetInstanceID(int instance_id) {
27 instance_id_ = instance_id;
28 has_instance_id_ = true;
29 }
30
24 std::string EventFilteringInfo::AsJSONString() const { 31 std::string EventFilteringInfo::AsJSONString() const {
25 std::string result; 32 std::string result;
26 base::DictionaryValue value; 33 base::DictionaryValue value;
27 if (has_url_) 34 if (has_url_)
28 value.SetString("url", url_.spec()); 35 value.SetString("url", url_.spec());
29 36
37 if (has_instance_id_)
38 value.SetInteger("instanceId", instance_id_);
39
30 base::JSONWriter::Write(&value, &result); 40 base::JSONWriter::Write(&value, &result);
31 return result; 41 return result;
32 } 42 }
33 43
34 scoped_ptr<base::Value> EventFilteringInfo::AsValue() const { 44 scoped_ptr<base::Value> EventFilteringInfo::AsValue() const {
35 if (IsEmpty()) 45 if (IsEmpty())
36 return scoped_ptr<base::Value>(base::Value::CreateNullValue()); 46 return scoped_ptr<base::Value>(base::Value::CreateNullValue());
37 47
38 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue); 48 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue);
39 if (has_url_) 49 if (has_url_)
40 result->SetString("url", url_.spec()); 50 result->SetString("url", url_.spec());
51
52 if (has_instance_id_)
53 result->SetInteger("instanceId", instance_id_);
41 return result.PassAs<base::Value>(); 54 return result.PassAs<base::Value>();
42 } 55 }
43 56
44 bool EventFilteringInfo::IsEmpty() const { 57 bool EventFilteringInfo::IsEmpty() const {
45 return !has_url_; 58 return !has_url_;
46 } 59 }
47 60
48 } // namespace extensions 61 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698