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_
8 #include "base/macros.h"
9 #include "base/memory/weak_ptr.h"
10 #include "mojo/public/cpp/application/lazy_interface_ptr.h"
11 #include "mojo/public/cpp/application/service_provider_impl.h"
12 #include "mojo/public/cpp/bindings/interface_impl.h"
13 #include "mojo/public/interfaces/application/application.mojom.h"
14 #include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h"
15 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h"
16 #include "mojo/services/public/cpp/view_manager/view_observer.h"
17 #include "mojo/services/public/interfaces/content_handler/content_handler.mojom.h"
18 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h"
19 #include "mojo/services/public/interfaces/network/url_loader.mojom.h"
20 #include "third_party/WebKit/public/web/WebFrameClient.h"
21 #include "third_party/WebKit/public/web/WebViewClient.h"
24 class MessageLoopProxy;
29 class WebMediaPlayerFactory;
32 class WebLayerTreeViewImpl;
34 // A view for a single HTML document.
35 class HTMLDocumentView : public mojo::InterfaceImpl<mojo::Application>,
36 public blink::WebViewClient,
37 public blink::WebFrameClient,
38 public ViewManagerDelegate,
41 // Load a new HTMLDocument with |response|.
43 // |service_provider_request| should be used to implement a
44 // ServiceProvider which exposes services to the connecting application.
45 // Commonly, the connecting application is the ViewManager and it will
46 // request ViewManagerClient.
48 // |shell| is the Shell connection for this mojo::Application.
49 HTMLDocumentView(URLResponsePtr response,
51 scoped_refptr<base::MessageLoopProxy> compositor_thread,
52 WebMediaPlayerFactory* web_media_player_factory);
53 virtual ~HTMLDocumentView();
56 // Application methods:
57 void AcceptConnection(const String& requestor_url,
58 ServiceProviderPtr provider) override;
59 void Initialize(Array<String> args) override;
61 // WebViewClient methods:
62 virtual blink::WebStorageNamespace* createSessionStorageNamespace();
64 // WebWidgetClient methods:
65 virtual void initializeLayerTreeView();
66 virtual blink::WebLayerTreeView* layerTreeView();
68 // WebFrameClient methods:
69 virtual blink::WebMediaPlayer* createMediaPlayer(
70 blink::WebLocalFrame* frame,
71 const blink::WebURL& url,
72 blink::WebMediaPlayerClient* client);
73 virtual blink::WebMediaPlayer* createMediaPlayer(
74 blink::WebLocalFrame* frame,
75 const blink::WebURL& url,
76 blink::WebMediaPlayerClient* client,
77 blink::WebContentDecryptionModule* initial_cdm);
78 virtual blink::WebFrame* createChildFrame(blink::WebLocalFrame* parent,
79 const blink::WebString& frameName);
80 virtual void frameDetached(blink::WebFrame*);
81 virtual blink::WebCookieJar* cookieJar(blink::WebLocalFrame* frame);
82 virtual blink::WebNavigationPolicy decidePolicyForNavigation(
83 blink::WebLocalFrame* frame, blink::WebDataSource::ExtraData* data,
84 const blink::WebURLRequest& request, blink::WebNavigationType nav_type,
85 blink::WebNavigationPolicy default_policy, bool isRedirect);
86 virtual void didAddMessageToConsole(
87 const blink::WebConsoleMessage& message,
88 const blink::WebString& source_name,
90 const blink::WebString& stack_trace);
91 virtual void didNavigateWithinPage(
92 blink::WebLocalFrame* frame,
93 const blink::WebHistoryItem& history_item,
94 blink::WebHistoryCommitType commit_type);
96 // ViewManagerDelegate methods:
97 void OnEmbed(ViewManager* view_manager,
99 ServiceProviderImpl* embedee_service_provider_impl,
100 scoped_ptr<ServiceProvider> embedder_service_provider) override;
101 void OnViewManagerDisconnected(ViewManager* view_manager) override;
103 // ViewObserver methods:
104 void OnViewBoundsChanged(View* view,
105 const Rect& old_bounds,
106 const Rect& new_bounds) override;
107 void OnViewDestroyed(View* view) override;
108 void OnViewInputEvent(View* view, const EventPtr& event) override;
110 void Load(URLResponsePtr response);
112 URLResponsePtr response_;
113 ServiceProviderImpl exported_services_;
114 scoped_ptr<ServiceProvider> embedder_service_provider_;
116 LazyInterfacePtr<NavigatorHost> navigator_host_;
117 blink::WebView* web_view_;
119 ViewManagerClientFactory view_manager_client_factory_;
120 scoped_ptr<WebLayerTreeViewImpl> web_layer_tree_view_impl_;
121 scoped_refptr<base::MessageLoopProxy> compositor_thread_;
122 WebMediaPlayerFactory* web_media_player_factory_;
124 base::WeakPtrFactory<HTMLDocumentView> weak_factory_;
125 DISALLOW_COPY_AND_ASSIGN(HTMLDocumentView);
130 #endif // MOJO_SERVICES_HTML_VIEWER_HTML_DOCUMENT_VIEW_H_