flutter_flutter/viewer/content_handler_impl.cc
James Robinson be2f656ab1 Pass ServiceProvider and ServiceProvider& params in Connect
In preperation for removing the Client annotation from ServiceProvider
this passes a second parameter of type ServiceProvider in the shell and
application Connect calls. In this patch the type signatures are updated
but the second parameter is basically unused. The intention is that the
first parameter |services| will be used for the connecting application to
request services from the connected application (as it does currently)
and the second parameter |exported_services| be used for the connecting
application to provide services to the connected application. We have
very few services exported in the second direction today - I'll update
them to use the second parameter in a follow-up patch.

R=darin@chromium.org

Review URL: https://codereview.chromium.org/845593003
2015-01-14 14:33:07 -08:00

83 lines
2.9 KiB
C++

// 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 "sky/viewer/content_handler_impl.h"
#include "base/bind.h"
#include "mojo/public/cpp/application/connect.h"
#include "mojo/services/network/public/interfaces/network_service.mojom.h"
#include "sky/viewer/document_view.h"
namespace sky {
class SkyApplication : public mojo::Application {
public:
SkyApplication(mojo::ShellPtr shell,
mojo::URLResponsePtr response)
: url_(response->url),
shell_(shell.Pass()),
initial_response_(response.Pass()) {
shell_.set_client(this);
mojo::ServiceProviderPtr service_provider;
shell_->ConnectToApplication("mojo:network_service",
mojo::GetProxy(&service_provider), nullptr);
mojo::ConnectToService(service_provider.get(), &network_service_);
}
void Initialize(mojo::Array<mojo::String> args) override {}
void AcceptConnection(const mojo::String& requestor_url,
mojo::InterfaceRequest<mojo::ServiceProvider> services,
mojo::ServiceProviderPtr exposed_services) override {
if (initial_response_) {
OnResponseReceived(mojo::URLLoaderPtr(), services.Pass(),
exposed_services.Pass(), initial_response_.Pass());
} else {
mojo::URLLoaderPtr loader;
network_service_->CreateURLLoader(mojo::GetProxy(&loader));
mojo::URLRequestPtr request(mojo::URLRequest::New());
request->url = url_;
request->auto_follow_redirects = true;
// |loader| will be pass to the OnResponseReceived method through a
// callback. Because order of evaluation is undefined, a reference to the
// raw pointer is needed.
mojo::URLLoader* raw_loader = loader.get();
raw_loader->Start(
request.Pass(),
base::Bind(&SkyApplication::OnResponseReceived,
base::Unretained(this), base::Passed(&loader),
base::Passed(&services), base::Passed(&exposed_services)));
}
}
private:
void OnResponseReceived(
mojo::URLLoaderPtr loader,
mojo::InterfaceRequest<mojo::ServiceProvider> services,
mojo::ServiceProviderPtr exposed_services,
mojo::URLResponsePtr response) {
new DocumentView(services.Pass(), exposed_services.Pass(), response.Pass(),
shell_.get());
}
mojo::String url_;
mojo::ShellPtr shell_;
mojo::NetworkServicePtr network_service_;
mojo::URLResponsePtr initial_response_;
};
ContentHandlerImpl::ContentHandlerImpl() {
}
ContentHandlerImpl::~ContentHandlerImpl() {
}
void ContentHandlerImpl::StartApplication(mojo::ShellPtr shell,
mojo::URLResponsePtr response) {
new SkyApplication(shell.Pass(), response.Pass());
}
} // namespace sky