Index: mojo/shell/content_handler_connection.cc |
diff --git a/mojo/shell/content_handler_connection.cc b/mojo/shell/content_handler_connection.cc |
index dd3c5cb9e1a9e496a3e69cdd9a958ad4909d5017..0dba7f9db60b81d3c63d9553cbba643614ea1b9a 100644 |
--- a/mojo/shell/content_handler_connection.cc |
+++ b/mojo/shell/content_handler_connection.cc |
@@ -4,6 +4,7 @@ |
#include "mojo/shell/content_handler_connection.h" |
+#include "base/bind.h" |
#include "mojo/shell/application_manager.h" |
namespace mojo { |
@@ -15,17 +16,24 @@ ContentHandlerConnection::ContentHandlerConnection( |
const GURL& content_handler_url, |
const GURL& requestor_url, |
const std::string& qualifier, |
- const CapabilityFilter& filter) |
+ const CapabilityFilter& filter, |
+ uint32_t id) |
: manager_(manager), |
content_handler_url_(content_handler_url), |
content_handler_qualifier_(qualifier), |
- connection_closed_(false) { |
+ connection_closed_(false), |
+ id_(id), |
+ got_nested_content_handler_id_(false), |
+ nested_content_handler_id_(0u), |
+ weak_ptr_factory_(this) { |
ServiceProviderPtr services; |
mojo::URLRequestPtr request(mojo::URLRequest::New()); |
request->url = mojo::String::From(content_handler_url.spec()); |
manager->ConnectToApplication( |
- originator, request.Pass(), qualifier, requestor_url, GetProxy(&services), |
- nullptr, filter, base::Closure()); |
+ originator, request.Pass(), qualifier, requestor_url, id, |
+ GetProxy(&services), nullptr, filter, base::Closure(), |
+ base::Bind(&ContentHandlerConnection::OnGotNestedContentHandlerID, |
+ weak_ptr_factory_.GetWeakPtr())); |
MessagePipe pipe; |
content_handler_.Bind( |
InterfacePtrInfo<ContentHandler>(pipe.handle0.Pass(), 0u)); |
@@ -42,11 +50,36 @@ void ContentHandlerConnection::CloseConnection() { |
delete this; |
} |
+void ContentHandlerConnection::ScheduleTargetIdCallback( |
+ const Shell::ConnectToApplicationCallback& connect_callback) { |
+ if (got_nested_content_handler_id_) |
+ connect_callback.Run(content_handler_id_for_callback()); |
+ else |
+ pending_content_handler_id_callbacks_.push_back(connect_callback); |
+} |
+ |
ContentHandlerConnection::~ContentHandlerConnection() { |
// If this DCHECK fails then something has tried to delete this object without |
// calling CloseConnection. |
DCHECK(connection_closed_); |
} |
+void ContentHandlerConnection::OnGotNestedContentHandlerID( |
+ uint32_t content_handler_id) { |
+ DCHECK(!got_nested_content_handler_id_); |
+ got_nested_content_handler_id_ = true; |
+ nested_content_handler_id_ = content_handler_id; |
+ for (auto callback : pending_content_handler_id_callbacks_) |
+ callback.Run(content_handler_id_for_callback()); |
+ pending_content_handler_id_callbacks_.clear(); |
+} |
+ |
+uint32_t ContentHandlerConnection::content_handler_id_for_callback() const { |
+ return nested_content_handler_id_ == |
+ ApplicationManager::kInvalidContentHandlerID |
+ ? id_ |
+ : nested_content_handler_id_; |
+} |
+ |
} // namespace shell |
} // namespace mojo |