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/public/cpp/application/interface_factory.h"
13 #include "mojo/public/cpp/application/lazy_interface_ptr.h"
14 #include "mojo/public/cpp/application/service_provider_impl.h"
15 #include "mojo/public/cpp/bindings/interface_impl.h"
16 #include "mojo/public/interfaces/application/application.mojom.h"
17 #include "mojo/services/content_handler/public/interfaces/content_handler.mojom.h"
18 #include "mojo/services/html_viewer/ax_provider_impl.h"
19 #include "mojo/services/navigation/public/interfaces/navigation.mojom.h"
20 #include "mojo/services/network/public/interfaces/url_loader.mojom.h"
21 #include "mojo/services/view_manager/public/cpp/view_manager_client_factory.h"
22 #include "mojo/services/view_manager/public/cpp/view_manager_delegate.h"
23 #include "mojo/services/view_manager/public/cpp/view_observer.h"
24 #include "third_party/WebKit/public/web/WebFrameClient.h"
25 #include "third_party/WebKit/public/web/WebViewClient.h"
28 class MessageLoopProxy
;
32 class WebEncryptedMediaClientImpl
;
40 namespace html_viewer
{
43 class WebLayerTreeViewImpl
;
44 class WebMediaPlayerFactory
;
46 // A view for a single HTML document.
47 class HTMLDocument
: public blink::WebViewClient
,
48 public blink::WebFrameClient
,
49 public mojo::ViewManagerDelegate
,
50 public mojo::ViewObserver
,
51 public mojo::InterfaceFactory
<mojo::AxProvider
> {
53 // Load a new HTMLDocument with |response|.
55 // |service_provider_request| should be used to implement a
56 // ServiceProvider which exposes services to the connecting application.
57 // Commonly, the connecting application is the ViewManager and it will
58 // request ViewManagerClient.
60 // |shell| is the Shell connection for this mojo::Application.
61 HTMLDocument(mojo::ServiceProviderPtr provider
,
62 mojo::URLResponsePtr response
,
64 scoped_refptr
<base::MessageLoopProxy
> compositor_thread
,
65 WebMediaPlayerFactory
* web_media_player_factory
);
66 virtual ~HTMLDocument();
69 // WebViewClient methods:
70 virtual blink::WebStorageNamespace
* createSessionStorageNamespace();
72 // WebWidgetClient methods:
73 virtual void initializeLayerTreeView();
74 virtual blink::WebLayerTreeView
* layerTreeView();
76 // WebFrameClient methods:
77 virtual blink::WebMediaPlayer
* createMediaPlayer(
78 blink::WebLocalFrame
* frame
,
79 const blink::WebURL
& url
,
80 blink::WebMediaPlayerClient
* client
);
81 virtual blink::WebMediaPlayer
* createMediaPlayer(
82 blink::WebLocalFrame
* frame
,
83 const blink::WebURL
& url
,
84 blink::WebMediaPlayerClient
* client
,
85 blink::WebContentDecryptionModule
* initial_cdm
);
86 virtual blink::WebFrame
* createChildFrame(blink::WebLocalFrame
* parent
,
87 const blink::WebString
& frameName
);
88 virtual void frameDetached(blink::WebFrame
*);
89 virtual blink::WebCookieJar
* cookieJar(blink::WebLocalFrame
* frame
);
90 virtual blink::WebNavigationPolicy
decidePolicyForNavigation(
91 blink::WebLocalFrame
* frame
,
92 blink::WebDataSource::ExtraData
* data
,
93 const blink::WebURLRequest
& request
,
94 blink::WebNavigationType nav_type
,
95 blink::WebNavigationPolicy default_policy
,
97 virtual void didAddMessageToConsole(const blink::WebConsoleMessage
& message
,
98 const blink::WebString
& source_name
,
100 const blink::WebString
& stack_trace
);
101 virtual void didNavigateWithinPage(blink::WebLocalFrame
* frame
,
102 const blink::WebHistoryItem
& history_item
,
103 blink::WebHistoryCommitType commit_type
);
104 virtual blink::WebEncryptedMediaClient
* encryptedMediaClient();
106 // ViewManagerDelegate methods:
109 mojo::ServiceProviderImpl
* embedee_service_provider_impl
,
110 scoped_ptr
<mojo::ServiceProvider
> embedder_service_provider
) override
;
111 void OnViewManagerDisconnected(mojo::ViewManager
* view_manager
) override
;
113 // ViewObserver methods:
114 void OnViewBoundsChanged(mojo::View
* view
,
115 const mojo::Rect
& old_bounds
,
116 const mojo::Rect
& new_bounds
) override
;
117 void OnViewDestroyed(mojo::View
* view
) override
;
118 void OnViewInputEvent(mojo::View
* view
, const mojo::EventPtr
& event
) override
;
120 // InterfaceFactory<AxProvider>
121 void Create(mojo::ApplicationConnection
* connection
,
122 mojo::InterfaceRequest
<mojo::AxProvider
> request
) override
;
124 void Load(mojo::URLResponsePtr response
);
126 mojo::URLResponsePtr response_
;
127 mojo::ServiceProviderImpl exported_services_
;
128 scoped_ptr
<mojo::ServiceProvider
> embedder_service_provider_
;
130 mojo::LazyInterfacePtr
<mojo::NavigatorHost
> navigator_host_
;
131 blink::WebView
* web_view_
;
133 mojo::ViewManagerClientFactory view_manager_client_factory_
;
134 scoped_ptr
<WebLayerTreeViewImpl
> web_layer_tree_view_impl_
;
135 scoped_refptr
<base::MessageLoopProxy
> compositor_thread_
;
136 WebMediaPlayerFactory
* web_media_player_factory_
;
138 // EncryptedMediaClient attached to this frame; lazily initialized.
139 media::WebEncryptedMediaClientImpl
* web_encrypted_media_client_
;
141 // HTMLDocument owns these pointers.
142 std::set
<AxProviderImpl
*> ax_provider_impls_
;
144 DISALLOW_COPY_AND_ASSIGN(HTMLDocument
);
147 } // namespace html_viewer
149 #endif // MOJO_SERVICES_HTML_VIEWER_HTML_DOCUMENT_H_