Forward accessibility events to the automation extension process.
[chromium-blink-merge.git] / components / html_viewer / html_document.h
blob2ddaf049521599a09547d60983051689380503b1
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 <map>
9 #include <set>
11 #include "base/callback.h"
12 #include "base/macros.h"
13 #include "components/html_viewer/ax_provider_impl.h"
14 #include "components/html_viewer/frame_tree_manager.h"
15 #include "components/html_viewer/touch_handler.h"
16 #include "components/view_manager/public/cpp/view_manager_client_factory.h"
17 #include "components/view_manager/public/cpp/view_manager_delegate.h"
18 #include "components/view_manager/public/cpp/view_observer.h"
19 #include "mandoline/services/navigation/public/interfaces/navigation.mojom.h"
20 #include "mandoline/tab/public/interfaces/frame_tree.mojom.h"
21 #include "mojo/application/public/cpp/app_lifetime_helper.h"
22 #include "mojo/application/public/cpp/interface_factory.h"
23 #include "mojo/application/public/cpp/lazy_interface_ptr.h"
24 #include "mojo/application/public/cpp/service_provider_impl.h"
25 #include "mojo/application/public/interfaces/application.mojom.h"
26 #include "mojo/application/public/interfaces/content_handler.mojom.h"
27 #include "mojo/services/network/public/interfaces/url_loader.mojom.h"
28 #include "third_party/WebKit/public/web/WebFrameClient.h"
29 #include "third_party/WebKit/public/web/WebSandboxFlags.h"
30 #include "third_party/WebKit/public/web/WebViewClient.h"
31 #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_impl.h"
33 namespace base {
34 class SingleThreadTaskRunner;
37 namespace mojo {
38 class ViewManager;
39 class View;
42 namespace html_viewer {
44 class AxProviderImpl;
45 class Setup;
46 class WebLayerTreeViewImpl;
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 mojo::InterfaceFactory<mandoline::FrameTreeClient> {
55 public:
56 // Load a new HTMLDocument with |response|.
57 // |html_document_app| is the application this app was created in, and
58 // |connection| the specific connection triggering this new instance.
59 // |setup| is used to obtain init type state (such as resources).
60 HTMLDocument(mojo::ApplicationImpl* html_document_app,
61 mojo::ApplicationConnection* connection,
62 mojo::URLResponsePtr response,
63 Setup* setup);
64 ~HTMLDocument() override;
66 private:
67 // Data associated with a child iframe.
68 struct ChildFrameData {
69 mojo::View* view;
70 blink::WebTreeScopeType scope;
73 using FrameToViewMap = std::map<blink::WebLocalFrame*, ChildFrameData>;
75 // Updates the size and scale factor of the webview and related classes from
76 // |root_|.
77 void UpdateWebviewSizeFromViewSize();
79 void InitSetupAndLoadIfNecessary();
81 // WebViewClient methods:
82 virtual blink::WebStorageNamespace* createSessionStorageNamespace();
84 // WebWidgetClient methods:
85 void initializeLayerTreeView() override;
86 blink::WebLayerTreeView* layerTreeView() override;
88 // WebFrameClient methods:
89 virtual blink::WebMediaPlayer* createMediaPlayer(
90 blink::WebLocalFrame* frame,
91 const blink::WebURL& url,
92 blink::WebMediaPlayerClient* client,
93 blink::WebContentDecryptionModule* initial_cdm);
94 virtual blink::WebFrame* createChildFrame(
95 blink::WebLocalFrame* parent,
96 blink::WebTreeScopeType scope,
97 const blink::WebString& frameName,
98 blink::WebSandboxFlags sandboxFlags);
99 virtual void frameDetached(blink::WebFrame* frame);
100 virtual blink::WebCookieJar* cookieJar(blink::WebLocalFrame* frame);
101 virtual blink::WebNavigationPolicy decidePolicyForNavigation(
102 const NavigationPolicyInfo& info);
104 virtual void didAddMessageToConsole(const blink::WebConsoleMessage& message,
105 const blink::WebString& source_name,
106 unsigned source_line,
107 const blink::WebString& stack_trace);
108 virtual void didFinishLoad(blink::WebLocalFrame* frame);
109 virtual void didNavigateWithinPage(blink::WebLocalFrame* frame,
110 const blink::WebHistoryItem& history_item,
111 blink::WebHistoryCommitType commit_type);
112 virtual blink::WebEncryptedMediaClient* encryptedMediaClient();
114 // ViewManagerDelegate methods:
115 void OnEmbed(mojo::View* root,
116 mojo::InterfaceRequest<mojo::ServiceProvider> services,
117 mojo::ServiceProviderPtr exposed_services) override;
118 void OnViewManagerDestroyed(mojo::ViewManager* view_manager) override;
120 // ViewObserver methods:
121 void OnViewBoundsChanged(mojo::View* view,
122 const mojo::Rect& old_bounds,
123 const mojo::Rect& new_bounds) override;
124 void OnViewViewportMetricsChanged(
125 mojo::View* view,
126 const mojo::ViewportMetrics& old_metrics,
127 const mojo::ViewportMetrics& new_metrics) 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 // mojo::InterfaceFactory<mandoline::FrameTreeClient>
136 void Create(
137 mojo::ApplicationConnection* connection,
138 mojo::InterfaceRequest<mandoline::FrameTreeClient> request) override;
140 void Load(mojo::URLResponsePtr response);
142 // Converts a WebLocalFrame to a WebRemoteFrame. Used once we know the
143 // url of a frame to trigger the navigation.
144 void ConvertLocalFrameToRemoteFrame(blink::WebLocalFrame* frame);
146 scoped_ptr<mojo::AppRefCount> app_refcount_;
147 mojo::ApplicationImpl* html_document_app_;
148 mojo::URLResponsePtr response_;
149 mojo::ServiceProviderPtr embedder_service_provider_;
150 mojo::ServiceProviderImpl embedder_exported_services_;
151 mojo::LazyInterfacePtr<mojo::NavigatorHost> navigator_host_;
152 blink::WebView* web_view_;
153 mojo::View* root_;
154 mojo::ViewManagerClientFactory view_manager_client_factory_;
155 scoped_ptr<WebLayerTreeViewImpl> web_layer_tree_view_impl_;
156 scoped_refptr<base::SingleThreadTaskRunner> compositor_thread_;
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 Setup* setup_;
167 scoped_ptr<TouchHandler> touch_handler_;
169 FrameToViewMap frame_to_view_;
171 FrameTreeManager frame_tree_manager_;
172 mojo::Binding<mandoline::FrameTreeClient> frame_tree_manager_binding_;
174 DISALLOW_COPY_AND_ASSIGN(HTMLDocument);
177 } // namespace html_viewer
179 #endif // COMPONENTS_HTML_VIEWER_HTML_DOCUMENT_H_