Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1100)

Side by Side Diff: sky/viewer/content_handler_impl.cc

Issue 1154223003: NOT FOR COMMIT: POC of using AuthenticatingURLLoader in Sky (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: updated comment Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sky/viewer/BUILD.gn ('k') | sky/viewer/viewer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "sky/viewer/content_handler_impl.h" 5 #include "sky/viewer/content_handler_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "mojo/public/cpp/application/connect.h" 8 #include "mojo/public/cpp/application/connect.h"
9 #include "mojo/public/cpp/bindings/strong_binding.h" 9 #include "mojo/public/cpp/bindings/strong_binding.h"
10 #include "mojo/public/cpp/utility/run_loop.h" 10 #include "mojo/public/cpp/utility/run_loop.h"
11 #include "mojo/services/network/public/interfaces/network_service.mojom.h" 11 #include "mojo/services/authenticating_url_loader/public/interfaces/authenticati ng_url_loader_factory.mojom.h"
12 #include "mojo/services/authentication/public/interfaces/authentication.mojom.h"
12 #include "sky/viewer/document_view.h" 13 #include "sky/viewer/document_view.h"
13 14
14 namespace sky { 15 namespace sky {
15 16
16 class SkyApplication : public mojo::Application { 17 class SkyApplication : public mojo::Application {
17 public: 18 public:
18 SkyApplication(mojo::InterfaceRequest<mojo::Application> application, 19 SkyApplication(mojo::InterfaceRequest<mojo::Application> application,
19 mojo::URLResponsePtr response) 20 mojo::URLResponsePtr response)
20 : binding_(this, application.Pass()), 21 : binding_(this, application.Pass()),
21 initial_response_(response.Pass()) {} 22 initial_response_(response.Pass()) {}
22 23
23 void Initialize(mojo::ShellPtr shell, 24 void Initialize(mojo::ShellPtr shell,
24 mojo::Array<mojo::String> args, 25 mojo::Array<mojo::String> args,
25 const mojo::String& url) override { 26 const mojo::String& url) override {
26 shell_ = shell.Pass(); 27 shell_ = shell.Pass();
27 mojo::ServiceProviderPtr service_provider; 28 mojo::ServiceProviderPtr service_provider;
28 shell_->ConnectToApplication("mojo:network_service", 29 shell_->ConnectToApplication("mojo:authenticating_url_loader",
29 mojo::GetProxy(&service_provider), nullptr); 30 mojo::GetProxy(&service_provider), nullptr);
30 mojo::ConnectToService(service_provider.get(), &network_service_); 31 mojo::ConnectToService(service_provider.get(),
32 &authenticating_url_loader_factory_);
33 shell_->ConnectToApplication("mojo:authentication",
34 mojo::GetProxy(&service_provider), nullptr);
35 authentication::AuthenticationServicePtr authentication_service;
36 mojo::ConnectToService(service_provider.get(), &authentication_service);
37 authenticating_url_loader_factory_->SetAuthenticationService(
38 authentication_service.Pass());
31 } 39 }
32 40
33 void AcceptConnection(const mojo::String& requestor_url, 41 void AcceptConnection(const mojo::String& requestor_url,
34 mojo::InterfaceRequest<mojo::ServiceProvider> services, 42 mojo::InterfaceRequest<mojo::ServiceProvider> services,
35 mojo::ServiceProviderPtr exposed_services, 43 mojo::ServiceProviderPtr exposed_services,
36 const mojo::String& url) override { 44 const mojo::String& url) override {
37 if (initial_response_) { 45 if (initial_response_) {
38 OnResponseReceived(mojo::URLLoaderPtr(), services.Pass(), 46 OnResponseReceived(mojo::AuthenticatingURLLoaderPtr(), services.Pass(),
39 exposed_services.Pass(), initial_response_.Pass()); 47 exposed_services.Pass(), initial_response_.Pass());
40 } else { 48 } else {
41 mojo::URLLoaderPtr loader; 49 mojo::AuthenticatingURLLoaderPtr loader;
42 network_service_->CreateURLLoader(mojo::GetProxy(&loader)); 50 authenticating_url_loader_factory_->CreateAuthenticatingURLLoader(
51 mojo::GetProxy(&loader));
43 mojo::URLRequestPtr request(mojo::URLRequest::New()); 52 mojo::URLRequestPtr request(mojo::URLRequest::New());
44 request->url = url; 53 request->url = url;
45 request->auto_follow_redirects = true; 54 request->auto_follow_redirects = true;
46 55
47 // |loader| will be pass to the OnResponseReceived method through a 56 // |loader| will be pass to the OnResponseReceived method through a
48 // callback. Because order of evaluation is undefined, a reference to the 57 // callback. Because order of evaluation is undefined, a reference to the
49 // raw pointer is needed. 58 // raw pointer is needed.
50 mojo::URLLoader* raw_loader = loader.get(); 59 mojo::AuthenticatingURLLoader* raw_loader = loader.get();
51 raw_loader->Start( 60 raw_loader->Start(
52 request.Pass(), 61 request.Pass(),
53 base::Bind(&SkyApplication::OnResponseReceived, 62 base::Bind(&SkyApplication::OnResponseReceived,
54 base::Unretained(this), base::Passed(&loader), 63 base::Unretained(this), base::Passed(&loader),
55 base::Passed(&services), base::Passed(&exposed_services))); 64 base::Passed(&services), base::Passed(&exposed_services)));
56 } 65 }
57 } 66 }
58 67
59 void RequestQuit() override { 68 void RequestQuit() override {
60 mojo::RunLoop::current()->Quit(); 69 mojo::RunLoop::current()->Quit();
61 } 70 }
62 71
63 private: 72 private:
64 void OnResponseReceived( 73 void OnResponseReceived(
65 mojo::URLLoaderPtr loader, 74 mojo::AuthenticatingURLLoaderPtr loader,
66 mojo::InterfaceRequest<mojo::ServiceProvider> services, 75 mojo::InterfaceRequest<mojo::ServiceProvider> services,
67 mojo::ServiceProviderPtr exposed_services, 76 mojo::ServiceProviderPtr exposed_services,
68 mojo::URLResponsePtr response) { 77 mojo::URLResponsePtr response) {
69 new DocumentView(services.Pass(), exposed_services.Pass(), response.Pass(), 78 new DocumentView(services.Pass(), exposed_services.Pass(), response.Pass(),
70 shell_.get()); 79 shell_.get());
71 } 80 }
72 81
73 mojo::StrongBinding<mojo::Application> binding_; 82 mojo::StrongBinding<mojo::Application> binding_;
74 mojo::ShellPtr shell_; 83 mojo::ShellPtr shell_;
75 mojo::NetworkServicePtr network_service_; 84 mojo::AuthenticatingURLLoaderFactoryPtr authenticating_url_loader_factory_;
76 mojo::URLResponsePtr initial_response_; 85 mojo::URLResponsePtr initial_response_;
77 }; 86 };
78 87
79 ContentHandlerImpl::ContentHandlerImpl( 88 ContentHandlerImpl::ContentHandlerImpl(
80 mojo::InterfaceRequest<mojo::ContentHandler> request) 89 mojo::InterfaceRequest<mojo::ContentHandler> request)
81 : binding_(this, request.Pass()) { 90 : binding_(this, request.Pass()) {
82 } 91 }
83 92
84 ContentHandlerImpl::~ContentHandlerImpl() { 93 ContentHandlerImpl::~ContentHandlerImpl() {
85 } 94 }
86 95
87 void ContentHandlerImpl::StartApplication( 96 void ContentHandlerImpl::StartApplication(
88 mojo::InterfaceRequest<mojo::Application> application, 97 mojo::InterfaceRequest<mojo::Application> application,
89 mojo::URLResponsePtr response) { 98 mojo::URLResponsePtr response) {
90 new SkyApplication(application.Pass(), response.Pass()); 99 new SkyApplication(application.Pass(), response.Pass());
91 } 100 }
92 101
93 } // namespace sky 102 } // namespace sky
OLDNEW
« no previous file with comments | « sky/viewer/BUILD.gn ('k') | sky/viewer/viewer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698