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

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

Issue 387113003: Add a content API to create a message channel. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address mnaganov's comments Created 6 years, 1 month 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
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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_contents.h" 5 #include "android_webview/native/aw_contents.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "android_webview/browser/aw_browser_context.h" 9 #include "android_webview/browser/aw_browser_context.h"
10 #include "android_webview/browser/aw_browser_main_parts.h" 10 #include "android_webview/browser/aw_browser_main_parts.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 #include "base/supports_user_data.h" 45 #include "base/supports_user_data.h"
46 #include "components/autofill/content/browser/content_autofill_driver.h" 46 #include "components/autofill/content/browser/content_autofill_driver.h"
47 #include "components/autofill/core/browser/autofill_manager.h" 47 #include "components/autofill/core/browser/autofill_manager.h"
48 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" 48 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
49 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett ings.h" 49 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett ings.h"
50 #include "components/navigation_interception/intercept_navigation_delegate.h" 50 #include "components/navigation_interception/intercept_navigation_delegate.h"
51 #include "content/public/browser/android/content_view_core.h" 51 #include "content/public/browser/android/content_view_core.h"
52 #include "content/public/browser/browser_thread.h" 52 #include "content/public/browser/browser_thread.h"
53 #include "content/public/browser/cert_store.h" 53 #include "content/public/browser/cert_store.h"
54 #include "content/public/browser/favicon_status.h" 54 #include "content/public/browser/favicon_status.h"
55 #include "content/public/browser/message_port_provider.h"
55 #include "content/public/browser/navigation_entry.h" 56 #include "content/public/browser/navigation_entry.h"
56 #include "content/public/browser/render_frame_host.h" 57 #include "content/public/browser/render_frame_host.h"
57 #include "content/public/browser/render_process_host.h" 58 #include "content/public/browser/render_process_host.h"
58 #include "content/public/browser/render_view_host.h" 59 #include "content/public/browser/render_view_host.h"
59 #include "content/public/browser/web_contents.h" 60 #include "content/public/browser/web_contents.h"
60 #include "content/public/common/renderer_preferences.h" 61 #include "content/public/common/renderer_preferences.h"
61 #include "content/public/common/ssl_status.h" 62 #include "content/public/common/ssl_status.h"
62 #include "jni/AwContents_jni.h" 63 #include "jni/AwContents_jni.h"
63 #include "net/base/auth.h" 64 #include "net/base/auth.h"
64 #include "net/cert/x509_certificate.h" 65 #include "net/cert/x509_certificate.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 125
125 base::subtle::Atomic32 g_instance_count = 0; 126 base::subtle::Atomic32 g_instance_count = 0;
126 127
127 void OnIoThreadClientReady(content::RenderFrameHost* rfh) { 128 void OnIoThreadClientReady(content::RenderFrameHost* rfh) {
128 int render_process_id = rfh->GetProcess()->GetID(); 129 int render_process_id = rfh->GetProcess()->GetID();
129 int render_frame_id = rfh->GetRoutingID(); 130 int render_frame_id = rfh->GetRoutingID();
130 AwResourceDispatcherHostDelegate::OnIoThreadClientReady( 131 AwResourceDispatcherHostDelegate::OnIoThreadClientReady(
131 render_process_id, render_frame_id); 132 render_process_id, render_frame_id);
132 } 133 }
133 134
135 void OnMessageChannelCreated(ScopedJavaGlobalRef<jobject>* callback,
136 int* port1, int* port2) {
137 JNIEnv* env = AttachCurrentThread();
138 Java_AwContents_onMessageChannelCreated(env, *port1, *port2,
139 callback->obj());
140 }
141
134 } // namespace 142 } // namespace
135 143
136 // static 144 // static
137 AwContents* AwContents::FromWebContents(WebContents* web_contents) { 145 AwContents* AwContents::FromWebContents(WebContents* web_contents) {
138 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 146 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
139 return AwContentsUserData::GetContents(web_contents); 147 return AwContentsUserData::GetContents(web_contents);
140 } 148 }
141 149
142 // static 150 // static
143 AwContents* AwContents::FromID(int render_process_id, int render_view_id) { 151 AwContents* AwContents::FromID(int render_process_id, int render_view_id) {
(...skipping 1024 matching lines...) Expand 10 before | Expand all | Expand 10 after
1168 TRIM_MEMORY_MODERATE = 60, 1176 TRIM_MEMORY_MODERATE = 60,
1169 }; 1177 };
1170 if (level >= TRIM_MEMORY_MODERATE) { 1178 if (level >= TRIM_MEMORY_MODERATE) {
1171 ReleaseHardwareDrawIfNeeded(); 1179 ReleaseHardwareDrawIfNeeded();
1172 return; 1180 return;
1173 } 1181 }
1174 1182
1175 browser_view_renderer_.TrimMemory(level, visible); 1183 browser_view_renderer_.TrimMemory(level, visible);
1176 } 1184 }
1177 1185
1186 // TODO(sgurun) add support for posting a frame whose name is known (only
1187 // main frame is supported at this time, see crbug.com/389721)
1188 void AwContents::PostMessageToFrame(JNIEnv* env, jobject obj,
1189 jstring frame_name, jstring message, jstring source_origin,
1190 jstring target_origin, jintArray msgPorts) {
1191
1192 base::string16* j_source_origin = new base::string16;
1193 ConvertJavaStringToUTF16(env, source_origin, j_source_origin);
1194 base::string16* j_target_origin = new base::string16;
1195 ConvertJavaStringToUTF16(env, target_origin, j_target_origin);
1196 base::string16* j_message = new base::string16;
1197 ConvertJavaStringToUTF16(env, message, j_message);
1198 std::vector<int>* j_ports = new std::vector<int>;
1199
1200 if (msgPorts != nullptr)
1201 base::android::JavaIntArrayToIntVector(env, msgPorts, j_ports);
1202
1203 BrowserThread::PostTask(
1204 BrowserThread::IO,
1205 FROM_HERE,
1206 base::Bind(&content::MessagePortProvider::PostMessageToFrame,
1207 web_contents_.get(),
1208 base::Owned(j_source_origin),
1209 base::Owned(j_target_origin),
1210 base::Owned(j_message),
1211 base::Owned(j_ports)));
1212 }
1213
1214 void AwContents::CreateMessageChannel(JNIEnv* env, jobject obj,
1215 jobject callback) {
1216 ScopedJavaGlobalRef<jobject>* j_callback = new ScopedJavaGlobalRef<jobject>();
1217 j_callback->Reset(env, callback);
1218
1219 int* port1 = new int;
1220 int* port2 = new int;
1221 BrowserThread::PostTaskAndReply(
1222 BrowserThread::IO,
1223 FROM_HERE,
1224 base::Bind(&content::MessagePortProvider::CreateMessageChannel,
1225 web_contents_.get(),
1226 port1,
1227 port2),
1228 base::Bind(&OnMessageChannelCreated,
1229 base::Owned(j_callback),
1230 base::Owned(port1),
1231 base::Owned(port2)));
1232 }
1233
1234
1178 void SetShouldDownloadFavicons(JNIEnv* env, jclass jclazz) { 1235 void SetShouldDownloadFavicons(JNIEnv* env, jclass jclazz) {
1179 g_should_download_favicons = true; 1236 g_should_download_favicons = true;
1180 } 1237 }
1181 1238
1182 } // namespace android_webview 1239 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698