content_view_core_impl.cc revision b2df76ea8fec9e32f6f3718986dba0d95315b29c
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 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"
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/utf_string_conversions.h"
152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/values.h"
162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "cc/layers/layer.h"
172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/browser/android/interstitial_page_delegate_android.h"
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/browser/android/load_url_params.h"
19b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#include "content/browser/android/media_player_manager_impl.h"
202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/browser/android/sync_input_event_filter.h"
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/browser/android/touch_point.h"
222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/browser/renderer_host/compositor_impl_android.h"
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/browser/renderer_host/java/java_bound_object.h"
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/browser/renderer_host/java/java_bridge_dispatcher_host_manager.h"
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/browser/renderer_host/render_view_host_impl.h"
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/browser/renderer_host/render_widget_host_impl.h"
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/browser/renderer_host/render_widget_host_view_android.h"
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/browser/ssl/ssl_host_state.h"
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/browser/web_contents/interstitial_page_impl.h"
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/browser/web_contents/navigation_controller_impl.h"
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/browser/web_contents/navigation_entry_impl.h"
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/browser/web_contents/web_contents_view_android.h"
33c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "content/common/input_messages.h"
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/common/view_messages.h"
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/browser_context.h"
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/favicon_status.h"
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_details.h"
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_service.h"
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_source.h"
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_types.h"
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/web_contents.h"
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/common/content_client.h"
432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/public/common/content_switches.h"
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/common/page_transition_types.h"
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "jni/ContentViewCore_jni.h"
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h"
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "third_party/WebKit/Source/WebKit/chromium/public/android/WebInputEventFactory.h"
49c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ui/android/view_android.h"
50c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ui/android/window_android.h"
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/android/java_bitmap.h"
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/screen.h"
532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/gfx/size_conversions.h"
542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/gfx/size_f.h"
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "webkit/glue/webmenuitem.h"
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "webkit/user_agent/user_agent_util.h"
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using base::android::AttachCurrentThread;
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using base::android::ConvertJavaStringToUTF16;
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using base::android::ConvertJavaStringToUTF8;
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using base::android::ConvertUTF16ToJavaString;
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using base::android::ConvertUTF8ToJavaString;
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using base::android::ScopedJavaGlobalRef;
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using base::android::ScopedJavaLocalRef;
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using WebKit::WebGestureEvent;
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using WebKit::WebInputEvent;
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using WebKit::WebInputEventFactory;
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)
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const void* kContentViewUserDataKey = &kContentViewUserDataKey;
822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)int GetRenderProcessIdFromRenderViewHost(RenderViewHost* host) {
842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DCHECK(host);
852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  RenderProcessHost* render_process = host->GetProcess();
862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DCHECK(render_process);
872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (render_process->HasConnection())
882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return render_process->GetHandle();
892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  else
902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return 0;
912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)ScopedJavaLocalRef<jobject> CreateJavaRect(
942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    JNIEnv* env,
952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    const gfx::Rect& rect) {
962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return ScopedJavaLocalRef<jobject>(
972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      Java_ContentViewCore_createRect(env,
982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                      static_cast<int>(rect.x()),
992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                      static_cast<int>(rect.y()),
1002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                      static_cast<int>(rect.right()),
1012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                      static_cast<int>(rect.bottom())));
1022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Enables a callback when the underlying WebContents is destroyed, to enable
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// nulling the back-pointer.
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ContentViewCoreImpl::ContentViewUserData
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : public base::SupportsUserData::Data {
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  explicit ContentViewUserData(ContentViewCoreImpl* content_view_core)
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      : content_view_core_(content_view_core) {
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~ContentViewUserData() {
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // TODO(joth): When chrome has finished removing the TabContents class (see
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // crbug.com/107201) consider inverting relationship, so ContentViewCore
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // would own WebContents. That effectively implies making the WebContents
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // destructor private on Android.
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    delete content_view_core_;
1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ContentViewCoreImpl* get() const { return content_view_core_; }
1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Not using scoped_ptr as ContentViewCoreImpl destructor is private.
1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ContentViewCoreImpl* content_view_core_;
1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_IMPLICIT_CONSTRUCTORS(ContentViewUserData);
1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ContentViewCoreImpl* ContentViewCoreImpl::FromWebContents(
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    content::WebContents* web_contents) {
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ContentViewCoreImpl::ContentViewUserData* data =
1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      reinterpret_cast<ContentViewCoreImpl::ContentViewUserData*>(
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          web_contents->GetUserData(kContentViewUserDataKey));
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return data ? data->get() : NULL;
1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ContentViewCore* ContentViewCore::FromWebContents(
1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    content::WebContents* web_contents) {
1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return ContentViewCoreImpl::FromWebContents(web_contents);
1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// static
1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ContentViewCore* ContentViewCore::GetNativeContentViewCore(JNIEnv* env,
1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                                           jobject obj) {
1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return reinterpret_cast<ContentViewCore*>(
1502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      Java_ContentViewCore_getNativeContentViewCore(env, obj));
1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ContentViewCoreImpl::ContentViewCoreImpl(JNIEnv* env, jobject obj,
1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                         bool hardware_accelerated,
1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                         WebContents* web_contents,
156c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                         ui::ViewAndroid* view_android,
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                         ui::WindowAndroid* window_android)
1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : java_ref_(env, obj),
1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      web_contents_(static_cast<WebContentsImpl*>(web_contents)),
1602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      root_layer_(cc::Layer::Create()),
1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      tab_crashed_(false),
162c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      view_android_(view_android),
1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      window_android_(window_android) {
1642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  CHECK(web_contents) <<
1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      "A ContentViewCoreImpl should be created with a valid WebContents.";
1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // When a tab is restored (from a saved state), it does not have a renderer
1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // process.  We treat it like the tab is crashed. If the content is loaded
1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // when the tab is shown, tab_crashed_ will be reset.  Since
1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // RenderWidgetHostView is associated with the lifetime of the renderer
1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // process, we use it to test whether there is a renderer process.
1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  tab_crashed_ = !(web_contents->GetRenderWidgetHostView());
1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TODO(leandrogracia): make use of the hardware_accelerated argument.
1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const gfx::Display& display =
1772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      gfx::Screen::GetNativeScreen()->GetPrimaryDisplay();
1782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  dpi_scale_ = display.device_scale_factor();
1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Currently, the only use case we have for overriding a user agent involves
1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // spoofing a desktop Linux user agent for "Request desktop site".
1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Automatically set it for all WebContents so that it is available when a
1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // NavigationEntry requires the user agent to be overridden.
1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const char kLinuxInfoStr[] = "X11; Linux x86_64";
1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::string product = content::GetContentClient()->GetProduct();
1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::string spoofed_ua =
1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      webkit_glue::BuildUserAgentFromOSAndProduct(kLinuxInfoStr, product);
1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  web_contents->SetUserAgentOverride(spoofed_ua);
1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  InitWebContents();
1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ContentViewCoreImpl::~ContentViewCoreImpl() {
1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  JNIEnv* env = base::android::AttachCurrentThread();
1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env);
1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  java_ref_.reset();
1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (!j_obj.is_null()) {
1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    Java_ContentViewCore_onNativeContentViewCoreDestroyed(
1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        env, j_obj.obj(), reinterpret_cast<jint>(this));
2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Make sure nobody calls back into this object while we are tearing things
2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // down.
2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  notification_registrar_.RemoveAll();
2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::OnJavaContentViewCoreDestroyed(JNIEnv* env,
2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                                         jobject obj) {
2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DCHECK(env->IsSameObject(java_ref_.get(env).obj(), obj));
2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  java_ref_.reset();
2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::InitWebContents() {
2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DCHECK(web_contents_);
2142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  notification_registrar_.Add(
2152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      this, NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      Source<NavigationController>(&web_contents_->GetController()));
2172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  notification_registrar_.Add(
2182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      this, NOTIFICATION_RENDERER_PROCESS_CREATED,
2192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      content::NotificationService::AllBrowserContextsAndSources());
2202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  notification_registrar_.Add(
2212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      this, NOTIFICATION_WEB_CONTENTS_CONNECTED,
2222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      Source<WebContents>(web_contents_));
223c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  notification_registrar_.Add(
224c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      this, NOTIFICATION_WEB_CONTENTS_SWAPPED,
225c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      Source<WebContents>(web_contents_));
2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static_cast<WebContentsViewAndroid*>(web_contents_->GetView())->
2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      SetContentViewCore(this);
2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DCHECK(!web_contents_->GetUserData(kContentViewUserDataKey));
2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  web_contents_->SetUserData(kContentViewUserDataKey,
2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             new ContentViewUserData(this));
2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::Observe(int type,
2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                  const NotificationSource& source,
2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                  const NotificationDetails& details) {
2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  switch (type) {
2382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    case NOTIFICATION_RENDER_VIEW_HOST_CHANGED: {
2392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      std::pair<RenderViewHost*, RenderViewHost*>* switched_details =
2402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)          Details<std::pair<RenderViewHost*, RenderViewHost*> >(details).ptr();
2412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      int old_pid = 0;
2422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      if (switched_details->first) {
2432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        old_pid = GetRenderProcessIdFromRenderViewHost(
2442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)            switched_details->first);
2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      }
2462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      int new_pid = GetRenderProcessIdFromRenderViewHost(
2472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)          web_contents_->GetRenderViewHost());
2482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      if (new_pid != old_pid) {
2492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        // Notify the Java side of the change of the current renderer process.
2502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        JNIEnv* env = AttachCurrentThread();
2512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
2522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        if (!obj.is_null()) {
2532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)          Java_ContentViewCore_onRenderProcessSwap(
2542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)              env, obj.obj(), old_pid, new_pid);
2552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        }
2562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      }
2572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      break;
2582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    }
2592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    case NOTIFICATION_RENDERER_PROCESS_CREATED: {
2602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      // Notify the Java side of the current renderer process.
2612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      RenderProcessHost* source_process_host =
2622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)          Source<RenderProcessHost>(source).ptr();
2632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      RenderProcessHost* current_process_host =
2642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)          web_contents_->GetRenderViewHost()->GetProcess();
2652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      if (source_process_host == current_process_host) {
2672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        int pid = GetRenderProcessIdFromRenderViewHost(
2682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)            web_contents_->GetRenderViewHost());
2692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        JNIEnv* env = AttachCurrentThread();
2702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
2712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        if (!obj.is_null()) {
2722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)          Java_ContentViewCore_onRenderProcessSwap(env, obj.obj(), 0, pid);
2732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        }
2742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      }
2752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      break;
2762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    }
2772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    case NOTIFICATION_WEB_CONTENTS_CONNECTED: {
2782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      JNIEnv* env = AttachCurrentThread();
2792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
2802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      if (!obj.is_null()) {
2812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        Java_ContentViewCore_onWebContentsConnected(env, obj.obj());
2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      }
2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      break;
2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    }
285c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    case NOTIFICATION_WEB_CONTENTS_SWAPPED: {
286c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      JNIEnv* env = AttachCurrentThread();
287c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
288c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      if (!obj.is_null()) {
289c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)        Java_ContentViewCore_onWebContentsSwapped(env, obj.obj());
290c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      }
291c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    }
2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)RenderWidgetHostViewAndroid*
2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ContentViewCoreImpl::GetRenderWidgetHostViewAndroid() {
2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  RenderWidgetHostView* rwhv = NULL;
2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (web_contents_) {
2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    rwhv = web_contents_->GetRenderWidgetHostView();
3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if (web_contents_->ShowingInterstitialPage()) {
3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      rwhv = static_cast<InterstitialPageImpl*>(
3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          web_contents_->GetInterstitialPage())->
3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)              GetRenderViewHost()->GetView();
3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    }
3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return static_cast<RenderWidgetHostViewAndroid*>(rwhv);
3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ScopedJavaLocalRef<jobject> ContentViewCoreImpl::GetJavaObject() {
3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  JNIEnv* env = AttachCurrentThread();
3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return java_ref_.get(env);
3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)jint ContentViewCoreImpl::GetBackgroundColor(JNIEnv* env, jobject obj) {
3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid();
3165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (!rwhva)
3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return SK_ColorWHITE;
3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return rwhva->GetCachedBackgroundColor();
3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::SetBackgroundColor(JNIEnv* env,
3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                             jobject obj,
3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                             jint color) {
3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid();
3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (!rwhva)
3265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return;
3272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  rwhva->OnDidChangeBodyBackgroundColor(color);
3285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::OnHide(JNIEnv* env, jobject obj) {
3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Hide();
3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::OnShow(JNIEnv* env, jobject obj) {
3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Show();
3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::Show() {
3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GetWebContents()->WasShown();
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)
3535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // 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);
3972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  for (size_t i = 0; i < update_frame_info_callbacks_.size(); ++i) {
3992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    update_frame_info_callbacks_[i].Run(
4002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        content_size, scroll_offset, page_scale_factor);
4012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
4025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ContentViewCoreImpl::SetTitle(const string16& title) {
4055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  JNIEnv* env = AttachCurrentThread();
4065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
4075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (obj.is_null())
4085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return;
4092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ScopedJavaLocalRef<jstring> jtitle =
4102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      ConvertUTF8ToJavaString(env, UTF16ToUTF8(title));
4112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  Java_ContentViewCore_setTitle(env, obj.obj(), jtitle.obj());
4125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ContentViewCoreImpl::OnBackgroundColorChanged(SkColor color) {
4155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  JNIEnv* env = AttachCurrentThread();
4165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
4175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (obj.is_null())
4185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return;
4192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  Java_ContentViewCore_onBackgroundColorChanged(env, obj.obj(), color);
4205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::ShowSelectPopupMenu(
4235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const std::vector<WebMenuItem>& items, int selected_item, bool multiple) {
4245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  JNIEnv* env = AttachCurrentThread();
4255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env);
4265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (j_obj.is_null())
4275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return;
4285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // For multi-select list popups we find the list of previous selections by
4305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // iterating through the items. But for single selection popups we take the
4315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // given |selected_item| as is.
4325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ScopedJavaLocalRef<jintArray> selected_array;
4335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (multiple) {
434c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    scoped_ptr<jint[]> native_selected_array(new jint[items.size()]);
4355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    size_t selected_count = 0;
4365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    for (size_t i = 0; i < items.size(); ++i) {
4375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (items[i].checked)
4385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        native_selected_array[selected_count++] = i;
4395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    }
4405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    selected_array.Reset(env, env->NewIntArray(selected_count));
4425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    env->SetIntArrayRegion(selected_array.obj(), 0, selected_count,
4435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                           native_selected_array.get());
4445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  } else {
4455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    selected_array.Reset(env, env->NewIntArray(1));
4465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    jint value = selected_item;
4475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    env->SetIntArrayRegion(selected_array.obj(), 0, 1, &value);
4485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
4495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ScopedJavaLocalRef<jintArray> enabled_array(env,
4515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                              env->NewIntArray(items.size()));
4525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::vector<string16> labels;
4535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  labels.reserve(items.size());
4545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  for (size_t i = 0; i < items.size(); ++i) {
4555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    labels.push_back(items[i].label);
4565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    jint enabled =
4575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        (items[i].type == WebMenuItem::GROUP ? POPUP_ITEM_TYPE_GROUP :
4585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            (items[i].enabled ? POPUP_ITEM_TYPE_ENABLED :
4595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                POPUP_ITEM_TYPE_DISABLED));
4605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    env->SetIntArrayRegion(enabled_array.obj(), i, 1, &enabled);
4615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
4625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ScopedJavaLocalRef<jobjectArray> items_array(
4635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      base::android::ToJavaArrayOfStrings(env, labels));
4645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Java_ContentViewCore_showSelectPopup(env, j_obj.obj(),
4655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                       items_array.obj(), enabled_array.obj(),
4665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                       multiple, selected_array.obj());
4675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ContentViewCoreImpl::ConfirmTouchEvent(InputEventAckState ack_result) {
4705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  JNIEnv* env = AttachCurrentThread();
4715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env);
4725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (j_obj.is_null())
4735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return;
4742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  Java_ContentViewCore_confirmTouchEvent(env, j_obj.obj(),
4752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                         static_cast<jint>(ack_result));
4765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::HasTouchEventHandlers(bool need_touch_events) {
4795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  JNIEnv* env = AttachCurrentThread();
4805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env);
4815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (j_obj.is_null())
4825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return;
4835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Java_ContentViewCore_hasTouchEventHandlers(env,
4845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                             j_obj.obj(),
4855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                             need_touch_events);
4865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool ContentViewCoreImpl::HasFocus() {
4895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  JNIEnv* env = AttachCurrentThread();
4905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
4915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (obj.is_null())
4925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return false;
4935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return Java_ContentViewCore_hasFocus(env, obj.obj());
4945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::OnSelectionChanged(const std::string& text) {
4975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  JNIEnv* env = AttachCurrentThread();
4985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
4995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (obj.is_null())
5005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return;
5015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ScopedJavaLocalRef<jstring> jtext = ConvertUTF8ToJavaString(env, text);
5025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Java_ContentViewCore_onSelectionChanged(env, obj.obj(), jtext.obj());
5035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::OnSelectionBoundsChanged(
5062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    const ViewHostMsg_SelectionBounds_Params& params) {
5075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  JNIEnv* env = AttachCurrentThread();
5085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
5095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (obj.is_null())
5105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return;
5112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ScopedJavaLocalRef<jobject> anchor_rect_dip(
5122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      CreateJavaRect(env, params.anchor_rect));
5132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ScopedJavaLocalRef<jobject> focus_rect_dip(
5142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      CreateJavaRect(env, params.focus_rect));
5155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Java_ContentViewCore_onSelectionBoundsChanged(env, obj.obj(),
5162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                                anchor_rect_dip.obj(),
5172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                                params.anchor_dir,
5182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                                focus_rect_dip.obj(),
5192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                                params.focus_dir,
5202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                                params.is_anchor_first);
5215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ContentViewCoreImpl::ShowPastePopup(int x_dip, int y_dip) {
5245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  JNIEnv* env = AttachCurrentThread();
5255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
5265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (obj.is_null())
5275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return;
5282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  Java_ContentViewCore_showPastePopup(env, obj.obj(),
5292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                      static_cast<jint>(x_dip),
5302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                      static_cast<jint>(y_dip));
5315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)unsigned int ContentViewCoreImpl::GetScaledContentTexture(
5342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    float scale,
5352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    gfx::Size* out_size) {
5365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid();
5375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (!view)
5385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return 0;
5395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return view->GetScaledContentTexture(scale, out_size);
5412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
5422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ContentViewCoreImpl::AddFrameInfoCallback(
5442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    const UpdateFrameInfoCallback& callback) {
5452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  update_frame_info_callbacks_.push_back(callback);
5462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
5472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ContentViewCoreImpl::RemoveFrameInfoCallback(
5492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    const UpdateFrameInfoCallback& callback) {
5502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  for (size_t i = 0; i < update_frame_info_callbacks_.size(); ++i) {
5512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    if (update_frame_info_callbacks_[i].Equals(callback)) {
5522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      update_frame_info_callbacks_.erase(
5532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)          update_frame_info_callbacks_.begin() + i);
5542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      return;
5552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    }
5562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
5575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::StartContentIntent(const GURL& content_url) {
5605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  JNIEnv* env = AttachCurrentThread();
5615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env);
5625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (j_obj.is_null())
5635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return;
5645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ScopedJavaLocalRef<jstring> jcontent_url =
5655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      ConvertUTF8ToJavaString(env, content_url.spec());
5665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Java_ContentViewCore_startContentIntent(env,
5675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                          j_obj.obj(),
5685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                          jcontent_url.obj());
5695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::ShowDisambiguationPopup(
5725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const gfx::Rect& target_rect,
5735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const SkBitmap& zoomed_bitmap) {
5745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  JNIEnv* env = AttachCurrentThread();
5755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
5775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (obj.is_null())
5785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return;
5795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ScopedJavaLocalRef<jobject> rect_object(CreateJavaRect(env, target_rect));
5815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ScopedJavaLocalRef<jobject> java_bitmap =
5835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      gfx::ConvertToJavaBitmap(&zoomed_bitmap);
5845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DCHECK(!java_bitmap.is_null());
5855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Java_ContentViewCore_showDisambiguationPopup(env,
5875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                               obj.obj(),
5885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                               rect_object.obj(),
5895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                               java_bitmap.obj());
5905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
592b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)ScopedJavaLocalRef<jobject> ContentViewCoreImpl::CreateSmoothScroller(
593b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)    bool scroll_down, int mouse_event_x, int mouse_event_y) {
5942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  JNIEnv* env = AttachCurrentThread();
5952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
5972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (obj.is_null())
598b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)    return ScopedJavaLocalRef<jobject>();
599b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  return Java_ContentViewCore_createSmoothScroller(
600b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)      env, obj.obj(), scroll_down, mouse_event_x, mouse_event_y);
6012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
6022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
603b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)void ContentViewCoreImpl::NotifyExternalSurface(
604b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)    int player_id, bool is_request, const gfx::RectF& rect) {
605c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  JNIEnv* env = AttachCurrentThread();
606c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
607c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
608c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  if (obj.is_null())
609c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return;
610c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
611b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  Java_ContentViewCore_notifyExternalSurface(
612b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)      env,
613b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)      obj.obj(),
614b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)      static_cast<jint>(player_id),
615b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)      static_cast<jboolean>(is_request),
616b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)      static_cast<jfloat>(rect.x()),
617b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)      static_cast<jfloat>(rect.y()),
618b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)      static_cast<jfloat>(rect.width()),
619b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)      static_cast<jfloat>(rect.height()));
620c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
621c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
6222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)gfx::Size ContentViewCoreImpl::GetPhysicalBackingSize() const {
6232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  JNIEnv* env = AttachCurrentThread();
6242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env);
6252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (j_obj.is_null())
6262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return gfx::Size();
6272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return gfx::Size(
6282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      Java_ContentViewCore_getPhysicalBackingWidthPix(env, j_obj.obj()),
6292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      Java_ContentViewCore_getPhysicalBackingHeightPix(env, j_obj.obj()));
6302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
6312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)gfx::Size ContentViewCoreImpl::GetViewportSizePix() const {
6332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  JNIEnv* env = AttachCurrentThread();
6342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env);
6352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (j_obj.is_null())
6362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return gfx::Size();
637c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  return gfx::Size(
638c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      Java_ContentViewCore_getViewportWidthPix(env, j_obj.obj()),
639c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      Java_ContentViewCore_getViewportHeightPix(env, j_obj.obj()));
640c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
641c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
642c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)gfx::Size ContentViewCoreImpl::GetViewportSizeOffsetPix() const {
643c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  JNIEnv* env = AttachCurrentThread();
644c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env);
645c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  if (j_obj.is_null())
646c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return gfx::Size();
647c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  return gfx::Size(
648c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      Java_ContentViewCore_getViewportSizeOffsetWidthPix(env, j_obj.obj()),
649c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      Java_ContentViewCore_getViewportSizeOffsetHeightPix(env, j_obj.obj()));
6502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
6512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)gfx::Size ContentViewCoreImpl::GetViewportSizeDip() const {
6532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return gfx::ToCeiledSize(
6542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      gfx::ScaleSize(GetViewportSizePix(), 1.0f / GetDpiScale()));
6552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
6562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
657c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)gfx::Size ContentViewCoreImpl::GetViewportSizeOffsetDip() const {
658c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  return gfx::ToCeiledSize(
659c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      gfx::ScaleSize(GetViewportSizeOffsetPix(), 1.0f / GetDpiScale()));
660c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
661c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
6622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)float ContentViewCoreImpl::GetOverdrawBottomHeightDip() const {
6635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  JNIEnv* env = AttachCurrentThread();
6645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env);
6655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (j_obj.is_null())
6662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return 0.f;
6672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return Java_ContentViewCore_getOverdrawBottomHeightPix(env, j_obj.obj())
6682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      / GetDpiScale();
6692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
6702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)InputEventAckState ContentViewCoreImpl::FilterInputEvent(
6722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    const WebKit::WebInputEvent& input_event) {
6732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (!input_event_filter_)
6742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
6752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return input_event_filter_->HandleInputEvent(input_event);
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);
6905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  tab_crashed_ = false;
6915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
693c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)void ContentViewCoreImpl::SetVSyncNotificationEnabled(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)
702c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)ui::ViewAndroid* ContentViewCoreImpl::GetViewAndroid() const {
703c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // view_android_ should never be null for Chrome.
704c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  DCHECK(view_android_);
705c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  return view_android_;
706c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
707c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
7082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)ui::WindowAndroid* ContentViewCoreImpl::GetWindowAndroid() const {
709c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // This should never be NULL for Chrome, but will be NULL for WebView.
710c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  DCHECK(window_android_);
7115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return window_android_;
7125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)scoped_refptr<cc::Layer> ContentViewCoreImpl::GetLayer() const {
7152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return root_layer_.get();
7162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
7172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
7185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// ----------------------------------------------------------------------------
7195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Methods called from Java via JNI
7205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// ----------------------------------------------------------------------------
7215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::SelectPopupMenuItems(JNIEnv* env, jobject obj,
7235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                               jintArray indices) {
7245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(
7255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      web_contents_->GetRenderViewHost());
7265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DCHECK(rvhi);
7275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (indices == NULL) {
7285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    rvhi->DidCancelPopupMenu();
7295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return;
7305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
7315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int selected_count = env->GetArrayLength(indices);
7335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::vector<int> selected_indices;
7345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  jint* indices_ptr = env->GetIntArrayElements(indices, NULL);
7355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  for (int i = 0; i < selected_count; ++i)
7365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    selected_indices.push_back(indices_ptr[i]);
7375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  env->ReleaseIntArrayElements(indices, indices_ptr, JNI_ABORT);
7385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  rvhi->DidSelectPopupMenuItems(selected_indices);
7395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::LoadUrl(
7425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    JNIEnv* env, jobject obj,
7435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    jstring url,
7445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    jint load_url_type,
7455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    jint transition_type,
7465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    jint ua_override_option,
7475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    jstring extra_headers,
7485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    jbyteArray post_data,
7495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    jstring base_url_for_data_url,
7505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    jstring virtual_url_for_data_url,
7515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    jboolean can_load_local_resources) {
7525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DCHECK(url);
7535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  NavigationController::LoadURLParams params(
7545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      GURL(ConvertJavaStringToUTF8(env, url)));
7555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  params.load_type = static_cast<NavigationController::LoadURLType>(
7575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      load_url_type);
7585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  params.transition_type = PageTransitionFromInt(transition_type);
7595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  params.override_user_agent =
7605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      static_cast<NavigationController::UserAgentOverrideOption>(
7615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          ua_override_option);
7625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (extra_headers)
7645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    params.extra_headers = ConvertJavaStringToUTF8(env, extra_headers);
7655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (post_data) {
7675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    std::vector<uint8> http_body_vector;
7682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    base::android::JavaByteArrayToByteVector(env, post_data, &http_body_vector);
7695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    params.browser_initiated_post_data =
7705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        base::RefCountedBytes::TakeVector(&http_body_vector);
7715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
7725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (base_url_for_data_url) {
7745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    params.base_url_for_data_url =
7755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        GURL(ConvertJavaStringToUTF8(env, base_url_for_data_url));
7765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
7775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (virtual_url_for_data_url) {
7795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    params.virtual_url_for_data_url =
7805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        GURL(ConvertJavaStringToUTF8(env, virtual_url_for_data_url));
7815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
7825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  params.can_load_local_resources = can_load_local_resources;
7845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  LoadUrl(params);
7865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)jint ContentViewCoreImpl::GetCurrentRenderProcessId(JNIEnv* env, jobject obj) {
7892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return GetRenderProcessIdFromRenderViewHost(
7902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      web_contents_->GetRenderViewHost());
7915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ScopedJavaLocalRef<jstring> ContentViewCoreImpl::GetURL(
7945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    JNIEnv* env, jobject) const {
7955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return ConvertUTF8ToJavaString(env, GetWebContents()->GetURL().spec());
7965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ScopedJavaLocalRef<jstring> ContentViewCoreImpl::GetTitle(
7995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    JNIEnv* env, jobject obj) const {
8005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return ConvertUTF16ToJavaString(env, GetWebContents()->GetTitle());
8015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)jboolean ContentViewCoreImpl::IsIncognito(JNIEnv* env, jobject obj) {
8045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return GetWebContents()->GetBrowserContext()->IsOffTheRecord();
8055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)WebContents* ContentViewCoreImpl::GetWebContents() const {
8085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return web_contents_;
8095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::SetFocus(JNIEnv* env, jobject obj, jboolean focused) {
8125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (!GetRenderWidgetHostViewAndroid())
8135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return;
8145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (focused)
8165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    GetRenderWidgetHostViewAndroid()->Focus();
8175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  else
8185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    GetRenderWidgetHostViewAndroid()->Blur();
8195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::SendOrientationChangeEvent(JNIEnv* env,
8225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                                     jobject obj,
8235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                                     jint orientation) {
8245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid();
8255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (rwhv)
8265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    rwhv->UpdateScreenInfo(rwhv->GetNativeView());
8275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(
8295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      web_contents_->GetRenderViewHost());
8305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  rvhi->SendOrientationChangeEvent(orientation);
8315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)jboolean ContentViewCoreImpl::SendTouchEvent(JNIEnv* env,
8345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                             jobject obj,
8355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                             jlong time_ms,
8365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                             jint type,
8375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                             jobjectArray pts) {
8385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid();
8395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (rwhv) {
8405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    using WebKit::WebTouchEvent;
8415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    WebKit::WebTouchEvent event;
8422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    TouchPoint::BuildWebTouchEvent(env, type, time_ms, GetDpiScale(), pts,
8432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        event);
8445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    rwhv->SendTouchEvent(event);
8455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return true;
8465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
8475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return false;
8485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)float ContentViewCoreImpl::GetTouchPaddingDip() {
8512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return 48.0f / GetDpiScale();
8525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)float ContentViewCoreImpl::GetDpiScale() const {
8555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return dpi_scale_;
8565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ContentViewCoreImpl::SetInputHandler(
8592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    WebKit::WebCompositorInputHandler* input_handler) {
8602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (!input_event_filter_)
8612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    input_event_filter_.reset(new SyncInputEventFilter);
8622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
8632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  input_event_filter_->SetInputHandler(input_handler);
8642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
8652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
866c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)void ContentViewCoreImpl::RequestContentClipping(
867c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    const gfx::Rect& clipping,
868c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    const gfx::Size& content_size) {
869c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid();
870c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  if (rwhv)
871c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    rwhv->RequestContentClipping(clipping, content_size);
872c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
873c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
8745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)jboolean ContentViewCoreImpl::SendMouseMoveEvent(JNIEnv* env,
8755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                                 jobject obj,
8765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                                 jlong time_ms,
8772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                                 jfloat x,
8782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                                 jfloat y) {
8795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid();
8805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (!rwhv)
8815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return false;
8825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  WebKit::WebMouseEvent event = WebInputEventFactory::mouseEvent(
8845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      WebInputEventFactory::MouseEventTypeMove,
8855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      WebKit::WebMouseEvent::ButtonNone,
8862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      time_ms / 1000.0, x / GetDpiScale(), y / GetDpiScale(), 0, 1);
8875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  rwhv->SendMouseEvent(event);
8895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return true;
8905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)jboolean ContentViewCoreImpl::SendMouseWheelEvent(JNIEnv* env,
8935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                                  jobject obj,
8945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                                  jlong time_ms,
8952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                                  jfloat x,
8962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                                  jfloat y,
8975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                                  jfloat vertical_axis) {
8985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid();
8995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (!rwhv)
9005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return false;
9015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  WebKit::WebInputEventFactory::MouseWheelDirectionType type;
9035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (vertical_axis > 0) {
9045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    type = WebInputEventFactory::MouseWheelDirectionTypeUp;
9055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  } else if (vertical_axis < 0) {
9065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    type = WebInputEventFactory::MouseWheelDirectionTypeDown;
9075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  } else {
9085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return false;
9095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
9105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  WebKit::WebMouseWheelEvent event = WebInputEventFactory::mouseWheelEvent(
9112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      type, time_ms / 1000.0, x / GetDpiScale(), y / GetDpiScale());
9125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  rwhv->SendMouseWheelEvent(event);
9145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return true;
9155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
9165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)WebGestureEvent ContentViewCoreImpl::MakeGestureEvent(
918c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    WebInputEvent::Type type, long time_ms, float x, float y,
919c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    InputEventVSyncStatus vsync_status) const {
9205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  WebGestureEvent event;
9215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  event.type = type;
9222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  event.x = x / GetDpiScale();
9232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  event.y = y / GetDpiScale();
9245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  event.timeStampSeconds = time_ms / 1000.0;
9252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  event.sourceDevice = WebGestureEvent::Touchscreen;
926c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  if (vsync_status == LAST_INPUT_EVENT_FOR_VSYNC)
927c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    event.modifiers |= WebInputEvent::IsLastInputEventForCurrentVSync;
9285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return event;
9295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
9305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ContentViewCoreImpl::SendGestureEvent(
9322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    const WebKit::WebGestureEvent& event) {
9332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid();
9342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (rwhv)
9352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    rwhv->SendGestureEvent(event);
9362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
9372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
9385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::ScrollBegin(JNIEnv* env, jobject obj, jlong time_ms,
9392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                      jfloat x, jfloat y) {
9405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  WebGestureEvent event = MakeGestureEvent(
941c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      WebInputEvent::GestureScrollBegin, time_ms, x, y,
942c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      NOT_LAST_INPUT_EVENT_FOR_VSYNC);
9432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SendGestureEvent(event);
9445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
9455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::ScrollEnd(JNIEnv* env, jobject obj, jlong time_ms) {
9475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  WebGestureEvent event = MakeGestureEvent(
948c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      WebInputEvent::GestureScrollEnd, time_ms, 0, 0,
949c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      NOT_LAST_INPUT_EVENT_FOR_VSYNC);
9502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SendGestureEvent(event);
9515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
9525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::ScrollBy(JNIEnv* env, jobject obj, jlong time_ms,
954c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                   jfloat x, jfloat y, jfloat dx, jfloat dy,
955c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                   jboolean last_input_event_for_vsync) {
956c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  InputEventVSyncStatus vsync_status =
957c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      last_input_event_for_vsync ? LAST_INPUT_EVENT_FOR_VSYNC
958c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                 : NOT_LAST_INPUT_EVENT_FOR_VSYNC;
9595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  WebGestureEvent event = MakeGestureEvent(
960c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      WebInputEvent::GestureScrollUpdate, time_ms, x, y, vsync_status);
9612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  event.data.scrollUpdate.deltaX = -dx / GetDpiScale();
9622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  event.data.scrollUpdate.deltaY = -dy / GetDpiScale();
9635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SendGestureEvent(event);
9655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
9665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::FlingStart(JNIEnv* env, jobject obj, jlong time_ms,
9682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                     jfloat x, jfloat y, jfloat vx, jfloat vy) {
9695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  WebGestureEvent event = MakeGestureEvent(
970c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      WebInputEvent::GestureFlingStart, time_ms, x, y,
971c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      NOT_LAST_INPUT_EVENT_FOR_VSYNC);
9725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Velocity should not be scaled by DIP since that interacts poorly with the
9742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // deceleration constants.  The DIP scaling is done on the renderer.
9752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  event.data.flingStart.velocityX = vx;
9762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  event.data.flingStart.velocityY = vy;
9772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
9782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SendGestureEvent(event);
9795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
9805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::FlingCancel(JNIEnv* env, jobject obj, jlong time_ms) {
9825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  WebGestureEvent event = MakeGestureEvent(
983c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      WebInputEvent::GestureFlingCancel, time_ms, 0, 0,
984c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      NOT_LAST_INPUT_EVENT_FOR_VSYNC);
9852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SendGestureEvent(event);
9865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
9875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::SingleTap(JNIEnv* env, jobject obj, jlong time_ms,
9892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                    jfloat x, jfloat y,
9905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                    jboolean disambiguation_popup_tap) {
9915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  WebGestureEvent event = MakeGestureEvent(
992c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      WebInputEvent::GestureTap, time_ms, x, y,
993c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      NOT_LAST_INPUT_EVENT_FOR_VSYNC);
9945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  event.data.tap.tapCount = 1;
9965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (!disambiguation_popup_tap) {
9972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    const float touch_padding_dip = GetTouchPaddingDip();
9982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    event.data.tap.width = touch_padding_dip;
9992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    event.data.tap.height = touch_padding_dip;
10005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
10015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SendGestureEvent(event);
10035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
10045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1005b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)void ContentViewCoreImpl::SingleTapUnconfirmed(JNIEnv* env, jobject obj,
1006b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)                                               jlong time_ms,
1007b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)                                               jfloat x, jfloat y) {
1008b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  WebGestureEvent event = MakeGestureEvent(
1009b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)      WebInputEvent::GestureTapUnconfirmed, time_ms, x, y,
1010b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)      NOT_LAST_INPUT_EVENT_FOR_VSYNC);
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(
1025c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      WebInputEvent::GestureTapDown, time_ms, x, y,
1026c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      NOT_LAST_INPUT_EVENT_FOR_VSYNC);
10272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SendGestureEvent(event);
10282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
10292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
10302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ContentViewCoreImpl::ShowPressCancel(JNIEnv* env,
10312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                          jobject obj,
10322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                          jlong time_ms,
10332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                          jfloat x,
10342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                          jfloat y) {
10352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  WebGestureEvent event = MakeGestureEvent(
1036c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      WebInputEvent::GestureTapCancel, time_ms, x, y,
1037c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      NOT_LAST_INPUT_EVENT_FOR_VSYNC);
10382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SendGestureEvent(event);
10395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
10405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::DoubleTap(JNIEnv* env, jobject obj, jlong time_ms,
10422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                    jfloat x, jfloat y) {
10435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  WebGestureEvent event = MakeGestureEvent(
1044c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      WebInputEvent::GestureDoubleTap, time_ms, x, y,
1045c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      NOT_LAST_INPUT_EVENT_FOR_VSYNC);
10462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SendGestureEvent(event);
10475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
10485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::LongPress(JNIEnv* env, jobject obj, jlong time_ms,
10502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                    jfloat x, jfloat y,
10515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                    jboolean disambiguation_popup_tap) {
10525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  WebGestureEvent event = MakeGestureEvent(
1053c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      WebInputEvent::GestureLongPress, time_ms, x, y,
1054c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      NOT_LAST_INPUT_EVENT_FOR_VSYNC);
10555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (!disambiguation_popup_tap) {
10572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    const float touch_padding_dip = GetTouchPaddingDip();
10582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    event.data.longPress.width = touch_padding_dip;
10592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    event.data.longPress.height = touch_padding_dip;
10605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
10615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SendGestureEvent(event);
10632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
10642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
10652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ContentViewCoreImpl::LongTap(JNIEnv* env, jobject obj, jlong time_ms,
10662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                  jfloat x, jfloat y,
10672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                  jboolean disambiguation_popup_tap) {
10682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  WebGestureEvent event = MakeGestureEvent(
1069c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      WebInputEvent::GestureLongTap, time_ms, x, y,
1070c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      NOT_LAST_INPUT_EVENT_FOR_VSYNC);
10712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
10722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (!disambiguation_popup_tap) {
10732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    const float touch_padding_dip = GetTouchPaddingDip();
10742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    event.data.longPress.width = touch_padding_dip;
10752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    event.data.longPress.height = touch_padding_dip;
10762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
10772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
10782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SendGestureEvent(event);
10795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
10805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::PinchBegin(JNIEnv* env, jobject obj, jlong time_ms,
10822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                     jfloat x, jfloat y) {
10835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  WebGestureEvent event = MakeGestureEvent(
1084c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      WebInputEvent::GesturePinchBegin, time_ms, x, y,
1085c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      NOT_LAST_INPUT_EVENT_FOR_VSYNC);
10862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SendGestureEvent(event);
10875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
10885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::PinchEnd(JNIEnv* env, jobject obj, jlong time_ms) {
10905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  WebGestureEvent event = MakeGestureEvent(
1091c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      WebInputEvent::GesturePinchEnd, time_ms, 0, 0,
1092c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      NOT_LAST_INPUT_EVENT_FOR_VSYNC);
10932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SendGestureEvent(event);
10945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
10955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::PinchBy(JNIEnv* env, jobject obj, jlong time_ms,
10972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                  jfloat anchor_x, jfloat anchor_y,
1098c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                  jfloat delta,
1099c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                  jboolean last_input_event_for_vsync) {
1100c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  InputEventVSyncStatus vsync_status =
1101c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      last_input_event_for_vsync ? LAST_INPUT_EVENT_FOR_VSYNC
1102c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                 : NOT_LAST_INPUT_EVENT_FOR_VSYNC;
11035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  WebGestureEvent event = MakeGestureEvent(
1104c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      WebInputEvent::GesturePinchUpdate, time_ms, anchor_x, anchor_y,
1105c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      vsync_status);
11065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  event.data.pinchUpdate.scale = delta;
11075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
11082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SendGestureEvent(event);
11095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
11105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
11115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::SelectBetweenCoordinates(JNIEnv* env, jobject obj,
11122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                                   jfloat x1, jfloat y1,
11132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                                   jfloat x2, jfloat y2) {
11145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (GetRenderWidgetHostViewAndroid()) {
11152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    GetRenderWidgetHostViewAndroid()->SelectRange(
11162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        gfx::Point(x1 / GetDpiScale(), y1 / GetDpiScale()),
11172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        gfx::Point(x2 / GetDpiScale(), y2 / GetDpiScale()));
11182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
11192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
11202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
11212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ContentViewCoreImpl::MoveCaret(JNIEnv* env, jobject obj,
11222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                    jfloat x, jfloat y) {
11232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (GetRenderWidgetHostViewAndroid()) {
11242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    GetRenderWidgetHostViewAndroid()->MoveCaret(
11252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        gfx::Point(x / GetDpiScale(), y / GetDpiScale()));
11265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
11275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
11285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
11295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)jboolean ContentViewCoreImpl::CanGoBack(JNIEnv* env, jobject obj) {
11305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return web_contents_->GetController().CanGoBack();
11315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
11325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
11335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)jboolean ContentViewCoreImpl::CanGoForward(JNIEnv* env, jobject obj) {
11345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return web_contents_->GetController().CanGoForward();
11355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
11365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
11375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)jboolean ContentViewCoreImpl::CanGoToOffset(JNIEnv* env, jobject obj,
11385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                            jint offset) {
11395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return web_contents_->GetController().CanGoToOffset(offset);
11405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
11415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
11425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::GoBack(JNIEnv* env, jobject obj) {
11435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  web_contents_->GetController().GoBack();
11445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  tab_crashed_ = false;
11455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
11465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
11475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::GoForward(JNIEnv* env, jobject obj) {
11485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  web_contents_->GetController().GoForward();
11495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  tab_crashed_ = false;
11505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
11515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
11525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::GoToOffset(JNIEnv* env, jobject obj, jint offset) {
11535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  web_contents_->GetController().GoToOffset(offset);
11545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
11555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
11562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ContentViewCoreImpl::GoToNavigationIndex(JNIEnv* env,
11572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                              jobject obj,
11582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                              jint index) {
11592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  web_contents_->GetController().GoToIndex(index);
11602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
11612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
11625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::StopLoading(JNIEnv* env, jobject obj) {
11635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  web_contents_->Stop();
11645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
11655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
11665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::Reload(JNIEnv* env, jobject obj) {
11675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Set check_for_repost parameter to false as we have no repost confirmation
11685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // dialog ("confirm form resubmission" screen will still appear, however).
11695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (web_contents_->GetController().NeedsReload())
11705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    web_contents_->GetController().LoadIfNecessary();
11715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  else
11725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    web_contents_->GetController().Reload(true);
11735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  tab_crashed_ = false;
11745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
11755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
11765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::CancelPendingReload(JNIEnv* env, jobject obj) {
11775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  web_contents_->GetController().CancelPendingReload();
11785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
11795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
11805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::ContinuePendingReload(JNIEnv* env, jobject obj) {
11815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  web_contents_->GetController().ContinuePendingReload();
11825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
11835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
11845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::ClearHistory(JNIEnv* env, jobject obj) {
11855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  web_contents_->GetController().PruneAllButActive();
11865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
11875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
11885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::AddJavascriptInterface(
11895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    JNIEnv* env,
11905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    jobject /* obj */,
11915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    jobject object,
11925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    jstring name,
11932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    jclass safe_annotation_clazz,
11942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    jobject retained_object_set) {
11955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ScopedJavaLocalRef<jobject> scoped_object(env, object);
11962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ScopedJavaLocalRef<jclass> scoped_clazz(env, safe_annotation_clazz);
11972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  JavaObjectWeakGlobalRef weak_retained_object_set(env, retained_object_set);
11982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
11995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // JavaBoundObject creates the NPObject with a ref count of 1, and
12005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // JavaBridgeDispatcherHostManager takes its own ref.
12012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  JavaBridgeDispatcherHostManager* java_bridge =
12022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      web_contents_->java_bridge_dispatcher_host_manager();
12032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  java_bridge->SetRetainedObjectSet(weak_retained_object_set);
12042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  NPObject* bound_object = JavaBoundObject::Create(scoped_object, scoped_clazz,
12052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                                   java_bridge->AsWeakPtr());
12062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  java_bridge->AddNamedObject(ConvertJavaStringToUTF16(env, name),
12072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                              bound_object);
12085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  WebKit::WebBindings::releaseObject(bound_object);
12095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
12105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
12115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::RemoveJavascriptInterface(JNIEnv* env,
12125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                                    jobject /* obj */,
12135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                                    jstring name) {
12145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  web_contents_->java_bridge_dispatcher_host_manager()->RemoveNamedObject(
12155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      ConvertJavaStringToUTF16(env, name));
12165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
12175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
12185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::UpdateVSyncParameters(JNIEnv* env, jobject /* obj */,
12195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                                jlong timebase_micros,
12205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                                jlong interval_micros) {
12215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid();
12225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (!view)
12235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return;
12245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
12255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  RenderWidgetHostImpl* host = RenderWidgetHostImpl::From(
12265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      view->GetRenderWidgetHost());
12275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
12285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  host->UpdateVSyncParameters(
12295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      base::TimeTicks::FromInternalValue(timebase_micros),
12305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      base::TimeDelta::FromMicroseconds(interval_micros));
12315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
12325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1233c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)void ContentViewCoreImpl::OnVSync(JNIEnv* env, jobject /* obj */,
1234c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                  jlong frame_time_micros) {
1235c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid();
1236c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  if (!view)
1237c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return;
1238c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1239c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  view->SendVSync(base::TimeTicks::FromInternalValue(frame_time_micros));
1240c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
1241c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
12425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)jboolean ContentViewCoreImpl::PopulateBitmapFromCompositor(JNIEnv* env,
12435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                                           jobject obj,
12445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                                           jobject jbitmap) {
12455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid();
12465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (!view)
12475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return false;
12485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
12495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return view->PopulateBitmapWithContents(jbitmap);
12505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
12515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
12522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ContentViewCoreImpl::WasResized(JNIEnv* env, jobject obj) {
12535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid();
12542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (view)
12552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    view->WasResized();
12562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
12572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
12582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ContentViewCoreImpl::ShowInterstitialPage(
12592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    JNIEnv* env, jobject obj, jstring jurl, jint delegate_ptr) {
12602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  GURL url(base::android::ConvertJavaStringToUTF8(env, jurl));
12612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  InterstitialPageDelegateAndroid* delegate =
12622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      reinterpret_cast<InterstitialPageDelegateAndroid*>(delegate_ptr);
12632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  InterstitialPage* interstitial = InterstitialPage::Create(
12642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      web_contents_, false, url, delegate);
12652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  delegate->set_interstitial_page(interstitial);
12662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  interstitial->Show();
12672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
12682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
12692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)jboolean ContentViewCoreImpl::IsShowingInterstitialPage(JNIEnv* env,
12702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                                        jobject obj) {
12712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return web_contents_->ShowingInterstitialPage();
12722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
12732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
12742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ContentViewCoreImpl::AttachExternalVideoSurface(JNIEnv* env,
12752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                                     jobject obj,
12762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                                     jint player_id,
12772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                                     jobject jsurface) {
1278c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#if defined(GOOGLE_TV)
12792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(
12802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      web_contents_->GetRenderViewHost());
12812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (rvhi && rvhi->media_player_manager()) {
12822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    rvhi->media_player_manager()->AttachExternalVideoSurface(
12832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        static_cast<int>(player_id), jsurface);
12842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
1285c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#endif
12862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
12872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
12882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ContentViewCoreImpl::DetachExternalVideoSurface(JNIEnv* env,
12892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                                     jobject obj,
12902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                                     jint player_id) {
1291c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#if defined(GOOGLE_TV)
12922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(
12932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      web_contents_->GetRenderViewHost());
12942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (rvhi && rvhi->media_player_manager()) {
12952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    rvhi->media_player_manager()->DetachExternalVideoSurface(
12962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        static_cast<int>(player_id));
12972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
1298c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#endif
12992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
13005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
13012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)jboolean ContentViewCoreImpl::IsRenderWidgetHostViewReady(JNIEnv* env,
13022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                                          jobject obj) {
13032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid();
13042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return view && view->HasValidFrame();
13052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
13062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
13072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ContentViewCoreImpl::ExitFullscreen(JNIEnv* env, jobject obj) {
13082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  RenderViewHost* host = web_contents_->GetRenderViewHost();
13092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  host->ExitFullscreen();
13102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
13112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1312c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)void ContentViewCoreImpl::UpdateTopControlsState(JNIEnv* env,
1313c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                                 jobject obj,
1314c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                                 bool enable_hiding,
1315c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                                 bool enable_showing,
1316c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                                 bool animate) {
13172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  RenderViewHost* host = web_contents_->GetRenderViewHost();
1318c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  host->Send(new ViewMsg_UpdateTopControlsState(host->GetRoutingID(),
1319c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                                enable_hiding,
1320c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                                enable_showing,
1321c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                                animate));
13222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
13232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
13242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ContentViewCoreImpl::ShowImeIfNeeded(JNIEnv* env, jobject obj) {
13252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  RenderViewHost* host = web_contents_->GetRenderViewHost();
13262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  host->Send(new ViewMsg_ShowImeIfNeeded(host->GetRoutingID()));
13275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
13285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
13295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::ScrollFocusedEditableNodeIntoView(JNIEnv* env,
13305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                                            jobject obj) {
13315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  RenderViewHost* host = web_contents_->GetRenderViewHost();
1332c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  host->Send(new InputMsg_ScrollFocusedEditableNodeIntoRect(
1333c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      host->GetRoutingID(), gfx::Rect()));
13345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
13355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
13362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace {
13372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
13382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)static void AddNavigationEntryToHistory(JNIEnv* env, jobject obj,
13392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                        jobject history,
13402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                        NavigationEntry* entry,
13412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                        int index) {
13422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Get the details of the current entry
13432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ScopedJavaLocalRef<jstring> j_url(
13442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      ConvertUTF8ToJavaString(env, entry->GetURL().spec()));
13452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ScopedJavaLocalRef<jstring> j_virtual_url(
13462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      ConvertUTF8ToJavaString(env, entry->GetVirtualURL().spec()));
13472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ScopedJavaLocalRef<jstring> j_original_url(
13482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      ConvertUTF8ToJavaString(env, entry->GetOriginalRequestURL().spec()));
13492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ScopedJavaLocalRef<jstring> j_title(
13502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      ConvertUTF16ToJavaString(env, entry->GetTitle()));
13512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ScopedJavaLocalRef<jobject> j_bitmap;
13522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const FaviconStatus& status = entry->GetFavicon();
13532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (status.valid && status.image.ToSkBitmap()->getSize() > 0)
13542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    j_bitmap = gfx::ConvertToJavaBitmap(status.image.ToSkBitmap());
13552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
13562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Add the item to the list
13572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  Java_ContentViewCore_addToNavigationHistory(
13582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      env, obj, history, index, j_url.obj(), j_virtual_url.obj(),
13592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      j_original_url.obj(), j_title.obj(), j_bitmap.obj());
13602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
13612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
13622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}  // namespace
13632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
13645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int ContentViewCoreImpl::GetNavigationHistory(JNIEnv* env,
13655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                              jobject obj,
1366c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                              jobject history) {
13675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Iterate through navigation entries to populate the list
13685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const NavigationController& controller = web_contents_->GetController();
13695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int count = controller.GetEntryCount();
13705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  for (int i = 0; i < count; ++i) {
13712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    AddNavigationEntryToHistory(
1372c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)        env, obj, history, controller.GetEntryAtIndex(i), i);
13735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
13745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
13755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return controller.GetCurrentEntryIndex();
13765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
13775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
13782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ContentViewCoreImpl::GetDirectedNavigationHistory(JNIEnv* env,
13792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                                       jobject obj,
1380c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                                       jobject history,
13812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                                       jboolean is_forward,
13822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                                       jint max_entries) {
13832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Iterate through navigation entries to populate the list
13842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const NavigationController& controller = web_contents_->GetController();
13852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  int count = controller.GetEntryCount();
13862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  int num_added = 0;
13872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  int increment_value = is_forward ? 1 : -1;
13882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  for (int i = controller.GetCurrentEntryIndex() + increment_value;
13892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)       i >= 0 && i < count;
13902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)       i += increment_value) {
13912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    if (num_added >= max_entries)
13922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      break;
13932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
13942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    AddNavigationEntryToHistory(
1395c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)        env, obj, history, controller.GetEntryAtIndex(i), i);
13962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    num_added++;
13972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
13982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
13992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1400c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)ScopedJavaLocalRef<jstring>
1401c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)ContentViewCoreImpl::GetOriginalUrlForActiveNavigationEntry(JNIEnv* env,
1402c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                                            jobject obj) {
1403c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  NavigationEntry* entry = web_contents_->GetController().GetActiveEntry();
1404c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  if (entry == NULL)
1405c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return ScopedJavaLocalRef<jstring>(env, NULL);
1406c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  return ConvertUTF8ToJavaString(env, entry->GetOriginalRequestURL().spec());
1407c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
1408c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
14095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int ContentViewCoreImpl::GetNativeImeAdapter(JNIEnv* env, jobject obj) {
14105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid();
14115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (!rwhva)
14125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return 0;
14135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return rwhva->GetNativeImeAdapter();
14145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
14155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
14165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)jboolean ContentViewCoreImpl::NeedsReload(JNIEnv* env, jobject obj) {
14175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return web_contents_->GetController().NeedsReload();
14185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
14195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
14205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::UndoScrollFocusedEditableNodeIntoView(
14215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    JNIEnv* env,
14225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    jobject obj) {
14235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  RenderViewHost* host = web_contents_->GetRenderViewHost();
14245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  host->Send(
14255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      new ViewMsg_UndoScrollFocusedEditableNodeIntoView(host->GetRoutingID()));
14265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
14275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
14282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace {
14292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void JavaScriptResultCallback(const ScopedJavaGlobalRef<jobject>& callback,
14302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                              const base::Value* result) {
14312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  JNIEnv* env = base::android::AttachCurrentThread();
14322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  std::string json;
14332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::JSONWriter::Write(result, &json);
14342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ScopedJavaLocalRef<jstring> j_json = ConvertUTF8ToJavaString(env, json);
14352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  Java_ContentViewCore_onEvaluateJavaScriptResult(env,
14362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                                  j_json.obj(),
14372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                                  callback.obj());
14382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
14392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}  // namespace
14402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
14412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ContentViewCoreImpl::EvaluateJavaScript(JNIEnv* env,
14425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                             jobject obj,
14432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                             jstring script,
14442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                             jobject callback) {
14455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  RenderViewHost* host = web_contents_->GetRenderViewHost();
14465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DCHECK(host);
14475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
14482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (!callback) {
14492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // No callback requested.
14502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    host->ExecuteJavascriptInWebFrame(string16(),  // frame_xpath
14512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                      ConvertJavaStringToUTF16(env, script));
14522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return;
14532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
14542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
14552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Secure the Java callback in a scoped object and give ownership of it to the
14562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // base::Callback.
14572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ScopedJavaGlobalRef<jobject> j_callback;
14582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  j_callback.Reset(env, callback);
14592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  content::RenderViewHost::JavascriptResultCallback c_callback =
14602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      base::Bind(&JavaScriptResultCallback, j_callback);
14612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
14622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  host->ExecuteJavascriptInWebFrameCallbackResult(
14632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      string16(),  // frame_xpath
14642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      ConvertJavaStringToUTF16(env, script),
14652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      c_callback);
14665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
14675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
14685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool ContentViewCoreImpl::GetUseDesktopUserAgent(
14695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    JNIEnv* env, jobject obj) {
14705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  NavigationEntry* entry = web_contents_->GetController().GetActiveEntry();
14715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return entry && entry->GetIsOverridingUserAgent();
14725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
14735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
14742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ContentViewCoreImpl::UpdateImeAdapter(int native_ime_adapter,
14755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                           int text_input_type,
14765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                           const std::string& text,
14775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                           int selection_start,
14785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                           int selection_end,
14795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                           int composition_start,
14805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                           int composition_end,
14815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                           bool show_ime_if_needed) {
14825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  JNIEnv* env = AttachCurrentThread();
14835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
14845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (obj.is_null())
14855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return;
14865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
14875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ScopedJavaLocalRef<jstring> jstring_text = ConvertUTF8ToJavaString(env, text);
14882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  Java_ContentViewCore_updateImeAdapter(env, obj.obj(),
14895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                        native_ime_adapter, text_input_type,
14905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                        jstring_text.obj(),
14915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                        selection_start, selection_end,
14925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                        composition_start, composition_end,
14935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                        show_ime_if_needed);
14945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
14955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
14962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ContentViewCoreImpl::ProcessImeBatchStateAck(bool is_begin) {
14972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  JNIEnv* env = AttachCurrentThread();
14982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
14992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (obj.is_null())
15002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return;
15012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  Java_ContentViewCore_processImeBatchStateAck(env, obj.obj(), is_begin);
15022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
15032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
15045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::ClearSslPreferences(JNIEnv* env, jobject obj) {
15055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SSLHostState* state = SSLHostState::GetFor(
15065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      web_contents_->GetController().GetBrowserContext());
15075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  state->Clear();
15085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
15095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
15105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ContentViewCoreImpl::SetUseDesktopUserAgent(
15115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    JNIEnv* env,
15125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    jobject obj,
15135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    jboolean enabled,
15145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    jboolean reload_on_state_change) {
15155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (GetUseDesktopUserAgent(env, obj) == enabled)
15165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return;
15175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
15185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Make sure the navigation entry actually exists.
15195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  NavigationEntry* entry = web_contents_->GetController().GetActiveEntry();
15205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (!entry)
15215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return;
15225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
15235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Set the flag in the NavigationEntry.
15245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  entry->SetIsOverridingUserAgent(enabled);
15255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
15265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Send the override to the renderer.
15275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (reload_on_state_change) {
15285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Reloading the page will send the override down as part of the
15295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // navigation IPC message.
15305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    NavigationControllerImpl& controller =
15315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        static_cast<NavigationControllerImpl&>(web_contents_->GetController());
15325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    controller.ReloadOriginalRequestURL(false);
15335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
15345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
15355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
15365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This is called for each ContentView.
15375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)jint Init(JNIEnv* env, jobject obj,
15385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          jboolean hardware_accelerated,
15395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          jint native_web_contents,
1540c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)          jint view_android,
1541c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)          jint window_android) {
15425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ContentViewCoreImpl* view = new ContentViewCoreImpl(
1543c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      env, obj, hardware_accelerated,
15445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      reinterpret_cast<WebContents*>(native_web_contents),
1545c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      reinterpret_cast<ui::ViewAndroid*>(view_android),
1546c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      reinterpret_cast<ui::WindowAndroid*>(window_android));
15475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return reinterpret_cast<jint>(view);
15485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
15495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
15505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool RegisterContentViewCore(JNIEnv* env) {
15512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return RegisterNativesImpl(env);
15525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
15535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
15545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace content
1555