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 "chrome/browser/ui/android/tab_contents/chrome_web_contents_view_delegate_android.h"
6
7#include "base/logging.h"
8#include "chrome/browser/ui/android/context_menu_helper.h"
9#include "content/public/browser/android/content_view_core.h"
10#include "content/public/browser/web_contents.h"
11#include "content/public/browser/web_contents_view_delegate.h"
12#include "content/public/common/context_menu_params.h"
13
14ChromeWebContentsViewDelegateAndroid::ChromeWebContentsViewDelegateAndroid(
15    content::WebContents* web_contents)
16    : web_contents_(web_contents) {
17}
18
19ChromeWebContentsViewDelegateAndroid::~ChromeWebContentsViewDelegateAndroid() {
20}
21
22content::WebDragDestDelegate*
23ChromeWebContentsViewDelegateAndroid::GetDragDestDelegate() {
24  // GetDragDestDelegate is a pure virtual method from WebContentsViewDelegate
25  // and must have an implementation although android doesn't use it.
26  NOTREACHED();
27  return NULL;
28}
29
30void ChromeWebContentsViewDelegateAndroid::ShowContextMenu(
31    content::RenderFrameHost* render_frame_host,
32    const content::ContextMenuParams& params) {
33  // Display paste pop-up only when selection is empty and editable.
34  if (params.is_editable && params.selection_text.empty()) {
35    content::ContentViewCore* content_view_core =
36        content::ContentViewCore::FromWebContents(web_contents_);
37    if (content_view_core) {
38      content_view_core->ShowPastePopup(params.selection_start.x(),
39                                        params.selection_start.y());
40      return;
41    }
42  }
43
44  // TODO(dtrainor, kouhei): Give WebView a Populator/delegate so it can use the
45  // same context menu code.
46  ContextMenuHelper* helper = ContextMenuHelper::FromWebContents(web_contents_);
47  if (helper)
48    helper->ShowContextMenu(params);
49}
50
51namespace chrome {
52
53content::WebContentsViewDelegate* CreateWebContentsViewDelegate(
54    content::WebContents* web_contents) {
55  return new ChromeWebContentsViewDelegateAndroid(web_contents);
56}
57
58}  // namespace chrome
59