content_view_core_impl.cc revision a36e5920737c6adbddd3e43b760e5de8431db6e0
1eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// Copyright 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/browser/android/content_view_core_impl.h" 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/android/jni_android.h" 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/android/jni_array.h" 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/android/jni_string.h" 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/android/scoped_java_ref.h" 112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/command_line.h" 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/json/json_writer.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/logging.h" 14868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/utf_string_conversions.h" 152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/values.h" 162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "cc/layers/layer.h" 177d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "cc/output/begin_frame_args.h" 187dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "content/browser/android/browser_media_player_manager.h" 192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/browser/android/interstitial_page_delegate_android.h" 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/browser/android/load_url_params.h" 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/browser/android/touch_point.h" 222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/browser/renderer_host/compositor_impl_android.h" 23bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch#include "content/browser/renderer_host/input/web_input_event_builders_android.h" 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/browser/renderer_host/java/java_bound_object.h" 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/browser/renderer_host/java/java_bridge_dispatcher_host_manager.h" 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/browser/renderer_host/render_view_host_impl.h" 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/browser/renderer_host/render_widget_host_impl.h" 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/browser/renderer_host/render_widget_host_view_android.h" 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/browser/ssl/ssl_host_state.h" 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/browser/web_contents/interstitial_page_impl.h" 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/browser/web_contents/navigation_controller_impl.h" 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/browser/web_contents/navigation_entry_impl.h" 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/browser/web_contents/web_contents_view_android.h" 34c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "content/common/input_messages.h" 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/common/view_messages.h" 36eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "content/public/browser/browser_accessibility_state.h" 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/browser_context.h" 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/favicon_status.h" 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_details.h" 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_service.h" 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_source.h" 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_types.h" 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/web_contents.h" 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/common/content_client.h" 452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/public/common/content_switches.h" 467dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "content/public/common/menu_item.h" 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/common/page_transition_types.h" 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "jni/ContentViewCore_jni.h" 497d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "third_party/WebKit/public/web/WebBindings.h" 507d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "third_party/WebKit/public/web/WebInputEvent.h" 51c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ui/android/view_android.h" 52c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ui/android/window_android.h" 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/android/java_bitmap.h" 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/screen.h" 552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/gfx/size_conversions.h" 562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/gfx/size_f.h" 5790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "webkit/common/user_agent/user_agent_util.h" 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using base::android::AttachCurrentThread; 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using base::android::ConvertJavaStringToUTF16; 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using base::android::ConvertJavaStringToUTF8; 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using base::android::ConvertUTF16ToJavaString; 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using base::android::ConvertUTF8ToJavaString; 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using base::android::ScopedJavaGlobalRef; 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using base::android::ScopedJavaLocalRef; 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using WebKit::WebGestureEvent; 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using WebKit::WebInputEvent; 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Describes the type and enabled state of a select popup item. 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Keep in sync with the value defined in SelectPopupDialog.java 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)enum PopupItemType { 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) POPUP_ITEM_TYPE_GROUP = 0, 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) POPUP_ITEM_TYPE_DISABLED, 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) POPUP_ITEM_TYPE_ENABLED 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace content { 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace { 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 817d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)const unsigned int kDefaultVSyncIntervalMicros = 16666u; 827d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// TODO(brianderson): Use adaptive draw-time estimation. 837d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)const float kDefaultBrowserCompositeVSyncFraction = 1.0f / 3; 847d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const void* kContentViewUserDataKey = &kContentViewUserDataKey; 862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)int GetRenderProcessIdFromRenderViewHost(RenderViewHost* host) { 882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(host); 892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) RenderProcessHost* render_process = host->GetProcess(); 902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(render_process); 912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (render_process->HasConnection()) 922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return render_process->GetHandle(); 932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) else 942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return 0; 952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)ScopedJavaLocalRef<jobject> CreateJavaRect( 982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) JNIEnv* env, 992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const gfx::Rect& rect) { 1002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return ScopedJavaLocalRef<jobject>( 1012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Java_ContentViewCore_createRect(env, 1022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static_cast<int>(rect.x()), 1032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static_cast<int>(rect.y()), 1042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static_cast<int>(rect.right()), 1052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static_cast<int>(rect.bottom()))); 1062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Enables a callback when the underlying WebContents is destroyed, to enable 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// nulling the back-pointer. 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ContentViewCoreImpl::ContentViewUserData 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : public base::SupportsUserData::Data { 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) explicit ContentViewUserData(ContentViewCoreImpl* content_view_core) 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : content_view_core_(content_view_core) { 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~ContentViewUserData() { 1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // TODO(joth): When chrome has finished removing the TabContents class (see 1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // crbug.com/107201) consider inverting relationship, so ContentViewCore 1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // would own WebContents. That effectively implies making the WebContents 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // destructor private on Android. 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) delete content_view_core_; 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ContentViewCoreImpl* get() const { return content_view_core_; } 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Not using scoped_ptr as ContentViewCoreImpl destructor is private. 1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ContentViewCoreImpl* content_view_core_; 1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_IMPLICIT_CONSTRUCTORS(ContentViewUserData); 1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static 1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ContentViewCoreImpl* ContentViewCoreImpl::FromWebContents( 1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::WebContents* web_contents) { 1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ContentViewCoreImpl::ContentViewUserData* data = 1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) reinterpret_cast<ContentViewCoreImpl::ContentViewUserData*>( 1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) web_contents->GetUserData(kContentViewUserDataKey)); 1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return data ? data->get() : NULL; 1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static 1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ContentViewCore* ContentViewCore::FromWebContents( 1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::WebContents* web_contents) { 1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return ContentViewCoreImpl::FromWebContents(web_contents); 1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// static 1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ContentViewCore* ContentViewCore::GetNativeContentViewCore(JNIEnv* env, 1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) jobject obj) { 1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return reinterpret_cast<ContentViewCore*>( 1542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Java_ContentViewCore_getNativeContentViewCore(env, obj)); 1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ContentViewCoreImpl::ContentViewCoreImpl(JNIEnv* env, jobject obj, 1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool hardware_accelerated, 1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WebContents* web_contents, 160c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ui::ViewAndroid* view_android, 1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui::WindowAndroid* window_android) 1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : java_ref_(env, obj), 1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) web_contents_(static_cast<WebContentsImpl*>(web_contents)), 1642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) root_layer_(cc::Layer::Create()), 1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) tab_crashed_(false), 1667d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) vsync_interval_(base::TimeDelta::FromMicroseconds( 1677d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) kDefaultVSyncIntervalMicros)), 1687d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) expected_browser_composite_time_(base::TimeDelta::FromMicroseconds( 1697d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) kDefaultVSyncIntervalMicros * kDefaultBrowserCompositeVSyncFraction)), 170c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) view_android_(view_android), 1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_android_(window_android) { 1722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CHECK(web_contents) << 1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "A ContentViewCoreImpl should be created with a valid WebContents."; 1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // When a tab is restored (from a saved state), it does not have a renderer 176eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // process. We treat it like the tab is crashed. If the content is loaded 177eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // when the tab is shown, tab_crashed_ will be reset. 178eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch UpdateTabCrashedFlag(); 1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // TODO(leandrogracia): make use of the hardware_accelerated argument. 1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const gfx::Display& display = 1832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); 1842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) dpi_scale_ = display.device_scale_factor(); 1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Currently, the only use case we have for overriding a user agent involves 1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // spoofing a desktop Linux user agent for "Request desktop site". 1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Automatically set it for all WebContents so that it is available when a 1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // NavigationEntry requires the user agent to be overridden. 1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char kLinuxInfoStr[] = "X11; Linux x86_64"; 1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string product = content::GetContentClient()->GetProduct(); 1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string spoofed_ua = 1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) webkit_glue::BuildUserAgentFromOSAndProduct(kLinuxInfoStr, product); 1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) web_contents->SetUserAgentOverride(spoofed_ua); 1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) InitWebContents(); 1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ContentViewCoreImpl::~ContentViewCoreImpl() { 2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) JNIEnv* env = base::android::AttachCurrentThread(); 2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); 2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) java_ref_.reset(); 2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!j_obj.is_null()) { 2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Java_ContentViewCore_onNativeContentViewCoreDestroyed( 2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) env, j_obj.obj(), reinterpret_cast<jint>(this)); 2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Make sure nobody calls back into this object while we are tearing things 2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // down. 2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) notification_registrar_.RemoveAll(); 2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::OnJavaContentViewCoreDestroyed(JNIEnv* env, 2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) jobject obj) { 2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(env->IsSameObject(java_ref_.get(env).obj(), obj)); 2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) java_ref_.reset(); 2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::InitWebContents() { 2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(web_contents_); 2202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) notification_registrar_.Add( 2212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) this, NOTIFICATION_RENDER_VIEW_HOST_CHANGED, 2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Source<NavigationController>(&web_contents_->GetController())); 2232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) notification_registrar_.Add( 2242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) this, NOTIFICATION_RENDERER_PROCESS_CREATED, 2252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::NotificationService::AllBrowserContextsAndSources()); 2262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) notification_registrar_.Add( 2272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) this, NOTIFICATION_WEB_CONTENTS_CONNECTED, 2282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Source<WebContents>(web_contents_)); 229c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) notification_registrar_.Add( 230c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) this, NOTIFICATION_WEB_CONTENTS_SWAPPED, 231c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) Source<WebContents>(web_contents_)); 2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static_cast<WebContentsViewAndroid*>(web_contents_->GetView())-> 2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SetContentViewCore(this); 2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(!web_contents_->GetUserData(kContentViewUserDataKey)); 2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) web_contents_->SetUserData(kContentViewUserDataKey, 2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) new ContentViewUserData(this)); 2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::Observe(int type, 2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const NotificationSource& source, 2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const NotificationDetails& details) { 2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) switch (type) { 2442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) case NOTIFICATION_RENDER_VIEW_HOST_CHANGED: { 2452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::pair<RenderViewHost*, RenderViewHost*>* switched_details = 2462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Details<std::pair<RenderViewHost*, RenderViewHost*> >(details).ptr(); 2472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int old_pid = 0; 2482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (switched_details->first) { 2492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) old_pid = GetRenderProcessIdFromRenderViewHost( 2502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) switched_details->first); 2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int new_pid = GetRenderProcessIdFromRenderViewHost( 2532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) web_contents_->GetRenderViewHost()); 2542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (new_pid != old_pid) { 2552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Notify the Java side of the change of the current renderer process. 2562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) JNIEnv* env = AttachCurrentThread(); 2572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 2582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (!obj.is_null()) { 2592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Java_ContentViewCore_onRenderProcessSwap( 2602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) env, obj.obj(), old_pid, new_pid); 2612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 2622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 2632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) break; 2642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 2652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) case NOTIFICATION_RENDERER_PROCESS_CREATED: { 2662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Notify the Java side of the current renderer process. 2672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) RenderProcessHost* source_process_host = 2682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Source<RenderProcessHost>(source).ptr(); 2692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) RenderProcessHost* current_process_host = 2702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) web_contents_->GetRenderViewHost()->GetProcess(); 2712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (source_process_host == current_process_host) { 2732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int pid = GetRenderProcessIdFromRenderViewHost( 2742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) web_contents_->GetRenderViewHost()); 2752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) JNIEnv* env = AttachCurrentThread(); 2762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 2772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (!obj.is_null()) { 2782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Java_ContentViewCore_onRenderProcessSwap(env, obj.obj(), 0, pid); 2792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 2802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 2812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) break; 2822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 2832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) case NOTIFICATION_WEB_CONTENTS_CONNECTED: { 2842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) JNIEnv* env = AttachCurrentThread(); 2852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 2862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (!obj.is_null()) { 2872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Java_ContentViewCore_onWebContentsConnected(env, obj.obj()); 2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) break; 2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 291c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) case NOTIFICATION_WEB_CONTENTS_SWAPPED: { 292c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) JNIEnv* env = AttachCurrentThread(); 293c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 294c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (!obj.is_null()) { 295c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) Java_ContentViewCore_onWebContentsSwapped(env, obj.obj()); 296c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 297c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)RenderWidgetHostViewAndroid* 3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ContentViewCoreImpl::GetRenderWidgetHostViewAndroid() { 3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RenderWidgetHostView* rwhv = NULL; 3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (web_contents_) { 3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) rwhv = web_contents_->GetRenderWidgetHostView(); 3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (web_contents_->ShowingInterstitialPage()) { 3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) rwhv = static_cast<InterstitialPageImpl*>( 3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) web_contents_->GetInterstitialPage())-> 3095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetRenderViewHost()->GetView(); 3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return static_cast<RenderWidgetHostViewAndroid*>(rwhv); 3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ScopedJavaLocalRef<jobject> ContentViewCoreImpl::GetJavaObject() { 3165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) JNIEnv* env = AttachCurrentThread(); 3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return java_ref_.get(env); 3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)jint ContentViewCoreImpl::GetBackgroundColor(JNIEnv* env, jobject obj) { 3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid(); 3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!rwhva) 3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return SK_ColorWHITE; 3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return rwhva->GetCachedBackgroundColor(); 3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::OnHide(JNIEnv* env, jobject obj) { 3285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Hide(); 3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::OnShow(JNIEnv* env, jobject obj) { 3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Show(); 3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::Show() { 3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetWebContents()->WasShown(); 337eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Displaying WebContents may trigger a lazy reload, spawning a new renderer 338eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // for the tab. 339eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch UpdateTabCrashedFlag(); 3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::Hide() { 3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetWebContents()->WasHidden(); 3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::OnTabCrashed() { 347c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) JNIEnv* env = AttachCurrentThread(); 348c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 349c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (obj.is_null()) 350c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) return; 351c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) Java_ContentViewCore_resetVSyncNotification(env, obj.obj()); 352c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 353eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // If |tab_crashed_| is already true, just return. e.g. if two tabs share the 3545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // render process, this will be called for each tab when the render process 3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // crashed. If user reload one tab, a new render process is created. It can be 3565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // shared by the other tab. But if user closes the tab before reload the other 3575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // tab, the new render process will be shut down. This will trigger the other 3585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // tab's OnTabCrashed() called again as two tabs share the same 3595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // BrowserRenderProcessHost. 3605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (tab_crashed_) 3615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 3625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) tab_crashed_ = true; 3635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Java_ContentViewCore_onTabCrash(env, obj.obj()); 3645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// All positions and sizes are in CSS pixels. 3672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Note that viewport_width/height is a best effort based. 3682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// ContentViewCore has the actual information about the physical viewport size. 3692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ContentViewCoreImpl::UpdateFrameInfo( 3702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const gfx::Vector2dF& scroll_offset, 3712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) float page_scale_factor, 3722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const gfx::Vector2dF& page_scale_factor_limits, 3732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const gfx::SizeF& content_size, 3742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const gfx::SizeF& viewport_size, 3752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const gfx::Vector2dF& controls_offset, 376c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const gfx::Vector2dF& content_offset, 377c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) float overdraw_bottom_height) { 3785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) JNIEnv* env = AttachCurrentThread(); 3795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 3805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (obj.is_null()) 3815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 3825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Java_ContentViewCore_updateFrameInfo( 3842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) env, obj.obj(), 3852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scroll_offset.x(), 3862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scroll_offset.y(), 3872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) page_scale_factor, 3882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) page_scale_factor_limits.x(), 3892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) page_scale_factor_limits.y(), 3902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content_size.width(), 3912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content_size.height(), 3922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) viewport_size.width(), 3932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) viewport_size.height(), 3942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) controls_offset.y(), 395c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) content_offset.y(), 396c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) overdraw_bottom_height); 3975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ContentViewCoreImpl::SetTitle(const string16& title) { 4005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) JNIEnv* env = AttachCurrentThread(); 4015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 4025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (obj.is_null()) 4035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 4042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ScopedJavaLocalRef<jstring> jtitle = 4052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ConvertUTF8ToJavaString(env, UTF16ToUTF8(title)); 4062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Java_ContentViewCore_setTitle(env, obj.obj(), jtitle.obj()); 4075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ContentViewCoreImpl::OnBackgroundColorChanged(SkColor color) { 4105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) JNIEnv* env = AttachCurrentThread(); 4115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 4125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (obj.is_null()) 4135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 4142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Java_ContentViewCore_onBackgroundColorChanged(env, obj.obj(), color); 4155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::ShowSelectPopupMenu( 4187dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch const std::vector<MenuItem>& items, int selected_item, bool multiple) { 4195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) JNIEnv* env = AttachCurrentThread(); 4205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); 4215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (j_obj.is_null()) 4225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 4235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // For multi-select list popups we find the list of previous selections by 4255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // iterating through the items. But for single selection popups we take the 4265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // given |selected_item| as is. 4275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ScopedJavaLocalRef<jintArray> selected_array; 4285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (multiple) { 429c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) scoped_ptr<jint[]> native_selected_array(new jint[items.size()]); 4305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) size_t selected_count = 0; 4315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (size_t i = 0; i < items.size(); ++i) { 4325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (items[i].checked) 4335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) native_selected_array[selected_count++] = i; 4345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4367dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch selected_array = ScopedJavaLocalRef<jintArray>( 4377dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch env, env->NewIntArray(selected_count)); 4385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) env->SetIntArrayRegion(selected_array.obj(), 0, selected_count, 4395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) native_selected_array.get()); 4405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } else { 4417dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch selected_array = ScopedJavaLocalRef<jintArray>(env, env->NewIntArray(1)); 4425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) jint value = selected_item; 4435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) env->SetIntArrayRegion(selected_array.obj(), 0, 1, &value); 4445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ScopedJavaLocalRef<jintArray> enabled_array(env, 4475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) env->NewIntArray(items.size())); 4485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::vector<string16> labels; 4495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) labels.reserve(items.size()); 4505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (size_t i = 0; i < items.size(); ++i) { 4515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) labels.push_back(items[i].label); 4525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) jint enabled = 4537dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch (items[i].type == MenuItem::GROUP ? POPUP_ITEM_TYPE_GROUP : 4545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) (items[i].enabled ? POPUP_ITEM_TYPE_ENABLED : 4555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) POPUP_ITEM_TYPE_DISABLED)); 4565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) env->SetIntArrayRegion(enabled_array.obj(), i, 1, &enabled); 4575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ScopedJavaLocalRef<jobjectArray> items_array( 4595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::android::ToJavaArrayOfStrings(env, labels)); 4605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Java_ContentViewCore_showSelectPopup(env, j_obj.obj(), 4615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) items_array.obj(), enabled_array.obj(), 4625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) multiple, selected_array.obj()); 4635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ContentViewCoreImpl::ConfirmTouchEvent(InputEventAckState ack_result) { 4665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) JNIEnv* env = AttachCurrentThread(); 4675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); 4685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (j_obj.is_null()) 4695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 4702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Java_ContentViewCore_confirmTouchEvent(env, j_obj.obj(), 4712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static_cast<jint>(ack_result)); 4725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 474a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)void ContentViewCoreImpl::UnhandledFlingStartEvent() { 475a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) JNIEnv* env = AttachCurrentThread(); 476a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); 477a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) if (j_obj.is_null()) 478a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) return; 479a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) Java_ContentViewCore_unhandledFlingStartEvent(env, j_obj.obj()); 480a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)} 481a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 4825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::HasTouchEventHandlers(bool need_touch_events) { 4835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) JNIEnv* env = AttachCurrentThread(); 4845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); 4855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (j_obj.is_null()) 4865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 4875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Java_ContentViewCore_hasTouchEventHandlers(env, 4885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) j_obj.obj(), 4895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) need_touch_events); 4905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool ContentViewCoreImpl::HasFocus() { 4935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) JNIEnv* env = AttachCurrentThread(); 4945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 4955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (obj.is_null()) 4965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 4975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return Java_ContentViewCore_hasFocus(env, obj.obj()); 4985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::OnSelectionChanged(const std::string& text) { 5015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) JNIEnv* env = AttachCurrentThread(); 5025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 5035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (obj.is_null()) 5045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 5055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ScopedJavaLocalRef<jstring> jtext = ConvertUTF8ToJavaString(env, text); 5065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Java_ContentViewCore_onSelectionChanged(env, obj.obj(), jtext.obj()); 5075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::OnSelectionBoundsChanged( 5102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const ViewHostMsg_SelectionBounds_Params& params) { 5115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) JNIEnv* env = AttachCurrentThread(); 5125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 5135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (obj.is_null()) 5145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 5152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ScopedJavaLocalRef<jobject> anchor_rect_dip( 5162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CreateJavaRect(env, params.anchor_rect)); 5172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ScopedJavaLocalRef<jobject> focus_rect_dip( 5182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CreateJavaRect(env, params.focus_rect)); 5195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Java_ContentViewCore_onSelectionBoundsChanged(env, obj.obj(), 5202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) anchor_rect_dip.obj(), 5212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) params.anchor_dir, 5222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) focus_rect_dip.obj(), 5232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) params.focus_dir, 5242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) params.is_anchor_first); 5255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ContentViewCoreImpl::ShowPastePopup(int x_dip, int y_dip) { 5285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) JNIEnv* env = AttachCurrentThread(); 5295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 5305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (obj.is_null()) 5315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 5322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Java_ContentViewCore_showPastePopup(env, obj.obj(), 5332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static_cast<jint>(x_dip), 5342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static_cast<jint>(y_dip)); 5355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)unsigned int ContentViewCoreImpl::GetScaledContentTexture( 5382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) float scale, 5392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Size* out_size) { 5405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); 5415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!view) 5425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return 0; 5435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return view->GetScaledContentTexture(scale, out_size); 5452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 5462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::StartContentIntent(const GURL& content_url) { 5485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) JNIEnv* env = AttachCurrentThread(); 5495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); 5505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (j_obj.is_null()) 5515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 5525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ScopedJavaLocalRef<jstring> jcontent_url = 5535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ConvertUTF8ToJavaString(env, content_url.spec()); 5545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Java_ContentViewCore_startContentIntent(env, 5555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) j_obj.obj(), 5565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) jcontent_url.obj()); 5575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::ShowDisambiguationPopup( 5605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const gfx::Rect& target_rect, 5615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const SkBitmap& zoomed_bitmap) { 5625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) JNIEnv* env = AttachCurrentThread(); 5635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 5655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (obj.is_null()) 5665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 5675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ScopedJavaLocalRef<jobject> rect_object(CreateJavaRect(env, target_rect)); 5695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ScopedJavaLocalRef<jobject> java_bitmap = 5715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::ConvertToJavaBitmap(&zoomed_bitmap); 5725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(!java_bitmap.is_null()); 5735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Java_ContentViewCore_showDisambiguationPopup(env, 5755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) obj.obj(), 5765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) rect_object.obj(), 5775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) java_bitmap.obj()); 5785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 580b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)ScopedJavaLocalRef<jobject> ContentViewCoreImpl::CreateSmoothScroller( 581b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) bool scroll_down, int mouse_event_x, int mouse_event_y) { 5822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) JNIEnv* env = AttachCurrentThread(); 5832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 5852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (obj.is_null()) 586b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) return ScopedJavaLocalRef<jobject>(); 587b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) return Java_ContentViewCore_createSmoothScroller( 588b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) env, obj.obj(), scroll_down, mouse_event_x, mouse_event_y); 5892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 5902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 591b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)void ContentViewCoreImpl::NotifyExternalSurface( 592b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) int player_id, bool is_request, const gfx::RectF& rect) { 593c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) JNIEnv* env = AttachCurrentThread(); 594c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 595c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 596c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (obj.is_null()) 597c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) return; 598c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 599b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) Java_ContentViewCore_notifyExternalSurface( 600b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) env, 601b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) obj.obj(), 602b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) static_cast<jint>(player_id), 603b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) static_cast<jboolean>(is_request), 604b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) static_cast<jfloat>(rect.x()), 605b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) static_cast<jfloat>(rect.y()), 606b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) static_cast<jfloat>(rect.width()), 607b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) static_cast<jfloat>(rect.height())); 608c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 609c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 610868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)ScopedJavaLocalRef<jobject> ContentViewCoreImpl::GetContentVideoViewClient() { 611868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) JNIEnv* env = AttachCurrentThread(); 612868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 613868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 614868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (obj.is_null()) 615868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) return ScopedJavaLocalRef<jobject>(); 616868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 617868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) return Java_ContentViewCore_getContentVideoViewClient(env, obj.obj()); 618868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 619868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 620868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)ScopedJavaLocalRef<jobject> ContentViewCoreImpl::GetContext() { 621868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) JNIEnv* env = AttachCurrentThread(); 622868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 623868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 624868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (obj.is_null()) 625868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) return ScopedJavaLocalRef<jobject>(); 626868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 627868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) return Java_ContentViewCore_getContext(env, obj.obj()); 628868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 629868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 6302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)gfx::Size ContentViewCoreImpl::GetPhysicalBackingSize() const { 6312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) JNIEnv* env = AttachCurrentThread(); 6322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); 6332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (j_obj.is_null()) 6342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return gfx::Size(); 6352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return gfx::Size( 6362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Java_ContentViewCore_getPhysicalBackingWidthPix(env, j_obj.obj()), 6372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Java_ContentViewCore_getPhysicalBackingHeightPix(env, j_obj.obj())); 6382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)gfx::Size ContentViewCoreImpl::GetViewportSizePix() const { 6412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) JNIEnv* env = AttachCurrentThread(); 6422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); 6432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (j_obj.is_null()) 6442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return gfx::Size(); 645c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) return gfx::Size( 646c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) Java_ContentViewCore_getViewportWidthPix(env, j_obj.obj()), 647c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) Java_ContentViewCore_getViewportHeightPix(env, j_obj.obj())); 648c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 649c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 650c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)gfx::Size ContentViewCoreImpl::GetViewportSizeOffsetPix() const { 651c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) JNIEnv* env = AttachCurrentThread(); 652c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); 653c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (j_obj.is_null()) 654c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) return gfx::Size(); 655c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) return gfx::Size( 656c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) Java_ContentViewCore_getViewportSizeOffsetWidthPix(env, j_obj.obj()), 657c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) Java_ContentViewCore_getViewportSizeOffsetHeightPix(env, j_obj.obj())); 6582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)gfx::Size ContentViewCoreImpl::GetViewportSizeDip() const { 6612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return gfx::ToCeiledSize( 6622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::ScaleSize(GetViewportSizePix(), 1.0f / GetDpiScale())); 6632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 665c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)gfx::Size ContentViewCoreImpl::GetViewportSizeOffsetDip() const { 666c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) return gfx::ToCeiledSize( 667c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) gfx::ScaleSize(GetViewportSizeOffsetPix(), 1.0f / GetDpiScale())); 668c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 669c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 6702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)float ContentViewCoreImpl::GetOverdrawBottomHeightDip() const { 6715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) JNIEnv* env = AttachCurrentThread(); 6725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); 6735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (j_obj.is_null()) 6742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return 0.f; 6752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return Java_ContentViewCore_getOverdrawBottomHeightPix(env, j_obj.obj()) 6762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) / GetDpiScale(); 6772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ContentViewCoreImpl::AttachLayer(scoped_refptr<cc::Layer> layer) { 6802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) root_layer_->AddChild(layer); 6812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ContentViewCoreImpl::RemoveLayer(scoped_refptr<cc::Layer> layer) { 6842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) layer->RemoveFromParent(); 6852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::LoadUrl( 6885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NavigationController::LoadURLParams& params) { 6895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetWebContents()->GetController().LoadURLWithParams(params); 690eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch UpdateTabCrashedFlag(); 6915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6937d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)void ContentViewCoreImpl::SetNeedsBeginFrame(bool enabled) { 694c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) JNIEnv* env = AttachCurrentThread(); 695c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 696c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (obj.is_null()) 697c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) return; 698c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) Java_ContentViewCore_setVSyncNotificationEnabled( 699c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) env, obj.obj(), static_cast<jboolean>(enabled)); 700c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 701c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 70290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)void ContentViewCoreImpl::SetNeedsAnimate() { 70390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) JNIEnv* env = AttachCurrentThread(); 70490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 70590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) if (obj.is_null()) 70690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return; 70790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) Java_ContentViewCore_setNeedsAnimate(env, obj.obj()); 70890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 70990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 710c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)ui::ViewAndroid* ContentViewCoreImpl::GetViewAndroid() const { 711c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // view_android_ should never be null for Chrome. 712c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) DCHECK(view_android_); 713c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) return view_android_; 714c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 715c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 7162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)ui::WindowAndroid* ContentViewCoreImpl::GetWindowAndroid() const { 717c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // This should never be NULL for Chrome, but will be NULL for WebView. 718c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) DCHECK(window_android_); 7195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return window_android_; 7205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)scoped_refptr<cc::Layer> ContentViewCoreImpl::GetLayer() const { 7232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return root_layer_.get(); 7242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 7252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// ---------------------------------------------------------------------------- 7275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Methods called from Java via JNI 7285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// ---------------------------------------------------------------------------- 7295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::SelectPopupMenuItems(JNIEnv* env, jobject obj, 7315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) jintArray indices) { 7325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>( 7335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) web_contents_->GetRenderViewHost()); 7345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(rvhi); 7355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (indices == NULL) { 7365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) rvhi->DidCancelPopupMenu(); 7375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 7385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 7395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int selected_count = env->GetArrayLength(indices); 7415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::vector<int> selected_indices; 7425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) jint* indices_ptr = env->GetIntArrayElements(indices, NULL); 7435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (int i = 0; i < selected_count; ++i) 7445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) selected_indices.push_back(indices_ptr[i]); 7455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) env->ReleaseIntArrayElements(indices, indices_ptr, JNI_ABORT); 7465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) rvhi->DidSelectPopupMenuItems(selected_indices); 7475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::LoadUrl( 7505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) JNIEnv* env, jobject obj, 7515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) jstring url, 7525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) jint load_url_type, 7535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) jint transition_type, 7545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) jint ua_override_option, 7555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) jstring extra_headers, 7565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) jbyteArray post_data, 7575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) jstring base_url_for_data_url, 7585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) jstring virtual_url_for_data_url, 7595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) jboolean can_load_local_resources) { 7605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(url); 7615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NavigationController::LoadURLParams params( 7625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL(ConvertJavaStringToUTF8(env, url))); 7635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) params.load_type = static_cast<NavigationController::LoadURLType>( 7655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) load_url_type); 7665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) params.transition_type = PageTransitionFromInt(transition_type); 7675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) params.override_user_agent = 7685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static_cast<NavigationController::UserAgentOverrideOption>( 7695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ua_override_option); 7705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (extra_headers) 7725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) params.extra_headers = ConvertJavaStringToUTF8(env, extra_headers); 7735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (post_data) { 7755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::vector<uint8> http_body_vector; 7762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::android::JavaByteArrayToByteVector(env, post_data, &http_body_vector); 7775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) params.browser_initiated_post_data = 7785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::RefCountedBytes::TakeVector(&http_body_vector); 7795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 7805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (base_url_for_data_url) { 7825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) params.base_url_for_data_url = 7835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL(ConvertJavaStringToUTF8(env, base_url_for_data_url)); 7845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 7855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (virtual_url_for_data_url) { 7875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) params.virtual_url_for_data_url = 7885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL(ConvertJavaStringToUTF8(env, virtual_url_for_data_url)); 7895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 7905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) params.can_load_local_resources = can_load_local_resources; 7925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoadUrl(params); 7945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)jint ContentViewCoreImpl::GetCurrentRenderProcessId(JNIEnv* env, jobject obj) { 7972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return GetRenderProcessIdFromRenderViewHost( 7982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) web_contents_->GetRenderViewHost()); 7995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 8005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ScopedJavaLocalRef<jstring> ContentViewCoreImpl::GetURL( 8025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) JNIEnv* env, jobject) const { 803868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // The current users of the Java API expect to use the active entry 804868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // rather than the visible entry, which is exposed by WebContents::GetURL. 805868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) content::NavigationEntry* entry = 806868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) web_contents_->GetController().GetActiveEntry(); 807868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) GURL url = entry ? entry->GetVirtualURL() : GURL::EmptyGURL(); 808868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) return ConvertUTF8ToJavaString(env, url.spec()); 8095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 8105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ScopedJavaLocalRef<jstring> ContentViewCoreImpl::GetTitle( 8125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) JNIEnv* env, jobject obj) const { 8135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return ConvertUTF16ToJavaString(env, GetWebContents()->GetTitle()); 8145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 8155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)jboolean ContentViewCoreImpl::IsIncognito(JNIEnv* env, jobject obj) { 8175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return GetWebContents()->GetBrowserContext()->IsOffTheRecord(); 8185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 8195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)WebContents* ContentViewCoreImpl::GetWebContents() const { 8215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return web_contents_; 8225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 8235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::SetFocus(JNIEnv* env, jobject obj, jboolean focused) { 8255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!GetRenderWidgetHostViewAndroid()) 8265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 8275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (focused) 8295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetRenderWidgetHostViewAndroid()->Focus(); 8305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) else 8315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetRenderWidgetHostViewAndroid()->Blur(); 8325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 8335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::SendOrientationChangeEvent(JNIEnv* env, 8355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) jobject obj, 8365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) jint orientation) { 8375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); 8385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (rwhv) 8395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) rwhv->UpdateScreenInfo(rwhv->GetNativeView()); 8405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>( 8425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) web_contents_->GetRenderViewHost()); 8435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) rvhi->SendOrientationChangeEvent(orientation); 8445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 8455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)jboolean ContentViewCoreImpl::SendTouchEvent(JNIEnv* env, 8475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) jobject obj, 8485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) jlong time_ms, 8495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) jint type, 8505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) jobjectArray pts) { 8515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); 8525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (rwhv) { 8535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) using WebKit::WebTouchEvent; 8545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WebKit::WebTouchEvent event; 8552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TouchPoint::BuildWebTouchEvent(env, type, time_ms, GetDpiScale(), pts, 8562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) event); 8575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) rwhv->SendTouchEvent(event); 8585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return true; 8595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 8605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 8615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 8625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)float ContentViewCoreImpl::GetTouchPaddingDip() { 8642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return 48.0f / GetDpiScale(); 8655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 8665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)float ContentViewCoreImpl::GetDpiScale() const { 8685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return dpi_scale_; 8695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 8705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 871c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)void ContentViewCoreImpl::RequestContentClipping( 872c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const gfx::Rect& clipping, 873c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const gfx::Size& content_size) { 874c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); 875c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (rwhv) 876c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) rwhv->RequestContentClipping(clipping, content_size); 877c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 878c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 8795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)jboolean ContentViewCoreImpl::SendMouseMoveEvent(JNIEnv* env, 8805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) jobject obj, 8815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) jlong time_ms, 8822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) jfloat x, 8832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) jfloat y) { 8845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); 8855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!rwhv) 8865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 8875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 888bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch WebKit::WebMouseEvent event = WebMouseEventBuilder::Build( 889bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch WebInputEvent::MouseMove, 8905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WebKit::WebMouseEvent::ButtonNone, 8912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) time_ms / 1000.0, x / GetDpiScale(), y / GetDpiScale(), 0, 1); 8925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) rwhv->SendMouseEvent(event); 8945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return true; 8955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 8965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)jboolean ContentViewCoreImpl::SendMouseWheelEvent(JNIEnv* env, 8985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) jobject obj, 8995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) jlong time_ms, 9002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) jfloat x, 9012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) jfloat y, 9025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) jfloat vertical_axis) { 9035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); 9045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!rwhv) 9055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 9065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 907bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch WebMouseWheelEventBuilder::Direction direction; 9085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (vertical_axis > 0) { 909bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch direction = WebMouseWheelEventBuilder::DIRECTION_UP; 9105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } else if (vertical_axis < 0) { 911bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch direction = WebMouseWheelEventBuilder::DIRECTION_DOWN; 9125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } else { 9135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 9145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 915bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch WebKit::WebMouseWheelEvent event = WebMouseWheelEventBuilder::Build( 916bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch direction, time_ms / 1000.0, x / GetDpiScale(), y / GetDpiScale()); 9175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) rwhv->SendMouseWheelEvent(event); 9195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return true; 9205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 9215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)WebGestureEvent ContentViewCoreImpl::MakeGestureEvent( 923868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) WebInputEvent::Type type, long time_ms, float x, float y) const { 924bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch return WebGestureEventBuilder::Build( 925bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch type, time_ms / 1000.0, x / GetDpiScale(), y / GetDpiScale()); 9265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 9275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ContentViewCoreImpl::SendGestureEvent( 9292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const WebKit::WebGestureEvent& event) { 9302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); 9312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (rwhv) 9322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) rwhv->SendGestureEvent(event); 9332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 9342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 935eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochvoid ContentViewCoreImpl::UpdateTabCrashedFlag() { 936eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Since RenderWidgetHostView is associated with the lifetime of the renderer 937eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // process, we use it to test whether there is a renderer process. 938eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch tab_crashed_ = !(web_contents_->GetRenderWidgetHostView()); 939eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch} 940eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 9415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::ScrollBegin(JNIEnv* env, jobject obj, jlong time_ms, 9422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) jfloat x, jfloat y) { 9435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WebGestureEvent event = MakeGestureEvent( 944868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) WebInputEvent::GestureScrollBegin, time_ms, x, y); 9452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SendGestureEvent(event); 9465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 9475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::ScrollEnd(JNIEnv* env, jobject obj, jlong time_ms) { 9495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WebGestureEvent event = MakeGestureEvent( 950868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) WebInputEvent::GestureScrollEnd, time_ms, 0, 0); 9512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SendGestureEvent(event); 9525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 9535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::ScrollBy(JNIEnv* env, jobject obj, jlong time_ms, 955c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) jfloat x, jfloat y, jfloat dx, jfloat dy, 956c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) jboolean last_input_event_for_vsync) { 9575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WebGestureEvent event = MakeGestureEvent( 958868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) WebInputEvent::GestureScrollUpdate, time_ms, x, y); 9592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) event.data.scrollUpdate.deltaX = -dx / GetDpiScale(); 9602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) event.data.scrollUpdate.deltaY = -dy / GetDpiScale(); 9615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SendGestureEvent(event); 963eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 964eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // TODO(brianderson): Clean up last_input_event_for_vsync. crbug.com/247043 965eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch if (last_input_event_for_vsync) { 966eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch SendBeginFrame(base::TimeTicks() + 967eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch base::TimeDelta::FromMilliseconds(time_ms)); 968eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch } 9695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 9705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::FlingStart(JNIEnv* env, jobject obj, jlong time_ms, 9722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) jfloat x, jfloat y, jfloat vx, jfloat vy) { 9735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WebGestureEvent event = MakeGestureEvent( 974868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) WebInputEvent::GestureFlingStart, time_ms, x, y); 9755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Velocity should not be scaled by DIP since that interacts poorly with the 9772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // deceleration constants. The DIP scaling is done on the renderer. 9782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) event.data.flingStart.velocityX = vx; 9792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) event.data.flingStart.velocityY = vy; 9802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 9812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SendGestureEvent(event); 9825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 9835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::FlingCancel(JNIEnv* env, jobject obj, jlong time_ms) { 9855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WebGestureEvent event = MakeGestureEvent( 986868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) WebInputEvent::GestureFlingCancel, time_ms, 0, 0); 9872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SendGestureEvent(event); 9885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 9895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::SingleTap(JNIEnv* env, jobject obj, jlong time_ms, 9912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) jfloat x, jfloat y, 9925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) jboolean disambiguation_popup_tap) { 9935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WebGestureEvent event = MakeGestureEvent( 994868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) WebInputEvent::GestureTap, time_ms, x, y); 9955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) event.data.tap.tapCount = 1; 9975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!disambiguation_popup_tap) { 9982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const float touch_padding_dip = GetTouchPaddingDip(); 9992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) event.data.tap.width = touch_padding_dip; 10002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) event.data.tap.height = touch_padding_dip; 10015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 10025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SendGestureEvent(event); 10045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 10055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1006b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)void ContentViewCoreImpl::SingleTapUnconfirmed(JNIEnv* env, jobject obj, 1007b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) jlong time_ms, 1008b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) jfloat x, jfloat y) { 1009b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) WebGestureEvent event = MakeGestureEvent( 1010868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) WebInputEvent::GestureTapUnconfirmed, time_ms, x, y); 1011b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 1012b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) event.data.tap.tapCount = 1; 1013b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 1014b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) const float touch_padding_dip = GetTouchPaddingDip(); 1015b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) event.data.tap.width = touch_padding_dip; 1016b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) event.data.tap.height = touch_padding_dip; 1017b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 1018b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) SendGestureEvent(event); 1019b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)} 1020b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 10215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::ShowPressState(JNIEnv* env, jobject obj, 10225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) jlong time_ms, 10232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) jfloat x, jfloat y) { 10245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WebGestureEvent event = MakeGestureEvent( 1025868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) WebInputEvent::GestureTapDown, time_ms, x, y); 10262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SendGestureEvent(event); 10272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 10282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 10292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ContentViewCoreImpl::ShowPressCancel(JNIEnv* env, 10302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) jobject obj, 10312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) jlong time_ms, 10322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) jfloat x, 10332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) jfloat y) { 10342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) WebGestureEvent event = MakeGestureEvent( 1035868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) WebInputEvent::GestureTapCancel, time_ms, x, y); 10362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SendGestureEvent(event); 10375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 10385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::DoubleTap(JNIEnv* env, jobject obj, jlong time_ms, 10402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) jfloat x, jfloat y) { 10415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WebGestureEvent event = MakeGestureEvent( 1042868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) WebInputEvent::GestureDoubleTap, time_ms, x, y); 10432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SendGestureEvent(event); 10445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 10455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::LongPress(JNIEnv* env, jobject obj, jlong time_ms, 10472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) jfloat x, jfloat y, 10485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) jboolean disambiguation_popup_tap) { 10495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WebGestureEvent event = MakeGestureEvent( 1050868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) WebInputEvent::GestureLongPress, time_ms, x, y); 10515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!disambiguation_popup_tap) { 10532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const float touch_padding_dip = GetTouchPaddingDip(); 10542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) event.data.longPress.width = touch_padding_dip; 10552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) event.data.longPress.height = touch_padding_dip; 10565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 10575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SendGestureEvent(event); 10592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 10602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 10612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ContentViewCoreImpl::LongTap(JNIEnv* env, jobject obj, jlong time_ms, 10622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) jfloat x, jfloat y, 10632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) jboolean disambiguation_popup_tap) { 10642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) WebGestureEvent event = MakeGestureEvent( 1065868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) WebInputEvent::GestureLongTap, time_ms, x, y); 10662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 10672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (!disambiguation_popup_tap) { 10682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const float touch_padding_dip = GetTouchPaddingDip(); 10692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) event.data.longPress.width = touch_padding_dip; 10702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) event.data.longPress.height = touch_padding_dip; 10712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 10722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 10732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SendGestureEvent(event); 10745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 10755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::PinchBegin(JNIEnv* env, jobject obj, jlong time_ms, 10772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) jfloat x, jfloat y) { 10785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WebGestureEvent event = MakeGestureEvent( 1079868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) WebInputEvent::GesturePinchBegin, time_ms, x, y); 10802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SendGestureEvent(event); 10815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 10825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::PinchEnd(JNIEnv* env, jobject obj, jlong time_ms) { 10845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WebGestureEvent event = MakeGestureEvent( 1085868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) WebInputEvent::GesturePinchEnd, time_ms, 0, 0); 10862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SendGestureEvent(event); 10875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 10885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::PinchBy(JNIEnv* env, jobject obj, jlong time_ms, 10902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) jfloat anchor_x, jfloat anchor_y, 1091c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) jfloat delta, 1092c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) jboolean last_input_event_for_vsync) { 10935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WebGestureEvent event = MakeGestureEvent( 1094868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) WebInputEvent::GesturePinchUpdate, time_ms, anchor_x, anchor_y); 10955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) event.data.pinchUpdate.scale = delta; 10965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SendGestureEvent(event); 1098eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 1099eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // TODO(brianderson): Clean up last_input_event_for_vsync. crbug.com/247043 1100eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch if (last_input_event_for_vsync) { 1101eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch SendBeginFrame(base::TimeTicks() + 1102eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch base::TimeDelta::FromMilliseconds(time_ms)); 1103eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch } 11045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 11055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 11065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::SelectBetweenCoordinates(JNIEnv* env, jobject obj, 11072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) jfloat x1, jfloat y1, 11082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) jfloat x2, jfloat y2) { 11095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (GetRenderWidgetHostViewAndroid()) { 11102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetRenderWidgetHostViewAndroid()->SelectRange( 11112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Point(x1 / GetDpiScale(), y1 / GetDpiScale()), 11122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Point(x2 / GetDpiScale(), y2 / GetDpiScale())); 11132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 11142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 11152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 11162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ContentViewCoreImpl::MoveCaret(JNIEnv* env, jobject obj, 11172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) jfloat x, jfloat y) { 11182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (GetRenderWidgetHostViewAndroid()) { 11192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetRenderWidgetHostViewAndroid()->MoveCaret( 11202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Point(x / GetDpiScale(), y / GetDpiScale())); 11215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 11225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 11235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 11245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)jboolean ContentViewCoreImpl::CanGoBack(JNIEnv* env, jobject obj) { 11255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return web_contents_->GetController().CanGoBack(); 11265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 11275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 11285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)jboolean ContentViewCoreImpl::CanGoForward(JNIEnv* env, jobject obj) { 11295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return web_contents_->GetController().CanGoForward(); 11305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 11315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 11325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)jboolean ContentViewCoreImpl::CanGoToOffset(JNIEnv* env, jobject obj, 11335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) jint offset) { 11345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return web_contents_->GetController().CanGoToOffset(offset); 11355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 11365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 11375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::GoBack(JNIEnv* env, jobject obj) { 11385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) web_contents_->GetController().GoBack(); 1139eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch UpdateTabCrashedFlag(); 11405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 11415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 11425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::GoForward(JNIEnv* env, jobject obj) { 11435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) web_contents_->GetController().GoForward(); 1144eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch UpdateTabCrashedFlag(); 11455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 11465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 11475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::GoToOffset(JNIEnv* env, jobject obj, jint offset) { 11485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) web_contents_->GetController().GoToOffset(offset); 1149eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch UpdateTabCrashedFlag(); 11505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 11515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 11522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ContentViewCoreImpl::GoToNavigationIndex(JNIEnv* env, 11532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) jobject obj, 11542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) jint index) { 11552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) web_contents_->GetController().GoToIndex(index); 1156eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch UpdateTabCrashedFlag(); 11572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 11582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 11595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::StopLoading(JNIEnv* env, jobject obj) { 11605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) web_contents_->Stop(); 11615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 11625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 11635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::Reload(JNIEnv* env, jobject obj) { 11645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Set check_for_repost parameter to false as we have no repost confirmation 11655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // dialog ("confirm form resubmission" screen will still appear, however). 11665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (web_contents_->GetController().NeedsReload()) 11675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) web_contents_->GetController().LoadIfNecessary(); 11685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) else 11695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) web_contents_->GetController().Reload(true); 1170eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch UpdateTabCrashedFlag(); 11715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 11725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 11735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::CancelPendingReload(JNIEnv* env, jobject obj) { 11745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) web_contents_->GetController().CancelPendingReload(); 11755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 11765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 11775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::ContinuePendingReload(JNIEnv* env, jobject obj) { 11785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) web_contents_->GetController().ContinuePendingReload(); 11795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 11805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 11815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::ClearHistory(JNIEnv* env, jobject obj) { 1182868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // TODO(creis): Do callers of this need to know if it fails? 1183868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (web_contents_->GetController().CanPruneAllButVisible()) 1184868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) web_contents_->GetController().PruneAllButVisible(); 11855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 11865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 11875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::AddJavascriptInterface( 11885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) JNIEnv* env, 11895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) jobject /* obj */, 11905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) jobject object, 11915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) jstring name, 11922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) jclass safe_annotation_clazz, 11932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) jobject retained_object_set) { 11945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ScopedJavaLocalRef<jobject> scoped_object(env, object); 11952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ScopedJavaLocalRef<jclass> scoped_clazz(env, safe_annotation_clazz); 11962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) JavaObjectWeakGlobalRef weak_retained_object_set(env, retained_object_set); 11972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 11985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // JavaBoundObject creates the NPObject with a ref count of 1, and 11995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // JavaBridgeDispatcherHostManager takes its own ref. 12002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) JavaBridgeDispatcherHostManager* java_bridge = 12012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) web_contents_->java_bridge_dispatcher_host_manager(); 12022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) java_bridge->SetRetainedObjectSet(weak_retained_object_set); 12032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NPObject* bound_object = JavaBoundObject::Create(scoped_object, scoped_clazz, 12042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) java_bridge->AsWeakPtr()); 12052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) java_bridge->AddNamedObject(ConvertJavaStringToUTF16(env, name), 12062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bound_object); 12075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WebKit::WebBindings::releaseObject(bound_object); 12085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 12095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 12105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::RemoveJavascriptInterface(JNIEnv* env, 12115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) jobject /* obj */, 12125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) jstring name) { 12135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) web_contents_->java_bridge_dispatcher_host_manager()->RemoveNamedObject( 12145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ConvertJavaStringToUTF16(env, name)); 12155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 12165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 12175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::UpdateVSyncParameters(JNIEnv* env, jobject /* obj */, 12185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) jlong timebase_micros, 12195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) jlong interval_micros) { 12205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); 12215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!view) 12225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 12235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 12245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RenderWidgetHostImpl* host = RenderWidgetHostImpl::From( 12255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) view->GetRenderWidgetHost()); 12265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 12275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) host->UpdateVSyncParameters( 12285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::TimeTicks::FromInternalValue(timebase_micros), 12295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::TimeDelta::FromMicroseconds(interval_micros)); 12307d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 12317d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) vsync_interval_ = 12327d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) base::TimeDelta::FromMicroseconds(interval_micros); 12337d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) expected_browser_composite_time_ = 12347d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) vsync_interval_ * kDefaultBrowserCompositeVSyncFraction; 12355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 12365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1237c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)void ContentViewCoreImpl::OnVSync(JNIEnv* env, jobject /* obj */, 1238c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) jlong frame_time_micros) { 1239eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch base::TimeTicks frame_time = 1240eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch base::TimeTicks::FromInternalValue(frame_time_micros); 1241eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch SendBeginFrame(frame_time); 1242eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch} 1243eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 1244eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochvoid ContentViewCoreImpl::SendBeginFrame(base::TimeTicks frame_time) { 1245c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); 1246c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (!view) 1247c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) return; 1248c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 12497d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) base::TimeTicks display_time = frame_time + vsync_interval_; 12507d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) base::TimeTicks deadline = display_time - expected_browser_composite_time_; 12517d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 125290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) view->SendBeginFrame( 12537d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) cc::BeginFrameArgs::Create(frame_time, deadline, vsync_interval_)); 125490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 125590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 125690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)jboolean ContentViewCoreImpl::OnAnimate(JNIEnv* env, jobject /* obj */, 125790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) jlong frame_time_micros) { 125890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); 125990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) if (!view) 126090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return false; 126190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 126290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return view->Animate(base::TimeTicks::FromInternalValue(frame_time_micros)); 1263c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 1264c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 12655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)jboolean ContentViewCoreImpl::PopulateBitmapFromCompositor(JNIEnv* env, 12665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) jobject obj, 12675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) jobject jbitmap) { 12685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); 12695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!view) 12705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 12715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 12725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return view->PopulateBitmapWithContents(jbitmap); 12735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 12745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 12752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ContentViewCoreImpl::WasResized(JNIEnv* env, jobject obj) { 12765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); 12772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (view) 12782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) view->WasResized(); 12792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 12802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 12812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ContentViewCoreImpl::ShowInterstitialPage( 12822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) JNIEnv* env, jobject obj, jstring jurl, jint delegate_ptr) { 12832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GURL url(base::android::ConvertJavaStringToUTF8(env, jurl)); 12842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) InterstitialPageDelegateAndroid* delegate = 12852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) reinterpret_cast<InterstitialPageDelegateAndroid*>(delegate_ptr); 12862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) InterstitialPage* interstitial = InterstitialPage::Create( 12872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) web_contents_, false, url, delegate); 12882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) delegate->set_interstitial_page(interstitial); 12892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) interstitial->Show(); 12902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 12912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 12922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)jboolean ContentViewCoreImpl::IsShowingInterstitialPage(JNIEnv* env, 12932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) jobject obj) { 12942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return web_contents_->ShowingInterstitialPage(); 12952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 12962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 12972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ContentViewCoreImpl::AttachExternalVideoSurface(JNIEnv* env, 12982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) jobject obj, 12992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) jint player_id, 13002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) jobject jsurface) { 1301c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#if defined(GOOGLE_TV) 13022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>( 13032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) web_contents_->GetRenderViewHost()); 13047dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch BrowserMediaPlayerManager* browser_media_player_manager = 13057dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch rvhi ? static_cast<BrowserMediaPlayerManager*>( 13067dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch rvhi->media_player_manager()) 130790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) : NULL; 13087dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch if (browser_media_player_manager) { 13097dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch browser_media_player_manager->AttachExternalVideoSurface( 13102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static_cast<int>(player_id), jsurface); 13112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1312c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#endif 13132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 13142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 13152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ContentViewCoreImpl::DetachExternalVideoSurface(JNIEnv* env, 13162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) jobject obj, 13172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) jint player_id) { 1318c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#if defined(GOOGLE_TV) 13192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>( 13202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) web_contents_->GetRenderViewHost()); 13217dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch BrowserMediaPlayerManager* browser_media_player_manager = 13227dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch rvhi ? static_cast<BrowserMediaPlayerManager*>( 13237dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch rvhi->media_player_manager()) 132490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) : NULL; 13257dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch if (browser_media_player_manager) { 13267dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch browser_media_player_manager->DetachExternalVideoSurface( 13272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static_cast<int>(player_id)); 13282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1329c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#endif 13302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 13315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 13322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)jboolean ContentViewCoreImpl::IsRenderWidgetHostViewReady(JNIEnv* env, 13332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) jobject obj) { 13342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); 13352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return view && view->HasValidFrame(); 13362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 13372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 13382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ContentViewCoreImpl::ExitFullscreen(JNIEnv* env, jobject obj) { 13392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) RenderViewHost* host = web_contents_->GetRenderViewHost(); 13402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) host->ExitFullscreen(); 13412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 13422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1343c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)void ContentViewCoreImpl::UpdateTopControlsState(JNIEnv* env, 1344c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) jobject obj, 1345c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) bool enable_hiding, 1346c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) bool enable_showing, 1347c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) bool animate) { 13482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) RenderViewHost* host = web_contents_->GetRenderViewHost(); 1349c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) host->Send(new ViewMsg_UpdateTopControlsState(host->GetRoutingID(), 1350c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) enable_hiding, 1351c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) enable_showing, 1352c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) animate)); 13532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 13542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 13552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ContentViewCoreImpl::ShowImeIfNeeded(JNIEnv* env, jobject obj) { 13562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) RenderViewHost* host = web_contents_->GetRenderViewHost(); 13572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) host->Send(new ViewMsg_ShowImeIfNeeded(host->GetRoutingID())); 13585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 13595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 13605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::ScrollFocusedEditableNodeIntoView(JNIEnv* env, 13615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) jobject obj) { 13625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RenderViewHost* host = web_contents_->GetRenderViewHost(); 1363c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) host->Send(new InputMsg_ScrollFocusedEditableNodeIntoRect( 1364c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) host->GetRoutingID(), gfx::Rect())); 13655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 13665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 13672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace { 13682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 13692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)static void AddNavigationEntryToHistory(JNIEnv* env, jobject obj, 13702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) jobject history, 13712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NavigationEntry* entry, 13722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int index) { 13732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Get the details of the current entry 13742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ScopedJavaLocalRef<jstring> j_url( 13752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ConvertUTF8ToJavaString(env, entry->GetURL().spec())); 13762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ScopedJavaLocalRef<jstring> j_virtual_url( 13772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ConvertUTF8ToJavaString(env, entry->GetVirtualURL().spec())); 13782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ScopedJavaLocalRef<jstring> j_original_url( 13792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ConvertUTF8ToJavaString(env, entry->GetOriginalRequestURL().spec())); 13802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ScopedJavaLocalRef<jstring> j_title( 13812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ConvertUTF16ToJavaString(env, entry->GetTitle())); 13822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ScopedJavaLocalRef<jobject> j_bitmap; 13832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const FaviconStatus& status = entry->GetFavicon(); 13842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (status.valid && status.image.ToSkBitmap()->getSize() > 0) 13852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) j_bitmap = gfx::ConvertToJavaBitmap(status.image.ToSkBitmap()); 13862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 13872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Add the item to the list 13882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Java_ContentViewCore_addToNavigationHistory( 13892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) env, obj, history, index, j_url.obj(), j_virtual_url.obj(), 13902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) j_original_url.obj(), j_title.obj(), j_bitmap.obj()); 13912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 13922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 13932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} // namespace 13942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 13955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int ContentViewCoreImpl::GetNavigationHistory(JNIEnv* env, 13965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) jobject obj, 1397c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) jobject history) { 13985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Iterate through navigation entries to populate the list 13995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const NavigationController& controller = web_contents_->GetController(); 14005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int count = controller.GetEntryCount(); 14015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (int i = 0; i < count; ++i) { 14022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) AddNavigationEntryToHistory( 1403c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) env, obj, history, controller.GetEntryAtIndex(i), i); 14045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 14055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 14065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return controller.GetCurrentEntryIndex(); 14075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 14085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 14092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ContentViewCoreImpl::GetDirectedNavigationHistory(JNIEnv* env, 14102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) jobject obj, 1411c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) jobject history, 14122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) jboolean is_forward, 14132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) jint max_entries) { 14142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Iterate through navigation entries to populate the list 14152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const NavigationController& controller = web_contents_->GetController(); 14162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int count = controller.GetEntryCount(); 14172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int num_added = 0; 14182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int increment_value = is_forward ? 1 : -1; 14192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) for (int i = controller.GetCurrentEntryIndex() + increment_value; 14202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) i >= 0 && i < count; 14212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) i += increment_value) { 14222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (num_added >= max_entries) 14232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) break; 14242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 14252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) AddNavigationEntryToHistory( 1426c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) env, obj, history, controller.GetEntryAtIndex(i), i); 14272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) num_added++; 14282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 14292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 14302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1431c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)ScopedJavaLocalRef<jstring> 1432c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)ContentViewCoreImpl::GetOriginalUrlForActiveNavigationEntry(JNIEnv* env, 1433c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) jobject obj) { 1434c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) NavigationEntry* entry = web_contents_->GetController().GetActiveEntry(); 1435c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (entry == NULL) 1436c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) return ScopedJavaLocalRef<jstring>(env, NULL); 1437c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) return ConvertUTF8ToJavaString(env, entry->GetOriginalRequestURL().spec()); 1438c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 1439c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 14405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int ContentViewCoreImpl::GetNativeImeAdapter(JNIEnv* env, jobject obj) { 14415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid(); 14425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!rwhva) 14435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return 0; 14445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return rwhva->GetNativeImeAdapter(); 14455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 14465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 14475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)jboolean ContentViewCoreImpl::NeedsReload(JNIEnv* env, jobject obj) { 14485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return web_contents_->GetController().NeedsReload(); 14495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 14505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 14515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::UndoScrollFocusedEditableNodeIntoView( 14525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) JNIEnv* env, 14535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) jobject obj) { 14545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RenderViewHost* host = web_contents_->GetRenderViewHost(); 14555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) host->Send( 14565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) new ViewMsg_UndoScrollFocusedEditableNodeIntoView(host->GetRoutingID())); 14575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 14585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 14592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace { 14602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void JavaScriptResultCallback(const ScopedJavaGlobalRef<jobject>& callback, 14612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::Value* result) { 14622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) JNIEnv* env = base::android::AttachCurrentThread(); 14632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::string json; 14642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::JSONWriter::Write(result, &json); 14652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ScopedJavaLocalRef<jstring> j_json = ConvertUTF8ToJavaString(env, json); 14662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Java_ContentViewCore_onEvaluateJavaScriptResult(env, 14672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) j_json.obj(), 14682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) callback.obj()); 14692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 14702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} // namespace 14712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 14722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ContentViewCoreImpl::EvaluateJavaScript(JNIEnv* env, 14735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) jobject obj, 14742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) jstring script, 14752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) jobject callback) { 14765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RenderViewHost* host = web_contents_->GetRenderViewHost(); 14775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(host); 14785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 14792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (!callback) { 14802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // No callback requested. 14812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) host->ExecuteJavascriptInWebFrame(string16(), // frame_xpath 14822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ConvertJavaStringToUTF16(env, script)); 14832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return; 14842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 14852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 14862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Secure the Java callback in a scoped object and give ownership of it to the 14872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // base::Callback. 14882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ScopedJavaGlobalRef<jobject> j_callback; 14892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) j_callback.Reset(env, callback); 14902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::RenderViewHost::JavascriptResultCallback c_callback = 14912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::Bind(&JavaScriptResultCallback, j_callback); 14922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 14932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) host->ExecuteJavascriptInWebFrameCallbackResult( 14942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) string16(), // frame_xpath 14952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ConvertJavaStringToUTF16(env, script), 14962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) c_callback); 14975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 14985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 14995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool ContentViewCoreImpl::GetUseDesktopUserAgent( 15005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) JNIEnv* env, jobject obj) { 15015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NavigationEntry* entry = web_contents_->GetController().GetActiveEntry(); 15025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return entry && entry->GetIsOverridingUserAgent(); 15035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 15045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 15052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ContentViewCoreImpl::UpdateImeAdapter(int native_ime_adapter, 15065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int text_input_type, 15075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::string& text, 15085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int selection_start, 15095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int selection_end, 15105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int composition_start, 15115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int composition_end, 15125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool show_ime_if_needed) { 15135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) JNIEnv* env = AttachCurrentThread(); 15145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 15155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (obj.is_null()) 15165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 15175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 15185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ScopedJavaLocalRef<jstring> jstring_text = ConvertUTF8ToJavaString(env, text); 15192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Java_ContentViewCore_updateImeAdapter(env, obj.obj(), 15205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) native_ime_adapter, text_input_type, 15215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) jstring_text.obj(), 15225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) selection_start, selection_end, 15235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) composition_start, composition_end, 15245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) show_ime_if_needed); 15255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 15265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 15272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ContentViewCoreImpl::ProcessImeBatchStateAck(bool is_begin) { 15282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) JNIEnv* env = AttachCurrentThread(); 15292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 15302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (obj.is_null()) 15312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return; 15322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Java_ContentViewCore_processImeBatchStateAck(env, obj.obj(), is_begin); 15332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 15342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 15355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::ClearSslPreferences(JNIEnv* env, jobject obj) { 15365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SSLHostState* state = SSLHostState::GetFor( 15375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) web_contents_->GetController().GetBrowserContext()); 15385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) state->Clear(); 15395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 15405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 15415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::SetUseDesktopUserAgent( 15425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) JNIEnv* env, 15435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) jobject obj, 15445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) jboolean enabled, 15455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) jboolean reload_on_state_change) { 15465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (GetUseDesktopUserAgent(env, obj) == enabled) 15475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 15485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 15495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Make sure the navigation entry actually exists. 15505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NavigationEntry* entry = web_contents_->GetController().GetActiveEntry(); 15515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!entry) 15525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 15535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 15545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Set the flag in the NavigationEntry. 15555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) entry->SetIsOverridingUserAgent(enabled); 15565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 15575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Send the override to the renderer. 15585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (reload_on_state_change) { 15595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Reloading the page will send the override down as part of the 15605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // navigation IPC message. 15615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NavigationControllerImpl& controller = 15625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static_cast<NavigationControllerImpl&>(web_contents_->GetController()); 15635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) controller.ReloadOriginalRequestURL(false); 15645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 15655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 15665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1567eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochvoid ContentViewCoreImpl::SetAccessibilityEnabled(JNIEnv* env, jobject obj, 1568eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch bool enabled) { 1569eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch RenderWidgetHostViewAndroid* host_view = GetRenderWidgetHostViewAndroid(); 1570eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch if (!host_view) 1571eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch return; 1572eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch RenderWidgetHostImpl* host_impl = RenderWidgetHostImpl::From( 1573eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch host_view->GetRenderWidgetHost()); 1574eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch if (enabled) { 1575eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch BrowserAccessibilityState::GetInstance()->EnableAccessibility(); 1576eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch if (host_impl) 1577eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch host_impl->SetAccessibilityMode(AccessibilityModeComplete); 1578eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch } else { 1579eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch BrowserAccessibilityState::GetInstance()->DisableAccessibility(); 1580eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch if (host_impl) 1581eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch host_impl->SetAccessibilityMode(AccessibilityModeOff); 1582eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch } 1583eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch} 1584eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 15855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This is called for each ContentView. 15865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)jint Init(JNIEnv* env, jobject obj, 15875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) jboolean hardware_accelerated, 15885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) jint native_web_contents, 1589c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) jint view_android, 1590c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) jint window_android) { 15915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ContentViewCoreImpl* view = new ContentViewCoreImpl( 1592c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) env, obj, hardware_accelerated, 15935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) reinterpret_cast<WebContents*>(native_web_contents), 1594c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) reinterpret_cast<ui::ViewAndroid*>(view_android), 1595c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) reinterpret_cast<ui::WindowAndroid*>(window_android)); 15965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return reinterpret_cast<jint>(view); 15975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 15985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 15995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool RegisterContentViewCore(JNIEnv* env) { 16002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return RegisterNativesImpl(env); 16015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 16025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 16035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace content 1604