summaryrefslogtreecommitdiffstats
path: root/mojo/examples/html_viewer/html_document_view.h
blob: 8bea2d28f7eab7e5764390973209616e3d50c2ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef MOJO_EXAMPLES_HTML_VIEWER_HTML_DOCUMENT_VIEW_H_
#define MOJO_EXAMPLES_HTML_VIEWER_HTML_DOCUMENT_VIEW_H_

#include "base/memory/weak_ptr.h"
#include "mojo/services/public/interfaces/network/url_loader.mojom.h"
#include "third_party/WebKit/public/web/WebFrameClient.h"
#include "third_party/WebKit/public/web/WebViewClient.h"

namespace mojo {

namespace view_manager {
class Node;
class ViewManager;
class View;
}

namespace examples {

// A view for a single HTML document.
class HTMLDocumentView : public blink::WebViewClient,
                         public blink::WebFrameClient {
 public:
  explicit HTMLDocumentView(view_manager::ViewManager* view_manager);
  virtual ~HTMLDocumentView();

  void AttachToNode(view_manager::Node* node);

  void Load(URLResponsePtr response,
            ScopedDataPipeConsumerHandle response_body_stream);

 private:
  // WebViewClient methods:
  virtual blink::WebStorageNamespace* createSessionStorageNamespace();

  // WebWidgetClient methods:
  virtual void didInvalidateRect(const blink::WebRect& rect);
  virtual bool allowsBrokenNullLayerTreeView() const;

  // WebFrameClient methods:
  virtual void didAddMessageToConsole(
      const blink::WebConsoleMessage& message,
      const blink::WebString& source_name,
      unsigned source_line,
      const blink::WebString& stack_trace);

  void Repaint();

  view_manager::ViewManager* view_manager_;
  view_manager::View* view_;
  blink::WebView* web_view_;
  bool repaint_pending_;

  base::WeakPtrFactory<HTMLDocumentView> weak_factory_;

  DISALLOW_COPY_AND_ASSIGN(HTMLDocumentView);
};

}  // namespace examples
}  // namespace mojo

#endif  // MOJO_EXAMPLES_HTML_VIEWER_HTML_DOCUMENT_VIEW_H_