Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/ui/ash/cast_config_delegate_chromeos.h" | 5 #include "chrome/browser/ui/ash/cast_config_delegate_chromeos.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 | 120 |
| 121 CastConfigDelegateChromeos::~CastConfigDelegateChromeos() { | 121 CastConfigDelegateChromeos::~CastConfigDelegateChromeos() { |
| 122 } | 122 } |
| 123 | 123 |
| 124 bool CastConfigDelegateChromeos::HasCastExtension() const { | 124 bool CastConfigDelegateChromeos::HasCastExtension() const { |
| 125 return FindCastExtension() != nullptr; | 125 return FindCastExtension() != nullptr; |
| 126 } | 126 } |
| 127 | 127 |
| 128 void CastConfigDelegateChromeos::GetReceiversAndActivities( | 128 void CastConfigDelegateChromeos::GetReceiversAndActivities( |
| 129 const ReceiversAndActivitesCallback& callback) { | 129 const ReceiversAndActivitesCallback& callback) { |
| 130 // The extension API methods are exported to the global namespace, not to | |
| 131 // backgroundSetup, even though they are conceptually methods on | |
| 132 // backgroundSetup. This means that to invoke the exported methods, we | |
| 133 // have to manually bind the this argument using call (versus doing the | |
| 134 // more expected backgroundSetup.getMirrorCapable...()). | |
|
achuithb
2015/06/05 23:46:49
Hmm, how about something more along the lines of:
| |
| 130 ExecuteJavaScriptWithCallback( | 135 ExecuteJavaScriptWithCallback( |
| 131 "backgroundSetup.getMirrorCapableReceiversAndActivities();", | 136 "getMirrorCapableReceiversAndActivities.call(backgroundSetup);", |
| 132 base::Bind(&GetReceiversAndActivitiesCallback, callback)); | 137 base::Bind(&GetReceiversAndActivitiesCallback, callback)); |
| 133 } | 138 } |
| 134 | 139 |
| 135 void CastConfigDelegateChromeos::CastToReceiver( | 140 void CastConfigDelegateChromeos::CastToReceiver( |
| 136 const std::string& receiver_id) { | 141 const std::string& receiver_id) { |
| 137 ExecuteJavaScript("backgroundSetup.launchDesktopMirroring('" + receiver_id + | 142 // See comment in GetReceiversAndActivities. |
| 138 "');"); | 143 ExecuteJavaScript("launchDesktopMirroring.call(backgroundSetup, '" + |
| 144 receiver_id + "');"); | |
| 139 } | 145 } |
| 140 | 146 |
| 141 void CastConfigDelegateChromeos::StopCasting() { | 147 void CastConfigDelegateChromeos::StopCasting() { |
| 142 ExecuteJavaScript("backgroundSetup.stopMirroring('user-stop')"); | 148 // See comment in GetReceiversAndActivities. |
| 143 | |
| 144 // TODO(jdufault): Remove this after the beta/release versions of the | 149 // TODO(jdufault): Remove this after the beta/release versions of the |
| 145 // cast extension have been updated so that they properly export the | 150 // cast extension have been updated so that they properly export the |
| 146 // stopMirroring function. For now, we try to invoke all of the other | 151 // stopMirroring function. For now, we try to invoke all of the other |
| 147 // names that the function goes by. See crbug.com/489929. | 152 // names that the function goes by. See crbug.com/489929. |
| 148 ExecuteJavaScript("backgroundSetup.stopCastMirroring('user-stop');"); | |
| 149 ExecuteJavaScript("backgroundSetup.Qu('user-stop');"); | 153 ExecuteJavaScript("backgroundSetup.Qu('user-stop');"); |
| 154 ExecuteJavaScript("stopCastMirroring.call(backgroundSetup, 'user-stop');"); | |
| 155 ExecuteJavaScript("stopMirroring.call(backgroundSetup, 'user-stop');"); | |
| 150 } | 156 } |
| 151 | 157 |
| 152 void CastConfigDelegateChromeos::LaunchCastOptions() { | 158 void CastConfigDelegateChromeos::LaunchCastOptions() { |
| 153 chrome::NavigateParams params( | 159 chrome::NavigateParams params( |
| 154 ProfileManager::GetActiveUserProfile(), | 160 ProfileManager::GetActiveUserProfile(), |
| 155 FindCastExtension()->GetResourceURL("options.html"), | 161 FindCastExtension()->GetResourceURL("options.html"), |
| 156 ui::PAGE_TRANSITION_LINK); | 162 ui::PAGE_TRANSITION_LINK); |
| 157 params.disposition = NEW_FOREGROUND_TAB; | 163 params.disposition = NEW_FOREGROUND_TAB; |
| 158 params.window_action = chrome::NavigateParams::SHOW_WINDOW; | 164 params.window_action = chrome::NavigateParams::SHOW_WINDOW; |
| 159 chrome::Navigate(¶ms); | 165 chrome::Navigate(¶ms); |
| 160 } | 166 } |
| 161 | 167 |
| 162 } // namespace chromeos | 168 } // namespace chromeos |
| OLD | NEW |