web_contents_view_guest.h revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
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 scoped_ptr<WebContentsViewPort> platform_view, 34 RenderViewHostDelegateView* platform_view_delegate_view); 35 virtual ~WebContentsViewGuest(); 36 37 WebContents* web_contents(); 38 39 void OnGuestInitialized(WebContentsView* parent_view); 40 41 // WebContentsView implementation -------------------------------------------- 42 43 virtual gfx::NativeView GetNativeView() const OVERRIDE; 44 virtual gfx::NativeView GetContentNativeView() const OVERRIDE; 45 virtual gfx::NativeWindow GetTopLevelNativeWindow() const OVERRIDE; 46 virtual void GetContainerBounds(gfx::Rect* out) const OVERRIDE; 47 virtual void OnTabCrashed(base::TerminationStatus status, 48 int error_code) OVERRIDE; 49 virtual void SizeContents(const gfx::Size& size) OVERRIDE; 50 virtual void Focus() OVERRIDE; 51 virtual void SetInitialFocus() OVERRIDE; 52 virtual void StoreFocus() OVERRIDE; 53 virtual void RestoreFocus() OVERRIDE; 54 virtual DropData* GetDropData() const OVERRIDE; 55 virtual gfx::Rect GetViewBounds() const OVERRIDE; 56#if defined(OS_MACOSX) 57 virtual void SetAllowOverlappingViews(bool overlapping) OVERRIDE; 58 virtual bool GetAllowOverlappingViews() const OVERRIDE; 59 virtual void SetOverlayView(WebContentsView* overlay, 60 const gfx::Point& offset) OVERRIDE; 61 virtual void RemoveOverlayView() OVERRIDE; 62#endif 63 64 // WebContentsViewPort implementation ---------------------------------------- 65 virtual void CreateView(const gfx::Size& initial_size, 66 gfx::NativeView context) OVERRIDE; 67 virtual RenderWidgetHostView* CreateViewForWidget( 68 RenderWidgetHost* render_widget_host) OVERRIDE; 69 virtual RenderWidgetHostView* CreateViewForPopupWidget( 70 RenderWidgetHost* render_widget_host) OVERRIDE; 71 virtual void SetPageTitle(const base::string16& title) OVERRIDE; 72 virtual void RenderViewCreated(RenderViewHost* host) OVERRIDE; 73 virtual void RenderViewSwappedIn(RenderViewHost* host) OVERRIDE; 74 virtual void SetOverscrollControllerEnabled(bool enabled) OVERRIDE; 75#if defined(OS_MACOSX) 76 virtual bool IsEventTracking() const OVERRIDE; 77 virtual void CloseTabAfterEventTracking() OVERRIDE; 78#endif 79 80 // Backend implementation of RenderViewHostDelegateView. 81 virtual void ShowContextMenu(RenderFrameHost* render_frame_host, 82 const ContextMenuParams& params) OVERRIDE; 83 virtual void ShowPopupMenu(const gfx::Rect& bounds, 84 int item_height, 85 double item_font_size, 86 int selected_item, 87 const std::vector<MenuItem>& items, 88 bool right_aligned, 89 bool allow_multiple_selection) OVERRIDE; 90 virtual void StartDragging(const DropData& drop_data, 91 blink::WebDragOperationsMask allowed_ops, 92 const gfx::ImageSkia& image, 93 const gfx::Vector2d& image_offset, 94 const DragEventSourceInfo& event_info) OVERRIDE; 95 virtual void UpdateDragCursor(blink::WebDragOperation operation) OVERRIDE; 96 virtual void GotFocus() OVERRIDE; 97 virtual void TakeFocus(bool reverse) OVERRIDE; 98 99 private: 100 // The WebContentsImpl whose contents we display. 101 WebContentsImpl* web_contents_; 102 BrowserPluginGuest* guest_; 103 // The platform dependent view backing this WebContentsView. 104 // Calls to this WebContentsViewGuest are forwarded to |platform_view_|. 105 scoped_ptr<WebContentsViewPort> platform_view_; 106 gfx::Size size_; 107 108 // Delegate view for guest's platform view. 109 RenderViewHostDelegateView* platform_view_delegate_view_; 110 111 DISALLOW_COPY_AND_ASSIGN(WebContentsViewGuest); 112}; 113 114} // namespace content 115 116#endif // CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_GUEST_H_ 117