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_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 HTMLFrameDelegate
,
55 public mojo::InterfaceFactory
<mojo::AxProvider
>,
56 public mojo::InterfaceFactory
<mandoline::FrameTreeClient
>,
57 public mojo::InterfaceFactory
<TestHTMLViewer
> {
59 using DeleteCallback
= base::Callback
<void(HTMLDocumentOOPIF
*)>;
60 using HTMLFrameCreationCallback
=
61 base::Callback
<HTMLFrame
*(HTMLFrame::CreateParams
*)>;
63 // Load a new HTMLDocument with |response|.
64 // |html_document_app| is the application this app was created in, and
65 // |connection| the specific connection triggering this new instance.
66 // |setup| is used to obtain init type state (such as resources).
67 HTMLDocumentOOPIF(mojo::ApplicationImpl
* html_document_app
,
68 mojo::ApplicationConnection
* connection
,
69 mojo::URLResponsePtr response
,
71 const DeleteCallback
& delete_callback
,
72 const HTMLFrameCreationCallback
& frame_creation_callback
);
74 // Deletes this object.
78 friend class DocumentResourceWaiter
; // So it can call LoadIfNecessary().
80 // Requests for interfaces before the document is loaded go here. Once
81 // loaded the requests are bound and BeforeLoadCache is deleted.
82 struct BeforeLoadCache
{
86 std::set
<mojo::InterfaceRequest
<mojo::AxProvider
>*> ax_provider_requests
;
87 std::set
<mojo::InterfaceRequest
<TestHTMLViewer
>*> test_interface_requests
;
90 ~HTMLDocumentOOPIF() override
;
92 void LoadIfNecessary();
95 BeforeLoadCache
* GetBeforeLoadCache();
97 // ViewManagerDelegate:
98 void OnEmbed(mojo::View
* root
) override
;
99 void OnViewManagerDestroyed(mojo::ViewManager
* view_manager
) override
;
102 void OnViewViewportMetricsChanged(
104 const mojo::ViewportMetrics
& old_metrics
,
105 const mojo::ViewportMetrics
& new_metrics
) override
;
106 void OnViewDestroyed(mojo::View
* view
) override
;
108 // HTMLFrameDelegate:
109 bool ShouldNavigateLocallyInMainFrame() override
;
110 void OnFrameDidFinishLoad() override
;
111 mojo::ApplicationImpl
* GetApp() override
;
112 HTMLFrame
* CreateHTMLFrame(HTMLFrame::CreateParams
* params
) override
;
113 void OnFrameSwappedToRemote() override
;
115 // mojo::InterfaceFactory<mojo::AxProvider>:
116 void Create(mojo::ApplicationConnection
* connection
,
117 mojo::InterfaceRequest
<mojo::AxProvider
> request
) override
;
119 // mojo::InterfaceFactory<mandoline::FrameTreeClient>:
121 mojo::ApplicationConnection
* connection
,
122 mojo::InterfaceRequest
<mandoline::FrameTreeClient
> request
) override
;
124 // mojo::InterfaceFactory<TestHTMLViewer>:
125 void Create(mojo::ApplicationConnection
* connection
,
126 mojo::InterfaceRequest
<TestHTMLViewer
> request
) override
;
128 scoped_ptr
<mojo::AppRefCount
> app_refcount_
;
129 mojo::ApplicationImpl
* html_document_app_
;
130 mojo::ApplicationConnection
* connection_
;
131 mojo::ViewManagerClientFactory view_manager_client_factory_
;
133 // HTMLDocument owns these pointers; binding requests after document load.
134 std::set
<AxProviderImpl
*> ax_providers_
;
136 ScopedVector
<TestHTMLViewerImpl
> test_html_viewers_
;
138 // Set to true when the local frame has finished loading.
139 bool did_finish_local_frame_load_
= false;
141 GlobalState
* global_state_
;
145 scoped_ptr
<DevToolsAgentImpl
> devtools_agent_
;
147 scoped_ptr
<DocumentResourceWaiter
> resource_waiter_
;
149 scoped_ptr
<BeforeLoadCache
> before_load_cache_
;
151 DeleteCallback delete_callback_
;
153 HTMLFrameCreationCallback frame_creation_callback_
;
157 DISALLOW_COPY_AND_ASSIGN(HTMLDocumentOOPIF
);
160 } // namespace html_viewer
162 #endif // COMPONENTS_HTML_VIEWER_HTML_DOCUMENT_OOPIF_H_