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 "chrome/browser/extensions/api/rtc_private/rtc_private_api.h" | 5 #include "chrome/browser/extensions/api/rtc_private/rtc_private_api.h" |
6 | 6 |
7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 // Web intent data structure fields. | 39 // Web intent data structure fields. |
40 const char kNameIntentField[] = "name"; | 40 const char kNameIntentField[] = "name"; |
41 const char kPhoneIntentField[] = "phone"; | 41 const char kPhoneIntentField[] = "phone"; |
42 const char kEmailIntentField[] = "email"; | 42 const char kEmailIntentField[] = "email"; |
43 | 43 |
44 // Returns the ActionType of intent action. | 44 // Returns the ActionType of intent action. |
45 api::rtc_private::ActionType GetLaunchAction( | 45 api::rtc_private::ActionType GetLaunchAction( |
46 RtcPrivateEventRouter::LaunchAction action) { | 46 RtcPrivateEventRouter::LaunchAction action) { |
47 switch (action) { | 47 switch (action) { |
48 case RtcPrivateEventRouter::LAUNCH_ACTIVATE: | 48 case RtcPrivateEventRouter::LAUNCH_ACTIVATE: |
49 return api::rtc_private::RTC_PRIVATE_ACTION_TYPE_NONE; | 49 return api::rtc_private::ACTION_TYPE_NONE; |
50 case RtcPrivateEventRouter::LAUNCH_CHAT: | 50 case RtcPrivateEventRouter::LAUNCH_CHAT: |
51 return api::rtc_private::RTC_PRIVATE_ACTION_TYPE_CHAT; | 51 return api::rtc_private::ACTION_TYPE_CHAT; |
52 case RtcPrivateEventRouter::LAUNCH_VOICE: | 52 case RtcPrivateEventRouter::LAUNCH_VOICE: |
53 return api::rtc_private::RTC_PRIVATE_ACTION_TYPE_VOICE; | 53 return api::rtc_private::ACTION_TYPE_VOICE; |
54 case RtcPrivateEventRouter::LAUNCH_VIDEO: | 54 case RtcPrivateEventRouter::LAUNCH_VIDEO: |
55 return api::rtc_private::RTC_PRIVATE_ACTION_TYPE_VIDEO; | 55 return api::rtc_private::ACTION_TYPE_VIDEO; |
56 } | 56 } |
57 return api::rtc_private::RTC_PRIVATE_ACTION_TYPE_NONE; | 57 return api::rtc_private::ACTION_TYPE_NONE; |
58 } | 58 } |
59 | 59 |
60 // Creates JSON payload string for contact web intent data. | 60 // Creates JSON payload string for contact web intent data. |
61 void GetContactIntentData(const Contact& contact, | 61 std::map<std::string, linked_ptr<base::Value> > GetContactIntentData( |
62 DictionaryValue* dict) { | 62 const Contact& contact) { |
| 63 std::map<std::string, linked_ptr<base::Value> > dict; |
| 64 |
63 // TODO(derat): This might require more name extraction magic than this. | 65 // TODO(derat): This might require more name extraction magic than this. |
64 dict->SetString(kNameIntentField, contact.full_name()); | 66 dict[kNameIntentField] = |
| 67 linked_ptr<base::Value>(new base::StringValue(contact.full_name())); |
65 | 68 |
66 ListValue* phone_list = new base::ListValue(); | 69 ListValue* phone_list = new base::ListValue(); |
67 dict->Set(kPhoneIntentField, phone_list); | 70 dict[kPhoneIntentField] = linked_ptr<base::Value>(phone_list); |
68 for (int i = 0; i < contact.phone_numbers_size(); i++) { | 71 for (int i = 0; i < contact.phone_numbers_size(); i++) { |
69 const Contact_PhoneNumber& phone_number = contact.phone_numbers(i); | 72 const Contact_PhoneNumber& phone_number = contact.phone_numbers(i); |
70 StringValue* value = Value::CreateStringValue(phone_number.number()); | 73 StringValue* value = Value::CreateStringValue(phone_number.number()); |
71 if (phone_number.primary()) | 74 if (phone_number.primary()) |
72 CHECK(phone_list->Insert(0, value)); | 75 CHECK(phone_list->Insert(0, value)); |
73 else | 76 else |
74 phone_list->Append(value); | 77 phone_list->Append(value); |
75 } | 78 } |
76 | 79 |
77 ListValue* email_list = new base::ListValue(); | 80 ListValue* email_list = new base::ListValue(); |
78 dict->Set(kEmailIntentField, email_list); | 81 dict[kEmailIntentField] = linked_ptr<base::Value>(email_list); |
79 for (int i = 0; i < contact.email_addresses_size(); i++) { | 82 for (int i = 0; i < contact.email_addresses_size(); i++) { |
80 const Contact_EmailAddress& email_address = contact.email_addresses(i); | 83 const Contact_EmailAddress& email_address = contact.email_addresses(i); |
81 StringValue* value = Value::CreateStringValue(email_address.address()); | 84 StringValue* value = Value::CreateStringValue(email_address.address()); |
82 if (email_address.primary()) | 85 if (email_address.primary()) |
83 CHECK(email_list->Insert(0, value)); | 86 CHECK(email_list->Insert(0, value)); |
84 else | 87 else |
85 email_list->Append(value); | 88 email_list->Append(value); |
86 } | 89 } |
| 90 |
| 91 return dict; |
87 } | 92 } |
88 | 93 |
89 } // namespace | 94 } // namespace |
90 | 95 |
91 void RtcPrivateEventRouter::DispatchLaunchEvent( | 96 void RtcPrivateEventRouter::DispatchLaunchEvent( |
92 Profile* profile, LaunchAction action, const Contact* contact) { | 97 Profile* profile, LaunchAction action, const Contact* contact) { |
93 if (action == RtcPrivateEventRouter::LAUNCH_ACTIVATE) { | 98 if (action == RtcPrivateEventRouter::LAUNCH_ACTIVATE) { |
94 scoped_ptr<Event> event(new Event( | 99 scoped_ptr<Event> event(new Event( |
95 kOnLaunchEvent, make_scoped_ptr(new ListValue()))); | 100 kOnLaunchEvent, make_scoped_ptr(new ListValue()))); |
96 event->restrict_to_profile = profile; | 101 event->restrict_to_profile = profile; |
97 ExtensionSystem::Get(profile)->event_router()->BroadcastEvent(event.Pass()); | 102 ExtensionSystem::Get(profile)->event_router()->BroadcastEvent(event.Pass()); |
98 } else { | 103 } else { |
99 DCHECK(contact); | 104 DCHECK(contact); |
100 extensions::api::rtc_private::LaunchData launch_data; | 105 extensions::api::rtc_private::LaunchData launch_data; |
101 launch_data.intent.action = GetLaunchAction(action); | 106 launch_data.intent.action = GetLaunchAction(action); |
102 GetContactIntentData(*contact, | 107 launch_data.intent.data.additional_properties = |
103 &launch_data.intent.data.additional_properties); | 108 GetContactIntentData(*contact); |
104 launch_data.intent.type = kMimeTypeJson; | 109 launch_data.intent.type = kMimeTypeJson; |
105 scoped_ptr<Event> event(new Event( | 110 scoped_ptr<Event> event(new Event( |
106 kOnLaunchEvent, api::rtc_private::OnLaunch::Create(launch_data))); | 111 kOnLaunchEvent, api::rtc_private::OnLaunch::Create(launch_data))); |
107 event->restrict_to_profile = profile; | 112 event->restrict_to_profile = profile; |
108 ExtensionSystem::Get(profile)->event_router()->BroadcastEvent(event.Pass()); | 113 ExtensionSystem::Get(profile)->event_router()->BroadcastEvent(event.Pass()); |
109 } | 114 } |
110 } | 115 } |
111 | 116 |
112 } // namespace extensions | 117 } // namespace extensions |
OLD | NEW |