web_contents_view_guest.h revision eb525c5499e34cc9c4b825d6d9e75bb07cc06ace
1// Copyright (c) 2012 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 CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_GUEST_H_
6#define CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_GUEST_H_
7
8#include <vector>
9
10#include "base/memory/scoped_ptr.h"
11#include "content/common/content_export.h"
12#include "content/common/drag_event_source_info.h"
13#include "content/port/browser/render_view_host_delegate_view.h"
14#include "content/port/browser/web_contents_view_port.h"
15
16namespace content {
17
18class WebContents;
19class WebContentsImpl;
20class BrowserPluginGuest;
21
22class CONTENT_EXPORT WebContentsViewGuest
23    : public WebContentsViewPort,
24      public RenderViewHostDelegateView {
25 public:
26  // The corresponding WebContentsImpl is passed in the constructor, and manages
27  // our lifetime. This doesn't need to be the case, but is this way currently
28  // because that's what was easiest when they were split.
29  // WebContentsViewGuest always has a backing platform dependent view,
30  // |platform_view|.
31  WebContentsViewGuest(WebContentsImpl* web_contents,
32                       BrowserPluginGuest* guest,
33                       WebContentsViewPort* platform_view,
34                       RenderViewHostDelegateView* platform_view_delegate_view);
35  virtual ~WebContentsViewGuest();
36
37  WebContents* web_contents();
38
39  // WebContentsView implementation --------------------------------------------
40
41  virtual gfx::NativeView GetNativeView() const OVERRIDE;
42  virtual gfx::NativeView GetContentNativeView() const OVERRIDE;
43  virtual gfx::NativeWindow GetTopLevelNativeWindow() const OVERRIDE;
44  virtual void GetContainerBounds(gfx::Rect* out) const OVERRIDE;
45  virtual void OnTabCrashed(base::TerminationStatus status,
46                            int error_code) OVERRIDE;
47  virtual void SizeContents(const gfx::Size& size) OVERRIDE;
48  virtual void Focus() OVERRIDE;
49  virtual void SetInitialFocus() OVERRIDE;
50  virtual void StoreFocus() OVERRIDE;
51  virtual void RestoreFocus() OVERRIDE;
52  virtual DropData* GetDropData() const OVERRIDE;
53  virtual gfx::Rect GetViewBounds() const OVERRIDE;
54#if defined(OS_MACOSX)
55  virtual void SetAllowOverlappingViews(bool overlapping) OVERRIDE;
56  virtual bool GetAllowOverlappingViews() const OVERRIDE;
57#endif
58
59  // WebContentsViewPort implementation ----------------------------------------
60  virtual void CreateView(const gfx::Size& initial_size,
61                          gfx::NativeView context) OVERRIDE;
62  virtual RenderWidgetHostView* CreateViewForWidget(
63      RenderWidgetHost* render_widget_host) OVERRIDE;
64  virtual RenderWidgetHostView* CreateViewForPopupWidget(
65      RenderWidgetHost* render_widget_host) OVERRIDE;
66  virtual void SetPageTitle(const string16& title) OVERRIDE;
67  virtual void RenderViewCreated(RenderViewHost* host) OVERRIDE;
68  virtual void RenderViewSwappedIn(RenderViewHost* host) OVERRIDE;
69  virtual void SetOverscrollControllerEnabled(bool enabled) OVERRIDE;
70#if defined(OS_MACOSX)
71  virtual bool IsEventTracking() const OVERRIDE;
72  virtual void CloseTabAfterEventTracking() OVERRIDE;
73#endif
74
75  // Backend implementation of RenderViewHostDelegateView.
76  virtual void ShowContextMenu(const ContextMenuParams& params) OVERRIDE;
77  virtual void ShowPopupMenu(const gfx::Rect& bounds,
78                             int item_height,
79                             double item_font_size,
80                             int selected_item,
81                             const std::vector<WebMenuItem>& items,
82                             bool right_aligned,
83                             bool allow_multiple_selection) OVERRIDE;
84  virtual void StartDragging(const DropData& drop_data,
85                             WebKit::WebDragOperationsMask allowed_ops,
86                             const gfx::ImageSkia& image,
87                             const gfx::Vector2d& image_offset,
88                             const DragEventSourceInfo& event_info) OVERRIDE;
89  virtual void UpdateDragCursor(WebKit::WebDragOperation operation) OVERRIDE;
90  virtual void GotFocus() OVERRIDE;
91  virtual void TakeFocus(bool reverse) OVERRIDE;
92
93 private:
94  // The WebContentsImpl whose contents we display.
95  WebContentsImpl* web_contents_;
96  BrowserPluginGuest* guest_;
97  // The platform dependent view backing this WebContentsView.
98  // Calls to this WebContentsViewGuest are forwarded to |platform_view_|.
99  WebContentsViewPort* platform_view_;
100  gfx::Size size_;
101
102  // Delegate view for guest's platform view.
103  RenderViewHostDelegateView* platform_view_delegate_view_;
104
105  DISALLOW_COPY_AND_ASSIGN(WebContentsViewGuest);
106};
107
108}  // namespace content
109
110#endif  // CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_GUEST_H_
111