Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(456)

Side by Side Diff: android_webview/native/aw_web_contents_view_delegate.cc

Issue 11471040: [Android WebView] Convert context menu callback to long press (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Lazy initialize to fix crash. Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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 "android_webview/native/aw_web_contents_view_delegate.h"
6
7 #include "android_webview/native/aw_contents.h"
8 #include "base/android/jni_android.h"
9 #include "content/public/browser/android/content_view_core.h"
10 #include "content/public/browser/web_contents.h"
11 #include "content/public/common/context_menu_params.h"
12 #include "jni/AwWebContentsViewDelegate_jni.h"
13
14 namespace android_webview {
15
16 // static
17 content::WebContentsViewDelegate* AwWebContentsViewDelegate::Create(
18 content::WebContents* web_contents) {
19 return new AwWebContentsViewDelegate(web_contents);
20 }
21
22 AwWebContentsViewDelegate::AwWebContentsViewDelegate(
23 content::WebContents* web_contents)
24 : web_contents_(web_contents) {
25 // Cannot instantiate web_contents_view_delegate_ here because
26 // AwContents::SetWebDelegate is not called yet.
27 }
28
29 AwWebContentsViewDelegate::~AwWebContentsViewDelegate() {}
30
31 content::WebDragDestDelegate* AwWebContentsViewDelegate::GetDragDestDelegate() {
32 // GetDragDestDelegate is a pure virtual method from WebContentsViewDelegate
33 // and must have an implementation although android doesn't use it.
34 NOTREACHED();
35 return NULL;
36 }
37
38 void AwWebContentsViewDelegate::ShowContextMenu(
39 const content::ContextMenuParams& params,
40 content::ContextMenuSourceType type) {
41 // TODO(boliu): Large blocks of this function are identical with
42 // ChromeWebContentsViewDelegateAndroid::ShowContextMenu. De-dup this if
43 // possible.
44
45 // Display paste pop-up only when selection is empty and editable.
46 if (params.is_editable && params.selection_text.empty()) {
47 content::ContentViewCore* content_view_core =
48 web_contents_->GetContentNativeView();
49 if (content_view_core) {
50 content_view_core->ShowPastePopup(params.selection_start.x(),
51 params.selection_start.y());
52 return;
53 }
54 }
55
56 // Lazy create Java object.
57 if (web_contents_view_delegate_.is_null()) {
58 AwContents* aw_contents = AwContents::FromWebContents(web_contents_);
59 if (!aw_contents)
60 return;
61
62 web_contents_view_delegate_.Reset(
63 aw_contents->CreateAwWebContentsViewDelegate());
64 }
65
66 // More hackery can be done to combine |params| with the rest of the
67 // hit test methods if context menus are not working.
68 JNIEnv* env = base::android::AttachCurrentThread();
69 Java_AwWebContentsViewDelegate_onShowContextMenu(
70 env,
71 web_contents_view_delegate_.obj());
72 }
73
74 bool RegisterAwWebContentsViewDelegate(JNIEnv* env) {
75 return RegisterNativesImpl(env) >= 0;
76 }
77
78 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698