Update comments of TabObserver#onLoadStarted and rename onContentChanged
[chromium-blink-merge.git] / components / html_viewer / html_document.h
blobb3633f73222fafe9ebb74be0dfb04b03b13c20ce
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/interface_factory.h"
19 #include "mojo/application/public/cpp/lazy_interface_ptr.h"
20 #include "mojo/application/public/cpp/service_provider_impl.h"
21 #include "mojo/application/public/interfaces/application.mojom.h"
22 #include "mojo/application/public/interfaces/content_handler.mojom.h"
23 #include "mojo/services/network/public/interfaces/url_loader.mojom.h"
24 #include "third_party/WebKit/public/web/WebFrameClient.h"
25 #include "third_party/WebKit/public/web/WebSandboxFlags.h"
26 #include "third_party/WebKit/public/web/WebViewClient.h"
27 #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_impl.h"
29 namespace base {
30 class MessageLoopProxy;
33 namespace media {
34 class CdmFactory;
35 class MediaPermission;
36 class WebEncryptedMediaClientImpl;
39 namespace mojo {
40 class ViewManager;
41 class View;
44 namespace html_viewer {
46 class AxProviderImpl;
47 class Setup;
48 class WebLayerTreeViewImpl;
49 class WebMediaPlayerFactory;
51 // A view for a single HTML document.
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 // Load a new HTMLDocument with |response|.
60 // |services| should be used to implement a ServiceProvider which exposes
61 // services to the connecting application.
62 // Commonly, the connecting application is the ViewManager and it will
63 // request ViewManagerClient.
65 // |shell| is the Shell connection for this mojo::Application.
66 HTMLDocument(mojo::InterfaceRequest<mojo::ServiceProvider> services,
67 mojo::URLResponsePtr response,
68 mojo::Shell* shell,
69 Setup* setup);
70 ~HTMLDocument() override;
72 private:
73 // Updates the size and scale factor of the webview and related classes from
74 // |root_|.
75 void UpdateWebviewSizeFromViewSize();
77 void InitSetupAndLoadIfNecessary();
79 // WebViewClient methods:
80 virtual blink::WebStorageNamespace* createSessionStorageNamespace();
82 // WebWidgetClient methods:
83 void initializeLayerTreeView() override;
84 blink::WebLayerTreeView* layerTreeView() override;
86 // WebFrameClient methods:
87 virtual blink::WebMediaPlayer* createMediaPlayer(
88 blink::WebLocalFrame* frame,
89 const blink::WebURL& url,
90 blink::WebMediaPlayerClient* client);
91 virtual blink::WebMediaPlayer* createMediaPlayer(
92 blink::WebLocalFrame* frame,
93 const blink::WebURL& url,
94 blink::WebMediaPlayerClient* client,
95 blink::WebContentDecryptionModule* initial_cdm);
96 virtual blink::WebFrame* createChildFrame(
97 blink::WebLocalFrame* parent,
98 const blink::WebString& frameName,
99 blink::WebSandboxFlags sandboxFlags);
100 virtual void frameDetached(blink::WebFrame*);
101 virtual blink::WebCookieJar* cookieJar(blink::WebLocalFrame* frame);
102 virtual blink::WebNavigationPolicy decidePolicyForNavigation(
103 blink::WebLocalFrame* frame,
104 blink::WebDataSource::ExtraData* data,
105 const blink::WebURLRequest& request,
106 blink::WebNavigationType nav_type,
107 blink::WebNavigationPolicy default_policy,
108 bool isRedirect);
109 virtual void didAddMessageToConsole(const blink::WebConsoleMessage& message,
110 const blink::WebString& source_name,
111 unsigned source_line,
112 const blink::WebString& stack_trace);
113 virtual void didFinishLoad(blink::WebLocalFrame* frame);
114 virtual void didNavigateWithinPage(blink::WebLocalFrame* frame,
115 const blink::WebHistoryItem& history_item,
116 blink::WebHistoryCommitType commit_type);
117 virtual blink::WebEncryptedMediaClient* encryptedMediaClient();
119 // ViewManagerDelegate methods:
120 void OnEmbed(mojo::View* root,
121 mojo::InterfaceRequest<mojo::ServiceProvider> services,
122 mojo::ServiceProviderPtr exposed_services) override;
123 void OnViewManagerDisconnected(mojo::ViewManager* view_manager) override;
125 // ViewObserver methods:
126 void OnViewBoundsChanged(mojo::View* view,
127 const mojo::Rect& old_bounds,
128 const mojo::Rect& new_bounds) override;
129 void OnViewViewportMetricsChanged(
130 mojo::View* view,
131 const mojo::ViewportMetrics& old_metrics,
132 const mojo::ViewportMetrics& new_metrics) override;
133 void OnViewDestroyed(mojo::View* view) override;
134 void OnViewInputEvent(mojo::View* view, const mojo::EventPtr& event) override;
136 // mojo::InterfaceFactory<mojo::AxProvider>
137 void Create(mojo::ApplicationConnection* connection,
138 mojo::InterfaceRequest<mojo::AxProvider> request) override;
140 void Load(mojo::URLResponsePtr response);
142 media::MediaPermission* GetMediaPermission();
143 media::CdmFactory* GetCdmFactory();
145 mojo::URLResponsePtr response_;
146 mojo::ServiceProviderImpl exported_services_;
147 mojo::ServiceProviderPtr embedder_service_provider_;
148 mojo::Shell* shell_;
149 mojo::LazyInterfacePtr<mojo::NavigatorHost> navigator_host_;
150 blink::WebView* web_view_;
151 mojo::View* root_;
152 mojo::ViewManagerClientFactory view_manager_client_factory_;
153 scoped_ptr<WebLayerTreeViewImpl> web_layer_tree_view_impl_;
154 scoped_refptr<base::MessageLoopProxy> compositor_thread_;
155 WebMediaPlayerFactory* web_media_player_factory_;
157 // EncryptedMediaClient attached to this frame; lazily initialized.
158 scoped_ptr<media::WebEncryptedMediaClientImpl> web_encrypted_media_client_;
160 scoped_ptr<media::MediaPermission> media_permission_;
161 scoped_ptr<media::CdmFactory> cdm_factory_;
163 // HTMLDocument owns these pointers; binding requests after document load.
164 std::set<mojo::InterfaceRequest<mojo::AxProvider>*> ax_provider_requests_;
165 std::set<AxProviderImpl*> ax_providers_;
167 // A flag set on didFinishLoad.
168 bool did_finish_load_ = false;
170 Setup* setup_;
172 scoped_ptr<TouchHandler> touch_handler_;
174 DISALLOW_COPY_AND_ASSIGN(HTMLDocument);
177 } // namespace html_viewer
179 #endif // COMPONENTS_HTML_VIEWER_HTML_DOCUMENT_H_