Home | History | Annotate | Download | only in html_viewer
      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.
      4 
      5 #ifndef MOJO_SERVICES_HTML_VIEWER_HTML_DOCUMENT_VIEW_H_
      6 #define MOJO_SERVICES_HTML_VIEWER_HTML_DOCUMENT_VIEW_H_
      7 
      8 #include "base/compiler_specific.h"
      9 #include "base/memory/weak_ptr.h"
     10 #include "mojo/public/cpp/application/lazy_interface_ptr.h"
     11 #include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h"
     12 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h"
     13 #include "mojo/services/public/cpp/view_manager/view_observer.h"
     14 #include "mojo/services/public/interfaces/content_handler/content_handler.mojom.h"
     15 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h"
     16 #include "mojo/services/public/interfaces/network/url_loader.mojom.h"
     17 #include "third_party/WebKit/public/web/WebFrameClient.h"
     18 #include "third_party/WebKit/public/web/WebViewClient.h"
     19 
     20 namespace base {
     21 class MessageLoopProxy;
     22 }
     23 
     24 namespace mojo {
     25 
     26 class WebMediaPlayerFactory;
     27 class ViewManager;
     28 class View;
     29 class WebLayerTreeViewImpl;
     30 
     31 // A view for a single HTML document.
     32 class HTMLDocumentView : public blink::WebViewClient,
     33                          public blink::WebFrameClient,
     34                          public ViewManagerDelegate,
     35                          public ViewObserver {
     36  public:
     37   // Load a new HTMLDocument with |response|.
     38   //
     39   // |service_provider_request| should be used to implement a
     40   // ServiceProvider which exposes services to the connecting application.
     41   // Commonly, the connecting application is the ViewManager and it will
     42   // request ViewManagerClient.
     43   //
     44   // |shell| is the Shell connection for this mojo::Application.
     45   HTMLDocumentView(URLResponsePtr response,
     46                    InterfaceRequest<ServiceProvider> service_provider_request,
     47                    Shell* shell,
     48                    scoped_refptr<base::MessageLoopProxy> compositor_thread,
     49                    WebMediaPlayerFactory* web_media_player_factory);
     50   virtual ~HTMLDocumentView();
     51 
     52  private:
     53   // WebViewClient methods:
     54   virtual blink::WebStorageNamespace* createSessionStorageNamespace();
     55 
     56   // WebWidgetClient methods:
     57   virtual void initializeLayerTreeView();
     58   virtual blink::WebLayerTreeView* layerTreeView();
     59 
     60   // WebFrameClient methods:
     61   virtual blink::WebMediaPlayer* createMediaPlayer(
     62       blink::WebLocalFrame* frame,
     63       const blink::WebURL& url,
     64       blink::WebMediaPlayerClient* client);
     65   virtual blink::WebMediaPlayer* createMediaPlayer(
     66       blink::WebLocalFrame* frame,
     67       const blink::WebURL& url,
     68       blink::WebMediaPlayerClient* client,
     69       blink::WebContentDecryptionModule* initial_cdm);
     70   virtual blink::WebFrame* createChildFrame(blink::WebLocalFrame* parent,
     71                                             const blink::WebString& frameName);
     72   virtual void frameDetached(blink::WebFrame*);
     73   virtual blink::WebCookieJar* cookieJar(blink::WebLocalFrame* frame);
     74   virtual blink::WebNavigationPolicy decidePolicyForNavigation(
     75       blink::WebLocalFrame* frame, blink::WebDataSource::ExtraData* data,
     76       const blink::WebURLRequest& request, blink::WebNavigationType nav_type,
     77       blink::WebNavigationPolicy default_policy, bool isRedirect);
     78   virtual void didAddMessageToConsole(
     79       const blink::WebConsoleMessage& message,
     80       const blink::WebString& source_name,
     81       unsigned source_line,
     82       const blink::WebString& stack_trace);
     83   virtual void didNavigateWithinPage(
     84       blink::WebLocalFrame* frame,
     85       const blink::WebHistoryItem& history_item,
     86       blink::WebHistoryCommitType commit_type);
     87 
     88   // ViewManagerDelegate methods:
     89   virtual void OnEmbed(
     90       ViewManager* view_manager,
     91       View* root,
     92       ServiceProviderImpl* embedee_service_provider_impl,
     93       scoped_ptr<ServiceProvider> embedder_service_provider) OVERRIDE;
     94   virtual void OnViewManagerDisconnected(ViewManager* view_manager) OVERRIDE;
     95 
     96   // ViewObserver methods:
     97   virtual void OnViewBoundsChanged(View* view,
     98                                    const gfx::Rect& old_bounds,
     99                                    const gfx::Rect& new_bounds) OVERRIDE;
    100   virtual void OnViewDestroyed(View* view) OVERRIDE;
    101   virtual void OnViewInputEvent(View* view, const EventPtr& event) OVERRIDE;
    102 
    103   void Load(URLResponsePtr response);
    104 
    105   URLResponsePtr response_;
    106   scoped_ptr<ServiceProvider> embedder_service_provider_;
    107   Shell* shell_;
    108   LazyInterfacePtr<NavigatorHost> navigator_host_;
    109   blink::WebView* web_view_;
    110   View* root_;
    111   ViewManagerClientFactory view_manager_client_factory_;
    112   scoped_ptr<WebLayerTreeViewImpl> web_layer_tree_view_impl_;
    113   scoped_refptr<base::MessageLoopProxy> compositor_thread_;
    114   WebMediaPlayerFactory* web_media_player_factory_;
    115 
    116   base::WeakPtrFactory<HTMLDocumentView> weak_factory_;
    117   DISALLOW_COPY_AND_ASSIGN(HTMLDocumentView);
    118 };
    119 
    120 }  // namespace mojo
    121 
    122 #endif  // MOJO_SERVICES_HTML_VIEWER_HTML_DOCUMENT_VIEW_H_
    123