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 16 namespace content { 17 18 class WebContents; 19 class WebContentsImpl; 20 class BrowserPluginGuest; 21 22 class 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(const ContextMenuParams& params) OVERRIDE; 82 virtual void ShowPopupMenu(const gfx::Rect& bounds, 83 int item_height, 84 double item_font_size, 85 int selected_item, 86 const std::vector<MenuItem>& items, 87 bool right_aligned, 88 bool allow_multiple_selection) OVERRIDE; 89 virtual void StartDragging(const DropData& drop_data, 90 blink::WebDragOperationsMask allowed_ops, 91 const gfx::ImageSkia& image, 92 const gfx::Vector2d& image_offset, 93 const DragEventSourceInfo& event_info) OVERRIDE; 94 virtual void UpdateDragCursor(blink::WebDragOperation operation) OVERRIDE; 95 virtual void GotFocus() OVERRIDE; 96 virtual void TakeFocus(bool reverse) OVERRIDE; 97 98 private: 99 // The WebContentsImpl whose contents we display. 100 WebContentsImpl* web_contents_; 101 BrowserPluginGuest* guest_; 102 // The platform dependent view backing this WebContentsView. 103 // Calls to this WebContentsViewGuest are forwarded to |platform_view_|. 104 scoped_ptr<WebContentsViewPort> platform_view_; 105 gfx::Size size_; 106 107 // Delegate view for guest's platform view. 108 RenderViewHostDelegateView* platform_view_delegate_view_; 109 110 DISALLOW_COPY_AND_ASSIGN(WebContentsViewGuest); 111 }; 112 113 } // namespace content 114 115 #endif // CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_GUEST_H_ 116