Port Android relocation packer to chromium build
[chromium-blink-merge.git] / mojo / services / html_viewer / html_document.h
blob217e2b8c266d4b90e0803b02efea17cf65ed0f9d
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_
8 #include <set>
10 #include "base/callback.h"
11 #include "base/macros.h"
12 #include "mojo/services/html_viewer/ax_provider_impl.h"
13 #include "mojo/services/network/public/interfaces/url_loader.mojom.h"
14 #include "third_party/WebKit/public/web/WebFrameClient.h"
15 #include "third_party/WebKit/public/web/WebSandboxFlags.h"
16 #include "third_party/WebKit/public/web/WebViewClient.h"
17 #include "third_party/mojo/src/mojo/public/cpp/application/interface_factory.h"
18 #include "third_party/mojo/src/mojo/public/cpp/application/lazy_interface_ptr.h"
19 #include "third_party/mojo/src/mojo/public/cpp/application/service_provider_impl.h"
20 #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_impl.h"
21 #include "third_party/mojo/src/mojo/public/interfaces/application/application.mojom.h"
22 #include "third_party/mojo_services/src/content_handler/public/interfaces/content_handler.mojom.h"
23 #include "third_party/mojo_services/src/navigation/public/interfaces/navigation.mojom.h"
24 #include "third_party/mojo_services/src/view_manager/public/cpp/view_manager_client_factory.h"
25 #include "third_party/mojo_services/src/view_manager/public/cpp/view_manager_delegate.h"
26 #include "third_party/mojo_services/src/view_manager/public/cpp/view_observer.h"
28 namespace base {
29 class MessageLoopProxy;
32 namespace media {
33 class MediaPermission;
34 class WebEncryptedMediaClientImpl;
37 namespace mojo {
38 class ViewManager;
39 class View;
42 namespace html_viewer {
44 class AxProviderImpl;
45 class WebLayerTreeViewImpl;
46 class WebMediaPlayerFactory;
48 // A view for a single HTML document.
49 class HTMLDocument : public blink::WebViewClient,
50 public blink::WebFrameClient,
51 public mojo::ViewManagerDelegate,
52 public mojo::ViewObserver,
53 public mojo::InterfaceFactory<mojo::AxProvider> {
54 public:
55 // Load a new HTMLDocument with |response|.
57 // |services| should be used to implement a ServiceProvider which exposes
58 // services to the connecting application.
59 // Commonly, the connecting application is the ViewManager and it will
60 // request ViewManagerClient.
62 // |shell| is the Shell connection for this mojo::Application.
63 HTMLDocument(mojo::InterfaceRequest<mojo::ServiceProvider> services,
64 mojo::URLResponsePtr response,
65 mojo::Shell* shell,
66 scoped_refptr<base::MessageLoopProxy> compositor_thread,
67 WebMediaPlayerFactory* web_media_player_factory,
68 bool is_headless);
69 virtual ~HTMLDocument();
71 private:
72 // Updates the size and scale factor of the webview and related classes from
73 // |root_|.
74 void UpdateWebviewSizeFromViewSize();
76 // WebViewClient methods:
77 virtual blink::WebStorageNamespace* createSessionStorageNamespace();
79 // WebWidgetClient methods:
80 virtual void initializeLayerTreeView();
81 virtual blink::WebLayerTreeView* layerTreeView();
83 // WebFrameClient methods:
84 virtual blink::WebMediaPlayer* createMediaPlayer(
85 blink::WebLocalFrame* frame,
86 const blink::WebURL& url,
87 blink::WebMediaPlayerClient* client);
88 virtual blink::WebMediaPlayer* createMediaPlayer(
89 blink::WebLocalFrame* frame,
90 const blink::WebURL& url,
91 blink::WebMediaPlayerClient* client,
92 blink::WebContentDecryptionModule* initial_cdm);
93 virtual blink::WebFrame* createChildFrame(
94 blink::WebLocalFrame* parent,
95 const blink::WebString& frameName,
96 blink::WebSandboxFlags sandboxFlags);
97 virtual void frameDetached(blink::WebFrame*);
98 virtual blink::WebCookieJar* cookieJar(blink::WebLocalFrame* frame);
99 virtual blink::WebNavigationPolicy decidePolicyForNavigation(
100 blink::WebLocalFrame* frame,
101 blink::WebDataSource::ExtraData* data,
102 const blink::WebURLRequest& request,
103 blink::WebNavigationType nav_type,
104 blink::WebNavigationPolicy default_policy,
105 bool isRedirect);
106 virtual void didAddMessageToConsole(const blink::WebConsoleMessage& message,
107 const blink::WebString& source_name,
108 unsigned source_line,
109 const blink::WebString& stack_trace);
110 virtual void didNavigateWithinPage(blink::WebLocalFrame* frame,
111 const blink::WebHistoryItem& history_item,
112 blink::WebHistoryCommitType commit_type);
113 virtual blink::WebEncryptedMediaClient* encryptedMediaClient();
115 // ViewManagerDelegate methods:
116 void OnEmbed(mojo::View* root,
117 mojo::InterfaceRequest<mojo::ServiceProvider> services,
118 mojo::ServiceProviderPtr exposed_services) override;
119 void OnViewManagerDisconnected(mojo::ViewManager* view_manager) override;
121 // ViewObserver methods:
122 void OnViewBoundsChanged(mojo::View* view,
123 const mojo::Rect& old_bounds,
124 const mojo::Rect& new_bounds) override;
125 void OnViewDestroyed(mojo::View* view) override;
126 void OnViewInputEvent(mojo::View* view, const mojo::EventPtr& event) override;
128 // InterfaceFactory<AxProvider>
129 void Create(mojo::ApplicationConnection* connection,
130 mojo::InterfaceRequest<mojo::AxProvider> request) override;
132 void Load(mojo::URLResponsePtr response);
134 mojo::URLResponsePtr response_;
135 mojo::ServiceProviderImpl exported_services_;
136 mojo::ServiceProviderPtr embedder_service_provider_;
137 mojo::Shell* shell_;
138 mojo::LazyInterfacePtr<mojo::NavigatorHost> navigator_host_;
139 blink::WebView* web_view_;
140 mojo::View* root_;
141 mojo::ViewManagerClientFactory view_manager_client_factory_;
142 scoped_ptr<WebLayerTreeViewImpl> web_layer_tree_view_impl_;
143 scoped_refptr<base::MessageLoopProxy> compositor_thread_;
144 WebMediaPlayerFactory* web_media_player_factory_;
146 // EncryptedMediaClient attached to this frame; lazily initialized.
147 scoped_ptr<media::WebEncryptedMediaClientImpl> web_encrypted_media_client_;
148 scoped_ptr<media::MediaPermission> media_permission_;
150 // HTMLDocument owns these pointers.
151 std::set<AxProviderImpl*> ax_provider_impls_;
153 // Set if the content will never be displayed.
154 bool is_headless_;
156 DISALLOW_COPY_AND_ASSIGN(HTMLDocument);
159 } // namespace html_viewer
161 #endif // MOJO_SERVICES_HTML_VIEWER_HTML_DOCUMENT_H_