OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/browser/web_contents/web_contents_android.h" | 5 #include "content/browser/web_contents/web_contents_android.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "content/browser/android/interstitial_page_delegate_android.h" | 10 #include "content/browser/android/interstitial_page_delegate_android.h" |
11 #include "content/browser/frame_host/interstitial_page_impl.h" | 11 #include "content/browser/frame_host/interstitial_page_impl.h" |
12 #include "content/browser/media/media_web_contents_observer.h" | 12 #include "content/browser/media/media_web_contents_observer.h" |
13 #include "content/browser/renderer_host/render_view_host_impl.h" | 13 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 14 #include "content/browser/transition_request_manager.h" |
| 15 #include "content/browser/web_contents/web_contents_impl.h" |
14 #include "content/common/frame_messages.h" | 16 #include "content/common/frame_messages.h" |
15 #include "content/common/input_messages.h" | 17 #include "content/common/input_messages.h" |
16 #include "content/common/view_messages.h" | 18 #include "content/common/view_messages.h" |
| 19 #include "content/public/browser/browser_context.h" |
17 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
18 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
19 #include "jni/WebContentsImpl_jni.h" | 22 #include "jni/WebContentsImpl_jni.h" |
20 | 23 |
21 using base::android::AttachCurrentThread; | 24 using base::android::AttachCurrentThread; |
22 using base::android::ConvertJavaStringToUTF8; | 25 using base::android::ConvertJavaStringToUTF8; |
| 26 using base::android::ConvertUTF8ToJavaString; |
23 | 27 |
24 namespace content { | 28 namespace content { |
25 | 29 |
26 // static | 30 // static |
27 WebContents* WebContents::FromJavaWebContents( | 31 WebContents* WebContents::FromJavaWebContents( |
28 jobject jweb_contents_android) { | 32 jobject jweb_contents_android) { |
29 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 33 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
30 if (!jweb_contents_android) | 34 if (!jweb_contents_android) |
31 return NULL; | 35 return NULL; |
32 | 36 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 return static_cast<RenderWidgetHostViewAndroid*>(rwhv); | 101 return static_cast<RenderWidgetHostViewAndroid*>(rwhv); |
98 } | 102 } |
99 | 103 |
100 jint WebContentsAndroid::GetBackgroundColor(JNIEnv* env, jobject obj) { | 104 jint WebContentsAndroid::GetBackgroundColor(JNIEnv* env, jobject obj) { |
101 RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid(); | 105 RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid(); |
102 if (!rwhva) | 106 if (!rwhva) |
103 return SK_ColorWHITE; | 107 return SK_ColorWHITE; |
104 return rwhva->GetCachedBackgroundColor(); | 108 return rwhva->GetCachedBackgroundColor(); |
105 } | 109 } |
106 | 110 |
| 111 ScopedJavaLocalRef<jstring> WebContentsAndroid::GetURL( |
| 112 JNIEnv* env, |
| 113 jobject obj) const { |
| 114 return ConvertUTF8ToJavaString(env, web_contents_->GetURL().spec()); |
| 115 } |
| 116 |
| 117 jboolean WebContentsAndroid::IsIncognito(JNIEnv* env, jobject obj) { |
| 118 return web_contents_->GetBrowserContext()->IsOffTheRecord(); |
| 119 } |
| 120 |
| 121 void WebContentsAndroid::SelectPopupMenuItems( |
| 122 JNIEnv* env, |
| 123 jobject obj, |
| 124 jintArray indices) { |
| 125 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>( |
| 126 web_contents_->GetRenderViewHost()); |
| 127 DCHECK(rvhi); |
| 128 if (indices == NULL) { |
| 129 rvhi->DidCancelPopupMenu(); |
| 130 return; |
| 131 } |
| 132 |
| 133 int selected_count = env->GetArrayLength(indices); |
| 134 std::vector<int> selected_indices; |
| 135 jint* indices_ptr = env->GetIntArrayElements(indices, NULL); |
| 136 for (int i = 0; i < selected_count; ++i) |
| 137 selected_indices.push_back(indices_ptr[i]); |
| 138 env->ReleaseIntArrayElements(indices, indices_ptr, JNI_ABORT); |
| 139 rvhi->DidSelectPopupMenuItems(selected_indices); |
| 140 } |
| 141 |
| 142 void WebContentsAndroid::ResumeResponseDeferredAtStart( |
| 143 JNIEnv* env, |
| 144 jobject obj) { |
| 145 static_cast<WebContentsImpl*>(web_contents_)-> |
| 146 ResumeResponseDeferredAtStart(); |
| 147 } |
| 148 |
| 149 void WebContentsAndroid::SetHasPendingNavigationTransitionForTesting( |
| 150 JNIEnv* env, |
| 151 jobject obj) { |
| 152 RenderFrameHost* frame = static_cast<WebContentsImpl*>(web_contents_)-> |
| 153 GetMainFrame(); |
| 154 BrowserThread::PostTask( |
| 155 BrowserThread::IO, |
| 156 FROM_HERE, |
| 157 base::Bind( |
| 158 &TransitionRequestManager::SetHasPendingTransitionRequest, |
| 159 base::Unretained(TransitionRequestManager::GetInstance()), |
| 160 frame->GetProcess()->GetID(), |
| 161 frame->GetRoutingID(), |
| 162 true)); |
| 163 } |
| 164 |
107 void WebContentsAndroid::OnHide(JNIEnv* env, jobject obj) { | 165 void WebContentsAndroid::OnHide(JNIEnv* env, jobject obj) { |
108 web_contents_->WasHidden(); | 166 web_contents_->WasHidden(); |
109 PauseVideo(); | 167 PauseVideo(); |
110 } | 168 } |
111 | 169 |
112 void WebContentsAndroid::OnShow(JNIEnv* env, jobject obj) { | 170 void WebContentsAndroid::OnShow(JNIEnv* env, jobject obj) { |
113 web_contents_->WasShown(); | 171 web_contents_->WasShown(); |
114 } | 172 } |
115 | 173 |
116 void WebContentsAndroid::PauseVideo() { | 174 void WebContentsAndroid::PauseVideo() { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 } | 253 } |
196 | 254 |
197 void WebContentsAndroid::SelectWordAroundCaret(JNIEnv* env, jobject obj) { | 255 void WebContentsAndroid::SelectWordAroundCaret(JNIEnv* env, jobject obj) { |
198 RenderViewHost* host = web_contents_->GetRenderViewHost(); | 256 RenderViewHost* host = web_contents_->GetRenderViewHost(); |
199 if (!host) | 257 if (!host) |
200 return; | 258 return; |
201 host->SelectWordAroundCaret(); | 259 host->SelectWordAroundCaret(); |
202 } | 260 } |
203 | 261 |
204 } // namespace content | 262 } // namespace content |
OLD | NEW |