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 "content/browser/android/content_view_core_impl.h" | 5 #include "content/browser/android/content_view_core_impl.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/android/jni_array.h" | 8 #include "base/android/jni_array.h" |
9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
10 #include "base/android/scoped_java_ref.h" | 10 #include "base/android/scoped_java_ref.h" |
(...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
812 } | 812 } |
813 | 813 |
814 scoped_refptr<cc::Layer> ContentViewCoreImpl::GetLayer() const { | 814 scoped_refptr<cc::Layer> ContentViewCoreImpl::GetLayer() const { |
815 return root_layer_.get(); | 815 return root_layer_.get(); |
816 } | 816 } |
817 | 817 |
818 // ---------------------------------------------------------------------------- | 818 // ---------------------------------------------------------------------------- |
819 // Methods called from Java via JNI | 819 // Methods called from Java via JNI |
820 // ---------------------------------------------------------------------------- | 820 // ---------------------------------------------------------------------------- |
821 | 821 |
822 void ContentViewCoreImpl::SelectPopupMenuItems(JNIEnv* env, jobject obj, | 822 void ContentViewCoreImpl::SelectPopupMenuItems( |
823 jintArray indices) { | 823 JNIEnv* env, |
| 824 jobject obj, |
| 825 jintArray indices) { |
824 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>( | 826 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>( |
825 web_contents_->GetRenderViewHost()); | 827 web_contents_->GetRenderViewHost()); |
826 DCHECK(rvhi); | 828 DCHECK(rvhi); |
827 if (indices == NULL) { | 829 if (indices == NULL) { |
828 rvhi->DidCancelPopupMenu(); | 830 rvhi->DidCancelPopupMenu(); |
829 return; | 831 return; |
830 } | 832 } |
831 | 833 |
832 int selected_count = env->GetArrayLength(indices); | 834 int selected_count = env->GetArrayLength(indices); |
833 std::vector<int> selected_indices; | 835 std::vector<int> selected_indices; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
888 params.referrer = content::Referrer( | 890 params.referrer = content::Referrer( |
889 GURL(ConvertJavaStringToUTF8(env, j_referrer_url)), | 891 GURL(ConvertJavaStringToUTF8(env, j_referrer_url)), |
890 static_cast<blink::WebReferrerPolicy>(referrer_policy)); | 892 static_cast<blink::WebReferrerPolicy>(referrer_policy)); |
891 } | 893 } |
892 | 894 |
893 params.is_renderer_initiated = is_renderer_initiated; | 895 params.is_renderer_initiated = is_renderer_initiated; |
894 | 896 |
895 LoadUrl(params); | 897 LoadUrl(params); |
896 } | 898 } |
897 | 899 |
898 ScopedJavaLocalRef<jstring> ContentViewCoreImpl::GetURL( | |
899 JNIEnv* env, jobject) const { | |
900 return ConvertUTF8ToJavaString(env, GetWebContents()->GetURL().spec()); | |
901 } | |
902 | |
903 jboolean ContentViewCoreImpl::IsIncognito(JNIEnv* env, jobject obj) { | |
904 return GetWebContents()->GetBrowserContext()->IsOffTheRecord(); | |
905 } | |
906 | |
907 WebContents* ContentViewCoreImpl::GetWebContents() const { | 900 WebContents* ContentViewCoreImpl::GetWebContents() const { |
908 return web_contents_; | 901 return web_contents_; |
909 } | 902 } |
910 | 903 |
911 void ContentViewCoreImpl::SetFocus(JNIEnv* env, jobject obj, jboolean focused) { | 904 void ContentViewCoreImpl::SetFocus(JNIEnv* env, jobject obj, jboolean focused) { |
912 SetFocusInternal(focused); | 905 SetFocusInternal(focused); |
913 } | 906 } |
914 | 907 |
915 void ContentViewCoreImpl::SetFocusInternal(bool focused) { | 908 void ContentViewCoreImpl::SetFocusInternal(bool focused) { |
916 if (!GetRenderWidgetHostViewAndroid()) | 909 if (!GetRenderWidgetHostViewAndroid()) |
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1492 static_cast<int>(x / dpi_scale()), | 1485 static_cast<int>(x / dpi_scale()), |
1493 static_cast<int>(y / dpi_scale()), | 1486 static_cast<int>(y / dpi_scale()), |
1494 static_cast<int>((width > 0 && width < dpi_scale()) ? | 1487 static_cast<int>((width > 0 && width < dpi_scale()) ? |
1495 1 : (int)(width / dpi_scale())), | 1488 1 : (int)(width / dpi_scale())), |
1496 static_cast<int>((height > 0 && height < dpi_scale()) ? | 1489 static_cast<int>((height > 0 && height < dpi_scale()) ? |
1497 1 : (int)(height / dpi_scale()))); | 1490 1 : (int)(height / dpi_scale()))); |
1498 GetWebContents()->Send(new ViewMsg_ExtractSmartClipData( | 1491 GetWebContents()->Send(new ViewMsg_ExtractSmartClipData( |
1499 GetWebContents()->GetRoutingID(), rect)); | 1492 GetWebContents()->GetRoutingID(), rect)); |
1500 } | 1493 } |
1501 | 1494 |
1502 void ContentViewCoreImpl::ResumeResponseDeferredAtStart(JNIEnv* env, | |
1503 jobject obj) { | |
1504 static_cast<WebContentsImpl*>(GetWebContents())-> | |
1505 ResumeResponseDeferredAtStart(); | |
1506 } | |
1507 | |
1508 void ContentViewCoreImpl::SetHasPendingNavigationTransitionForTesting( | |
1509 JNIEnv* env, | |
1510 jobject obj) { | |
1511 RenderFrameHost* frame = static_cast<WebContentsImpl*>(GetWebContents())-> | |
1512 GetMainFrame(); | |
1513 BrowserThread::PostTask( | |
1514 BrowserThread::IO, | |
1515 FROM_HERE, | |
1516 base::Bind( | |
1517 &TransitionRequestManager::SetHasPendingTransitionRequest, | |
1518 base::Unretained(TransitionRequestManager::GetInstance()), | |
1519 frame->GetProcess()->GetID(), | |
1520 frame->GetRoutingID(), | |
1521 true)); | |
1522 } | |
1523 | |
1524 jint ContentViewCoreImpl::GetCurrentRenderProcessId(JNIEnv* env, jobject obj) { | 1495 jint ContentViewCoreImpl::GetCurrentRenderProcessId(JNIEnv* env, jobject obj) { |
1525 return GetRenderProcessIdFromRenderViewHost( | 1496 return GetRenderProcessIdFromRenderViewHost( |
1526 web_contents_->GetRenderViewHost()); | 1497 web_contents_->GetRenderViewHost()); |
1527 } | 1498 } |
1528 | 1499 |
1529 void ContentViewCoreImpl::SetBackgroundOpaque(JNIEnv* env, jobject jobj, | 1500 void ContentViewCoreImpl::SetBackgroundOpaque(JNIEnv* env, jobject jobj, |
1530 jboolean opaque) { | 1501 jboolean opaque) { |
1531 if (GetRenderWidgetHostViewAndroid()) | 1502 if (GetRenderWidgetHostViewAndroid()) |
1532 GetRenderWidgetHostViewAndroid()->SetBackgroundOpaque(opaque); | 1503 GetRenderWidgetHostViewAndroid()->SetBackgroundOpaque(opaque); |
1533 } | 1504 } |
1534 | 1505 |
1535 void ContentViewCoreImpl::RequestTextSurroundingSelection( | 1506 void ContentViewCoreImpl::RequestTextSurroundingSelection( |
1536 int max_length, | 1507 int max_length, |
1537 const base::Callback< | 1508 const base::Callback< |
1538 void(const base::string16& content, int start_offset, int end_offset)>& | 1509 void(const base::string16& content, int start_offset, int end_offset)>& |
1539 callback) { | 1510 callback) { |
1540 DCHECK(!callback.is_null()); | 1511 DCHECK(!callback.is_null()); |
1541 RenderFrameHost* focused_frame = web_contents_->GetFocusedFrame(); | 1512 RenderFrameHost* focused_frame = web_contents_->GetFocusedFrame(); |
1542 if (!focused_frame) | 1513 if (!focused_frame) |
1543 return; | 1514 return; |
1544 if (GetRenderWidgetHostViewAndroid()) { | 1515 if (GetRenderWidgetHostViewAndroid()) { |
1545 GetRenderWidgetHostViewAndroid()->SetTextSurroundingSelectionCallback( | 1516 GetRenderWidgetHostViewAndroid()->SetTextSurroundingSelectionCallback( |
1546 callback); | 1517 callback); |
1547 focused_frame->Send(new FrameMsg_TextSurroundingSelectionRequest( | 1518 focused_frame->Send(new FrameMsg_TextSurroundingSelectionRequest( |
1548 focused_frame->GetRoutingID(), max_length)); | 1519 focused_frame->GetRoutingID(), max_length)); |
1549 } | 1520 } |
1550 } | 1521 } |
1551 | 1522 |
1552 void ContentViewCoreImpl::DidDeferAfterResponseStarted( | |
1553 const scoped_refptr<net::HttpResponseHeaders>& headers, | |
1554 const GURL& url) { | |
1555 JNIEnv* env = AttachCurrentThread(); | |
1556 ScopedJavaLocalRef<jobject> obj(java_ref_.get(env)); | |
1557 if (obj.is_null()) | |
1558 return; | |
1559 | |
1560 std::vector<GURL> entering_stylesheets; | |
1561 std::string transition_color; | |
1562 if (headers) { | |
1563 TransitionRequestManager::ParseTransitionStylesheetsFromHeaders( | |
1564 headers, entering_stylesheets, url); | |
1565 | |
1566 headers->EnumerateHeader( | |
1567 NULL, "X-Transition-Entering-Color", &transition_color); | |
1568 } | |
1569 | |
1570 ScopedJavaLocalRef<jstring> jstring_transition_color(ConvertUTF8ToJavaString( | |
1571 env, transition_color)); | |
1572 | |
1573 Java_ContentViewCore_didDeferAfterResponseStarted( | |
1574 env, obj.obj(), jstring_transition_color.obj()); | |
1575 | |
1576 std::vector<GURL>::const_iterator iter = entering_stylesheets.begin(); | |
1577 for (; iter != entering_stylesheets.end(); ++iter) { | |
1578 ScopedJavaLocalRef<jstring> jstring_url(ConvertUTF8ToJavaString( | |
1579 env, iter->spec())); | |
1580 Java_ContentViewCore_addEnteringStylesheetToTransition( | |
1581 env, obj.obj(), jstring_url.obj()); | |
1582 } | |
1583 } | |
1584 | |
1585 bool ContentViewCoreImpl::WillHandleDeferAfterResponseStarted() { | |
1586 JNIEnv* env = AttachCurrentThread(); | |
1587 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | |
1588 if (obj.is_null()) | |
1589 return false; | |
1590 | |
1591 return Java_ContentViewCore_willHandleDeferAfterResponseStarted(env, | |
1592 obj.obj()); | |
1593 } | |
1594 | |
1595 void ContentViewCoreImpl::DidStartNavigationTransitionForFrame(int64 frame_id) { | 1523 void ContentViewCoreImpl::DidStartNavigationTransitionForFrame(int64 frame_id) { |
1596 JNIEnv* env = AttachCurrentThread(); | 1524 JNIEnv* env = AttachCurrentThread(); |
1597 ScopedJavaLocalRef<jobject> obj(java_ref_.get(env)); | 1525 ScopedJavaLocalRef<jobject> obj(java_ref_.get(env)); |
1598 if (obj.is_null()) | 1526 if (obj.is_null()) |
1599 return; | 1527 return; |
1600 Java_ContentViewCore_didStartNavigationTransitionForFrame( | 1528 Java_ContentViewCore_didStartNavigationTransitionForFrame( |
1601 env, obj.obj(), frame_id); | 1529 env, obj.obj(), frame_id); |
1602 } | 1530 } |
1603 | 1531 |
1604 void ContentViewCoreImpl::OnSmartClipDataExtracted( | 1532 void ContentViewCoreImpl::OnSmartClipDataExtracted( |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1637 reinterpret_cast<ui::WindowAndroid*>(window_android), | 1565 reinterpret_cast<ui::WindowAndroid*>(window_android), |
1638 retained_objects_set); | 1566 retained_objects_set); |
1639 return reinterpret_cast<intptr_t>(view); | 1567 return reinterpret_cast<intptr_t>(view); |
1640 } | 1568 } |
1641 | 1569 |
1642 bool RegisterContentViewCore(JNIEnv* env) { | 1570 bool RegisterContentViewCore(JNIEnv* env) { |
1643 return RegisterNativesImpl(env); | 1571 return RegisterNativesImpl(env); |
1644 } | 1572 } |
1645 | 1573 |
1646 } // namespace content | 1574 } // namespace content |
OLD | NEW |