1 // Copyright 2015 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.
5 #ifndef COMPONENTS_HTML_VIEWER_HTML_DOCUMENT_APPLICATION_DELEGATE_H_
6 #define COMPONENTS_HTML_VIEWER_HTML_DOCUMENT_APPLICATION_DELEGATE_H_
10 #include "base/macros.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "components/html_viewer/html_factory.h"
14 #include "mojo/application/public/cpp/application_delegate.h"
15 #include "mojo/application/public/cpp/application_impl.h"
16 #include "mojo/services/network/public/interfaces/url_loader_factory.mojom.h"
17 #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_request.h"
19 namespace html_viewer
{
24 // ApplicationDelegate created by the content handler for a specific url.
25 class HTMLDocumentApplicationDelegate
: public mojo::ApplicationDelegate
,
28 HTMLDocumentApplicationDelegate(
29 mojo::InterfaceRequest
<mojo::Application
> request
,
30 mojo::URLResponsePtr response
,
31 GlobalState
* global_state
,
32 scoped_ptr
<mojo::AppRefCount
> parent_app_refcount
);
34 void set_html_factory(HTMLFactory
* factory
) { html_factory_
= factory
; }
35 HTMLFactory
* html_factory() { return html_factory_
; }
38 class ServiceConnectorQueue
;
40 ~HTMLDocumentApplicationDelegate() override
;
42 // Callback from the quit closure. We key off this rather than
43 // ApplicationDelegate::Quit() as we don't want to shut down the messageloop
44 // when we quit (the messageloop is shared among multiple
45 // HTMLDocumentApplicationDelegates).
48 // ApplicationDelegate:
49 void Initialize(mojo::ApplicationImpl
* app
) override
;
50 bool ConfigureIncomingConnection(
51 mojo::ApplicationConnection
* connection
) override
;
53 void OnHTMLDocumentDeleted2(HTMLDocument
* document
);
54 void OnResponseReceived(scoped_ptr
<mojo::AppRefCount
> app_refcount
,
55 mojo::URLLoaderPtr loader
,
56 mojo::ApplicationConnection
* connection
,
57 scoped_ptr
<ServiceConnectorQueue
> connector_queue
,
58 mojo::URLResponsePtr response
);
61 HTMLFrame
* CreateHTMLFrame(HTMLFrame::CreateParams
* params
) override
;
62 HTMLWidgetRootLocal
* CreateHTMLWidgetRootLocal(
63 HTMLWidgetRootLocal::CreateParams
* params
) override
;
65 mojo::ApplicationImpl app_
;
66 // AppRefCount of the parent (HTMLViewer).
67 scoped_ptr
<mojo::AppRefCount
> parent_app_refcount_
;
68 const mojo::String url_
;
69 mojo::URLLoaderFactoryPtr url_loader_factory_
;
70 mojo::URLResponsePtr initial_response_
;
71 GlobalState
* global_state_
;
73 // As we create HTMLDocuments they are added here. They are removed when the
74 // HTMLDocument is deleted.
75 std::set
<HTMLDocument
*> documents2_
;
77 HTMLFactory
* html_factory_
;
79 base::WeakPtrFactory
<HTMLDocumentApplicationDelegate
> weak_factory_
;
81 DISALLOW_COPY_AND_ASSIGN(HTMLDocumentApplicationDelegate
);
84 } // namespace html_viewer
86 #endif // COMPONENTS_HTML_VIEWER_HTML_DOCUMENT_APPLICATION_DELEGATE_H_