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.
5 #ifndef COMPONENTS_HTML_VIEWER_HTML_DOCUMENT_OOPIF_H_
6 #define COMPONENTS_HTML_VIEWER_HTML_DOCUMENT_OOPIF_H_
10 #include "base/callback.h"
11 #include "base/macros.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/scoped_vector.h"
14 #include "components/html_viewer/ax_provider_impl.h"
15 #include "components/html_viewer/html_frame_tree_manager_delegate.h"
16 #include "components/html_viewer/public/interfaces/test_html_viewer.mojom.h"
17 #include "components/view_manager/public/cpp/view_manager_client_factory.h"
18 #include "components/view_manager/public/cpp/view_manager_delegate.h"
19 #include "components/view_manager/public/cpp/view_observer.h"
20 #include "mandoline/tab/public/interfaces/frame_tree.mojom.h"
21 #include "mojo/application/public/cpp/app_lifetime_helper.h"
22 #include "mojo/application/public/cpp/interface_factory.h"
23 #include "mojo/application/public/cpp/service_provider_impl.h"
24 #include "mojo/application/public/interfaces/application.mojom.h"
25 #include "mojo/services/network/public/interfaces/url_loader.mojom.h"
28 class SingleThreadTaskRunner
;
36 namespace html_viewer
{
39 class DevToolsAgentImpl
;
40 class DocumentResourceWaiter
;
42 class HTMLFrameTreeManager
;
43 class TestHTMLViewerImpl
;
44 class WebLayerTreeViewImpl
;
46 // A view for a single HTML document.
48 // HTMLDocument is deleted in one of two ways:
49 // . When the View the HTMLDocument is embedded in is destroyed.
50 // . Explicitly by way of Destroy().
51 class HTMLDocumentOOPIF
52 : public mojo::ViewManagerDelegate
,
53 public mojo::ViewObserver
,
54 public HTMLFrameTreeManagerDelegate
,
55 public mojo::InterfaceFactory
<mojo::AxProvider
>,
56 public mojo::InterfaceFactory
<mandoline::FrameTreeClient
>,
57 public mojo::InterfaceFactory
<TestHTMLViewer
> {
59 using DeleteCallback
= base::Callback
<void(HTMLDocumentOOPIF
*)>;
61 // Load a new HTMLDocument with |response|.
62 // |html_document_app| is the application this app was created in, and
63 // |connection| the specific connection triggering this new instance.
64 // |setup| is used to obtain init type state (such as resources).
65 HTMLDocumentOOPIF(mojo::ApplicationImpl
* html_document_app
,
66 mojo::ApplicationConnection
* connection
,
67 mojo::URLResponsePtr response
,
69 const DeleteCallback
& delete_callback
);
71 // Deletes this object.
75 friend class DocumentResourceWaiter
; // So it can call LoadIfNecessary().
77 // Requests for interfaces before the document is loaded go here. Once
78 // loaded the requests are bound and BeforeLoadCache is deleted.
79 struct BeforeLoadCache
{
83 std::set
<mojo::InterfaceRequest
<mojo::AxProvider
>*> ax_provider_requests
;
84 std::set
<mojo::InterfaceRequest
<TestHTMLViewer
>*> test_interface_requests
;
87 ~HTMLDocumentOOPIF() override
;
89 void LoadIfNecessary();
92 BeforeLoadCache
* GetBeforeLoadCache();
94 // ViewManagerDelegate:
95 void OnEmbed(mojo::View
* root
) override
;
96 void OnViewManagerDestroyed(mojo::ViewManager
* view_manager
) override
;
99 void OnViewViewportMetricsChanged(
101 const mojo::ViewportMetrics
& old_metrics
,
102 const mojo::ViewportMetrics
& new_metrics
) override
;
103 void OnViewDestroyed(mojo::View
* view
) override
;
105 // HTMLFrameTreeManagerDelegate:
106 bool ShouldNavigateLocallyInMainFrame() override
;
107 void OnFrameDidFinishLoad(HTMLFrame
* frame
) override
;
109 // mojo::InterfaceFactory<mojo::AxProvider>:
110 void Create(mojo::ApplicationConnection
* connection
,
111 mojo::InterfaceRequest
<mojo::AxProvider
> request
) override
;
113 // mojo::InterfaceFactory<mandoline::FrameTreeClient>:
115 mojo::ApplicationConnection
* connection
,
116 mojo::InterfaceRequest
<mandoline::FrameTreeClient
> request
) override
;
118 // mojo::InterfaceFactory<TestHTMLViewer>:
119 void Create(mojo::ApplicationConnection
* connection
,
120 mojo::InterfaceRequest
<TestHTMLViewer
> request
) override
;
122 scoped_ptr
<mojo::AppRefCount
> app_refcount_
;
123 mojo::ApplicationImpl
* html_document_app_
;
124 mojo::ApplicationConnection
* connection_
;
125 mojo::ViewManagerClientFactory view_manager_client_factory_
;
127 // HTMLDocument owns these pointers; binding requests after document load.
128 std::set
<AxProviderImpl
*> ax_providers_
;
130 ScopedVector
<TestHTMLViewerImpl
> test_html_viewers_
;
132 // Set to true when the local frame has finished loading.
133 bool did_finish_local_frame_load_
= false;
135 GlobalState
* global_state_
;
137 scoped_ptr
<HTMLFrameTreeManager
> frame_tree_manager_
;
138 scoped_ptr
<mojo::Binding
<mandoline::FrameTreeClient
>>
139 frame_tree_manager_binding_
;
141 scoped_ptr
<DevToolsAgentImpl
> devtools_agent_
;
143 scoped_ptr
<DocumentResourceWaiter
> resource_waiter_
;
145 scoped_ptr
<BeforeLoadCache
> before_load_cache_
;
147 DeleteCallback delete_callback_
;
149 DISALLOW_COPY_AND_ASSIGN(HTMLDocumentOOPIF
);
152 } // namespace html_viewer
154 #endif // COMPONENTS_HTML_VIEWER_HTML_DOCUMENT_OOPIF_H_