Index: chrome/browser/ui/ash/cast_config_delegate_chromeos.cc |
diff --git a/chrome/browser/ui/ash/cast_config_delegate_chromeos.cc b/chrome/browser/ui/ash/cast_config_delegate_chromeos.cc |
index d90c2f16da557144d7f3cfea1e52ae10554ee3be..9b7e6ef882ef7b7e34bc4879b1f6b8bd87b6afb0 100644 |
--- a/chrome/browser/ui/ash/cast_config_delegate_chromeos.cc |
+++ b/chrome/browser/ui/ash/cast_config_delegate_chromeos.cc |
@@ -8,12 +8,15 @@ |
#include "base/memory/scoped_ptr.h" |
#include "base/strings/utf_string_conversions.h" |
+#include "chrome/browser/extensions/api/cast_devices_private/cast_devices_private_api.h" |
#include "chrome/browser/extensions/api/tab_capture/tab_capture_api.h" |
#include "chrome/browser/profiles/profile_manager.h" |
#include "chrome/browser/ui/browser_navigator.h" |
+#include "chrome/common/extensions/api/cast_devices_private.h" |
#include "content/public/browser/browser_context.h" |
#include "content/public/browser/render_frame_host.h" |
#include "content/public/browser/render_view_host.h" |
+#include "extensions/browser/event_router.h" |
#include "extensions/browser/extension_host.h" |
#include "extensions/browser/extension_registry.h" |
#include "extensions/browser/process_manager.h" |
@@ -22,14 +25,15 @@ |
namespace chromeos { |
namespace { |
-using JavaScriptResultCallback = |
- content::RenderFrameHost::JavaScriptResultCallback; |
+Profile* GetProfile() { |
+ // TODO(jdufault): Figure out how to correctly handle multiprofile mode. |
+ // See crbug.com/488751 |
+ return ProfileManager::GetActiveUserProfile(); |
+} |
// Returns the cast extension if it exists. |
const extensions::Extension* FindCastExtension() { |
- // TODO(jdufault): Figure out how to correctly handle multiprofile mode. |
- // See crbug.com/488751 |
- Profile* profile = ProfileManager::GetActiveUserProfile(); |
+ Profile* profile = GetProfile(); |
const extensions::ExtensionRegistry* extension_registry = |
extensions::ExtensionRegistry::Get(profile); |
const extensions::ExtensionSet& enabled_extensions = |
@@ -45,74 +49,6 @@ const extensions::Extension* FindCastExtension() { |
return nullptr; |
} |
-// Utility method that returns the currently active RenderViewHost. |
-content::RenderViewHost* GetRenderViewHost() { |
- const extensions::Extension* extension = FindCastExtension(); |
- if (!extension) |
- return nullptr; |
- // TODO(jdufault): Figure out how to correctly handle multiprofile mode. |
- // See crbug.com/488751 |
- Profile* profile = ProfileManager::GetActiveUserProfile(); |
- if (!profile) |
- return nullptr; |
- extensions::ProcessManager* pm = extensions::ProcessManager::Get(profile); |
- return pm->GetBackgroundHostForExtension(extension->id())->render_view_host(); |
-} |
- |
-// Executes JavaScript in the context of the cast extension's background page. |
-void ExecuteJavaScript(const std::string& javascript) { |
- auto rvh = GetRenderViewHost(); |
- if (!rvh) |
- return; |
- rvh->GetMainFrame()->ExecuteJavaScript(base::UTF8ToUTF16(javascript)); |
-} |
- |
-// Executes JavaScript in the context of the cast extension's background page. |
-// Invokes |callback| with the return value of the invoked javascript. |
-void ExecuteJavaScriptWithCallback(const std::string& javascript, |
- const JavaScriptResultCallback& callback) { |
- auto rvh = GetRenderViewHost(); |
- if (!rvh) |
- return; |
- rvh->GetMainFrame()->ExecuteJavaScript(base::UTF8ToUTF16(javascript), |
- callback); |
-} |
- |
-// Handler for GetReceiversAndActivities. |
-void GetReceiversAndActivitiesCallback( |
- const ash::CastConfigDelegate::ReceiversAndActivitesCallback& callback, |
- const base::Value* value) { |
- ash::CastConfigDelegate::ReceiversAndActivites receiver_activites; |
- const base::ListValue* ra_list = nullptr; |
- if (value->GetAsList(&ra_list)) { |
- for (auto i = ra_list->begin(); i != ra_list->end(); ++i) { |
- const base::DictionaryValue* ra_dict = nullptr; |
- if ((*i)->GetAsDictionary(&ra_dict)) { |
- const base::DictionaryValue* receiver_dict(nullptr), |
- *activity_dict(nullptr); |
- ash::CastConfigDelegate::ReceiverAndActivity receiver_activity; |
- if (ra_dict->GetDictionary("receiver", &receiver_dict)) { |
- receiver_dict->GetString("name", &receiver_activity.receiver.name); |
- receiver_dict->GetString("id", &receiver_activity.receiver.id); |
- } |
- if (ra_dict->GetDictionary("activity", &activity_dict) && |
- !activity_dict->empty()) { |
- activity_dict->GetString("id", &receiver_activity.activity.id); |
- activity_dict->GetString("title", &receiver_activity.activity.title); |
- activity_dict->GetString("activityType", |
- &receiver_activity.activity.activity_type); |
- activity_dict->GetBoolean("allowStop", |
- &receiver_activity.activity.allow_stop); |
- activity_dict->GetInteger("tabId", |
- &receiver_activity.activity.tab_id); |
- } |
- receiver_activites[receiver_activity.receiver.id] = receiver_activity; |
- } |
- } |
- } |
- callback.Run(receiver_activites); |
-} |
- |
} // namespace |
CastConfigDelegateChromeos::CastConfigDelegateChromeos() { |
@@ -122,39 +58,48 @@ CastConfigDelegateChromeos::~CastConfigDelegateChromeos() { |
} |
bool CastConfigDelegateChromeos::HasCastExtension() const { |
- // TODO(jdufault): Temporarily disable the cast tray integration until we |
- // figure out how to get ExecuteJavaScriptInIsolatedWorld to work as expected. |
- // See crbug.com/514952. |
- return false; |
+ return FindCastExtension() != nullptr; |
} |
-void CastConfigDelegateChromeos::GetReceiversAndActivities( |
+CastConfigDelegateChromeos::DeviceUpdateSubscription |
+CastConfigDelegateChromeos::RegisterDeviceUpdateObserver( |
const ReceiversAndActivitesCallback& callback) { |
- // The methods in backgroundSetup are renamed during minification, so we have |
- // to bind the exported global API methods to backgroundSetup using call(). |
- ExecuteJavaScriptWithCallback( |
- "getMirrorCapableReceiversAndActivities.call(backgroundSetup);", |
- base::Bind(&GetReceiversAndActivitiesCallback, callback)); |
+ auto listeners = extensions::CastDeviceUpdateListeners::Get(GetProfile()); |
+ return listeners->RegisterCallback(callback); |
+} |
+ |
+void CastConfigDelegateChromeos::RequestDeviceRefresh() { |
+ scoped_ptr<base::ListValue> args = |
+ extensions::api::cast_devices_private::UpdateDevicesRequested::Create(); |
+ scoped_ptr<extensions::Event> event(new extensions::Event( |
+ extensions::events::CAST_DEVICES_PRIVATE_ON_UPDATE_DEVICES_REQUESTED, |
+ extensions::api::cast_devices_private::UpdateDevicesRequested::kEventName, |
+ args.Pass())); |
+ extensions::EventRouter::Get(GetProfile()) |
+ ->DispatchEventToExtension(FindCastExtension()->id(), event.Pass()); |
} |
void CastConfigDelegateChromeos::CastToReceiver( |
const std::string& receiver_id) { |
- // The methods in backgroundSetup are renamed during minification, so we have |
- // to bind the exported global API methods to backgroundSetup using call(). |
- ExecuteJavaScript("launchDesktopMirroring.call(backgroundSetup, '" + |
- receiver_id + "');"); |
+ scoped_ptr<base::ListValue> args = |
+ extensions::api::cast_devices_private::StartCast::Create(receiver_id); |
+ scoped_ptr<extensions::Event> event(new extensions::Event( |
+ extensions::events::CAST_DEVICES_PRIVATE_ON_START_CAST, |
+ extensions::api::cast_devices_private::StartCast::kEventName, |
+ args.Pass())); |
+ extensions::EventRouter::Get(GetProfile()) |
+ ->DispatchEventToExtension(FindCastExtension()->id(), event.Pass()); |
} |
void CastConfigDelegateChromeos::StopCasting() { |
- // The methods in backgroundSetup are renamed during minification, so we have |
- // to bind the exported global API methods to backgroundSetup using call(). |
- ExecuteJavaScript("stopMirroring.call(backgroundSetup, 'user-stop');"); |
- |
- // TODO(jdufault): Remove this after the beta/release versions of the |
- // cast extension have been updated so that they properly export the |
- // stopMirroring function. For now, we try to invoke all of the other |
- // names that the function goes by. See crbug.com/489929. |
- ExecuteJavaScript("backgroundSetup.Qu('user-stop');"); |
+ scoped_ptr<base::ListValue> args = |
+ extensions::api::cast_devices_private::StopCast::Create("user-stop"); |
+ scoped_ptr<extensions::Event> event(new extensions::Event( |
+ extensions::events::CAST_DEVICES_PRIVATE_ON_STOP_CAST, |
+ extensions::api::cast_devices_private::StopCast::kEventName, |
+ args.Pass())); |
+ extensions::EventRouter::Get(GetProfile()) |
+ ->DispatchEventToExtension(FindCastExtension()->id(), event.Pass()); |
} |
void CastConfigDelegateChromeos::LaunchCastOptions() { |