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

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: Removed setHasPendingNavigationTransitionForTesting from CVC. 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 582 matching lines...) Expand 10 before | Expand all | Expand 10 after
1505 static_cast<int>(x / dpi_scale()), 1497 static_cast<int>(x / dpi_scale()),
1506 static_cast<int>(y / dpi_scale()), 1498 static_cast<int>(y / dpi_scale()),
1507 static_cast<int>((width > 0 && width < dpi_scale()) ? 1499 static_cast<int>((width > 0 && width < dpi_scale()) ?
1508 1 : (int)(width / dpi_scale())), 1500 1 : (int)(width / dpi_scale())),
1509 static_cast<int>((height > 0 && height < dpi_scale()) ? 1501 static_cast<int>((height > 0 && height < dpi_scale()) ?
1510 1 : (int)(height / dpi_scale()))); 1502 1 : (int)(height / dpi_scale())));
1511 GetWebContents()->Send(new ViewMsg_ExtractSmartClipData( 1503 GetWebContents()->Send(new ViewMsg_ExtractSmartClipData(
1512 GetWebContents()->GetRoutingID(), rect)); 1504 GetWebContents()->GetRoutingID(), rect));
1513 } 1505 }
1514 1506
1515 void ContentViewCoreImpl::ResumeResponseDeferredAtStart(JNIEnv* env,
1516 jobject obj) {
1517 static_cast<WebContentsImpl*>(GetWebContents())->
1518 ResumeResponseDeferredAtStart();
1519 }
1520
1521 void ContentViewCoreImpl::SetHasPendingNavigationTransitionForTesting(
1522 JNIEnv* env,
1523 jobject obj) {
1524 CommandLine::ForCurrentProcess()->AppendSwitch(
1525 switches::kEnableExperimentalWebPlatformFeatures);
1526 RenderFrameHost* frame = static_cast<WebContentsImpl*>(GetWebContents())->
1527 GetMainFrame();
1528 BrowserThread::PostTask(
1529 BrowserThread::IO,
1530 FROM_HERE,
1531 base::Bind(
1532 &TransitionRequestManager::AddPendingTransitionRequestData,
1533 base::Unretained(TransitionRequestManager::GetInstance()),
1534 frame->GetProcess()->GetID(),
1535 frame->GetRoutingID(),
1536 "*", "", ""));
1537 }
1538
1539 jint ContentViewCoreImpl::GetCurrentRenderProcessId(JNIEnv* env, jobject obj) { 1507 jint ContentViewCoreImpl::GetCurrentRenderProcessId(JNIEnv* env, jobject obj) {
1540 return GetRenderProcessIdFromRenderViewHost( 1508 return GetRenderProcessIdFromRenderViewHost(
1541 web_contents_->GetRenderViewHost()); 1509 web_contents_->GetRenderViewHost());
1542 } 1510 }
1543 1511
1544 void ContentViewCoreImpl::SetBackgroundOpaque(JNIEnv* env, jobject jobj, 1512 void ContentViewCoreImpl::SetBackgroundOpaque(JNIEnv* env, jobject jobj,
1545 jboolean opaque) { 1513 jboolean opaque) {
1546 if (GetRenderWidgetHostViewAndroid()) 1514 if (GetRenderWidgetHostViewAndroid())
1547 GetRenderWidgetHostViewAndroid()->SetBackgroundOpaque(opaque); 1515 GetRenderWidgetHostViewAndroid()->SetBackgroundOpaque(opaque);
1548 } 1516 }
1549 1517
1550 void ContentViewCoreImpl::SetupTransitionView(
1551 JNIEnv* env, jobject jobj, jstring markup) {
1552 if (!GetWebContents()) return;
1553 GetWebContents()->GetMainFrame()->Send(new FrameMsg_SetupTransitionView(
1554 GetWebContents()->GetMainFrame()->GetRoutingID(),
1555 ConvertJavaStringToUTF8(env, markup)));
1556 }
1557
1558 void ContentViewCoreImpl::BeginExitTransition(
1559 JNIEnv* env, jobject jobj, jstring css_selector) {
1560 if (!GetWebContents()) return;
1561 GetWebContents()->GetMainFrame()->Send(new FrameMsg_BeginExitTransition(
1562 GetWebContents()->GetMainFrame()->GetRoutingID(),
1563 ConvertJavaStringToUTF8(env, css_selector)));
1564 }
1565
1566 void ContentViewCoreImpl::RequestTextSurroundingSelection( 1518 void ContentViewCoreImpl::RequestTextSurroundingSelection(
1567 int max_length, 1519 int max_length,
1568 const base::Callback< 1520 const base::Callback<
1569 void(const base::string16& content, int start_offset, int end_offset)>& 1521 void(const base::string16& content, int start_offset, int end_offset)>&
1570 callback) { 1522 callback) {
1571 DCHECK(!callback.is_null()); 1523 DCHECK(!callback.is_null());
1572 RenderFrameHost* focused_frame = web_contents_->GetFocusedFrame(); 1524 RenderFrameHost* focused_frame = web_contents_->GetFocusedFrame();
1573 if (!focused_frame) 1525 if (!focused_frame)
1574 return; 1526 return;
1575 if (GetRenderWidgetHostViewAndroid()) { 1527 if (GetRenderWidgetHostViewAndroid()) {
1576 GetRenderWidgetHostViewAndroid()->SetTextSurroundingSelectionCallback( 1528 GetRenderWidgetHostViewAndroid()->SetTextSurroundingSelectionCallback(
1577 callback); 1529 callback);
1578 focused_frame->Send(new FrameMsg_TextSurroundingSelectionRequest( 1530 focused_frame->Send(new FrameMsg_TextSurroundingSelectionRequest(
1579 focused_frame->GetRoutingID(), max_length)); 1531 focused_frame->GetRoutingID(), max_length));
1580 } 1532 }
1581 } 1533 }
1582 1534
1583 void ContentViewCoreImpl::DidDeferAfterResponseStarted(
1584 const TransitionLayerData& transition_data) {
1585 JNIEnv* env = AttachCurrentThread();
1586 ScopedJavaLocalRef<jobject> obj(java_ref_.get(env));
1587 if (obj.is_null())
1588 return;
1589
1590 std::vector<GURL> entering_stylesheets;
1591 std::string transition_color;
1592 if (transition_data.response_headers) {
1593 TransitionRequestManager::ParseTransitionStylesheetsFromHeaders(
1594 transition_data.response_headers, entering_stylesheets,
1595 transition_data.request_url);
1596
1597 transition_data.response_headers->EnumerateHeader(
1598 NULL, "X-Transition-Entering-Color", &transition_color);
1599 }
1600
1601 ScopedJavaLocalRef<jstring> jstring_markup(ConvertUTF8ToJavaString(
1602 env, transition_data.markup));
1603
1604 ScopedJavaLocalRef<jstring> jstring_css_selector(ConvertUTF8ToJavaString(
1605 env, transition_data.css_selector));
1606
1607 ScopedJavaLocalRef<jstring> jstring_transition_color(ConvertUTF8ToJavaString(
1608 env, transition_color));
1609
1610 Java_ContentViewCore_didDeferAfterResponseStarted(
1611 env, obj.obj(), jstring_markup.obj(), jstring_css_selector.obj(),
1612 jstring_transition_color.obj());
1613
1614 std::vector<GURL>::const_iterator iter = entering_stylesheets.begin();
1615 for (; iter != entering_stylesheets.end(); ++iter) {
1616 ScopedJavaLocalRef<jstring> jstring_url(ConvertUTF8ToJavaString(
1617 env, iter->spec()));
1618 Java_ContentViewCore_addEnteringStylesheetToTransition(
1619 env, obj.obj(), jstring_url.obj());
1620 }
1621 }
1622
1623 bool ContentViewCoreImpl::WillHandleDeferAfterResponseStarted() {
1624 JNIEnv* env = AttachCurrentThread();
1625 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
1626 if (obj.is_null())
1627 return false;
1628
1629 return Java_ContentViewCore_willHandleDeferAfterResponseStarted(env,
1630 obj.obj());
1631 }
1632
1633 void ContentViewCoreImpl::DidStartNavigationTransitionForFrame(int64 frame_id) {
1634 JNIEnv* env = AttachCurrentThread();
1635 ScopedJavaLocalRef<jobject> obj(java_ref_.get(env));
1636 if (obj.is_null())
1637 return;
1638 Java_ContentViewCore_didStartNavigationTransitionForFrame(
1639 env, obj.obj(), frame_id);
1640 }
1641
1642 void ContentViewCoreImpl::OnSmartClipDataExtracted( 1535 void ContentViewCoreImpl::OnSmartClipDataExtracted(
1643 const base::string16& text, 1536 const base::string16& text,
1644 const base::string16& html, 1537 const base::string16& html,
1645 const gfx::Rect& clip_rect) { 1538 const gfx::Rect& clip_rect) {
1646 JNIEnv* env = AttachCurrentThread(); 1539 JNIEnv* env = AttachCurrentThread();
1647 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 1540 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
1648 if (obj.is_null()) 1541 if (obj.is_null())
1649 return; 1542 return;
1650 ScopedJavaLocalRef<jstring> jtext = ConvertUTF16ToJavaString(env, text); 1543 ScopedJavaLocalRef<jstring> jtext = ConvertUTF16ToJavaString(env, text);
1651 ScopedJavaLocalRef<jstring> jhtml = ConvertUTF16ToJavaString(env, html); 1544 ScopedJavaLocalRef<jstring> jhtml = ConvertUTF16ToJavaString(env, html);
(...skipping 23 matching lines...) Expand all
1675 reinterpret_cast<ui::WindowAndroid*>(window_android), 1568 reinterpret_cast<ui::WindowAndroid*>(window_android),
1676 retained_objects_set); 1569 retained_objects_set);
1677 return reinterpret_cast<intptr_t>(view); 1570 return reinterpret_cast<intptr_t>(view);
1678 } 1571 }
1679 1572
1680 bool RegisterContentViewCore(JNIEnv* env) { 1573 bool RegisterContentViewCore(JNIEnv* env) {
1681 return RegisterNativesImpl(env); 1574 return RegisterNativesImpl(env);
1682 } 1575 }
1683 1576
1684 } // namespace content 1577 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/android/content_view_core_impl.h ('k') | content/browser/web_contents/web_contents_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698