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

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

Issue 11418292: [Android WebView] Plumb WebContentsDelegate::CloseContents to embedder. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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
« no previous file with comments | « android_webview/native/aw_web_contents_delegate.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "android_webview/native/aw_web_contents_delegate.h" 5 #include "android_webview/native/aw_web_contents_delegate.h"
6 6
7 #include "android_webview/browser/find_helper.h" 7 #include "android_webview/browser/find_helper.h"
8 #include "android_webview/native/aw_contents.h" 8 #include "android_webview/native/aw_contents.h"
9 #include "android_webview/native/aw_javascript_dialog_creator.h" 9 #include "android_webview/native/aw_javascript_dialog_creator.h"
10 #include "base/android/scoped_java_ref.h"
10 #include "base/lazy_instance.h" 11 #include "base/lazy_instance.h"
11 #include "base/message_loop.h" 12 #include "base/message_loop.h"
12 #include "content/public/browser/android/download_controller_android.h" 13 #include "content/public/browser/android/download_controller_android.h"
13 #include "content/public/browser/web_contents.h" 14 #include "content/public/browser/web_contents.h"
14 #include "jni/AwWebContentsDelegate_jni.h" 15 #include "jni/AwWebContentsDelegate_jni.h"
15 #include "net/http/http_request_headers.h" 16 #include "net/http/http_request_headers.h"
16 17
17 using base::android::AttachCurrentThread; 18 using base::android::AttachCurrentThread;
19 using base::android::ScopedJavaLocalRef;
18 using content::WebContents; 20 using content::WebContents;
19 21
20 namespace android_webview { 22 namespace android_webview {
21 23
22 static base::LazyInstance<AwJavaScriptDialogCreator>::Leaky 24 static base::LazyInstance<AwJavaScriptDialogCreator>::Leaky
23 g_javascript_dialog_creator = LAZY_INSTANCE_INITIALIZER; 25 g_javascript_dialog_creator = LAZY_INSTANCE_INITIALIZER;
24 26
25 AwWebContentsDelegate::AwWebContentsDelegate( 27 AwWebContentsDelegate::AwWebContentsDelegate(
26 JNIEnv* env, 28 JNIEnv* env,
27 jobject obj) 29 jobject obj)
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 71
70 void AwWebContentsDelegate::AddNewContents(content::WebContents* source, 72 void AwWebContentsDelegate::AddNewContents(content::WebContents* source,
71 content::WebContents* new_contents, 73 content::WebContents* new_contents,
72 WindowOpenDisposition disposition, 74 WindowOpenDisposition disposition,
73 const gfx::Rect& initial_pos, 75 const gfx::Rect& initial_pos,
74 bool user_gesture, 76 bool user_gesture,
75 bool* was_blocked) { 77 bool* was_blocked) {
76 JNIEnv* env = AttachCurrentThread(); 78 JNIEnv* env = AttachCurrentThread();
77 79
78 bool is_dialog = disposition == NEW_POPUP; 80 bool is_dialog = disposition == NEW_POPUP;
79 bool create_popup = Java_AwWebContentsDelegate_addNewContents(env, 81 ScopedJavaLocalRef<jobject> java_delegate = GetJavaDelegate(env);
80 GetJavaDelegate(env).obj(), is_dialog, user_gesture); 82 bool create_popup = false;
83
84 if (java_delegate.obj()) {
85 create_popup = Java_AwWebContentsDelegate_addNewContents(env,
86 java_delegate.obj(), is_dialog, user_gesture);
87 }
81 88
82 if (create_popup) { 89 if (create_popup) {
83 // The embedder would like to display the popup and we will receive 90 // The embedder would like to display the popup and we will receive
84 // a callback from them later with an AwContents to use to display 91 // a callback from them later with an AwContents to use to display
85 // it. The source AwContents takes ownership of the new WebContents 92 // it. The source AwContents takes ownership of the new WebContents
86 // until then, and when the callback is made we will swap the WebContents 93 // until then, and when the callback is made we will swap the WebContents
87 // out into the new AwContents. 94 // out into the new AwContents.
88 AwContents::FromWebContents(source)->SetPendingWebContentsForPopup( 95 AwContents::FromWebContents(source)->SetPendingWebContentsForPopup(
89 make_scoped_ptr(new_contents)); 96 make_scoped_ptr(new_contents));
90 // Hide the WebContents for the pop up now, we will show it again 97 // Hide the WebContents for the pop up now, we will show it again
91 // when the user calls us back with an AwContents to use to show it. 98 // when the user calls us back with an AwContents to use to show it.
92 new_contents->WasHidden(); 99 new_contents->WasHidden();
93 } else { 100 } else {
94 // The embedder has forgone their chance to display this popup 101 // The embedder has forgone their chance to display this popup
95 // window, so we're done with the WebContents now. We use 102 // window, so we're done with the WebContents now. We use
96 // DeleteSoon as WebContentsImpl may call methods on |new_contents| 103 // DeleteSoon as WebContentsImpl may call methods on |new_contents|
97 // after this method returns. 104 // after this method returns.
98 MessageLoop::current()->DeleteSoon(FROM_HERE, new_contents); 105 MessageLoop::current()->DeleteSoon(FROM_HERE, new_contents);
99 } 106 }
100 107
101 if (was_blocked) { 108 if (was_blocked) {
102 *was_blocked = !create_popup; 109 *was_blocked = !create_popup;
103 } 110 }
104 } 111 }
105 112
113 void AwWebContentsDelegate::CloseContents(content::WebContents* source) {
114 JNIEnv* env = AttachCurrentThread();
115
116 ScopedJavaLocalRef<jobject> java_delegate = GetJavaDelegate(env);
117 if (java_delegate.obj()) {
118 Java_AwWebContentsDelegate_closeContents(env, java_delegate.obj());
119 }
120 }
121
106 bool RegisterAwWebContentsDelegate(JNIEnv* env) { 122 bool RegisterAwWebContentsDelegate(JNIEnv* env) {
107 return RegisterNativesImpl(env); 123 return RegisterNativesImpl(env);
108 } 124 }
109 125
110 } // namespace android_webview 126 } // namespace android_webview
OLDNEW
« no previous file with comments | « android_webview/native/aw_web_contents_delegate.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698