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.
5 #include "android_webview/native/aw_web_contents_view_delegate.h"
7 #include "android_webview/native/aw_contents.h"
8 #include "content/public/browser/android/content_view_core.h"
9 #include "content/public/browser/web_contents.h"
10 #include "content/public/browser/web_contents_view.h"
11 #include "content/public/common/context_menu_params.h"
13 namespace android_webview
{
16 content::WebContentsViewDelegate
* AwWebContentsViewDelegate::Create(
17 content::WebContents
* web_contents
) {
18 return new AwWebContentsViewDelegate(web_contents
);
21 AwWebContentsViewDelegate::AwWebContentsViewDelegate(
22 content::WebContents
* web_contents
)
23 : web_contents_(web_contents
) {
24 // Cannot instantiate web_contents_view_delegate_ here because
25 // AwContents::SetWebDelegate is not called yet.
28 AwWebContentsViewDelegate::~AwWebContentsViewDelegate() {}
30 content::WebDragDestDelegate
* AwWebContentsViewDelegate::GetDragDestDelegate() {
31 // GetDragDestDelegate is a pure virtual method from WebContentsViewDelegate
32 // and must have an implementation although android doesn't use it.
37 void AwWebContentsViewDelegate::ShowContextMenu(
38 const content::ContextMenuParams
& params
) {
39 // TODO(boliu): Large blocks of this function are identical with
40 // ChromeWebContentsViewDelegateAndroid::ShowContextMenu. De-dup this if
43 // Display paste pop-up only when selection is empty and editable.
44 if (params
.is_editable
&& params
.selection_text
.empty()) {
45 content::ContentViewCore
* content_view_core
=
46 content::ContentViewCore::FromWebContents(web_contents_
);
47 if (content_view_core
) {
48 content_view_core
->ShowPastePopup(params
.selection_start
.x(),
49 params
.selection_start
.y());
54 AwContents
* aw_contents
= AwContents::FromWebContents(web_contents_
);
58 // Context menu callback in Chromium is triggered by WebKit on an
59 // unhandled GestureLongPress event. Convert the context menu callback
60 // back into a long click event for Android WebView since the view
61 // system may choose to handle the gesture.
62 aw_contents
->PerformLongClick();
65 } // namespace android_webview