Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / mojo / services / html_viewer / html_document_view.h
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_observer.h"
12 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h"
13 #include "mojo/services/public/interfaces/network/url_loader.mojom.h"
14 #include "third_party/WebKit/public/web/WebFrameClient.h"
15 #include "third_party/WebKit/public/web/WebViewClient.h"
16
17 namespace mojo {
18
19 class ViewManager;
20 class View;
21
22 // A view for a single HTML document.
23 class HTMLDocumentView : public blink::WebViewClient,
24                          public blink::WebFrameClient,
25                          public ViewObserver {
26  public:
27   HTMLDocumentView(ServiceProvider* service_provider,
28                    ViewManager* view_manager);
29   virtual ~HTMLDocumentView();
30
31   void AttachToView(View* view);
32
33   void Load(URLResponsePtr response);
34
35  private:
36   // WebViewClient methods:
37   virtual blink::WebStorageNamespace* createSessionStorageNamespace();
38
39   // WebWidgetClient methods:
40   virtual void didInvalidateRect(const blink::WebRect& rect);
41   virtual bool allowsBrokenNullLayerTreeView() const;
42
43   // WebFrameClient methods:
44   virtual blink::WebCookieJar* cookieJar(blink::WebLocalFrame* frame);
45   virtual blink::WebNavigationPolicy decidePolicyForNavigation(
46       blink::WebLocalFrame* frame, blink::WebDataSource::ExtraData* data,
47       const blink::WebURLRequest& request, blink::WebNavigationType nav_type,
48       blink::WebNavigationPolicy default_policy, bool isRedirect);
49   virtual void didAddMessageToConsole(
50       const blink::WebConsoleMessage& message,
51       const blink::WebString& source_name,
52       unsigned source_line,
53       const blink::WebString& stack_trace);
54   virtual void didNavigateWithinPage(
55       blink::WebLocalFrame* frame,
56       const blink::WebHistoryItem& history_item,
57       blink::WebHistoryCommitType commit_type);
58
59   // ViewObserver methods:
60   virtual void OnViewBoundsChanged(View* view,
61                                    const gfx::Rect& old_bounds,
62                                    const gfx::Rect& new_bounds) OVERRIDE;
63   virtual void OnViewDestroyed(View* view) OVERRIDE;
64   virtual void OnViewInputEvent(View* view, const EventPtr& event) OVERRIDE;
65
66   void Repaint();
67
68   ViewManager* view_manager_;
69   View* view_;
70   blink::WebView* web_view_;
71   View* root_;
72   bool repaint_pending_;
73   LazyInterfacePtr<NavigatorHost> navigator_host_;
74
75   base::WeakPtrFactory<HTMLDocumentView> weak_factory_;
76   DISALLOW_COPY_AND_ASSIGN(HTMLDocumentView);
77 };
78
79 }  // namespace mojo
80
81 #endif  // MOJO_SERVICES_HTML_VIEWER_HTML_DOCUMENT_VIEW_H_