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

Side by Side Diff: content/browser/android/content_view_core_impl.cc

Issue 414423002: Removing ContentViewCore dependencies from few functions which acts as direct wrapper to WebContents (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Formatted native file changes to correct inclusion order. Created 6 years, 4 months 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
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 "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 807 matching lines...) Expand 10 before | Expand all | Expand 10 after
818 } 818 }
819 819
820 scoped_refptr<cc::Layer> ContentViewCoreImpl::GetLayer() const { 820 scoped_refptr<cc::Layer> ContentViewCoreImpl::GetLayer() const {
821 return root_layer_.get(); 821 return root_layer_.get();
822 } 822 }
823 823
824 // ---------------------------------------------------------------------------- 824 // ----------------------------------------------------------------------------
825 // Methods called from Java via JNI 825 // Methods called from Java via JNI
826 // ---------------------------------------------------------------------------- 826 // ----------------------------------------------------------------------------
827 827
828 void ContentViewCoreImpl::SelectPopupMenuItems(JNIEnv* env, jobject obj, 828 void ContentViewCoreImpl::SelectPopupMenuItems(JNIEnv* env,
829 jobject obj,
829 jintArray indices) { 830 jintArray indices) {
830 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>( 831 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(
831 web_contents_->GetRenderViewHost()); 832 web_contents_->GetRenderViewHost());
832 DCHECK(rvhi); 833 DCHECK(rvhi);
833 if (indices == NULL) { 834 if (indices == NULL) {
834 rvhi->DidCancelPopupMenu(); 835 rvhi->DidCancelPopupMenu();
835 return; 836 return;
836 } 837 }
837 838
838 int selected_count = env->GetArrayLength(indices); 839 int selected_count = env->GetArrayLength(indices);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
894 params.referrer = content::Referrer( 895 params.referrer = content::Referrer(
895 GURL(ConvertJavaStringToUTF8(env, j_referrer_url)), 896 GURL(ConvertJavaStringToUTF8(env, j_referrer_url)),
896 static_cast<blink::WebReferrerPolicy>(referrer_policy)); 897 static_cast<blink::WebReferrerPolicy>(referrer_policy));
897 } 898 }
898 899
899 params.is_renderer_initiated = is_renderer_initiated; 900 params.is_renderer_initiated = is_renderer_initiated;
900 901
901 LoadUrl(params); 902 LoadUrl(params);
902 } 903 }
903 904
904 ScopedJavaLocalRef<jstring> ContentViewCoreImpl::GetURL(
905 JNIEnv* env, jobject) const {
906 return ConvertUTF8ToJavaString(env, GetWebContents()->GetURL().spec());
907 }
908
909 jboolean ContentViewCoreImpl::IsIncognito(JNIEnv* env, jobject obj) {
910 return GetWebContents()->GetBrowserContext()->IsOffTheRecord();
911 }
912
913 WebContents* ContentViewCoreImpl::GetWebContents() const { 905 WebContents* ContentViewCoreImpl::GetWebContents() const {
914 return web_contents_; 906 return web_contents_;
915 } 907 }
916 908
917 void ContentViewCoreImpl::SetFocus(JNIEnv* env, jobject obj, jboolean focused) { 909 void ContentViewCoreImpl::SetFocus(JNIEnv* env, jobject obj, jboolean focused) {
918 SetFocusInternal(focused); 910 SetFocusInternal(focused);
919 } 911 }
920 912
921 void ContentViewCoreImpl::SetFocusInternal(bool focused) { 913 void ContentViewCoreImpl::SetFocusInternal(bool focused) {
922 if (!GetRenderWidgetHostViewAndroid()) 914 if (!GetRenderWidgetHostViewAndroid())
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after
1498 static_cast<int>(x / dpi_scale()), 1490 static_cast<int>(x / dpi_scale()),
1499 static_cast<int>(y / dpi_scale()), 1491 static_cast<int>(y / dpi_scale()),
1500 static_cast<int>((width > 0 && width < dpi_scale()) ? 1492 static_cast<int>((width > 0 && width < dpi_scale()) ?
1501 1 : (int)(width / dpi_scale())), 1493 1 : (int)(width / dpi_scale())),
1502 static_cast<int>((height > 0 && height < dpi_scale()) ? 1494 static_cast<int>((height > 0 && height < dpi_scale()) ?
1503 1 : (int)(height / dpi_scale()))); 1495 1 : (int)(height / dpi_scale())));
1504 GetWebContents()->Send(new ViewMsg_ExtractSmartClipData( 1496 GetWebContents()->Send(new ViewMsg_ExtractSmartClipData(
1505 GetWebContents()->GetRoutingID(), rect)); 1497 GetWebContents()->GetRoutingID(), rect));
1506 } 1498 }
1507 1499
1508 void ContentViewCoreImpl::ResumeResponseDeferredAtStart(JNIEnv* env,
1509 jobject obj) {
1510 static_cast<WebContentsImpl*>(GetWebContents())->
1511 ResumeResponseDeferredAtStart();
1512 }
1513
1514 void ContentViewCoreImpl::SetHasPendingNavigationTransitionForTesting(
1515 JNIEnv* env,
1516 jobject obj) {
1517 RenderFrameHost* frame = static_cast<WebContentsImpl*>(GetWebContents())->
1518 GetMainFrame();
1519 BrowserThread::PostTask(
1520 BrowserThread::IO,
1521 FROM_HERE,
1522 base::Bind(
1523 &TransitionRequestManager::SetHasPendingTransitionRequest,
1524 base::Unretained(TransitionRequestManager::GetInstance()),
1525 frame->GetProcess()->GetID(),
1526 frame->GetRoutingID(),
1527 true));
1528 }
1529
1530 jint ContentViewCoreImpl::GetCurrentRenderProcessId(JNIEnv* env, jobject obj) { 1500 jint ContentViewCoreImpl::GetCurrentRenderProcessId(JNIEnv* env, jobject obj) {
1531 return GetRenderProcessIdFromRenderViewHost( 1501 return GetRenderProcessIdFromRenderViewHost(
1532 web_contents_->GetRenderViewHost()); 1502 web_contents_->GetRenderViewHost());
1533 } 1503 }
1534 1504
1535 void ContentViewCoreImpl::SetBackgroundOpaque(JNIEnv* env, jobject jobj, 1505 void ContentViewCoreImpl::SetBackgroundOpaque(JNIEnv* env, jobject jobj,
1536 jboolean opaque) { 1506 jboolean opaque) {
1537 if (GetRenderWidgetHostViewAndroid()) 1507 if (GetRenderWidgetHostViewAndroid())
1538 GetRenderWidgetHostViewAndroid()->SetBackgroundOpaque(opaque); 1508 GetRenderWidgetHostViewAndroid()->SetBackgroundOpaque(opaque);
1539 } 1509 }
1540 1510
1541 void ContentViewCoreImpl::RequestTextSurroundingSelection( 1511 void ContentViewCoreImpl::RequestTextSurroundingSelection(
1542 int max_length, 1512 int max_length,
1543 const base::Callback< 1513 const base::Callback<
1544 void(const base::string16& content, int start_offset, int end_offset)>& 1514 void(const base::string16& content, int start_offset, int end_offset)>&
1545 callback) { 1515 callback) {
1546 DCHECK(!callback.is_null()); 1516 DCHECK(!callback.is_null());
1547 RenderFrameHost* focused_frame = web_contents_->GetFocusedFrame(); 1517 RenderFrameHost* focused_frame = web_contents_->GetFocusedFrame();
1548 if (!focused_frame) 1518 if (!focused_frame)
1549 return; 1519 return;
1550 if (GetRenderWidgetHostViewAndroid()) { 1520 if (GetRenderWidgetHostViewAndroid()) {
1551 GetRenderWidgetHostViewAndroid()->SetTextSurroundingSelectionCallback( 1521 GetRenderWidgetHostViewAndroid()->SetTextSurroundingSelectionCallback(
1552 callback); 1522 callback);
1553 focused_frame->Send(new FrameMsg_TextSurroundingSelectionRequest( 1523 focused_frame->Send(new FrameMsg_TextSurroundingSelectionRequest(
1554 focused_frame->GetRoutingID(), max_length)); 1524 focused_frame->GetRoutingID(), max_length));
1555 } 1525 }
1556 } 1526 }
1557 1527
1558 void ContentViewCoreImpl::DidDeferAfterResponseStarted(
1559 const scoped_refptr<net::HttpResponseHeaders>& headers,
1560 const GURL& url) {
1561 JNIEnv* env = AttachCurrentThread();
1562 ScopedJavaLocalRef<jobject> obj(java_ref_.get(env));
1563 if (obj.is_null())
1564 return;
1565
1566 std::vector<GURL> entering_stylesheets;
1567 std::string transition_color;
1568 if (headers) {
1569 TransitionRequestManager::ParseTransitionStylesheetsFromHeaders(
1570 headers, entering_stylesheets, url);
1571
1572 headers->EnumerateHeader(
1573 NULL, "X-Transition-Entering-Color", &transition_color);
1574 }
1575
1576 ScopedJavaLocalRef<jstring> jstring_transition_color(ConvertUTF8ToJavaString(
1577 env, transition_color));
1578
1579 Java_ContentViewCore_didDeferAfterResponseStarted(
1580 env, obj.obj(), jstring_transition_color.obj());
1581
1582 std::vector<GURL>::const_iterator iter = entering_stylesheets.begin();
1583 for (; iter != entering_stylesheets.end(); ++iter) {
1584 ScopedJavaLocalRef<jstring> jstring_url(ConvertUTF8ToJavaString(
1585 env, iter->spec()));
1586 Java_ContentViewCore_addEnteringStylesheetToTransition(
1587 env, obj.obj(), jstring_url.obj());
1588 }
1589 }
1590
1591 bool ContentViewCoreImpl::WillHandleDeferAfterResponseStarted() {
1592 JNIEnv* env = AttachCurrentThread();
1593 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
1594 if (obj.is_null())
1595 return false;
1596
1597 return Java_ContentViewCore_willHandleDeferAfterResponseStarted(env,
1598 obj.obj());
1599 }
1600
1601 void ContentViewCoreImpl::DidStartNavigationTransitionForFrame(int64 frame_id) {
1602 JNIEnv* env = AttachCurrentThread();
1603 ScopedJavaLocalRef<jobject> obj(java_ref_.get(env));
1604 if (obj.is_null())
1605 return;
1606 Java_ContentViewCore_didStartNavigationTransitionForFrame(
1607 env, obj.obj(), frame_id);
1608 }
1609
1610 void ContentViewCoreImpl::OnSmartClipDataExtracted( 1528 void ContentViewCoreImpl::OnSmartClipDataExtracted(
1611 const base::string16& text, 1529 const base::string16& text,
1612 const base::string16& html, 1530 const base::string16& html,
1613 const gfx::Rect& clip_rect) { 1531 const gfx::Rect& clip_rect) {
1614 JNIEnv* env = AttachCurrentThread(); 1532 JNIEnv* env = AttachCurrentThread();
1615 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 1533 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
1616 if (obj.is_null()) 1534 if (obj.is_null())
1617 return; 1535 return;
1618 ScopedJavaLocalRef<jstring> jtext = ConvertUTF16ToJavaString(env, text); 1536 ScopedJavaLocalRef<jstring> jtext = ConvertUTF16ToJavaString(env, text);
1619 ScopedJavaLocalRef<jstring> jhtml = ConvertUTF16ToJavaString(env, html); 1537 ScopedJavaLocalRef<jstring> jhtml = ConvertUTF16ToJavaString(env, html);
(...skipping 23 matching lines...) Expand all
1643 reinterpret_cast<ui::WindowAndroid*>(window_android), 1561 reinterpret_cast<ui::WindowAndroid*>(window_android),
1644 retained_objects_set); 1562 retained_objects_set);
1645 return reinterpret_cast<intptr_t>(view); 1563 return reinterpret_cast<intptr_t>(view);
1646 } 1564 }
1647 1565
1648 bool RegisterContentViewCore(JNIEnv* env) { 1566 bool RegisterContentViewCore(JNIEnv* env) {
1649 return RegisterNativesImpl(env); 1567 return RegisterNativesImpl(env);
1650 } 1568 }
1651 1569
1652 } // namespace content 1570 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698