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" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "base/value_conversions.h" | 12 #include "base/value_conversions.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "chrome/browser/chromeos/contacts/contact_manager.h" | |
15 #include "chrome/browser/chromeos/contacts/contact.pb.h" | 14 #include "chrome/browser/chromeos/contacts/contact.pb.h" |
16 #include "chrome/browser/extensions/event_router.h" | 15 #include "chrome/browser/extensions/event_router.h" |
17 #include "chrome/browser/extensions/extension_service.h" | 16 #include "chrome/browser/extensions/extension_service.h" |
18 #include "chrome/browser/extensions/extension_system.h" | 17 #include "chrome/browser/extensions/extension_system.h" |
19 #include "chrome/browser/extensions/state_store.h" | 18 #include "chrome/browser/extensions/state_store.h" |
20 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/common/chrome_notification_types.h" | 20 #include "chrome/common/chrome_notification_types.h" |
22 #include "chrome/common/extensions/api/rtc_private.h" | 21 #include "chrome/common/extensions/api/rtc_private.h" |
23 #include "content/public/browser/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
24 | 23 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 action_str = kVideoAction; | 63 action_str = kVideoAction; |
65 break; | 64 break; |
66 default: | 65 default: |
67 NOTREACHED() << "Unknown action " << action; | 66 NOTREACHED() << "Unknown action " << action; |
68 break; | 67 break; |
69 } | 68 } |
70 return action_str; | 69 return action_str; |
71 } | 70 } |
72 | 71 |
73 // Creates JSON payload string for contact web intent data. | 72 // Creates JSON payload string for contact web intent data. |
74 void GetContactIntentData(Contact* contact, | 73 void GetContactIntentData(const Contact& contact, |
75 DictionaryValue* dict) { | 74 DictionaryValue* dict) { |
76 // TODO(derat): This might require more name extraction magic than this. | 75 // TODO(derat): This might require more name extraction magic than this. |
77 dict->SetString(kNameIntentField, contact->full_name()); | 76 dict->SetString(kNameIntentField, contact.full_name()); |
78 | 77 |
79 ListValue* phone_list = new base::ListValue(); | 78 ListValue* phone_list = new base::ListValue(); |
80 dict->Set(kPhoneIntentField, phone_list); | 79 dict->Set(kPhoneIntentField, phone_list); |
81 for (int i = 0; i < contact->phone_numbers_size(); i++) { | 80 for (int i = 0; i < contact.phone_numbers_size(); i++) { |
82 const Contact_PhoneNumber& phone_number = contact->phone_numbers(i); | 81 const Contact_PhoneNumber& phone_number = contact.phone_numbers(i); |
83 StringValue* value = Value::CreateStringValue(phone_number.number()); | 82 StringValue* value = Value::CreateStringValue(phone_number.number()); |
84 if (phone_number.primary()) | 83 if (phone_number.primary()) |
85 CHECK(phone_list->Insert(0, value)); | 84 CHECK(phone_list->Insert(0, value)); |
86 else | 85 else |
87 phone_list->Append(value); | 86 phone_list->Append(value); |
88 } | 87 } |
89 | 88 |
90 ListValue* email_list = new base::ListValue(); | 89 ListValue* email_list = new base::ListValue(); |
91 dict->Set(kEmailIntentField, email_list); | 90 dict->Set(kEmailIntentField, email_list); |
92 for (int i = 0; i < contact->email_addresses_size(); i++) { | 91 for (int i = 0; i < contact.email_addresses_size(); i++) { |
93 const Contact_EmailAddress& email_address = contact->email_addresses(i); | 92 const Contact_EmailAddress& email_address = contact.email_addresses(i); |
94 StringValue* value = Value::CreateStringValue(email_address.address()); | 93 StringValue* value = Value::CreateStringValue(email_address.address()); |
95 if (email_address.primary()) | 94 if (email_address.primary()) |
96 CHECK(email_list->Insert(0, value)); | 95 CHECK(email_list->Insert(0, value)); |
97 else | 96 else |
98 email_list->Append(value); | 97 email_list->Append(value); |
99 } | 98 } |
100 } | 99 } |
101 | 100 |
102 } // namespace | 101 } // namespace |
103 | 102 |
104 void RtcPrivateEventRouter::DispatchLaunchEvent( | 103 void RtcPrivateEventRouter::DispatchLaunchEvent( |
105 Profile* profile, LaunchAction action, Contact* contact) { | 104 Profile* profile, LaunchAction action, const Contact* contact) { |
106 if (action == RtcPrivateEventRouter::LAUNCH_ACTIVATE) { | 105 if (action == RtcPrivateEventRouter::LAUNCH_ACTIVATE) { |
107 extensions::ExtensionSystem::Get(profile)->event_router()-> | 106 extensions::ExtensionSystem::Get(profile)->event_router()-> |
108 DispatchEventToRenderers( | 107 DispatchEventToRenderers( |
109 kOnLaunchEvent, | 108 kOnLaunchEvent, |
110 scoped_ptr<ListValue>(new ListValue()), | 109 scoped_ptr<ListValue>(new ListValue()), |
111 profile, | 110 profile, |
112 GURL()); | 111 GURL()); |
113 } else { | 112 } else { |
| 113 DCHECK(contact); |
114 extensions::api::rtc_private::LaunchData launch_data; | 114 extensions::api::rtc_private::LaunchData launch_data; |
115 launch_data.intent.action = GetLaunchAction(action); | 115 launch_data.intent.action = GetLaunchAction(action); |
116 GetContactIntentData(contact, | 116 GetContactIntentData(*contact, |
117 &launch_data.intent.data.additional_properties); | 117 &launch_data.intent.data.additional_properties); |
118 launch_data.intent.type = kMimeTypeJson; | 118 launch_data.intent.type = kMimeTypeJson; |
119 extensions::ExtensionSystem::Get(profile)->event_router()-> | 119 extensions::ExtensionSystem::Get(profile)->event_router()-> |
120 DispatchEventToRenderers( | 120 DispatchEventToRenderers( |
121 kOnLaunchEvent, | 121 kOnLaunchEvent, |
122 extensions::api::rtc_private::OnLaunch::Create(launch_data), | 122 extensions::api::rtc_private::OnLaunch::Create(launch_data), |
123 profile, | 123 profile, |
124 GURL()); | 124 GURL()); |
125 } | 125 } |
126 } | 126 } |
127 | 127 |
128 } // namespace extensions | 128 } // namespace extensions |
OLD | NEW |