web_contents_view_guest.cc revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
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#include "content/browser/web_contents/web_contents_view_guest.h"
6
7#include "build/build_config.h"
8#include "content/browser/browser_plugin/browser_plugin_guest.h"
9#include "content/browser/renderer_host/render_view_host_factory.h"
10#include "content/browser/renderer_host/render_view_host_impl.h"
11#include "content/browser/renderer_host/render_widget_host_view_guest.h"
12#include "content/browser/web_contents/interstitial_page_impl.h"
13#include "content/browser/web_contents/web_contents_impl.h"
14#include "content/public/browser/web_contents_delegate.h"
15#include "ui/gfx/image/image_skia.h"
16#include "ui/gfx/point.h"
17#include "ui/gfx/rect.h"
18#include "ui/gfx/size.h"
19#include "webkit/glue/webdropdata.h"
20
21using WebKit::WebDragOperation;
22using WebKit::WebDragOperationsMask;
23
24namespace content {
25
26WebContentsViewGuest::WebContentsViewGuest(
27    WebContentsImpl* web_contents,
28    BrowserPluginGuest* guest,
29    WebContentsViewPort* platform_view)
30    : web_contents_(web_contents),
31      guest_(guest),
32      platform_view_(platform_view) {
33}
34
35WebContentsViewGuest::~WebContentsViewGuest() {
36}
37
38gfx::NativeView WebContentsViewGuest::GetNativeView() const {
39  return NULL;
40}
41
42gfx::NativeView WebContentsViewGuest::GetContentNativeView() const {
43  RenderWidgetHostView* rwhv = web_contents_->GetRenderWidgetHostView();
44  if (!rwhv)
45    return NULL;
46  return rwhv->GetNativeView();
47}
48
49gfx::NativeWindow WebContentsViewGuest::GetTopLevelNativeWindow() const {
50  return guest_->embedder_web_contents()->GetView()->GetTopLevelNativeWindow();
51}
52
53void WebContentsViewGuest::GetContainerBounds(gfx::Rect* out) const {
54  platform_view_->GetContainerBounds(out);
55}
56
57void WebContentsViewGuest::SizeContents(const gfx::Size& size) {
58  platform_view_->SizeContents(size);
59}
60
61void WebContentsViewGuest::SetInitialFocus() {
62  platform_view_->SetInitialFocus();
63}
64
65gfx::Rect WebContentsViewGuest::GetViewBounds() const {
66  return platform_view_->GetViewBounds();
67}
68
69#if defined(OS_MACOSX)
70void WebContentsViewGuest::SetAllowOverlappingViews(bool overlapping) {
71  platform_view_->SetAllowOverlappingViews(overlapping);
72}
73#endif
74
75void WebContentsViewGuest::CreateView(const gfx::Size& initial_size,
76                                      gfx::NativeView context) {
77  platform_view_->CreateView(initial_size, context);
78}
79
80RenderWidgetHostView* WebContentsViewGuest::CreateViewForWidget(
81    RenderWidgetHost* render_widget_host) {
82  if (render_widget_host->GetView()) {
83    // During testing, the view will already be set up in most cases to the
84    // test view, so we don't want to clobber it with a real one. To verify that
85    // this actually is happening (and somebody isn't accidentally creating the
86    // view twice), we check for the RVH Factory, which will be set when we're
87    // making special ones (which go along with the special views).
88    DCHECK(RenderViewHostFactory::has_factory());
89    return render_widget_host->GetView();
90  }
91
92  RenderWidgetHostView* platform_widget = NULL;
93  platform_widget = platform_view_->CreateViewForWidget(render_widget_host);
94
95  RenderWidgetHostView* view = new RenderWidgetHostViewGuest(
96      render_widget_host,
97      guest_,
98      platform_widget);
99
100  return view;
101}
102
103RenderWidgetHostView* WebContentsViewGuest::CreateViewForPopupWidget(
104    RenderWidgetHost* render_widget_host) {
105  return RenderWidgetHostViewPort::CreateViewForWidget(render_widget_host);
106}
107
108void WebContentsViewGuest::SetPageTitle(const string16& title) {
109}
110
111void WebContentsViewGuest::RenderViewCreated(RenderViewHost* host) {
112  platform_view_->RenderViewCreated(host);
113}
114
115void WebContentsViewGuest::RenderViewSwappedIn(RenderViewHost* host) {
116  platform_view_->RenderViewSwappedIn(host);
117}
118
119void WebContentsViewGuest::SetOverscrollControllerEnabled(bool enabled) {
120  // This should never override the setting of the embedder view.
121}
122
123#if defined(OS_MACOSX)
124bool WebContentsViewGuest::IsEventTracking() const {
125  return false;
126}
127
128void WebContentsViewGuest::CloseTabAfterEventTracking() {
129}
130#endif
131
132WebContents* WebContentsViewGuest::web_contents() {
133  return web_contents_;
134}
135
136void WebContentsViewGuest::RestoreFocus() {
137  platform_view_->RestoreFocus();
138}
139
140void WebContentsViewGuest::OnTabCrashed(base::TerminationStatus status,
141                                        int error_code) {
142}
143
144void WebContentsViewGuest::Focus() {
145  platform_view_->Focus();
146}
147
148void WebContentsViewGuest::StoreFocus() {
149  platform_view_->StoreFocus();
150}
151
152WebDropData* WebContentsViewGuest::GetDropData() const {
153  NOTIMPLEMENTED();
154  return NULL;
155}
156
157void WebContentsViewGuest::UpdateDragCursor(WebDragOperation operation) {
158  NOTIMPLEMENTED();
159}
160
161void WebContentsViewGuest::GotFocus() {
162}
163
164void WebContentsViewGuest::TakeFocus(bool reverse) {
165}
166
167void WebContentsViewGuest::ShowContextMenu(
168    const ContextMenuParams& params,
169    ContextMenuSourceType type) {
170  NOTIMPLEMENTED();
171}
172
173void WebContentsViewGuest::ShowPopupMenu(const gfx::Rect& bounds,
174                                         int item_height,
175                                         double item_font_size,
176                                         int selected_item,
177                                         const std::vector<WebMenuItem>& items,
178                                         bool right_aligned,
179                                         bool allow_multiple_selection) {
180  // External popup menus are only used on Mac and Android.
181  NOTIMPLEMENTED();
182}
183
184void WebContentsViewGuest::StartDragging(
185    const WebDropData& drop_data,
186    WebDragOperationsMask ops,
187    const gfx::ImageSkia& image,
188    const gfx::Vector2d& image_offset,
189    const DragEventSourceInfo& event_info) {
190  NOTIMPLEMENTED();
191}
192
193}  // namespace content
194