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

Unified Diff: chrome/browser/extensions/api/rtc_private/rtc_private_api.cc

Issue 10919086: Wired chrome.rtcPrivate API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/rtc_private/rtc_private_api.cc
diff --git a/chrome/browser/extensions/api/rtc_private/rtc_private_api.cc b/chrome/browser/extensions/api/rtc_private/rtc_private_api.cc
new file mode 100644
index 0000000000000000000000000000000000000000..465323b356f631bc3a9f030d9620fef5c7a71632
--- /dev/null
+++ b/chrome/browser/extensions/api/rtc_private/rtc_private_api.cc
@@ -0,0 +1,141 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/extensions/api/rtc_private/rtc_private_api.h"
+
+#include "base/json/json_writer.h"
+#include "base/message_loop.h"
+#include "base/stringprintf.h"
+#include "base/time.h"
+#include "base/utf_string_conversions.h"
+#include "base/value_conversions.h"
+#include "base/values.h"
+#include "chrome/browser/chromeos/contacts/contact_manager.h"
+#include "chrome/browser/chromeos/contacts/contact.pb.h"
+#include "chrome/browser/extensions/event_router.h"
+#include "chrome/browser/extensions/extension_service.h"
+#include "chrome/browser/extensions/extension_system.h"
+#include "chrome/browser/extensions/state_store.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/common/chrome_notification_types.h"
+#include "content/public/browser/notification_service.h"
+
+using base::DictionaryValue;
+using base::ListValue;
+using base::Value;
+using contacts::Contact;
+using contacts::Contact_EmailAddress;
+using contacts::Contact_PhoneNumber;
+
+namespace extensions {
+
+namespace {
+
+// Launch event name.
+const char kOnLaunchEvent[] = "rtcPrivate.onLaunch";
+// Default RTC extension id.
+const char kDefaultRtcExtensionId[] = "ljclpkphhpbpinifbeabbhlfddcpfdde";
+// Web intent data payload mimetype.
+const char kMimeTypeJson[] = "application/json";
+// Web intent actions.
+const char kActivateAction[] = "activate";
+const char kChatAction[] = "chat";
+const char kVoiceAction[] = "voice";
+const char kVideoAction[] = "video";
+// Web intent data structure fields.
+const char kNameIntentField[] = "name";
+const char kPhoneIntentField[] = "phone";
+const char kEmailIntentField[] = "email";
+
+const char kIntentField[] = "intent";
Mihai Parparita -not on Chrome 2012/09/05 20:11:09 There should be a LaunchIntent struct that gets au
zel 2012/09/05 21:30:44 Done.
+const char kActionField[] = "action";
+const char kDataField[] = "data";
+const char kTypeField[] = "type";
+
+// Returns string representation of intent action.
+const char* GetLaunchAction(RtcPrivateApi::LaunchAction action) {
+ const char* action_str = kActivateAction;
+ switch (action) {
+ case RtcPrivateApi::LAUNCH_ACTIVATE:
+ action_str = kActivateAction;
+ break;
+ case RtcPrivateApi::LAUNCH_CHAT:
+ action_str = kChatAction;
+ break;
+ case RtcPrivateApi::LAUNCH_VOICE:
+ action_str = kVoiceAction;
+ break;
+ case RtcPrivateApi::LAUNCH_VIDEO:
+ action_str = kVideoAction;
+ break;
+ default:
+ NOTREACHED() << "Unknown action " << action;
+ break;
+ }
+ return action_str;
+}
+
+// Creates JSON payload string for contact web intent data.
+std::string GetContactIntentData(Contact* contact) {
+ base::DictionaryValue dict;
+
+ // TODO(derat): This might require more name extraction magic than this.
+ dict.SetString(kNameIntentField, contact->full_name());
+
+ ListValue* phone_list = new base::ListValue();
+ dict.Set(kPhoneIntentField, phone_list);
+ for (int i = 0; i < contact->phone_numbers_size(); i++) {
+ const Contact_PhoneNumber& phone_number = contact->phone_numbers(i);
+ StringValue* value = Value::CreateStringValue(phone_number.number());
+ if (phone_number.primary())
+ CHECK(phone_list->Insert(0, value));
+ else
+ phone_list->Append(value);
+ }
+
+ ListValue* email_list = new base::ListValue();
+ dict.Set(kPhoneIntentField, email_list);
+ for (int i = 0; i < contact->email_addresses_size(); i++) {
+ const Contact_EmailAddress& email_address = contact->email_addresses(i);
+ StringValue* value = Value::CreateStringValue(email_address.address());
+ if (email_address.primary())
+ CHECK(email_list->Insert(0, value));
+ else
+ email_list->Append(value);
+ }
+
+ std::string data;
+ base::JSONWriter::Write(&dict, &data);
+ return data;
+}
+
+
+} // namespace
+
+
+void RtcPrivateApi::RaiseLaunchEvent(Profile* profile,
+ LaunchAction action,
+ Contact* contact) {
+ scoped_ptr<ListValue> args(new ListValue());
+ if (action != RtcPrivateApi::LAUNCH_ACTIVATE) {
+ DictionaryValue* launch_data = new DictionaryValue();
+ args->Append(launch_data);
+ DictionaryValue* intent = new DictionaryValue();
+ launch_data->Set(kIntentField, intent);
+ intent->SetString(kActionField, GetLaunchAction(action));
+ if (contact) {
+ intent->SetString(kDataField, GetContactIntentData(contact));
+ intent->SetString(kTypeField, kMimeTypeJson);
+ }
+ }
+
+ extensions::ExtensionSystem::Get(profile)->event_router()->
+ DispatchEventToRenderers(
+ kOnLaunchEvent,
+ args.Pass(),
+ profile,
+ GURL());
+}
+
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698