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

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

Powered by Google App Engine
This is Rietveld 408576698