| Index: android_webview/native/aw_web_contents_view_delegate.cc
|
| diff --git a/android_webview/native/aw_web_contents_view_delegate.cc b/android_webview/native/aw_web_contents_view_delegate.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..9828e4a9543e77024c958dc63b5c87a560ca9652
|
| --- /dev/null
|
| +++ b/android_webview/native/aw_web_contents_view_delegate.cc
|
| @@ -0,0 +1,74 @@
|
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "android_webview/native/aw_web_contents_view_delegate.h"
|
| +
|
| +#include "android_webview/browser/aw_web_contents_view_delegate_factory.h"
|
| +#include "android_webview/native/aw_contents.h"
|
| +#include "base/android/jni_android.h"
|
| +#include "content/public/browser/android/content_view_core.h"
|
| +#include "content/public/browser/web_contents.h"
|
| +#include "content/public/common/context_menu_params.h"
|
| +#include "jni/AwWebContentsViewDelegate_jni.h"
|
| +
|
| +namespace android_webview {
|
| +
|
| +content::WebContentsViewDelegate* CreateAwWebContentsViewDelegate(
|
| + content::WebContents* web_contents) {
|
| + return new AwWebContentsViewDelegate(web_contents);
|
| +}
|
| +
|
| +AwWebContentsViewDelegate::AwWebContentsViewDelegate(
|
| + content::WebContents* web_contents)
|
| + : web_contents_(web_contents) {
|
| + // Cannot instantiate web_contents_view_delegate_ here because
|
| + // AwContents::SetWebDelegate is not called yet.
|
| +}
|
| +
|
| +AwWebContentsViewDelegate::~AwWebContentsViewDelegate() {}
|
| +
|
| +content::WebDragDestDelegate* AwWebContentsViewDelegate::GetDragDestDelegate() {
|
| + // GetDragDestDelegate is a pure virtual method from WebContentsViewDelegate
|
| + // and must have an implementation although android doesn't use it.
|
| + NOTREACHED();
|
| + return NULL;
|
| +}
|
| +
|
| +void AwWebContentsViewDelegate::ShowContextMenu(
|
| + const content::ContextMenuParams& params,
|
| + content::ContextMenuSourceType type) {
|
| + // Display paste pop-up only when selection is empty and editable.
|
| + if (params.is_editable && params.selection_text.empty()) {
|
| + content::ContentViewCore* content_view_core =
|
| + web_contents_->GetContentNativeView();
|
| + if (content_view_core) {
|
| + content_view_core->ShowPastePopup(params.selection_start.x(),
|
| + params.selection_start.y());
|
| + return;
|
| + }
|
| + }
|
| +
|
| + // Lazy create Java object.
|
| + if (web_contents_view_delegate_.is_null()) {
|
| + AwContents* aw_contents = AwContents::FromWebContents(web_contents_);
|
| + if (!aw_contents)
|
| + return;
|
| +
|
| + web_contents_view_delegate_.Reset(
|
| + aw_contents->CreateAwWebContentsViewDelegate());
|
| + }
|
| +
|
| + // More hackery can be done to combine |params| with the rest of the
|
| + // hit test methods if context menus are not working.
|
| + JNIEnv* env = base::android::AttachCurrentThread();
|
| + Java_AwWebContentsViewDelegate_onShowContextMenu(
|
| + env,
|
| + web_contents_view_delegate_.obj());
|
| +}
|
| +
|
| +bool RegisterAwWebContentsViewDelegate(JNIEnv* env) {
|
| + return RegisterNativesImpl(env) >= 0;
|
| +}
|
| +
|
| +} // namespace android_webview
|
|
|