summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkelvinp@chromium.org <kelvinp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-06 10:50:48 +0000
committerkelvinp@chromium.org <kelvinp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-06 10:50:48 +0000
commitb560539c1fabaf41e75050e93cf3474d6c30cd8c (patch)
treead4b80688dcaf921ffb7722ce1d366baf3060b51
parent401afd2f9a36dda440a8296de49e40671440dd4c (diff)
downloadchromium_src-b560539c1fabaf41e75050e93cf3474d6c30cd8c.zip
chromium_src-b560539c1fabaf41e75050e93cf3474d6c30cd8c.tar.gz
chromium_src-b560539c1fabaf41e75050e93cf3474d6c30cd8c.tar.bz2
Third Party Authentication for Android Part I - TokenFetcherProxy.
This is part I of the effort to support third party authentication for android. The TokenFetcherProxy is generalized version of the existing PepperTokenFetcher. It is used by the ThirdPartyClientAuthenticator to fetch auth tokens from both the webapp and the android client. BUG=329109 Review URL: https://codereview.chromium.org/311983003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@275386 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--remoting/client/jni/chromoting_jni_instance.cc10
-rw-r--r--remoting/client/jni/chromoting_jni_instance.h8
-rw-r--r--remoting/client/plugin/chromoting_instance.cc19
-rw-r--r--remoting/client/plugin/chromoting_instance.h6
-rw-r--r--remoting/client/plugin/pepper_token_fetcher.cc40
-rw-r--r--remoting/client/plugin/pepper_token_fetcher.h44
-rw-r--r--remoting/client/token_fetcher_proxy.cc37
-rw-r--r--remoting/client/token_fetcher_proxy.h48
-rw-r--r--remoting/remoting_srcs.gypi4
9 files changed, 119 insertions, 97 deletions
diff --git a/remoting/client/jni/chromoting_jni_instance.cc b/remoting/client/jni/chromoting_jni_instance.cc
index 5dd94b3..efe2ea5 100644
--- a/remoting/client/jni/chromoting_jni_instance.cc
+++ b/remoting/client/jni/chromoting_jni_instance.cc
@@ -15,6 +15,7 @@
#include "remoting/client/jni/chromoting_jni_runtime.h"
#include "remoting/client/log_to_server.h"
#include "remoting/client/software_video_renderer.h"
+#include "remoting/client/token_fetcher_proxy.h"
#include "remoting/jingle_glue/chromium_port_allocator.h"
#include "remoting/jingle_glue/chromium_socket_factory.h"
#include "remoting/jingle_glue/network_settings.h"
@@ -105,6 +106,15 @@ void ChromotingJniInstance::Cleanup() {
this));
}
+void ChromotingJniInstance::FetchThirdPartyToken(
+ const GURL& token_url,
+ const std::string& client_id,
+ const std::string& scope,
+ base::WeakPtr<TokenFetcherProxy> jni_token_fetcher) {
+ // TODO(kelvinp) Calls into the jni_runtime_ to obtain a token from the
+ // android app (Android Third Party Auth - Part II).
+}
+
void ChromotingJniInstance::ProvideSecret(const std::string& pin,
bool create_pairing,
const std::string& device_name) {
diff --git a/remoting/client/jni/chromoting_jni_instance.h b/remoting/client/jni/chromoting_jni_instance.h
index 0840497..126ce18 100644
--- a/remoting/client/jni/chromoting_jni_instance.h
+++ b/remoting/client/jni/chromoting_jni_instance.h
@@ -17,6 +17,7 @@
#include "remoting/client/client_user_interface.h"
#include "remoting/client/frame_consumer_proxy.h"
#include "remoting/client/jni/jni_frame_consumer.h"
+#include "remoting/client/token_fetcher_proxy.h"
#include "remoting/jingle_glue/xmpp_signal_strategy.h"
#include "remoting/protocol/clipboard_stub.h"
#include "remoting/protocol/connection_to_host.h"
@@ -58,6 +59,13 @@ class ChromotingJniInstance
// up. Must be called before destruction.
void Cleanup();
+ // Requests the android app to fetch a third-party token.
+ void FetchThirdPartyToken(
+ const GURL& token_url,
+ const std::string& client_id,
+ const std::string& scope,
+ const base::WeakPtr<TokenFetcherProxy> token_fetcher_proxy);
+
// Provides the user's PIN and resumes the host authentication attempt. Call
// on the UI thread once the user has finished entering this PIN into the UI,
// but only after the UI has been asked to provide a PIN (via FetchSecret()).
diff --git a/remoting/client/plugin/chromoting_instance.cc b/remoting/client/plugin/chromoting_instance.cc
index f7083b6..2790229 100644
--- a/remoting/client/plugin/chromoting_instance.cc
+++ b/remoting/client/plugin/chromoting_instance.cc
@@ -47,9 +47,9 @@
#include "remoting/client/plugin/pepper_audio_player.h"
#include "remoting/client/plugin/pepper_input_handler.h"
#include "remoting/client/plugin/pepper_port_allocator.h"
-#include "remoting/client/plugin/pepper_token_fetcher.h"
#include "remoting/client/plugin/pepper_view.h"
#include "remoting/client/software_video_renderer.h"
+#include "remoting/client/token_fetcher_proxy.h"
#include "remoting/protocol/connection_to_host.h"
#include "remoting/protocol/host_stub.h"
#include "remoting/protocol/libjingle_transport_factory.h"
@@ -452,12 +452,12 @@ void ChromotingInstance::FetchThirdPartyToken(
const GURL& token_url,
const std::string& host_public_key,
const std::string& scope,
- base::WeakPtr<PepperTokenFetcher> pepper_token_fetcher) {
+ base::WeakPtr<TokenFetcherProxy> token_fetcher_proxy) {
// Once the Session object calls this function, it won't continue the
// authentication until the callback is called (or connection is canceled).
// So, it's impossible to reach this with a callback already registered.
- DCHECK(!pepper_token_fetcher_.get());
- pepper_token_fetcher_ = pepper_token_fetcher;
+ DCHECK(!token_fetcher_proxy_.get());
+ token_fetcher_proxy_ = token_fetcher_proxy;
scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue());
data->SetString("tokenUrl", token_url.spec());
data->SetString("hostPublicKey", host_public_key);
@@ -537,7 +537,10 @@ protocol::CursorShapeStub* ChromotingInstance::GetCursorShapeStub() {
scoped_ptr<protocol::ThirdPartyClientAuthenticator::TokenFetcher>
ChromotingInstance::GetTokenFetcher(const std::string& host_public_key) {
return scoped_ptr<protocol::ThirdPartyClientAuthenticator::TokenFetcher>(
- new PepperTokenFetcher(weak_factory_.GetWeakPtr(), host_public_key));
+ new TokenFetcherProxy(
+ base::Bind(&ChromotingInstance::FetchThirdPartyToken,
+ weak_factory_.GetWeakPtr()),
+ host_public_key));
}
void ChromotingInstance::InjectClipboardEvent(
@@ -940,9 +943,9 @@ void ChromotingInstance::HandleOnThirdPartyTokenFetched(
LOG(ERROR) << "Invalid onThirdPartyTokenFetched data.";
return;
}
- if (pepper_token_fetcher_.get()) {
- pepper_token_fetcher_->OnTokenFetched(token, shared_secret);
- pepper_token_fetcher_.reset();
+ if (token_fetcher_proxy_.get()) {
+ token_fetcher_proxy_->OnTokenFetched(token, shared_secret);
+ token_fetcher_proxy_.reset();
} else {
LOG(WARNING) << "Ignored OnThirdPartyTokenFetched without a pending fetch.";
}
diff --git a/remoting/client/plugin/chromoting_instance.h b/remoting/client/plugin/chromoting_instance.h
index 121f1ad..3f6b0c6 100644
--- a/remoting/client/plugin/chromoting_instance.h
+++ b/remoting/client/plugin/chromoting_instance.h
@@ -61,7 +61,7 @@ class DelegatingSignalStrategy;
class FrameConsumer;
class FrameConsumerProxy;
class PepperAudioPlayer;
-class PepperTokenFetcher;
+class TokenFetcherProxy;
class PepperView;
class RectangleUpdateDecoder;
class SignalStrategy;
@@ -178,7 +178,7 @@ class ChromotingInstance :
const GURL& token_url,
const std::string& host_public_key,
const std::string& scope,
- const base::WeakPtr<PepperTokenFetcher> pepper_token_fetcher);
+ const base::WeakPtr<TokenFetcherProxy> pepper_token_fetcher);
private:
FRIEND_TEST_ALL_PREFIXES(ChromotingInstanceTest, TestCaseSetup);
@@ -294,7 +294,7 @@ class ChromotingInstance :
// webapp for decoding.
bool use_media_source_rendering_;
- base::WeakPtr<PepperTokenFetcher> pepper_token_fetcher_;
+ base::WeakPtr<TokenFetcherProxy> token_fetcher_proxy_;
// Weak reference to this instance, used for global logging and task posting.
base::WeakPtrFactory<ChromotingInstance> weak_factory_;
diff --git a/remoting/client/plugin/pepper_token_fetcher.cc b/remoting/client/plugin/pepper_token_fetcher.cc
deleted file mode 100644
index 7a7aca9..0000000
--- a/remoting/client/plugin/pepper_token_fetcher.cc
+++ /dev/null
@@ -1,40 +0,0 @@
-// Copyright 2013 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 "remoting/client/plugin/pepper_token_fetcher.h"
-
-#include "remoting/client/plugin/chromoting_instance.h"
-
-namespace remoting {
-
-PepperTokenFetcher::PepperTokenFetcher(base::WeakPtr<ChromotingInstance> plugin,
- const std::string& host_public_key)
- : plugin_(plugin),
- host_public_key_(host_public_key),
- weak_factory_(this) {
-}
-
-PepperTokenFetcher::~PepperTokenFetcher() {
-}
-
-void PepperTokenFetcher::FetchThirdPartyToken(
- const GURL& token_url,
- const std::string& scope,
- const TokenFetchedCallback& token_fetched_callback) {
- if (plugin_.get()) {
- token_fetched_callback_ = token_fetched_callback;
- plugin_->FetchThirdPartyToken(token_url, host_public_key_, scope,
- weak_factory_.GetWeakPtr());
- }
-}
-
-void PepperTokenFetcher::OnTokenFetched(
- const std::string& token, const std::string& shared_secret) {
- if (!token_fetched_callback_.is_null()) {
- token_fetched_callback_.Run(token, shared_secret);
- token_fetched_callback_.Reset();
- }
-}
-
-} // namespace remoting
diff --git a/remoting/client/plugin/pepper_token_fetcher.h b/remoting/client/plugin/pepper_token_fetcher.h
deleted file mode 100644
index b914f51..0000000
--- a/remoting/client/plugin/pepper_token_fetcher.h
+++ /dev/null
@@ -1,44 +0,0 @@
-// Copyright 2013 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.
-
-#ifndef REMOTING_CLIENT_PLUGIN_PEPPER_TOKEN_FETCHER_H_
-#define REMOTING_CLIENT_PLUGIN_PEPPER_TOKEN_FETCHER_H_
-
-#include "base/callback.h"
-#include "base/memory/weak_ptr.h"
-#include "remoting/protocol/third_party_client_authenticator.h"
-
-namespace remoting {
-
-class ChromotingInstance;
-
-class PepperTokenFetcher
- : public protocol::ThirdPartyClientAuthenticator::TokenFetcher {
- public:
- PepperTokenFetcher(base::WeakPtr<ChromotingInstance> plugin,
- const std::string& host_public_key);
- virtual ~PepperTokenFetcher();
-
- // protocol::TokenClientAuthenticator::TokenFetcher interface.
- virtual void FetchThirdPartyToken(
- const GURL& token_url,
- const std::string& scope,
- const TokenFetchedCallback& token_fetched_callback) OVERRIDE;
-
- // Called by ChromotingInstance when the webapp finishes fetching the token.
- void OnTokenFetched(const std::string& token,
- const std::string& shared_secret);
-
- private:
- base::WeakPtr<ChromotingInstance> plugin_;
- std::string host_public_key_;
- TokenFetchedCallback token_fetched_callback_;
- base::WeakPtrFactory<PepperTokenFetcher> weak_factory_;
-
- DISALLOW_COPY_AND_ASSIGN(PepperTokenFetcher);
-};
-
-} // namespace remoting
-
-#endif // REMOTING_CLIENT_PLUGIN_PEPPER_TOKEN_FETCHER_H_
diff --git a/remoting/client/token_fetcher_proxy.cc b/remoting/client/token_fetcher_proxy.cc
new file mode 100644
index 0000000..c1082b2
--- /dev/null
+++ b/remoting/client/token_fetcher_proxy.cc
@@ -0,0 +1,37 @@
+// Copyright 2014 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 "remoting/client/token_fetcher_proxy.h"
+
+namespace remoting {
+
+TokenFetcherProxy::TokenFetcherProxy(
+ const TokenFetcherCallback& token_fetcher_impl,
+ const std::string& host_public_key)
+ : host_public_key_(host_public_key),
+ token_fetcher_impl_(token_fetcher_impl),
+ weak_factory_(this) {
+}
+
+TokenFetcherProxy::~TokenFetcherProxy() {
+}
+
+void TokenFetcherProxy::FetchThirdPartyToken(
+ const GURL& token_url,
+ const std::string& scope,
+ const TokenFetchedCallback& token_fetched_callback) {
+ token_fetched_callback_ = token_fetched_callback;
+ token_fetcher_impl_.Run(
+ token_url, host_public_key_, scope, weak_factory_.GetWeakPtr());
+}
+
+void TokenFetcherProxy::OnTokenFetched(
+ const std::string& token, const std::string& shared_secret) {
+ if (!token_fetched_callback_.is_null()) {
+ token_fetched_callback_.Run(token, shared_secret);
+ token_fetched_callback_.Reset();
+ }
+}
+
+} // namespace remoting
diff --git a/remoting/client/token_fetcher_proxy.h b/remoting/client/token_fetcher_proxy.h
new file mode 100644
index 0000000..f7cec09
--- /dev/null
+++ b/remoting/client/token_fetcher_proxy.h
@@ -0,0 +1,48 @@
+// Copyright 2014 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.
+
+#ifndef REMOTING_CLIENT_TOKEN_FETCHER_PROXY_H_
+#define REMOTING_CLIENT_TOKEN_FETCHER_PROXY_H_
+
+#include "base/callback.h"
+#include "base/memory/weak_ptr.h"
+#include "remoting/protocol/third_party_client_authenticator.h"
+
+namespace remoting {
+
+class TokenFetcherProxy
+ : public protocol::ThirdPartyClientAuthenticator::TokenFetcher {
+ public:
+ typedef base::Callback<void(
+ const GURL& token_url,
+ const std::string& host_public_key,
+ const std::string& scope,
+ base::WeakPtr<TokenFetcherProxy>)> TokenFetcherCallback;
+
+ TokenFetcherProxy(const TokenFetcherCallback& token_fetcher_impl,
+ const std::string& host_public_key);
+ virtual ~TokenFetcherProxy();
+
+ // protocol::TokenClientAuthenticator::TokenFetcher interface.
+ virtual void FetchThirdPartyToken(
+ const GURL& token_url,
+ const std::string& scope,
+ const TokenFetchedCallback& token_fetched_callback) OVERRIDE;
+
+ // Called by the token fetching implementation when the token is fetched.
+ void OnTokenFetched(const std::string& token,
+ const std::string& shared_secret);
+
+ private:
+ std::string host_public_key_;
+ TokenFetcherCallback token_fetcher_impl_;
+ TokenFetchedCallback token_fetched_callback_;
+ base::WeakPtrFactory<TokenFetcherProxy> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(TokenFetcherProxy);
+};
+
+} // namespace remoting
+
+#endif // REMOTING_CLIENT_TOKEN_FETCHER_PROXY_H_
diff --git a/remoting/remoting_srcs.gypi b/remoting/remoting_srcs.gypi
index 25785e2..b0af707 100644
--- a/remoting/remoting_srcs.gypi
+++ b/remoting/remoting_srcs.gypi
@@ -218,6 +218,8 @@
'client/server_log_entry_client.h',
'client/software_video_renderer.cc',
'client/software_video_renderer.h',
+ 'client/token_fetcher_proxy.cc',
+ 'client/token_fetcher_proxy.h',
'client/video_renderer.h',
],
@@ -244,8 +246,6 @@
'client/plugin/pepper_plugin_thread_delegate.h',
'client/plugin/pepper_port_allocator.cc',
'client/plugin/pepper_port_allocator.h',
- 'client/plugin/pepper_token_fetcher.cc',
- 'client/plugin/pepper_token_fetcher.h',
'client/plugin/pepper_util.cc',
'client/plugin/pepper_util.h',
'client/plugin/pepper_view.cc',