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/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 FrameTreeManager
;
44 class TestHTMLViewerImpl
;
45 class WebLayerTreeViewImpl
;
47 // A view for a single HTML document.
49 // HTMLDocument is deleted in one of two ways:
50 // . When the View the HTMLDocument is embedded in is destroyed.
51 // . Explicitly by way of Destroy().
52 class HTMLDocumentOOPIF
53 : public mojo::ViewManagerDelegate
,
54 public mojo::ViewObserver
,
55 public FrameTreeManagerDelegate
,
56 public mojo::InterfaceFactory
<mojo::AxProvider
>,
57 public mojo::InterfaceFactory
<mandoline::FrameTreeClient
>,
58 public mojo::InterfaceFactory
<TestHTMLViewer
> {
60 using DeleteCallback
= base::Callback
<void(HTMLDocumentOOPIF
*)>;
62 // Load a new HTMLDocument with |response|.
63 // |html_document_app| is the application this app was created in, and
64 // |connection| the specific connection triggering this new instance.
65 // |setup| is used to obtain init type state (such as resources).
66 HTMLDocumentOOPIF(mojo::ApplicationImpl
* html_document_app
,
67 mojo::ApplicationConnection
* connection
,
68 mojo::URLResponsePtr response
,
70 const DeleteCallback
& delete_callback
);
72 // Deletes this object.
76 friend class DocumentResourceWaiter
; // So it can call LoadIfNecessary().
78 // Requests for interfaces before the document is loaded go here. Once
79 // loaded the requests are bound and BeforeLoadCache is deleted.
80 struct BeforeLoadCache
{
84 std::set
<mojo::InterfaceRequest
<mojo::AxProvider
>*> ax_provider_requests
;
85 std::set
<mojo::InterfaceRequest
<TestHTMLViewer
>*> test_interface_requests
;
88 ~HTMLDocumentOOPIF() override
;
90 void LoadIfNecessary();
93 BeforeLoadCache
* GetBeforeLoadCache();
95 // ViewManagerDelegate:
96 void OnEmbed(mojo::View
* root
) override
;
97 void OnViewManagerDestroyed(mojo::ViewManager
* view_manager
) override
;
100 void OnViewViewportMetricsChanged(
102 const mojo::ViewportMetrics
& old_metrics
,
103 const mojo::ViewportMetrics
& new_metrics
) override
;
104 void OnViewDestroyed(mojo::View
* view
) override
;
106 // FrameTreeManagerDelegate:
107 bool ShouldNavigateLocallyInMainFrame() override
;
108 void OnFrameDidFinishLoad(Frame
* frame
) override
;
110 // mojo::InterfaceFactory<mojo::AxProvider>:
111 void Create(mojo::ApplicationConnection
* connection
,
112 mojo::InterfaceRequest
<mojo::AxProvider
> request
) override
;
114 // mojo::InterfaceFactory<mandoline::FrameTreeClient>:
116 mojo::ApplicationConnection
* connection
,
117 mojo::InterfaceRequest
<mandoline::FrameTreeClient
> request
) override
;
119 // mojo::InterfaceFactory<TestHTMLViewer>:
120 void Create(mojo::ApplicationConnection
* connection
,
121 mojo::InterfaceRequest
<TestHTMLViewer
> request
) override
;
123 scoped_ptr
<mojo::AppRefCount
> app_refcount_
;
124 mojo::ApplicationImpl
* html_document_app_
;
125 mojo::ApplicationConnection
* connection_
;
126 mojo::ViewManagerClientFactory view_manager_client_factory_
;
128 // HTMLDocument owns these pointers; binding requests after document load.
129 std::set
<AxProviderImpl
*> ax_providers_
;
131 ScopedVector
<TestHTMLViewerImpl
> test_html_viewers_
;
133 // Set to true when the local frame has finished loading.
134 bool did_finish_local_frame_load_
= false;
136 GlobalState
* global_state_
;
138 scoped_ptr
<FrameTreeManager
> frame_tree_manager_
;
139 scoped_ptr
<mojo::Binding
<mandoline::FrameTreeClient
>>
140 frame_tree_manager_binding_
;
142 scoped_ptr
<DevToolsAgentImpl
> devtools_agent_
;
144 scoped_ptr
<DocumentResourceWaiter
> resource_waiter_
;
146 scoped_ptr
<BeforeLoadCache
> before_load_cache_
;
148 DeleteCallback delete_callback_
;
150 DISALLOW_COPY_AND_ASSIGN(HTMLDocumentOOPIF
);
153 } // namespace html_viewer
155 #endif // COMPONENTS_HTML_VIEWER_HTML_DOCUMENT_OOPIF_H_