[Telemetry] Always uploading browser log if enabled instead of wait for crash to...
[chromium-blink-merge.git] / components / html_viewer / html_document_oopif.h
blob719d89afbe58e750f32041a2903dce7f99702600
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_
8 #include <set>
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"
27 namespace base {
28 class SingleThreadTaskRunner;
31 namespace mojo {
32 class ViewManager;
33 class View;
36 namespace html_viewer {
38 class AxProviderImpl;
39 class DevToolsAgentImpl;
40 class DocumentResourceWaiter;
41 class GlobalState;
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> {
58 public:
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,
68 GlobalState* setup,
69 const DeleteCallback& delete_callback);
71 // Deletes this object.
72 void Destroy();
74 private:
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 {
80 BeforeLoadCache();
81 ~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();
90 void Load();
92 BeforeLoadCache* GetBeforeLoadCache();
94 // ViewManagerDelegate:
95 void OnEmbed(mojo::View* root) override;
96 void OnViewManagerDestroyed(mojo::ViewManager* view_manager) override;
98 // ViewObserver:
99 void OnViewViewportMetricsChanged(
100 mojo::View* view,
101 const mojo::ViewportMetrics& old_metrics,
102 const mojo::ViewportMetrics& new_metrics) override;
103 void OnViewDestroyed(mojo::View* view) override;
105 // HTMLFrameDelegate:
106 bool ShouldNavigateLocallyInMainFrame() override;
107 void OnFrameDidFinishLoad() override;
108 mojo::ApplicationImpl* GetApp() override;
110 // mojo::InterfaceFactory<mojo::AxProvider>:
111 void Create(mojo::ApplicationConnection* connection,
112 mojo::InterfaceRequest<mojo::AxProvider> request) override;
114 // mojo::InterfaceFactory<mandoline::FrameTreeClient>:
115 void Create(
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 HTMLFrame* frame_;
140 scoped_ptr<DevToolsAgentImpl> devtools_agent_;
142 scoped_ptr<DocumentResourceWaiter> resource_waiter_;
144 scoped_ptr<BeforeLoadCache> before_load_cache_;
146 DeleteCallback delete_callback_;
148 DISALLOW_COPY_AND_ASSIGN(HTMLDocumentOOPIF);
151 } // namespace html_viewer
153 #endif // COMPONENTS_HTML_VIEWER_HTML_DOCUMENT_OOPIF_H_