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

Side by Side Diff: mojo/apps/js/content_handler_impl.cc

Issue 687273002: mojo: Update content handler API (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Rename content_handler.h Created 6 years, 1 month 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "mojo/apps/js/content_handler_impl.h"
6
7 #include "mojo/apps/js/application_delegate_impl.h"
8 #include "mojo/apps/js/js_app.h"
9 #include "mojo/common/data_pipe_utils.h"
10
11 namespace mojo {
12 namespace apps {
13
14 class ContentHandlerJSApp : public JSApp {
15 public:
16 ContentHandlerJSApp(ApplicationDelegateImpl* app_delegate_impl,
17 URLResponsePtr content,
18 InterfaceRequest<ServiceProvider> sp)
19 : JSApp(app_delegate_impl),
20 content_(content.Pass()),
21 requestor_service_provider_(sp.Pass()) {
22 }
23
24 bool Load(std::string* source, std::string* file_name) override {
25 *file_name = content_->url;
26 if (content_.is_null())
27 return false;
28 return common::BlockingCopyToString(content_->body.Pass(), source);
29 }
30
31 virtual MessagePipeHandle RequestorMessagePipeHandle() override {
32 return requestor_service_provider_.PassMessagePipe().release();
33 }
34
35 private:
36 URLResponsePtr content_;
37 InterfaceRequest<ServiceProvider> requestor_service_provider_;
38 };
39
40
41 ContentHandlerImpl::ContentHandlerImpl(ApplicationDelegateImpl* app)
42 : app_delegate_impl_(app) {
43 }
44
45 ContentHandlerImpl::~ContentHandlerImpl() {
46 }
47
48 void ContentHandlerImpl::OnConnect(
49 const mojo::String& requestor_url,
50 URLResponsePtr content,
51 InterfaceRequest<ServiceProvider> sp) {
52 scoped_ptr<JSApp> js_app(
53 new ContentHandlerJSApp(app_delegate_impl_, content.Pass(), sp.Pass()));
54 app_delegate_impl_->StartJSApp(js_app.Pass());
55 }
56
57 } // namespace apps
58 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698