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_VIEW_H_
6 #define MOJO_SERVICES_HTML_VIEWER_HTML_DOCUMENT_VIEW_H_
10 #include "base/macros.h"
11 #include "mojo/public/cpp/application/interface_factory.h"
12 #include "mojo/public/cpp/application/lazy_interface_ptr.h"
13 #include "mojo/public/cpp/application/service_provider_impl.h"
14 #include "mojo/public/cpp/bindings/interface_impl.h"
15 #include "mojo/public/interfaces/application/application.mojom.h"
16 #include "mojo/services/html_viewer/ax_provider_impl.h"
17 #include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h"
18 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h"
19 #include "mojo/services/public/cpp/view_manager/view_observer.h"
20 #include "mojo/services/public/interfaces/content_handler/content_handler.mojom.h"
21 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h"
22 #include "mojo/services/public/interfaces/network/url_loader.mojom.h"
23 #include "third_party/WebKit/public/web/WebFrameClient.h"
24 #include "third_party/WebKit/public/web/WebViewClient.h"
27 class MessageLoopProxy
;
33 class WebMediaPlayerFactory
;
36 class WebLayerTreeViewImpl
;
38 // A view for a single HTML document.
39 class HTMLDocumentView
: public mojo::InterfaceImpl
<mojo::Application
>,
40 public blink::WebViewClient
,
41 public blink::WebFrameClient
,
42 public ViewManagerDelegate
,
44 public InterfaceFactory
<AxProvider
> {
46 // Load a new HTMLDocument with |response|.
48 // |service_provider_request| should be used to implement a
49 // ServiceProvider which exposes services to the connecting application.
50 // Commonly, the connecting application is the ViewManager and it will
51 // request ViewManagerClient.
53 // |shell| is the Shell connection for this mojo::Application.
54 HTMLDocumentView(URLResponsePtr response
,
56 scoped_refptr
<base::MessageLoopProxy
> compositor_thread
,
57 WebMediaPlayerFactory
* web_media_player_factory
);
58 virtual ~HTMLDocumentView();
61 // Application methods:
62 void AcceptConnection(const String
& requestor_url
,
63 ServiceProviderPtr provider
) override
;
64 void Initialize(Array
<String
> args
) override
;
66 // WebViewClient methods:
67 virtual blink::WebStorageNamespace
* createSessionStorageNamespace();
69 // WebWidgetClient methods:
70 virtual void initializeLayerTreeView();
71 virtual blink::WebLayerTreeView
* layerTreeView();
73 // WebFrameClient methods:
74 virtual blink::WebMediaPlayer
* createMediaPlayer(
75 blink::WebLocalFrame
* frame
,
76 const blink::WebURL
& url
,
77 blink::WebMediaPlayerClient
* client
);
78 virtual blink::WebMediaPlayer
* createMediaPlayer(
79 blink::WebLocalFrame
* frame
,
80 const blink::WebURL
& url
,
81 blink::WebMediaPlayerClient
* client
,
82 blink::WebContentDecryptionModule
* initial_cdm
);
83 virtual blink::WebFrame
* createChildFrame(blink::WebLocalFrame
* parent
,
84 const blink::WebString
& frameName
);
85 virtual void frameDetached(blink::WebFrame
*);
86 virtual blink::WebCookieJar
* cookieJar(blink::WebLocalFrame
* frame
);
87 virtual blink::WebNavigationPolicy
decidePolicyForNavigation(
88 blink::WebLocalFrame
* frame
, blink::WebDataSource::ExtraData
* data
,
89 const blink::WebURLRequest
& request
, blink::WebNavigationType nav_type
,
90 blink::WebNavigationPolicy default_policy
, bool isRedirect
);
91 virtual void didAddMessageToConsole(
92 const blink::WebConsoleMessage
& message
,
93 const blink::WebString
& source_name
,
95 const blink::WebString
& stack_trace
);
96 virtual void didNavigateWithinPage(
97 blink::WebLocalFrame
* frame
,
98 const blink::WebHistoryItem
& history_item
,
99 blink::WebHistoryCommitType commit_type
);
101 // ViewManagerDelegate methods:
102 void OnEmbed(ViewManager
* view_manager
,
104 ServiceProviderImpl
* embedee_service_provider_impl
,
105 scoped_ptr
<ServiceProvider
> embedder_service_provider
) override
;
106 void OnViewManagerDisconnected(ViewManager
* view_manager
) override
;
108 // ViewObserver methods:
109 void OnViewBoundsChanged(View
* view
,
110 const Rect
& old_bounds
,
111 const Rect
& new_bounds
) override
;
112 void OnViewDestroyed(View
* view
) override
;
113 void OnViewInputEvent(View
* view
, const EventPtr
& event
) override
;
115 // InterfaceFactory<AxProvider>
116 void Create(ApplicationConnection
* connection
,
117 InterfaceRequest
<AxProvider
> request
) override
;
119 void Load(URLResponsePtr response
);
121 URLResponsePtr response_
;
122 ServiceProviderImpl exported_services_
;
123 scoped_ptr
<ServiceProvider
> embedder_service_provider_
;
125 LazyInterfacePtr
<NavigatorHost
> navigator_host_
;
126 blink::WebView
* web_view_
;
128 ViewManagerClientFactory view_manager_client_factory_
;
129 scoped_ptr
<WebLayerTreeViewImpl
> web_layer_tree_view_impl_
;
130 scoped_refptr
<base::MessageLoopProxy
> compositor_thread_
;
131 WebMediaPlayerFactory
* web_media_player_factory_
;
133 // HTMLDocumentView owns these pointers.
134 std::set
<AxProviderImpl
*> ax_provider_impls_
;
136 DISALLOW_COPY_AND_ASSIGN(HTMLDocumentView
);
141 #endif // MOJO_SERVICES_HTML_VIEWER_HTML_DOCUMENT_VIEW_H_