Remove 'blink::WebSerializedOrigin' (7/7)
[chromium-blink-merge.git] / components / html_viewer / html_document.h
blob6b3470516b11c1297c6233b9b12171baba3dcd0a
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_H_
6 #define COMPONENTS_HTML_VIEWER_HTML_DOCUMENT_H_
8 #include <set>
10 #include "base/callback.h"
11 #include "base/macros.h"
12 #include "components/html_viewer/ax_provider_impl.h"
13 #include "components/html_viewer/touch_handler.h"
14 #include "components/view_manager/public/cpp/view_manager_client_factory.h"
15 #include "components/view_manager/public/cpp/view_manager_delegate.h"
16 #include "components/view_manager/public/cpp/view_observer.h"
17 #include "mandoline/services/navigation/public/interfaces/navigation.mojom.h"
18 #include "mojo/application/public/cpp/app_lifetime_helper.h"
19 #include "mojo/application/public/cpp/interface_factory.h"
20 #include "mojo/application/public/cpp/lazy_interface_ptr.h"
21 #include "mojo/application/public/cpp/service_provider_impl.h"
22 #include "mojo/application/public/interfaces/application.mojom.h"
23 #include "mojo/application/public/interfaces/content_handler.mojom.h"
24 #include "mojo/services/network/public/interfaces/url_loader.mojom.h"
25 #include "third_party/WebKit/public/web/WebFrameClient.h"
26 #include "third_party/WebKit/public/web/WebSandboxFlags.h"
27 #include "third_party/WebKit/public/web/WebViewClient.h"
28 #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_impl.h"
30 namespace base {
31 class SingleThreadTaskRunner;
34 namespace mojo {
35 class ViewManager;
36 class View;
39 namespace html_viewer {
41 class AxProviderImpl;
42 class DevToolsAgentImpl;
43 class GeolocationClientImpl;
44 class GlobalState;
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 HTMLDocument : public blink::WebViewClient,
53 public blink::WebFrameClient,
54 public mojo::ViewManagerDelegate,
55 public mojo::ViewObserver,
56 public mojo::InterfaceFactory<mojo::AxProvider> {
57 public:
58 using DeleteCallback = base::Callback<void(HTMLDocument*)>;
60 struct CreateParams {
61 CreateParams(mojo::ApplicationImpl* html_document_app,
62 mojo::ApplicationConnection* connection,
63 mojo::URLResponsePtr response,
64 GlobalState* global_state,
65 const DeleteCallback& delete_callback);
66 ~CreateParams();
68 mojo::ApplicationImpl* html_document_app;
69 mojo::ApplicationConnection* connection;
70 mojo::URLResponsePtr response;
71 GlobalState* global_state;
72 DeleteCallback delete_callback;
75 // Load a new HTMLDocument with |response|.
76 // |html_document_app| is the application this app was created in, and
77 // |connection| the specific connection triggering this new instance.
78 // |setup| is used to obtain init type state (such as resources).
79 explicit HTMLDocument(CreateParams* params);
81 // Deletes this object.
82 void Destroy();
84 blink::WebView* web_view() const { return web_view_; }
86 protected:
87 ~HTMLDocument() override;
89 // WebViewClient methods:
90 virtual blink::WebStorageNamespace* createSessionStorageNamespace();
92 // WebWidgetClient methods:
93 void initializeLayerTreeView() override;
94 blink::WebLayerTreeView* layerTreeView() override;
96 // WebFrameClient methods:
97 virtual blink::WebMediaPlayer* createMediaPlayer(
98 blink::WebLocalFrame* frame,
99 const blink::WebURL& url,
100 blink::WebMediaPlayerClient* client,
101 blink::WebMediaPlayerEncryptedMediaClient* encrypted_client,
102 blink::WebContentDecryptionModule* initial_cdm);
103 virtual blink::WebFrame* createChildFrame(
104 blink::WebLocalFrame* parent,
105 blink::WebTreeScopeType scope,
106 const blink::WebString& frameName,
107 blink::WebSandboxFlags sandboxFlags);
108 virtual void frameDetached(blink::WebFrame* frame, DetachType type);
109 virtual blink::WebCookieJar* cookieJar(blink::WebLocalFrame* frame);
110 virtual blink::WebNavigationPolicy decidePolicyForNavigation(
111 const NavigationPolicyInfo& info);
112 virtual blink::WebGeolocationClient* geolocationClient();
114 virtual void didAddMessageToConsole(const blink::WebConsoleMessage& message,
115 const blink::WebString& source_name,
116 unsigned source_line,
117 const blink::WebString& stack_trace);
118 virtual void didFinishLoad(blink::WebLocalFrame* frame);
119 virtual void didNavigateWithinPage(blink::WebLocalFrame* frame,
120 const blink::WebHistoryItem& history_item,
121 blink::WebHistoryCommitType commit_type);
122 virtual blink::WebEncryptedMediaClient* encryptedMediaClient();
124 private:
125 // Data associated with a child iframe.
126 struct ChildFrameData {
127 mojo::View* view;
128 blink::WebTreeScopeType scope;
131 // Updates the size and scale factor of the webview and related classes from
132 // |root_|.
133 void UpdateWebviewSizeFromViewSize();
135 void InitGlobalStateAndLoadIfNecessary();
137 // ViewManagerDelegate methods:
138 void OnEmbed(mojo::View* root) override;
139 void OnViewManagerDestroyed(mojo::ViewManager* view_manager) override;
141 // ViewObserver methods:
142 void OnViewBoundsChanged(mojo::View* view,
143 const mojo::Rect& old_bounds,
144 const mojo::Rect& new_bounds) override;
145 void OnViewViewportMetricsChanged(
146 mojo::View* view,
147 const mojo::ViewportMetrics& old_metrics,
148 const mojo::ViewportMetrics& new_metrics) override;
149 void OnViewDestroyed(mojo::View* view) override;
150 void OnViewInputEvent(mojo::View* view, const mojo::EventPtr& event) override;
151 void OnViewFocusChanged(mojo::View* gained_focus,
152 mojo::View* lost_focus) override;
154 // mojo::InterfaceFactory<mojo::AxProvider>
155 void Create(mojo::ApplicationConnection* connection,
156 mojo::InterfaceRequest<mojo::AxProvider> request) override;
158 void Load(mojo::URLResponsePtr response);
160 // Converts a WebLocalFrame to a WebRemoteFrame. Used once we know the
161 // url of a frame to trigger the navigation.
162 void ConvertLocalFrameToRemoteFrame(blink::WebLocalFrame* frame);
164 // Updates the focus state of |web_view_| based on the focus state of |root_|.
165 void UpdateFocus();
167 scoped_ptr<mojo::AppRefCount> app_refcount_;
168 mojo::ApplicationImpl* html_document_app_;
169 mojo::URLResponsePtr response_;
170 mojo::LazyInterfacePtr<mojo::NavigatorHost> navigator_host_;
171 blink::WebView* web_view_;
172 mojo::View* root_;
173 mojo::ViewManagerClientFactory view_manager_client_factory_;
174 scoped_ptr<WebLayerTreeViewImpl> web_layer_tree_view_impl_;
175 scoped_refptr<base::SingleThreadTaskRunner> compositor_thread_;
176 scoped_ptr<GeolocationClientImpl> geolocation_client_impl_;
178 // HTMLDocument owns these pointers; binding requests after document load.
179 std::set<mojo::InterfaceRequest<mojo::AxProvider>*> ax_provider_requests_;
180 std::set<AxProviderImpl*> ax_providers_;
182 // A flag set on didFinishLoad.
183 bool did_finish_load_ = false;
185 GlobalState* global_state_;
187 scoped_ptr<TouchHandler> touch_handler_;
189 scoped_ptr<DevToolsAgentImpl> devtools_agent_;
191 DeleteCallback delete_callback_;
193 DISALLOW_COPY_AND_ASSIGN(HTMLDocument);
196 } // namespace html_viewer
198 #endif // COMPONENTS_HTML_VIEWER_HTML_DOCUMENT_H_