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 MOJO_SERVICES_HTML_VIEWER_HTML_DOCUMENT_H_
6 #define MOJO_SERVICES_HTML_VIEWER_HTML_DOCUMENT_H_
10 #include "base/callback.h"
11 #include "base/macros.h"
12 #include "mojo/services/html_viewer/ax_provider_impl.h"
13 #include "mojo/services/html_viewer/touch_handler.h"
14 #include "mojo/services/network/public/interfaces/url_loader.mojom.h"
15 #include "third_party/WebKit/public/web/WebFrameClient.h"
16 #include "third_party/WebKit/public/web/WebSandboxFlags.h"
17 #include "third_party/WebKit/public/web/WebViewClient.h"
18 #include "third_party/mojo/src/mojo/public/cpp/application/interface_factory.h"
19 #include "third_party/mojo/src/mojo/public/cpp/application/lazy_interface_ptr.h"
20 #include "third_party/mojo/src/mojo/public/cpp/application/service_provider_impl.h"
21 #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_impl.h"
22 #include "third_party/mojo/src/mojo/public/interfaces/application/application.mojom.h"
23 #include "third_party/mojo_services/src/content_handler/public/interfaces/content_handler.mojom.h"
24 #include "third_party/mojo_services/src/navigation/public/interfaces/navigation.mojom.h"
25 #include "third_party/mojo_services/src/view_manager/public/cpp/view_manager_client_factory.h"
26 #include "third_party/mojo_services/src/view_manager/public/cpp/view_manager_delegate.h"
27 #include "third_party/mojo_services/src/view_manager/public/cpp/view_observer.h"
30 class MessageLoopProxy
;
35 class MediaPermission
;
36 class WebEncryptedMediaClientImpl
;
44 namespace html_viewer
{
47 class WebLayerTreeViewImpl
;
48 class WebMediaPlayerFactory
;
50 // A view for a single HTML document.
51 class HTMLDocument
: public blink::WebViewClient
,
52 public blink::WebFrameClient
,
53 public mojo::ViewManagerDelegate
,
54 public mojo::ViewObserver
,
55 public mojo::InterfaceFactory
<mojo::AxProvider
> {
57 // Load a new HTMLDocument with |response|.
59 // |services| should be used to implement a ServiceProvider which exposes
60 // services to the connecting application.
61 // Commonly, the connecting application is the ViewManager and it will
62 // request ViewManagerClient.
64 // |shell| is the Shell connection for this mojo::Application.
65 HTMLDocument(mojo::InterfaceRequest
<mojo::ServiceProvider
> services
,
66 mojo::URLResponsePtr response
,
68 scoped_refptr
<base::MessageLoopProxy
> compositor_thread
,
69 WebMediaPlayerFactory
* web_media_player_factory
,
71 ~HTMLDocument() override
;
74 // Updates the size and scale factor of the webview and related classes from
76 void UpdateWebviewSizeFromViewSize();
78 // WebViewClient methods:
79 virtual blink::WebStorageNamespace
* createSessionStorageNamespace();
81 // WebWidgetClient methods:
82 void initializeLayerTreeView() override
;
83 blink::WebLayerTreeView
* layerTreeView() override
;
85 // WebFrameClient methods:
86 virtual blink::WebMediaPlayer
* createMediaPlayer(
87 blink::WebLocalFrame
* frame
,
88 const blink::WebURL
& url
,
89 blink::WebMediaPlayerClient
* client
);
90 virtual blink::WebMediaPlayer
* createMediaPlayer(
91 blink::WebLocalFrame
* frame
,
92 const blink::WebURL
& url
,
93 blink::WebMediaPlayerClient
* client
,
94 blink::WebContentDecryptionModule
* initial_cdm
);
95 virtual blink::WebFrame
* createChildFrame(
96 blink::WebLocalFrame
* parent
,
97 const blink::WebString
& frameName
,
98 blink::WebSandboxFlags sandboxFlags
);
99 virtual void frameDetached(blink::WebFrame
*);
100 virtual blink::WebCookieJar
* cookieJar(blink::WebLocalFrame
* frame
);
101 virtual blink::WebNavigationPolicy
decidePolicyForNavigation(
102 blink::WebLocalFrame
* frame
,
103 blink::WebDataSource::ExtraData
* data
,
104 const blink::WebURLRequest
& request
,
105 blink::WebNavigationType nav_type
,
106 blink::WebNavigationPolicy default_policy
,
108 virtual void didAddMessageToConsole(const blink::WebConsoleMessage
& message
,
109 const blink::WebString
& source_name
,
110 unsigned source_line
,
111 const blink::WebString
& stack_trace
);
112 virtual void didFinishLoad(blink::WebLocalFrame
* frame
);
113 virtual void didNavigateWithinPage(blink::WebLocalFrame
* frame
,
114 const blink::WebHistoryItem
& history_item
,
115 blink::WebHistoryCommitType commit_type
);
116 virtual blink::WebEncryptedMediaClient
* encryptedMediaClient();
118 // ViewManagerDelegate methods:
119 void OnEmbed(mojo::View
* root
,
120 mojo::InterfaceRequest
<mojo::ServiceProvider
> services
,
121 mojo::ServiceProviderPtr exposed_services
) override
;
122 void OnViewManagerDisconnected(mojo::ViewManager
* view_manager
) override
;
124 // ViewObserver methods:
125 void OnViewBoundsChanged(mojo::View
* view
,
126 const mojo::Rect
& old_bounds
,
127 const mojo::Rect
& new_bounds
) override
;
128 void OnViewDestroyed(mojo::View
* view
) override
;
129 void OnViewInputEvent(mojo::View
* view
, const mojo::EventPtr
& event
) override
;
131 // mojo::InterfaceFactory<mojo::AxProvider>
132 void Create(mojo::ApplicationConnection
* connection
,
133 mojo::InterfaceRequest
<mojo::AxProvider
> request
) override
;
135 void Load(mojo::URLResponsePtr response
);
137 media::MediaPermission
* GetMediaPermission();
138 media::CdmFactory
* GetCdmFactory();
140 mojo::URLResponsePtr response_
;
141 mojo::ServiceProviderImpl exported_services_
;
142 mojo::ServiceProviderPtr embedder_service_provider_
;
144 mojo::LazyInterfacePtr
<mojo::NavigatorHost
> navigator_host_
;
145 blink::WebView
* web_view_
;
147 mojo::ViewManagerClientFactory view_manager_client_factory_
;
148 scoped_ptr
<WebLayerTreeViewImpl
> web_layer_tree_view_impl_
;
149 scoped_refptr
<base::MessageLoopProxy
> compositor_thread_
;
150 WebMediaPlayerFactory
* web_media_player_factory_
;
152 // EncryptedMediaClient attached to this frame; lazily initialized.
153 scoped_ptr
<media::WebEncryptedMediaClientImpl
> web_encrypted_media_client_
;
155 scoped_ptr
<media::MediaPermission
> media_permission_
;
156 scoped_ptr
<media::CdmFactory
> cdm_factory_
;
158 // HTMLDocument owns these pointers; binding requests after document load.
159 std::set
<mojo::InterfaceRequest
<mojo::AxProvider
>*> ax_provider_requests_
;
160 std::set
<AxProviderImpl
*> ax_providers_
;
162 // A flag set on didFinishLoad.
163 bool did_finish_load_
= false;
165 // Set if the content will never be displayed.
168 scoped_ptr
<TouchHandler
> touch_handler_
;
170 float device_pixel_ratio_
;
172 DISALLOW_COPY_AND_ASSIGN(HTMLDocument
);
175 } // namespace html_viewer
177 #endif // MOJO_SERVICES_HTML_VIEWER_HTML_DOCUMENT_H_