#include "base/android/jni_string.h"
#include "base/android/scoped_java_ref.h"
#include "base/command_line.h"
-#include "base/json/json_writer.h"
#include "base/logging.h"
#include "base/metrics/histogram.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "cc/layers/layer.h"
+#include "cc/layers/solid_color_layer.h"
#include "cc/output/begin_frame_args.h"
+#include "content/browser/accessibility/browser_accessibility_state_impl.h"
#include "content/browser/android/gesture_event_type.h"
#include "content/browser/android/interstitial_page_delegate_android.h"
+#include "content/browser/android/java/gin_java_bridge_dispatcher_host.h"
#include "content/browser/android/load_url_params.h"
+#include "content/browser/android/popup_touch_handle_drawable.h"
#include "content/browser/frame_host/interstitial_page_impl.h"
-#include "content/browser/frame_host/navigation_controller_impl.h"
-#include "content/browser/frame_host/navigation_entry_impl.h"
-#include "content/browser/media/android/browser_media_player_manager.h"
+#include "content/browser/geolocation/geolocation_dispatcher_host.h"
+#include "content/browser/media/media_web_contents_observer.h"
#include "content/browser/renderer_host/compositor_impl_android.h"
#include "content/browser/renderer_host/input/motion_event_android.h"
#include "content/browser/renderer_host/input/web_input_event_builders_android.h"
#include "content/browser/renderer_host/input/web_input_event_util.h"
-#include "content/browser/renderer_host/java/java_bound_object.h"
-#include "content/browser/renderer_host/java/java_bridge_dispatcher_host_manager.h"
#include "content/browser/renderer_host/render_view_host_impl.h"
#include "content/browser/renderer_host/render_widget_host_impl.h"
#include "content/browser/renderer_host/render_widget_host_view_android.h"
-#include "content/browser/screen_orientation/screen_orientation_dispatcher_host.h"
-#include "content/browser/ssl/ssl_host_state.h"
+#include "content/browser/transition_request_manager.h"
#include "content/browser/web_contents/web_contents_view_android.h"
+#include "content/common/frame_messages.h"
#include "content/common/input/web_input_event_traits.h"
#include "content/common/input_messages.h"
#include "content/common/view_messages.h"
-#include "content/public/browser/android/external_video_surface_container.h"
-#include "content/public/browser/browser_accessibility_state.h"
#include "content/public/browser/browser_context.h"
+#include "content/public/browser/browser_thread.h"
#include "content/public/browser/favicon_status.h"
-#include "content/public/browser/notification_details.h"
-#include "content/public/browser/notification_service.h"
-#include "content/public/browser/notification_source.h"
-#include "content/public/browser/notification_types.h"
#include "content/public/browser/render_frame_host.h"
+#include "content/public/browser/screen_orientation_dispatcher_host.h"
+#include "content/public/browser/ssl_host_state_delegate.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_client.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/menu_item.h"
-#include "content/public/common/page_transition_types.h"
#include "content/public/common/user_agent.h"
#include "jni/ContentViewCore_jni.h"
-#include "third_party/WebKit/public/web/WebBindings.h"
#include "third_party/WebKit/public/web/WebInputEvent.h"
#include "ui/base/android/view_android.h"
#include "ui/base/android/window_android.h"
-#include "ui/events/gesture_detection/gesture_config_helper.h"
#include "ui/gfx/android/java_bitmap.h"
#include "ui/gfx/screen.h"
#include "ui/gfx/size_conversions.h"
using base::android::ConvertJavaStringToUTF8;
using base::android::ConvertUTF16ToJavaString;
using base::android::ConvertUTF8ToJavaString;
-using base::android::ScopedJavaGlobalRef;
using base::android::ScopedJavaLocalRef;
using blink::WebGestureEvent;
using blink::WebInputEvent;
namespace {
-const unsigned int kDefaultVSyncIntervalMicros = 16666u;
-// TODO(brianderson): Use adaptive draw-time estimation.
-const float kDefaultBrowserCompositeVSyncFraction = 1.0f / 3;
-
const void* kContentViewUserDataKey = &kContentViewUserDataKey;
int GetRenderProcessIdFromRenderViewHost(RenderViewHost* host) {
return display.device_scale_factor();
}
-ui::GestureProvider::Config GetGestureProviderConfig() {
- ui::GestureProvider::Config config = ui::DefaultGestureProviderConfig();
- config.disable_click_delay =
- CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableClickDelay);
- return config;
-}
-
} // namespace
// Enables a callback when the underlying WebContents is destroyed, to enable
Java_ContentViewCore_getNativeContentViewCore(env, obj));
}
-ContentViewCoreImpl::ContentViewCoreImpl(JNIEnv* env,
- jobject obj,
- WebContents* web_contents,
- ui::ViewAndroid* view_android,
- ui::WindowAndroid* window_android)
+ContentViewCoreImpl::ContentViewCoreImpl(
+ JNIEnv* env,
+ jobject obj,
+ WebContents* web_contents,
+ ui::ViewAndroid* view_android,
+ ui::WindowAndroid* window_android,
+ jobject java_bridge_retained_object_set)
: WebContentsObserver(web_contents),
java_ref_(env, obj),
web_contents_(static_cast<WebContentsImpl*>(web_contents)),
- root_layer_(cc::Layer::Create()),
+ root_layer_(cc::SolidColorLayer::Create()),
dpi_scale_(GetPrimaryDisplayDeviceScaleFactor()),
- vsync_interval_(base::TimeDelta::FromMicroseconds(
- kDefaultVSyncIntervalMicros)),
- expected_browser_composite_time_(base::TimeDelta::FromMicroseconds(
- kDefaultVSyncIntervalMicros * kDefaultBrowserCompositeVSyncFraction)),
view_android_(view_android),
window_android_(window_android),
- gesture_provider_(GetGestureProviderConfig(), this),
device_orientation_(0),
- geolocation_needs_pause_(false) {
+ accessibility_enabled_(false) {
CHECK(web_contents) <<
"A ContentViewCoreImpl should be created with a valid WebContents.";
+ DCHECK(view_android_);
+ DCHECK(window_android_);
+
+ root_layer_->SetBackgroundColor(GetBackgroundColor(env, obj));
+ gfx::Size physical_size(
+ Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj),
+ Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj));
+ root_layer_->SetBounds(physical_size);
+ root_layer_->SetIsDrawable(true);
// Currently, the only use case we have for overriding a user agent involves
// spoofing a desktop Linux user agent for "Request desktop site".
BuildUserAgentFromOSAndProduct(kLinuxInfoStr, product);
web_contents->SetUserAgentOverride(spoofed_ua);
+ java_bridge_dispatcher_host_.reset(
+ new GinJavaBridgeDispatcherHost(web_contents,
+ java_bridge_retained_object_set));
+
InitWebContents();
}
Java_ContentViewCore_onNativeContentViewCoreDestroyed(
env, j_obj.obj(), reinterpret_cast<intptr_t>(this));
}
- // Make sure nobody calls back into this object while we are tearing things
- // down.
- notification_registrar_.RemoveAll();
}
base::android::ScopedJavaLocalRef<jobject>
jobject obj) {
DCHECK(env->IsSameObject(java_ref_.get(env).obj(), obj));
java_ref_.reset();
+ // Java peer has gone, ContentViewCore is not functional and waits to
+ // be destroyed with WebContents.
+ // We need to reset WebContentsViewAndroid's reference, otherwise, there
+ // could have call in when swapping the WebContents,
+ // see http://crbug.com/383939 .
+ DCHECK(web_contents_);
+ static_cast<WebContentsViewAndroid*>(
+ static_cast<WebContentsImpl*>(web_contents_)->GetView())->
+ SetContentViewCore(NULL);
}
void ContentViewCoreImpl::InitWebContents() {
DCHECK(web_contents_);
- notification_registrar_.Add(
- this, NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
- Source<WebContents>(web_contents_));
- notification_registrar_.Add(
- this, NOTIFICATION_RENDERER_PROCESS_CREATED,
- content::NotificationService::AllBrowserContextsAndSources());
- notification_registrar_.Add(
- this, NOTIFICATION_WEB_CONTENTS_CONNECTED,
- Source<WebContents>(web_contents_));
-
- static_cast<WebContentsViewAndroid*>(web_contents_->GetView())->
- SetContentViewCore(this);
+ static_cast<WebContentsViewAndroid*>(
+ static_cast<WebContentsImpl*>(web_contents_)->GetView())->
+ SetContentViewCore(this);
DCHECK(!web_contents_->GetUserData(kContentViewUserDataKey));
web_contents_->SetUserData(kContentViewUserDataKey,
new ContentViewUserData(this));
}
-void ContentViewCoreImpl::Observe(int type,
- const NotificationSource& source,
- const NotificationDetails& details) {
- switch (type) {
- case NOTIFICATION_RENDER_VIEW_HOST_CHANGED: {
- std::pair<RenderViewHost*, RenderViewHost*>* switched_details =
- Details<std::pair<RenderViewHost*, RenderViewHost*> >(details).ptr();
- int old_pid = 0;
- if (switched_details->first) {
- old_pid = GetRenderProcessIdFromRenderViewHost(
- switched_details->first);
-
- RenderWidgetHostViewAndroid* view =
- static_cast<RenderWidgetHostViewAndroid*>(
- switched_details->first->GetView());
- if (view)
- view->SetContentViewCore(NULL);
-
- view = static_cast<RenderWidgetHostViewAndroid*>(
- switched_details->second->GetView());
-
- if (view)
- view->SetContentViewCore(this);
- }
- int new_pid = GetRenderProcessIdFromRenderViewHost(
- web_contents_->GetRenderViewHost());
- if (new_pid != old_pid) {
- // Notify the Java side of the change of the current renderer process.
- JNIEnv* env = AttachCurrentThread();
- ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
- if (!obj.is_null()) {
- Java_ContentViewCore_onRenderProcessSwap(
- env, obj.obj(), old_pid, new_pid);
- }
- }
- SetFocusInternal(HasFocus());
- if (geolocation_needs_pause_)
- PauseOrResumeGeolocation(true);
- break;
- }
- case NOTIFICATION_RENDERER_PROCESS_CREATED: {
- // Notify the Java side of the current renderer process.
- RenderProcessHost* source_process_host =
- Source<RenderProcessHost>(source).ptr();
- RenderProcessHost* current_process_host =
- web_contents_->GetRenderViewHost()->GetProcess();
-
- if (source_process_host == current_process_host) {
- int pid = GetRenderProcessIdFromRenderViewHost(
- web_contents_->GetRenderViewHost());
- JNIEnv* env = AttachCurrentThread();
- ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
- if (!obj.is_null()) {
- Java_ContentViewCore_onRenderProcessSwap(env, obj.obj(), 0, pid);
- }
- }
- break;
- }
- case NOTIFICATION_WEB_CONTENTS_CONNECTED: {
- JNIEnv* env = AttachCurrentThread();
- ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
- if (!obj.is_null()) {
- Java_ContentViewCore_onWebContentsConnected(env, obj.obj());
- }
- break;
- }
- }
-}
-
void ContentViewCoreImpl::RenderViewReady() {
+ JNIEnv* env = AttachCurrentThread();
+ ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
+ if (!obj.is_null())
+ Java_ContentViewCore_onRenderProcessChange(env, obj.obj());
+
if (device_orientation_ != 0)
SendOrientationChangeEventInternal();
}
-void ContentViewCoreImpl::OnGestureEvent(const ui::GestureEventData& gesture) {
- SendGestureEvent(
- CreateWebGestureEventFromGestureEventData(gesture, 1.f / dpi_scale()));
+void ContentViewCoreImpl::RenderViewHostChanged(RenderViewHost* old_host,
+ RenderViewHost* new_host) {
+ int old_pid = 0;
+ if (old_host) {
+ old_pid = GetRenderProcessIdFromRenderViewHost(old_host);
+
+ RenderWidgetHostViewAndroid* view =
+ static_cast<RenderWidgetHostViewAndroid*>(old_host->GetView());
+ if (view)
+ view->SetContentViewCore(NULL);
+
+ view = static_cast<RenderWidgetHostViewAndroid*>(new_host->GetView());
+ if (view)
+ view->SetContentViewCore(this);
+ }
+ int new_pid = GetRenderProcessIdFromRenderViewHost(
+ web_contents_->GetRenderViewHost());
+ if (new_pid != old_pid) {
+ // Notify the Java side that the renderer process changed.
+ JNIEnv* env = AttachCurrentThread();
+ ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
+ if (!obj.is_null()) {
+ Java_ContentViewCore_onRenderProcessChange(env, obj.obj());
+ }
+ }
+
+ SetFocusInternal(HasFocus());
+ SetAccessibilityEnabledInternal(accessibility_enabled_);
}
RenderWidgetHostViewAndroid*
return rwhva->GetCachedBackgroundColor();
}
-void ContentViewCoreImpl::OnHide(JNIEnv* env, jobject obj) {
- Hide();
-}
-
-void ContentViewCoreImpl::OnShow(JNIEnv* env, jobject obj) {
- Show();
-}
-
-void ContentViewCoreImpl::Show() {
- GetWebContents()->WasShown();
-}
-
-void ContentViewCoreImpl::Hide() {
- GetWebContents()->WasHidden();
- PauseVideo();
-}
-
-void ContentViewCoreImpl::PauseVideo() {
- RenderViewHost* host = web_contents_->GetRenderViewHost();
- if (host)
- host->Send(new ViewMsg_PauseVideo(host->GetRoutingID()));
-}
-
void ContentViewCoreImpl::PauseOrResumeGeolocation(bool should_pause) {
- geolocation_needs_pause_ = should_pause;
- RenderViewHostImpl* rvh =
- static_cast<RenderViewHostImpl*>(web_contents_->GetRenderViewHost());
- if (rvh) {
- scoped_refptr<GeolocationDispatcherHost> geolocation_dispatcher =
- static_cast<RenderProcessHostImpl*>(
- web_contents_->GetRenderProcessHost())->
- geolocation_dispatcher_host();
- if (geolocation_dispatcher.get()) {
- BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
- base::Bind(&GeolocationDispatcherHost::PauseOrResume,
- geolocation_dispatcher,
- rvh->GetRoutingID(),
- should_pause));
- geolocation_needs_pause_ = false;
- }
- }
-}
-
-void ContentViewCoreImpl::OnTabCrashed() {
- JNIEnv* env = AttachCurrentThread();
- ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
- if (obj.is_null())
- return;
- Java_ContentViewCore_resetVSyncNotification(env, obj.obj());
+ web_contents_->geolocation_dispatcher_host()->PauseOrResume(should_pause);
}
// All positions and sizes are in CSS pixels.
const gfx::SizeF& content_size,
const gfx::SizeF& viewport_size,
const gfx::Vector2dF& controls_offset,
- const gfx::Vector2dF& content_offset,
- float overdraw_bottom_height) {
+ const gfx::Vector2dF& content_offset) {
JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
if (obj.is_null())
return;
- if (window_android_) {
- gfx::Vector2dF window_offset(
- Java_ContentViewCore_getLocationInWindowX(env, obj.obj()),
- Java_ContentViewCore_getLocationInWindowY(env, obj.obj()));
- window_android_->set_content_offset(
- gfx::ScaleVector2d(content_offset, dpi_scale_) + window_offset);
- }
+ window_android_->set_content_offset(
+ gfx::ScaleVector2d(content_offset, dpi_scale_));
Java_ContentViewCore_updateFrameInfo(
env, obj.obj(),
viewport_size.width(),
viewport_size.height(),
controls_offset.y(),
- content_offset.y(),
- overdraw_bottom_height);
-#if defined(VIDEO_HOLE)
- ExternalVideoSurfaceContainer* surface_container =
- ExternalVideoSurfaceContainer::FromWebContents(web_contents_);
- if (surface_container)
- surface_container->OnFrameInfoUpdated();
-#endif // defined(VIDEO_HOLE)
+ content_offset.y());
}
void ContentViewCoreImpl::SetTitle(const base::string16& title) {
}
void ContentViewCoreImpl::OnBackgroundColorChanged(SkColor color) {
+ root_layer_->SetBackgroundColor(color);
+
JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
if (obj.is_null())
}
void ContentViewCoreImpl::ShowSelectPopupMenu(
- const std::vector<MenuItem>& items, int selected_item, bool multiple) {
+ RenderFrameHost* frame,
+ const gfx::Rect& bounds,
+ const std::vector<MenuItem>& items,
+ int selected_item,
+ bool multiple) {
JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env);
if (j_obj.is_null())
return;
+ ScopedJavaLocalRef<jobject> bounds_rect(CreateJavaRect(env, bounds));
+
// For multi-select list popups we find the list of previous selections by
// iterating through the items. But for single selection popups we take the
// given |selected_item| as is.
}
ScopedJavaLocalRef<jobjectArray> items_array(
base::android::ToJavaArrayOfStrings(env, labels));
- Java_ContentViewCore_showSelectPopup(env, j_obj.obj(),
- items_array.obj(), enabled_array.obj(),
- multiple, selected_array.obj());
+ Java_ContentViewCore_showSelectPopup(env,
+ j_obj.obj(),
+ reinterpret_cast<intptr_t>(frame),
+ bounds_rect.obj(),
+ items_array.obj(),
+ enabled_array.obj(),
+ multiple,
+ selected_array.obj());
}
-void ContentViewCoreImpl::ConfirmTouchEvent(InputEventAckState ack_result) {
- const bool event_consumed = ack_result == INPUT_EVENT_ACK_STATE_CONSUMED;
- gesture_provider_.OnTouchEventAck(event_consumed);
+void ContentViewCoreImpl::HideSelectPopupMenu() {
+ JNIEnv* env = AttachCurrentThread();
+ ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env);
+ if (!j_obj.is_null())
+ Java_ContentViewCore_hideSelectPopup(env, j_obj.obj());
}
void ContentViewCoreImpl::OnGestureEventAck(const blink::WebGestureEvent& event,
case WebInputEvent::GesturePinchEnd:
Java_ContentViewCore_onPinchEndEventAck(env, j_obj.obj());
break;
- case WebInputEvent::GestureDoubleTap:
- Java_ContentViewCore_onDoubleTapEventAck(env, j_obj.obj());
+ case WebInputEvent::GestureTap:
+ Java_ContentViewCore_onSingleTapEventAck(
+ env,
+ j_obj.obj(),
+ ack_result == INPUT_EVENT_ACK_STATE_CONSUMED,
+ event.x * dpi_scale(),
+ event.y * dpi_scale());
break;
default:
break;
Java_ContentViewCore_onSelectionChanged(env, obj.obj(), jtext.obj());
}
-void ContentViewCoreImpl::OnSelectionBoundsChanged(
- const ViewHostMsg_SelectionBounds_Params& params) {
+void ContentViewCoreImpl::OnSelectionEvent(SelectionEventType event,
+ const gfx::PointF& position) {
JNIEnv* env = AttachCurrentThread();
- ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
- if (obj.is_null())
+ ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env);
+ if (j_obj.is_null())
return;
- ScopedJavaLocalRef<jobject> anchor_rect_dip(
- CreateJavaRect(env, params.anchor_rect));
- ScopedJavaLocalRef<jobject> focus_rect_dip(
- CreateJavaRect(env, params.focus_rect));
- Java_ContentViewCore_onSelectionBoundsChanged(env, obj.obj(),
- anchor_rect_dip.obj(),
- params.anchor_dir,
- focus_rect_dip.obj(),
- params.focus_dir,
- params.is_anchor_first);
+ Java_ContentViewCore_onSelectionEvent(
+ env, j_obj.obj(), event, position.x(), position.y());
+}
+
+scoped_ptr<TouchHandleDrawable>
+ContentViewCoreImpl::CreatePopupTouchHandleDrawable() {
+ JNIEnv* env = AttachCurrentThread();
+ ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
+ if (obj.is_null()) {
+ NOTREACHED();
+ return scoped_ptr<TouchHandleDrawable>();
+ }
+ return scoped_ptr<TouchHandleDrawable>(new PopupTouchHandleDrawable(
+ Java_ContentViewCore_createPopupTouchHandleDrawable(env, obj.obj()),
+ dpi_scale_));
}
void ContentViewCoreImpl::ShowPastePopup(int x_dip, int y_dip) {
+ RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid();
+ if (!view)
+ return;
+
+ view->OnShowingPastePopup(gfx::PointF(x_dip, y_dip));
+
JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
if (obj.is_null())
return;
- Java_ContentViewCore_showPastePopup(env, obj.obj(),
- static_cast<jint>(x_dip),
- static_cast<jint>(y_dip));
+ Java_ContentViewCore_showPastePopupWithFeedback(env, obj.obj(),
+ static_cast<jint>(x_dip),
+ static_cast<jint>(y_dip));
}
void ContentViewCoreImpl::GetScaledContentBitmap(
float scale,
- jobject jbitmap_config,
+ SkColorType color_type,
gfx::Rect src_subrect,
const base::Callback<void(bool, const SkBitmap&)>& result_callback) {
RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid();
result_callback.Run(false, SkBitmap());
return;
}
- SkBitmap::Config skbitmap_format = gfx::ConvertToSkiaConfig(jbitmap_config);
- view->GetScaledContentBitmap(scale, skbitmap_format, src_subrect,
+
+ view->GetScaledContentBitmap(scale, color_type, src_subrect,
result_callback);
}
}
void ContentViewCoreImpl::ShowDisambiguationPopup(
- const gfx::Rect& target_rect,
+ const gfx::Rect& rect_pixels,
const SkBitmap& zoomed_bitmap) {
JNIEnv* env = AttachCurrentThread();
if (obj.is_null())
return;
- ScopedJavaLocalRef<jobject> rect_object(CreateJavaRect(env, target_rect));
+ ScopedJavaLocalRef<jobject> rect_object(CreateJavaRect(env, rect_pixels));
ScopedJavaLocalRef<jobject> java_bitmap =
gfx::ConvertToJavaBitmap(&zoomed_bitmap);
gfx::Size ContentViewCoreImpl::GetViewSize() const {
gfx::Size size = GetViewportSizeDip();
- gfx::Size offset = GetViewportSizeOffsetDip();
- size.Enlarge(-offset.width(), -offset.height());
+ size.Enlarge(0, -GetTopControlsLayoutHeightDip());
return size;
}
Java_ContentViewCore_getViewportHeightPix(env, j_obj.obj()));
}
-gfx::Size ContentViewCoreImpl::GetViewportSizeOffsetPix() const {
+int ContentViewCoreImpl::GetTopControlsLayoutHeightPix() const {
JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env);
if (j_obj.is_null())
- return gfx::Size();
- return gfx::Size(
- Java_ContentViewCore_getViewportSizeOffsetWidthPix(env, j_obj.obj()),
- Java_ContentViewCore_getViewportSizeOffsetHeightPix(env, j_obj.obj()));
+ return 0;
+ return Java_ContentViewCore_getTopControlsLayoutHeightPix(env, j_obj.obj());
}
gfx::Size ContentViewCoreImpl::GetViewportSizeDip() const {
gfx::ScaleSize(GetViewportSizePix(), 1.0f / dpi_scale()));
}
-gfx::Size ContentViewCoreImpl::GetViewportSizeOffsetDip() const {
- return gfx::ToCeiledSize(
- gfx::ScaleSize(GetViewportSizeOffsetPix(), 1.0f / dpi_scale()));
-}
-
-float ContentViewCoreImpl::GetOverdrawBottomHeightDip() const {
- JNIEnv* env = AttachCurrentThread();
- ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env);
- if (j_obj.is_null())
- return 0.f;
- return Java_ContentViewCore_getOverdrawBottomHeightPix(env, j_obj.obj())
- / dpi_scale();
+float ContentViewCoreImpl::GetTopControlsLayoutHeightDip() const {
+ return GetTopControlsLayoutHeightPix() / dpi_scale();
}
void ContentViewCoreImpl::AttachLayer(scoped_refptr<cc::Layer> layer) {
- root_layer_->AddChild(layer);
+ root_layer_->InsertChild(layer, 0);
+ root_layer_->SetIsDrawable(false);
}
void ContentViewCoreImpl::RemoveLayer(scoped_refptr<cc::Layer> layer) {
layer->RemoveFromParent();
-}
-void ContentViewCoreImpl::LoadUrl(
- NavigationController::LoadURLParams& params) {
- GetWebContents()->GetController().LoadURLWithParams(params);
+ if (!root_layer_->children().size())
+ root_layer_->SetIsDrawable(true);
}
-void ContentViewCoreImpl::AddBeginFrameSubscriber() {
- JNIEnv* env = AttachCurrentThread();
- ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
- if (obj.is_null())
+void ContentViewCoreImpl::SelectBetweenCoordinates(const gfx::PointF& start,
+ const gfx::PointF& end) {
+ if (!web_contents_)
return;
- Java_ContentViewCore_addVSyncSubscriber(env, obj.obj());
-}
-void ContentViewCoreImpl::RemoveBeginFrameSubscriber() {
- JNIEnv* env = AttachCurrentThread();
- ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
- if (obj.is_null())
+ gfx::Point start_point = gfx::Point(start.x(), start.y());
+ gfx::Point end_point = gfx::Point(end.x(), end.y());
+ if (start_point == end_point)
return;
- Java_ContentViewCore_removeVSyncSubscriber(env, obj.obj());
-}
-void ContentViewCoreImpl::SetNeedsAnimate() {
- JNIEnv* env = AttachCurrentThread();
- ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
- if (obj.is_null())
- return;
- Java_ContentViewCore_setNeedsAnimate(env, obj.obj());
+ web_contents_->SelectRange(start_point, end_point);
}
ui::ViewAndroid* ContentViewCoreImpl::GetViewAndroid() const {
- // view_android_ should never be null for Chrome.
- DCHECK(view_android_);
return view_android_;
}
ui::WindowAndroid* ContentViewCoreImpl::GetWindowAndroid() const {
- // This should never be NULL for Chrome, but will be NULL for WebView.
- DCHECK(window_android_);
return window_android_;
}
// Methods called from Java via JNI
// ----------------------------------------------------------------------------
-void ContentViewCoreImpl::SelectPopupMenuItems(JNIEnv* env, jobject obj,
+void ContentViewCoreImpl::SelectPopupMenuItems(JNIEnv* env,
+ jobject obj,
+ jlong selectPopupSourceFrame,
jintArray indices) {
- RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(
- web_contents_->GetRenderViewHost());
- DCHECK(rvhi);
+ RenderFrameHostImpl* rfhi =
+ reinterpret_cast<RenderFrameHostImpl*>(selectPopupSourceFrame);
+ DCHECK(rfhi);
if (indices == NULL) {
- rvhi->DidCancelPopupMenu();
+ rfhi->DidCancelPopupMenu();
return;
}
for (int i = 0; i < selected_count; ++i)
selected_indices.push_back(indices_ptr[i]);
env->ReleaseIntArrayElements(indices, indices_ptr, JNI_ABORT);
- rvhi->DidSelectPopupMenuItems(selected_indices);
-}
-
-void ContentViewCoreImpl::LoadUrl(
- JNIEnv* env, jobject obj,
- jstring url,
- jint load_url_type,
- jint transition_type,
- jint ua_override_option,
- jstring extra_headers,
- jbyteArray post_data,
- jstring base_url_for_data_url,
- jstring virtual_url_for_data_url,
- jboolean can_load_local_resources) {
- DCHECK(url);
- NavigationController::LoadURLParams params(
- GURL(ConvertJavaStringToUTF8(env, url)));
-
- params.load_type = static_cast<NavigationController::LoadURLType>(
- load_url_type);
- params.transition_type = PageTransitionFromInt(transition_type);
- params.override_user_agent =
- static_cast<NavigationController::UserAgentOverrideOption>(
- ua_override_option);
-
- if (extra_headers)
- params.extra_headers = ConvertJavaStringToUTF8(env, extra_headers);
-
- if (post_data) {
- std::vector<uint8> http_body_vector;
- base::android::JavaByteArrayToByteVector(env, post_data, &http_body_vector);
- params.browser_initiated_post_data =
- base::RefCountedBytes::TakeVector(&http_body_vector);
- }
-
- if (base_url_for_data_url) {
- params.base_url_for_data_url =
- GURL(ConvertJavaStringToUTF8(env, base_url_for_data_url));
- }
-
- if (virtual_url_for_data_url) {
- params.virtual_url_for_data_url =
- GURL(ConvertJavaStringToUTF8(env, virtual_url_for_data_url));
- }
-
- params.can_load_local_resources = can_load_local_resources;
-
- LoadUrl(params);
-}
-
-ScopedJavaLocalRef<jstring> ContentViewCoreImpl::GetURL(
- JNIEnv* env, jobject) const {
- return ConvertUTF8ToJavaString(env, GetWebContents()->GetURL().spec());
-}
-
-ScopedJavaLocalRef<jstring> ContentViewCoreImpl::GetTitle(
- JNIEnv* env, jobject obj) const {
- return ConvertUTF16ToJavaString(env, GetWebContents()->GetTitle());
-}
-
-jboolean ContentViewCoreImpl::IsIncognito(JNIEnv* env, jobject obj) {
- return GetWebContents()->GetBrowserContext()->IsOffTheRecord();
+ rfhi->DidSelectPopupMenuItems(selected_indices);
}
WebContents* ContentViewCoreImpl::GetWebContents() const {
}
}
-void ContentViewCoreImpl::CancelActiveTouchSequenceIfNecessary() {
- RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid();
- // Avoid synthesizing a touch cancel event if it cannot be forwarded.
- if (!rwhv)
- return;
-
- const ui::MotionEvent* current_down_event =
- gesture_provider_.GetCurrentDownEvent();
- if (!current_down_event)
- return;
-
- scoped_ptr<ui::MotionEvent> cancel_event = current_down_event->Cancel();
- DCHECK(cancel_event);
- if (!gesture_provider_.OnTouchEvent(*cancel_event))
- return;
-
- rwhv->SendTouchEvent(
- CreateWebTouchEventFromMotionEvent(*cancel_event, 1.f / dpi_scale()));
-}
-
jboolean ContentViewCoreImpl::OnTouchEvent(JNIEnv* env,
jobject obj,
jobject motion_event,
jint pointer_id_0,
jint pointer_id_1,
jfloat touch_major_0,
- jfloat touch_major_1) {
+ jfloat touch_major_1,
+ jfloat touch_minor_0,
+ jfloat touch_minor_1,
+ jfloat orientation_0,
+ jfloat orientation_1,
+ jfloat raw_pos_x,
+ jfloat raw_pos_y,
+ jint android_tool_type_0,
+ jint android_tool_type_1,
+ jint android_button_state,
+ jint android_meta_state,
+ jboolean is_touch_handle_event) {
RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid();
+ // Avoid synthesizing a touch event if it cannot be forwarded.
if (!rwhv)
return false;
- MotionEventAndroid event(env,
+ MotionEventAndroid event(1.f / dpi_scale(),
+ env,
motion_event,
time_ms,
android_action,
pointer_id_0,
pointer_id_1,
touch_major_0,
- touch_major_1);
-
- if (!gesture_provider_.OnTouchEvent(event))
- return false;
-
- rwhv->SendTouchEvent(WebTouchEventBuilder::Build(event, 1.f / dpi_scale()));
- return true;
+ touch_major_1,
+ touch_minor_0,
+ touch_minor_1,
+ orientation_0,
+ orientation_1,
+ raw_pos_x,
+ raw_pos_y,
+ android_tool_type_0,
+ android_tool_type_1,
+ android_button_state,
+ android_meta_state);
+
+ return is_touch_handle_event ? rwhv->OnTouchHandleEvent(event)
+ : rwhv->OnTouchEvent(event);
}
float ContentViewCoreImpl::GetDpiScale() const {
void ContentViewCoreImpl::SelectBetweenCoordinates(JNIEnv* env, jobject obj,
jfloat x1, jfloat y1,
jfloat x2, jfloat y2) {
- if (!web_contents_ || !web_contents_->GetFocusedFrame())
- return;
-
- RenderFrameHostImpl* frame =
- static_cast<RenderFrameHostImpl*>(web_contents_->GetFocusedFrame());
- frame->SelectRange(gfx::Point(x1 / dpi_scale(), y1 / dpi_scale()),
- gfx::Point(x2 / dpi_scale(), y2 / dpi_scale()));
+ SelectBetweenCoordinates(gfx::PointF(x1 / dpi_scale(), y1 / dpi_scale()),
+ gfx::PointF(x2 / dpi_scale(), y2 / dpi_scale()));
}
void ContentViewCoreImpl::MoveCaret(JNIEnv* env, jobject obj,
jfloat x, jfloat y) {
if (GetRenderWidgetHostViewAndroid()) {
GetRenderWidgetHostViewAndroid()->MoveCaret(
- gfx::Point(x / dpi_scale(), y / dpi_scale()));
+ gfx::Point(x / dpi_scale_, y / dpi_scale_));
}
}
-void ContentViewCoreImpl::ResetGestureDetectors(JNIEnv* env, jobject obj) {
- gesture_provider_.ResetGestureDetectors();
-}
-
-void ContentViewCoreImpl::IgnoreRemainingTouchEvents(JNIEnv* env, jobject obj) {
- CancelActiveTouchSequenceIfNecessary();
-}
-
-void ContentViewCoreImpl::OnWindowFocusLost(JNIEnv* env, jobject obj) {
- CancelActiveTouchSequenceIfNecessary();
+void ContentViewCoreImpl::HideTextHandles(JNIEnv* env, jobject obj) {
+ if (GetRenderWidgetHostViewAndroid())
+ GetRenderWidgetHostViewAndroid()->HideTextHandles();
}
-void ContentViewCoreImpl::SetDoubleTapSupportForPageEnabled(JNIEnv* env,
- jobject obj,
- jboolean enabled) {
- gesture_provider_.SetDoubleTapSupportForPageEnabled(enabled);
+void ContentViewCoreImpl::ResetGestureDetection(JNIEnv* env, jobject obj) {
+ RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid();
+ if (rwhv)
+ rwhv->ResetGestureDetection();
}
void ContentViewCoreImpl::SetDoubleTapSupportEnabled(JNIEnv* env,
jobject obj,
jboolean enabled) {
- gesture_provider_.SetDoubleTapSupportForPlatformEnabled(enabled);
+ RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid();
+ if (rwhv)
+ rwhv->SetDoubleTapSupportEnabled(enabled);
}
void ContentViewCoreImpl::SetMultiTouchZoomSupportEnabled(JNIEnv* env,
jobject obj,
jboolean enabled) {
- gesture_provider_.SetMultiTouchSupportEnabled(enabled);
-}
-
-void ContentViewCoreImpl::LoadIfNecessary(JNIEnv* env, jobject obj) {
- web_contents_->GetController().LoadIfNecessary();
-}
-
-void ContentViewCoreImpl::RequestRestoreLoad(JNIEnv* env, jobject obj) {
- web_contents_->GetController().SetNeedsReload();
-}
-
-void ContentViewCoreImpl::StopLoading(JNIEnv* env, jobject obj) {
- web_contents_->Stop();
-}
-
-void ContentViewCoreImpl::Reload(JNIEnv* env,
- jobject obj,
- jboolean check_for_repost) {
- if (web_contents_->GetController().NeedsReload())
- web_contents_->GetController().LoadIfNecessary();
- else
- web_contents_->GetController().Reload(check_for_repost);
-}
-
-void ContentViewCoreImpl::ReloadIgnoringCache(JNIEnv* env,
- jobject obj,
- jboolean check_for_repost) {
- web_contents_->GetController().ReloadIgnoringCache(check_for_repost);
-}
-
-void ContentViewCoreImpl::CancelPendingReload(JNIEnv* env, jobject obj) {
- web_contents_->GetController().CancelPendingReload();
-}
-
-void ContentViewCoreImpl::ContinuePendingReload(JNIEnv* env, jobject obj) {
- web_contents_->GetController().ContinuePendingReload();
-}
-
-void ContentViewCoreImpl::ClearHistory(JNIEnv* env, jobject obj) {
- // TODO(creis): Do callers of this need to know if it fails?
- if (web_contents_->GetController().CanPruneAllButLastCommitted())
- web_contents_->GetController().PruneAllButLastCommitted();
+ RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid();
+ if (rwhv)
+ rwhv->SetMultiTouchZoomSupportEnabled(enabled);
}
void ContentViewCoreImpl::SetAllowJavascriptInterfacesInspection(
JNIEnv* env,
jobject obj,
jboolean allow) {
- web_contents_->java_bridge_dispatcher_host_manager()
- ->SetAllowObjectContentsInspection(allow);
+ java_bridge_dispatcher_host_->SetAllowObjectContentsInspection(allow);
}
void ContentViewCoreImpl::AddJavascriptInterface(
jobject /* obj */,
jobject object,
jstring name,
- jclass safe_annotation_clazz,
- jobject retained_object_set) {
+ jclass safe_annotation_clazz) {
ScopedJavaLocalRef<jobject> scoped_object(env, object);
ScopedJavaLocalRef<jclass> scoped_clazz(env, safe_annotation_clazz);
- JavaObjectWeakGlobalRef weak_retained_object_set(env, retained_object_set);
-
- // JavaBoundObject creates the NPObject with a ref count of 1, and
- // JavaBridgeDispatcherHostManager takes its own ref.
- JavaBridgeDispatcherHostManager* java_bridge =
- web_contents_->java_bridge_dispatcher_host_manager();
- java_bridge->SetRetainedObjectSet(weak_retained_object_set);
- NPObject* bound_object =
- JavaBoundObject::Create(scoped_object,
- scoped_clazz,
- java_bridge->AsWeakPtr(),
- java_bridge->GetAllowObjectContentsInspection());
- java_bridge->AddNamedObject(ConvertJavaStringToUTF16(env, name),
- bound_object);
- blink::WebBindings::releaseObject(bound_object);
+ java_bridge_dispatcher_host_->AddNamedObject(
+ ConvertJavaStringToUTF8(env, name), scoped_object, scoped_clazz);
}
void ContentViewCoreImpl::RemoveJavascriptInterface(JNIEnv* env,
jobject /* obj */,
jstring name) {
- web_contents_->java_bridge_dispatcher_host_manager()->RemoveNamedObject(
- ConvertJavaStringToUTF16(env, name));
-}
-
-void ContentViewCoreImpl::UpdateVSyncParameters(JNIEnv* env, jobject /* obj */,
- jlong timebase_micros,
- jlong interval_micros) {
- RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid();
- if (!view)
- return;
-
- RenderWidgetHostImpl* host = RenderWidgetHostImpl::From(
- view->GetRenderWidgetHost());
-
- host->UpdateVSyncParameters(
- base::TimeTicks::FromInternalValue(timebase_micros),
- base::TimeDelta::FromMicroseconds(interval_micros));
-
- vsync_interval_ =
- base::TimeDelta::FromMicroseconds(interval_micros);
- expected_browser_composite_time_ =
- vsync_interval_ * kDefaultBrowserCompositeVSyncFraction;
-}
-
-void ContentViewCoreImpl::OnVSync(JNIEnv* env, jobject /* obj */,
- jlong frame_time_micros) {
- base::TimeTicks frame_time =
- base::TimeTicks::FromInternalValue(frame_time_micros);
- SendBeginFrame(frame_time);
-}
-
-void ContentViewCoreImpl::SendBeginFrame(base::TimeTicks frame_time) {
- RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid();
- if (!view)
- return;
-
- base::TimeTicks display_time = frame_time + vsync_interval_;
- base::TimeTicks deadline = display_time - expected_browser_composite_time_;
-
- view->SendBeginFrame(
- cc::BeginFrameArgs::Create(frame_time, deadline, vsync_interval_));
-}
-
-jboolean ContentViewCoreImpl::OnAnimate(JNIEnv* env, jobject /* obj */,
- jlong frame_time_micros) {
- RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid();
- if (!view)
- return false;
-
- return view->Animate(base::TimeTicks::FromInternalValue(frame_time_micros));
+ java_bridge_dispatcher_host_->RemoveNamedObject(
+ ConvertJavaStringToUTF8(env, name));
}
void ContentViewCoreImpl::WasResized(JNIEnv* env, jobject obj) {
RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid();
+ gfx::Size physical_size(
+ Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj),
+ Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj));
+ root_layer_->SetBounds(physical_size);
+
if (view) {
RenderWidgetHostImpl* host = RenderWidgetHostImpl::From(
view->GetRenderWidgetHost());
}
}
-void ContentViewCoreImpl::ShowInterstitialPage(
- JNIEnv* env, jobject obj, jstring jurl, jint delegate_ptr) {
- GURL url(base::android::ConvertJavaStringToUTF8(env, jurl));
- InterstitialPageDelegateAndroid* delegate =
- reinterpret_cast<InterstitialPageDelegateAndroid*>(delegate_ptr);
- InterstitialPage* interstitial = InterstitialPage::Create(
- web_contents_, false, url, delegate);
- delegate->set_interstitial_page(interstitial);
- interstitial->Show();
-}
-
-jboolean ContentViewCoreImpl::IsShowingInterstitialPage(JNIEnv* env,
- jobject obj) {
- return web_contents_->ShowingInterstitialPage();
-}
-
-jboolean ContentViewCoreImpl::IsRenderWidgetHostViewReady(JNIEnv* env,
- jobject obj) {
- RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid();
- return view && view->HasValidFrame();
-}
-
-void ContentViewCoreImpl::ExitFullscreen(JNIEnv* env, jobject obj) {
- RenderViewHost* host = web_contents_->GetRenderViewHost();
- if (!host)
- return;
- host->ExitFullscreen();
-}
-
-void ContentViewCoreImpl::UpdateTopControlsState(JNIEnv* env,
- jobject obj,
- bool enable_hiding,
- bool enable_showing,
- bool animate) {
- RenderViewHost* host = web_contents_->GetRenderViewHost();
- if (!host)
- return;
- host->Send(new ViewMsg_UpdateTopControlsState(host->GetRoutingID(),
- enable_hiding,
- enable_showing,
- animate));
-}
-
-void ContentViewCoreImpl::ShowImeIfNeeded(JNIEnv* env, jobject obj) {
- RenderViewHost* host = web_contents_->GetRenderViewHost();
- host->Send(new ViewMsg_ShowImeIfNeeded(host->GetRoutingID()));
-}
-
-void ContentViewCoreImpl::ScrollFocusedEditableNodeIntoView(JNIEnv* env,
- jobject obj) {
- RenderViewHost* host = web_contents_->GetRenderViewHost();
- host->Send(new InputMsg_ScrollFocusedEditableNodeIntoRect(
- host->GetRoutingID(), gfx::Rect()));
-}
-
-namespace {
-
-static void AddNavigationEntryToHistory(JNIEnv* env, jobject obj,
- jobject history,
- NavigationEntry* entry,
- int index) {
- // Get the details of the current entry
- ScopedJavaLocalRef<jstring> j_url(
- ConvertUTF8ToJavaString(env, entry->GetURL().spec()));
- ScopedJavaLocalRef<jstring> j_virtual_url(
- ConvertUTF8ToJavaString(env, entry->GetVirtualURL().spec()));
- ScopedJavaLocalRef<jstring> j_original_url(
- ConvertUTF8ToJavaString(env, entry->GetOriginalRequestURL().spec()));
- ScopedJavaLocalRef<jstring> j_title(
- ConvertUTF16ToJavaString(env, entry->GetTitle()));
- ScopedJavaLocalRef<jobject> j_bitmap;
- const FaviconStatus& status = entry->GetFavicon();
- if (status.valid && status.image.ToSkBitmap()->getSize() > 0)
- j_bitmap = gfx::ConvertToJavaBitmap(status.image.ToSkBitmap());
-
- // Add the item to the list
- Java_ContentViewCore_addToNavigationHistory(
- env, obj, history, index, j_url.obj(), j_virtual_url.obj(),
- j_original_url.obj(), j_title.obj(), j_bitmap.obj());
-}
-
-} // namespace
-
-int ContentViewCoreImpl::GetNavigationHistory(JNIEnv* env,
- jobject obj,
- jobject history) {
- // Iterate through navigation entries to populate the list
- const NavigationController& controller = web_contents_->GetController();
- int count = controller.GetEntryCount();
- for (int i = 0; i < count; ++i) {
- AddNavigationEntryToHistory(
- env, obj, history, controller.GetEntryAtIndex(i), i);
- }
-
- return controller.GetCurrentEntryIndex();
-}
-
-void ContentViewCoreImpl::GetDirectedNavigationHistory(JNIEnv* env,
- jobject obj,
- jobject history,
- jboolean is_forward,
- jint max_entries) {
- // Iterate through navigation entries to populate the list
- const NavigationController& controller = web_contents_->GetController();
- int count = controller.GetEntryCount();
- int num_added = 0;
- int increment_value = is_forward ? 1 : -1;
- for (int i = controller.GetCurrentEntryIndex() + increment_value;
- i >= 0 && i < count;
- i += increment_value) {
- if (num_added >= max_entries)
- break;
-
- AddNavigationEntryToHistory(
- env, obj, history, controller.GetEntryAtIndex(i), i);
- num_added++;
- }
-}
-
-ScopedJavaLocalRef<jstring>
-ContentViewCoreImpl::GetOriginalUrlForActiveNavigationEntry(JNIEnv* env,
- jobject obj) {
- NavigationEntry* entry = web_contents_->GetController().GetVisibleEntry();
- if (entry == NULL)
- return ScopedJavaLocalRef<jstring>(env, NULL);
- return ConvertUTF8ToJavaString(env, entry->GetOriginalRequestURL().spec());
-}
-
-int ContentViewCoreImpl::GetNativeImeAdapter(JNIEnv* env, jobject obj) {
+long ContentViewCoreImpl::GetNativeImeAdapter(JNIEnv* env, jobject obj) {
RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid();
if (!rwhva)
return 0;
return rwhva->GetNativeImeAdapter();
}
-namespace {
-void JavaScriptResultCallback(const ScopedJavaGlobalRef<jobject>& callback,
- const base::Value* result) {
- JNIEnv* env = base::android::AttachCurrentThread();
- std::string json;
- base::JSONWriter::Write(result, &json);
- ScopedJavaLocalRef<jstring> j_json = ConvertUTF8ToJavaString(env, json);
- Java_ContentViewCore_onEvaluateJavaScriptResult(env,
- j_json.obj(),
- callback.obj());
-}
-} // namespace
+// TODO(sgurun) add support for posting a frame whose name is known (only
+// main frame is supported at this time, see crbug.com/389721)
+// TODO(sgurun) add support for passing message ports
+void ContentViewCoreImpl::PostMessageToFrame(JNIEnv* env, jobject obj,
+ jstring frame_name, jstring message, jstring source_origin,
+ jstring target_origin) {
-void ContentViewCoreImpl::EvaluateJavaScript(JNIEnv* env,
- jobject obj,
- jstring script,
- jobject callback,
- jboolean start_renderer) {
- RenderViewHost* rvh = web_contents_->GetRenderViewHost();
- DCHECK(rvh);
-
- if (start_renderer && !rvh->IsRenderViewLive()) {
- if (!web_contents_->CreateRenderViewForInitialEmptyDocument()) {
- LOG(ERROR) << "Failed to create RenderView in EvaluateJavaScript";
+ RenderViewHost* host = web_contents_->GetRenderViewHost();
+ if (!host)
return;
- }
- }
-
- if (!callback) {
- // No callback requested.
- web_contents_->GetMainFrame()->ExecuteJavaScript(
- ConvertJavaStringToUTF16(env, script));
- return;
- }
-
- // Secure the Java callback in a scoped object and give ownership of it to the
- // base::Callback.
- ScopedJavaGlobalRef<jobject> j_callback;
- j_callback.Reset(env, callback);
- content::RenderFrameHost::JavaScriptResultCallback c_callback =
- base::Bind(&JavaScriptResultCallback, j_callback);
-
- web_contents_->GetMainFrame()->ExecuteJavaScript(
- ConvertJavaStringToUTF16(env, script),
- c_callback);
-}
-
-bool ContentViewCoreImpl::GetUseDesktopUserAgent(
- JNIEnv* env, jobject obj) {
- NavigationEntry* entry = web_contents_->GetController().GetVisibleEntry();
- return entry && entry->GetIsOverridingUserAgent();
+ ViewMsg_PostMessage_Params params;
+ params.source_origin = ConvertJavaStringToUTF16(env, source_origin);
+ params.target_origin = ConvertJavaStringToUTF16(env, target_origin);
+ params.data = ConvertJavaStringToUTF16(env, message);
+ params.is_data_raw_string = true;
+ params.source_routing_id = MSG_ROUTING_NONE;
+ host->Send(new ViewMsg_PostMessageEvent(host->GetRoutingID(), params));
}
void ContentViewCoreImpl::UpdateImeAdapter(long native_ime_adapter,
int text_input_type,
+ int text_input_flags,
const std::string& text,
int selection_start,
int selection_end,
int composition_start,
int composition_end,
bool show_ime_if_needed,
- bool require_ack) {
+ bool is_non_ime_change) {
JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
if (obj.is_null())
return;
ScopedJavaLocalRef<jstring> jstring_text = ConvertUTF8ToJavaString(env, text);
- Java_ContentViewCore_updateImeAdapter(env, obj.obj(),
- native_ime_adapter, text_input_type,
+ Java_ContentViewCore_updateImeAdapter(env,
+ obj.obj(),
+ native_ime_adapter,
+ text_input_type,
+ text_input_flags,
jstring_text.obj(),
- selection_start, selection_end,
- composition_start, composition_end,
- show_ime_if_needed, require_ack);
+ selection_start,
+ selection_end,
+ composition_start,
+ composition_end,
+ show_ime_if_needed,
+ is_non_ime_change);
}
-void ContentViewCoreImpl::ClearSslPreferences(JNIEnv* env, jobject obj) {
- SSLHostState* state = SSLHostState::GetFor(
- web_contents_->GetController().GetBrowserContext());
- state->Clear();
+void ContentViewCoreImpl::SetAccessibilityEnabled(JNIEnv* env, jobject obj,
+ bool enabled) {
+ SetAccessibilityEnabledInternal(enabled);
}
-void ContentViewCoreImpl::SetUseDesktopUserAgent(
- JNIEnv* env,
- jobject obj,
- jboolean enabled,
- jboolean reload_on_state_change) {
- if (GetUseDesktopUserAgent(env, obj) == enabled)
- return;
-
- // Make sure the navigation entry actually exists.
- NavigationEntry* entry = web_contents_->GetController().GetVisibleEntry();
- if (!entry)
- return;
-
- // Set the flag in the NavigationEntry.
- entry->SetIsOverridingUserAgent(enabled);
-
- // Send the override to the renderer.
- if (reload_on_state_change) {
- // Reloading the page will send the override down as part of the
- // navigation IPC message.
- NavigationControllerImpl& controller =
- static_cast<NavigationControllerImpl&>(web_contents_->GetController());
- controller.ReloadOriginalRequestURL(false);
- }
+bool ContentViewCoreImpl::IsFullscreenRequiredForOrientationLock() const {
+ JNIEnv* env = AttachCurrentThread();
+ ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
+ if (obj.is_null())
+ return true;
+ return Java_ContentViewCore_isFullscreenRequiredForOrientationLock(env,
+ obj.obj());
}
-void ContentViewCoreImpl::SetAccessibilityEnabled(JNIEnv* env, jobject obj,
- bool enabled) {
- RenderWidgetHostViewAndroid* host_view = GetRenderWidgetHostViewAndroid();
- if (!host_view)
- return;
- RenderWidgetHostImpl* host_impl = RenderWidgetHostImpl::From(
- host_view->GetRenderWidgetHost());
- BrowserAccessibilityState* accessibility_state =
- BrowserAccessibilityState::GetInstance();
+void ContentViewCoreImpl::SetAccessibilityEnabledInternal(bool enabled) {
+ accessibility_enabled_ = enabled;
+ BrowserAccessibilityStateImpl* accessibility_state =
+ BrowserAccessibilityStateImpl::GetInstance();
if (enabled) {
// This enables accessibility globally unless it was explicitly disallowed
// by a command-line flag.
accessibility_state->OnScreenReaderDetected();
// If it was actually enabled globally, enable it for this RenderWidget now.
- if (accessibility_state->IsAccessibleBrowser() && host_impl)
- host_impl->AddAccessibilityMode(AccessibilityModeComplete);
+ if (accessibility_state->IsAccessibleBrowser() && web_contents_)
+ web_contents_->AddAccessibilityMode(AccessibilityModeComplete);
} else {
accessibility_state->ResetAccessibilityMode();
- if (host_impl)
- host_impl->ResetAccessibilityMode();
+ if (web_contents_) {
+ web_contents_->SetAccessibilityMode(
+ accessibility_state->accessibility_mode());
+ }
}
}
if (rwhv)
rwhv->UpdateScreenInfo(GetViewAndroid());
- RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(
- web_contents_->GetRenderViewHost());
- rvhi->SendOrientationChangeEvent(device_orientation_);
-
- // TODO(mlamouri): temporary plumbing for Screen Orientation, this will change
- // in the future. It might leave ContentViewCoreImpl or simply replace the
- // SendOrientationChangeEvent call above.
- blink::WebScreenOrientation orientation =
- blink::WebScreenOrientationPortraitPrimary;
-
- switch (device_orientation_) {
- case 0:
- orientation = blink::WebScreenOrientationPortraitPrimary;
- break;
- case 90:
- orientation = blink::WebScreenOrientationLandscapePrimary;
- break;
- case -90:
- orientation = blink::WebScreenOrientationLandscapeSecondary;
- break;
- case 180:
- orientation = blink::WebScreenOrientationPortraitSecondary;
- break;
- default:
- NOTREACHED();
- }
-
- ScreenOrientationDispatcherHost* sodh =
- static_cast<RenderProcessHostImpl*>(web_contents_->
- GetRenderProcessHost())->screen_orientation_dispatcher_host();
-
- // sodh can be null if the RenderProcessHost is in the process of being
- // destroyed or not yet initialized.
- if (sodh)
- sodh->OnOrientationChange(orientation);
+ static_cast<WebContentsImpl*>(web_contents())->
+ screen_orientation_dispatcher_host()->OnOrientationChange();
}
void ContentViewCoreImpl::ExtractSmartClipData(JNIEnv* env,
web_contents_->GetRenderViewHost());
}
+void ContentViewCoreImpl::SetBackgroundOpaque(JNIEnv* env, jobject jobj,
+ jboolean opaque) {
+ if (GetRenderWidgetHostViewAndroid())
+ GetRenderWidgetHostViewAndroid()->SetBackgroundOpaque(opaque);
+}
+
+void ContentViewCoreImpl::RequestTextSurroundingSelection(
+ int max_length,
+ const base::Callback<
+ void(const base::string16& content, int start_offset, int end_offset)>&
+ callback) {
+ DCHECK(!callback.is_null());
+ RenderFrameHost* focused_frame = web_contents_->GetFocusedFrame();
+ if (!focused_frame)
+ return;
+ if (GetRenderWidgetHostViewAndroid()) {
+ GetRenderWidgetHostViewAndroid()->SetTextSurroundingSelectionCallback(
+ callback);
+ focused_frame->Send(new FrameMsg_TextSurroundingSelectionRequest(
+ focused_frame->GetRoutingID(), max_length));
+ }
+}
+
void ContentViewCoreImpl::OnSmartClipDataExtracted(
- const base::string16& result) {
+ const base::string16& text,
+ const base::string16& html,
+ const gfx::Rect& clip_rect) {
JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
if (obj.is_null())
return;
- ScopedJavaLocalRef<jstring> jresult = ConvertUTF16ToJavaString(env, result);
+ ScopedJavaLocalRef<jstring> jtext = ConvertUTF16ToJavaString(env, text);
+ ScopedJavaLocalRef<jstring> jhtml = ConvertUTF16ToJavaString(env, html);
+ ScopedJavaLocalRef<jobject> clip_rect_object(CreateJavaRect(env, clip_rect));
Java_ContentViewCore_onSmartClipDataExtracted(
- env, obj.obj(), jresult.obj());
+ env, obj.obj(), jtext.obj(), jhtml.obj(), clip_rect_object.obj());
}
-void ContentViewCoreImpl::WebContentsDestroyed(WebContents* web_contents) {
- WebContentsViewAndroid* wcva =
- static_cast<WebContentsViewAndroid*>(web_contents->GetView());
+void ContentViewCoreImpl::WebContentsDestroyed() {
+ WebContentsViewAndroid* wcva = static_cast<WebContentsViewAndroid*>(
+ static_cast<WebContentsImpl*>(web_contents())->GetView());
DCHECK(wcva);
wcva->SetContentViewCore(NULL);
}
jobject obj,
jlong native_web_contents,
jlong view_android,
- jlong window_android) {
+ jlong window_android,
+ jobject retained_objects_set) {
ContentViewCoreImpl* view = new ContentViewCoreImpl(
env, obj,
reinterpret_cast<WebContents*>(native_web_contents),
reinterpret_cast<ui::ViewAndroid*>(view_android),
- reinterpret_cast<ui::WindowAndroid*>(window_android));
+ reinterpret_cast<ui::WindowAndroid*>(window_android),
+ retained_objects_set);
return reinterpret_cast<intptr_t>(view);
}