OLD | NEW |
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 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 base::subtle::NoBarrier_AtomicIncrement(&g_instance_count, -1); | 276 base::subtle::NoBarrier_AtomicIncrement(&g_instance_count, -1); |
277 // When the last WebView is destroyed free all discardable memory allocated by | 277 // When the last WebView is destroyed free all discardable memory allocated by |
278 // Chromium, because the app process may continue to run for a long time | 278 // Chromium, because the app process may continue to run for a long time |
279 // without ever using another WebView. | 279 // without ever using another WebView. |
280 if (base::subtle::NoBarrier_Load(&g_instance_count) == 0) { | 280 if (base::subtle::NoBarrier_Load(&g_instance_count) == 0) { |
281 base::MemoryPressureListener::NotifyMemoryPressure( | 281 base::MemoryPressureListener::NotifyMemoryPressure( |
282 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); | 282 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
283 } | 283 } |
284 } | 284 } |
285 | 285 |
286 jlong AwContents::GetWebContents(JNIEnv* env, jobject obj) { | 286 base::android::ScopedJavaLocalRef<jobject> |
| 287 AwContents::GetWebContents(JNIEnv* env, jobject obj) { |
287 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 288 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
288 DCHECK(web_contents_); | 289 DCHECK(web_contents_); |
289 return reinterpret_cast<intptr_t>(web_contents_.get()); | 290 if (!web_contents_) |
| 291 return base::android::ScopedJavaLocalRef<jobject>(); |
| 292 |
| 293 return web_contents_->GetJavaWebContents(); |
290 } | 294 } |
291 | 295 |
292 void AwContents::Destroy(JNIEnv* env, jobject obj) { | 296 void AwContents::Destroy(JNIEnv* env, jobject obj) { |
293 java_ref_.reset(); | 297 java_ref_.reset(); |
294 delete this; | 298 delete this; |
295 } | 299 } |
296 | 300 |
297 static jlong Init(JNIEnv* env, jclass, jobject browser_context) { | 301 static jlong Init(JNIEnv* env, jclass, jobject browser_context) { |
298 // TODO(joth): Use |browser_context| to get the native BrowserContext, rather | 302 // TODO(joth): Use |browser_context| to get the native BrowserContext, rather |
299 // than hard-code the default instance lookup here. | 303 // than hard-code the default instance lookup here. |
(...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1100 | 1104 |
1101 AwMessagePortServiceImpl::GetInstance()->CreateMessageChannel(env, callback, | 1105 AwMessagePortServiceImpl::GetInstance()->CreateMessageChannel(env, callback, |
1102 GetMessagePortMessageFilter()); | 1106 GetMessagePortMessageFilter()); |
1103 } | 1107 } |
1104 | 1108 |
1105 void SetShouldDownloadFavicons(JNIEnv* env, jclass jclazz) { | 1109 void SetShouldDownloadFavicons(JNIEnv* env, jclass jclazz) { |
1106 g_should_download_favicons = true; | 1110 g_should_download_favicons = true; |
1107 } | 1111 } |
1108 | 1112 |
1109 } // namespace android_webview | 1113 } // namespace android_webview |
OLD | NEW |