OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/android/content_view_core_impl.h" | 5 #include "content/browser/android/content_view_core_impl.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/android/jni_array.h" | 8 #include "base/android/jni_array.h" |
9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
10 #include "base/android/scoped_java_ref.h" | 10 #include "base/android/scoped_java_ref.h" |
(...skipping 19 matching lines...) Expand all Loading... | |
30 #include "content/browser/renderer_host/input/web_input_event_builders_android.h " | 30 #include "content/browser/renderer_host/input/web_input_event_builders_android.h " |
31 #include "content/browser/renderer_host/input/web_input_event_util.h" | 31 #include "content/browser/renderer_host/input/web_input_event_util.h" |
32 #include "content/browser/renderer_host/java/java_bound_object.h" | 32 #include "content/browser/renderer_host/java/java_bound_object.h" |
33 #include "content/browser/renderer_host/java/java_bridge_dispatcher_host_manager .h" | 33 #include "content/browser/renderer_host/java/java_bridge_dispatcher_host_manager .h" |
34 #include "content/browser/renderer_host/render_view_host_impl.h" | 34 #include "content/browser/renderer_host/render_view_host_impl.h" |
35 #include "content/browser/renderer_host/render_widget_host_impl.h" | 35 #include "content/browser/renderer_host/render_widget_host_impl.h" |
36 #include "content/browser/renderer_host/render_widget_host_view_android.h" | 36 #include "content/browser/renderer_host/render_widget_host_view_android.h" |
37 #include "content/browser/screen_orientation/screen_orientation_dispatcher_host. h" | 37 #include "content/browser/screen_orientation/screen_orientation_dispatcher_host. h" |
38 #include "content/browser/ssl/ssl_host_state.h" | 38 #include "content/browser/ssl/ssl_host_state.h" |
39 #include "content/browser/web_contents/web_contents_view_android.h" | 39 #include "content/browser/web_contents/web_contents_view_android.h" |
40 #include "content/common/frame_messages.h" | |
40 #include "content/common/input/web_input_event_traits.h" | 41 #include "content/common/input/web_input_event_traits.h" |
41 #include "content/common/input_messages.h" | 42 #include "content/common/input_messages.h" |
42 #include "content/common/view_messages.h" | 43 #include "content/common/view_messages.h" |
43 #include "content/public/browser/browser_accessibility_state.h" | 44 #include "content/public/browser/browser_accessibility_state.h" |
44 #include "content/public/browser/browser_context.h" | 45 #include "content/public/browser/browser_context.h" |
45 #include "content/public/browser/favicon_status.h" | 46 #include "content/public/browser/favicon_status.h" |
46 #include "content/public/browser/render_frame_host.h" | 47 #include "content/public/browser/render_frame_host.h" |
47 #include "content/public/browser/web_contents.h" | 48 #include "content/public/browser/web_contents.h" |
48 #include "content/public/common/content_client.h" | 49 #include "content/public/common/content_client.h" |
49 #include "content/public/common/content_switches.h" | 50 #include "content/public/common/content_switches.h" |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
215 ui::WindowAndroid* window_android, | 216 ui::WindowAndroid* window_android, |
216 jobject java_bridge_retained_object_set) | 217 jobject java_bridge_retained_object_set) |
217 : WebContentsObserver(web_contents), | 218 : WebContentsObserver(web_contents), |
218 java_ref_(env, obj), | 219 java_ref_(env, obj), |
219 web_contents_(static_cast<WebContentsImpl*>(web_contents)), | 220 web_contents_(static_cast<WebContentsImpl*>(web_contents)), |
220 root_layer_(cc::SolidColorLayer::Create()), | 221 root_layer_(cc::SolidColorLayer::Create()), |
221 dpi_scale_(GetPrimaryDisplayDeviceScaleFactor()), | 222 dpi_scale_(GetPrimaryDisplayDeviceScaleFactor()), |
222 view_android_(view_android), | 223 view_android_(view_android), |
223 window_android_(window_android), | 224 window_android_(window_android), |
224 device_orientation_(0), | 225 device_orientation_(0), |
225 accessibility_enabled_(false) { | 226 accessibility_enabled_(false), |
227 text_surroundings_delegate_(NULL) { | |
226 CHECK(web_contents) << | 228 CHECK(web_contents) << |
227 "A ContentViewCoreImpl should be created with a valid WebContents."; | 229 "A ContentViewCoreImpl should be created with a valid WebContents."; |
228 | 230 |
229 root_layer_->SetBackgroundColor(GetBackgroundColor(env, obj)); | 231 root_layer_->SetBackgroundColor(GetBackgroundColor(env, obj)); |
230 gfx::Size physical_size( | 232 gfx::Size physical_size( |
231 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), | 233 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), |
232 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); | 234 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); |
233 root_layer_->SetBounds(physical_size); | 235 root_layer_->SetBounds(physical_size); |
234 root_layer_->SetIsDrawable(true); | 236 root_layer_->SetIsDrawable(true); |
235 | 237 |
236 // Currently, the only use case we have for overriding a user agent involves | 238 // Currently, the only use case we have for overriding a user agent involves |
237 // spoofing a desktop Linux user agent for "Request desktop site". | 239 // spoofing a desktop Linux user agent for "Request desktop site". |
238 // Automatically set it for all WebContents so that it is available when a | 240 // Automatically set it for all WebContents so that it is available when a |
239 // NavigationEntry requires the user agent to be overridden. | 241 // NavigationEntry requires the user agent to be overridden. |
240 const char kLinuxInfoStr[] = "X11; Linux x86_64"; | 242 const char kLinuxInfoStr[] = "X11; Linux x86_64"; |
241 std::string product = content::GetContentClient()->GetProduct(); | 243 std::string product = content::GetContentClient()->GetProduct(); |
242 std::string spoofed_ua = | 244 std::string spoofed_ua = |
243 BuildUserAgentFromOSAndProduct(kLinuxInfoStr, product); | 245 BuildUserAgentFromOSAndProduct(kLinuxInfoStr, product); |
244 web_contents->SetUserAgentOverride(spoofed_ua); | 246 web_contents->SetUserAgentOverride(spoofed_ua); |
245 | 247 |
246 java_bridge_dispatcher_host_manager_.reset( | 248 java_bridge_dispatcher_host_manager_.reset( |
247 new JavaBridgeDispatcherHostManager(web_contents, | 249 new JavaBridgeDispatcherHostManager(web_contents, |
248 java_bridge_retained_object_set)); | 250 java_bridge_retained_object_set)); |
249 | |
jdduke (slow)
2014/06/17 22:43:26
Hmm, did you remove this line break? If so, maybe
donnd
2014/06/18 00:09:58
Looks like I did -- replaced.
| |
250 InitWebContents(); | 251 InitWebContents(); |
251 } | 252 } |
252 | 253 |
253 ContentViewCoreImpl::~ContentViewCoreImpl() { | 254 ContentViewCoreImpl::~ContentViewCoreImpl() { |
254 JNIEnv* env = base::android::AttachCurrentThread(); | 255 JNIEnv* env = base::android::AttachCurrentThread(); |
255 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 256 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
256 java_ref_.reset(); | 257 java_ref_.reset(); |
257 if (!j_obj.is_null()) { | 258 if (!j_obj.is_null()) { |
258 Java_ContentViewCore_onNativeContentViewCoreDestroyed( | 259 Java_ContentViewCore_onNativeContentViewCoreDestroyed( |
259 env, j_obj.obj(), reinterpret_cast<intptr_t>(this)); | 260 env, j_obj.obj(), reinterpret_cast<intptr_t>(this)); |
(...skipping 1271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1531 // If it was actually enabled globally, enable it for this RenderWidget now. | 1532 // If it was actually enabled globally, enable it for this RenderWidget now. |
1532 if (accessibility_state->IsAccessibleBrowser() && host_impl) | 1533 if (accessibility_state->IsAccessibleBrowser() && host_impl) |
1533 host_impl->AddAccessibilityMode(AccessibilityModeComplete); | 1534 host_impl->AddAccessibilityMode(AccessibilityModeComplete); |
1534 } else { | 1535 } else { |
1535 accessibility_state->ResetAccessibilityMode(); | 1536 accessibility_state->ResetAccessibilityMode(); |
1536 if (host_impl) | 1537 if (host_impl) |
1537 host_impl->ResetAccessibilityMode(); | 1538 host_impl->ResetAccessibilityMode(); |
1538 } | 1539 } |
1539 } | 1540 } |
1540 | 1541 |
1542 void ContentViewCoreImpl::SetTextSurroundingsDelegate( | |
1543 TextSurroundingsDelegate* delegate) { | |
1544 text_surroundings_delegate_ = delegate; | |
1545 } | |
1546 | |
1547 void ContentViewCoreImpl::OnTextSurroundingSelectionResponse( | |
1548 const base::string16& content, | |
1549 int start_offset, | |
1550 int end_offset) { | |
1551 if (text_surroundings_delegate_ != NULL) { | |
jdduke (slow)
2014/06/17 22:43:26
Nit, no need for "!= NULL", you can just do:
if (
donnd
2014/06/18 00:09:58
Done.
| |
1552 text_surroundings_delegate_->OnTextSurroundingSelectionResponse( | |
1553 content, start_offset, end_offset); | |
1554 } | |
1555 } | |
1556 | |
1541 void ContentViewCoreImpl::SendOrientationChangeEventInternal() { | 1557 void ContentViewCoreImpl::SendOrientationChangeEventInternal() { |
1542 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); | 1558 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); |
1543 if (rwhv) | 1559 if (rwhv) |
1544 rwhv->UpdateScreenInfo(GetViewAndroid()); | 1560 rwhv->UpdateScreenInfo(GetViewAndroid()); |
1545 | 1561 |
1546 // TODO(mlamouri): temporary plumbing for Screen Orientation, this will change | 1562 // TODO(mlamouri): temporary plumbing for Screen Orientation, this will change |
1547 // in the future. The OnResize IPC message sent from UpdateScreenInfo() will | 1563 // in the future. The OnResize IPC message sent from UpdateScreenInfo() will |
1548 // propagate the information. | 1564 // propagate the information. |
1549 blink::WebScreenOrientationType orientation = | 1565 blink::WebScreenOrientationType orientation = |
1550 blink::WebScreenOrientationPortraitPrimary; | 1566 blink::WebScreenOrientationPortraitPrimary; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1597 return GetRenderProcessIdFromRenderViewHost( | 1613 return GetRenderProcessIdFromRenderViewHost( |
1598 web_contents_->GetRenderViewHost()); | 1614 web_contents_->GetRenderViewHost()); |
1599 } | 1615 } |
1600 | 1616 |
1601 void ContentViewCoreImpl::SetBackgroundOpaque(JNIEnv* env, jobject jobj, | 1617 void ContentViewCoreImpl::SetBackgroundOpaque(JNIEnv* env, jobject jobj, |
1602 jboolean opaque) { | 1618 jboolean opaque) { |
1603 if (GetRenderWidgetHostViewAndroid()) | 1619 if (GetRenderWidgetHostViewAndroid()) |
1604 GetRenderWidgetHostViewAndroid()->SetBackgroundOpaque(opaque); | 1620 GetRenderWidgetHostViewAndroid()->SetBackgroundOpaque(opaque); |
1605 } | 1621 } |
1606 | 1622 |
1623 void ContentViewCoreImpl::RequestTextSurroundingSelection( | |
1624 int max_length) const { | |
1625 RenderFrameHost* focused_frame = web_contents_->GetFocusedFrame(); | |
jdduke (slow)
2014/06/17 22:43:26
What guarantees do we have that focused_frame will
jdduke (slow)
2014/06/17 22:43:26
Should we enforce that |text_surroundings_delegate
donnd
2014/06/18 00:09:58
Good idea to check it. I'm cribbing off of Mounir
donnd
2014/06/18 00:09:58
Done.
| |
1626 focused_frame->Send(new FrameMsg_TextSurroundingSelectionRequest( | |
1627 focused_frame->GetRoutingID(), max_length)); | |
1628 } | |
1629 | |
1607 void ContentViewCoreImpl::OnSmartClipDataExtracted( | 1630 void ContentViewCoreImpl::OnSmartClipDataExtracted( |
1608 const base::string16& result) { | 1631 const base::string16& result) { |
1609 JNIEnv* env = AttachCurrentThread(); | 1632 JNIEnv* env = AttachCurrentThread(); |
1610 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 1633 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
1611 if (obj.is_null()) | 1634 if (obj.is_null()) |
1612 return; | 1635 return; |
1613 ScopedJavaLocalRef<jstring> jresult = ConvertUTF16ToJavaString(env, result); | 1636 ScopedJavaLocalRef<jstring> jresult = ConvertUTF16ToJavaString(env, result); |
1614 Java_ContentViewCore_onSmartClipDataExtracted( | 1637 Java_ContentViewCore_onSmartClipDataExtracted( |
1615 env, obj.obj(), jresult.obj()); | 1638 env, obj.obj(), jresult.obj()); |
1616 } | 1639 } |
(...skipping 19 matching lines...) Expand all Loading... | |
1636 reinterpret_cast<ui::WindowAndroid*>(window_android), | 1659 reinterpret_cast<ui::WindowAndroid*>(window_android), |
1637 retained_objects_set); | 1660 retained_objects_set); |
1638 return reinterpret_cast<intptr_t>(view); | 1661 return reinterpret_cast<intptr_t>(view); |
1639 } | 1662 } |
1640 | 1663 |
1641 bool RegisterContentViewCore(JNIEnv* env) { | 1664 bool RegisterContentViewCore(JNIEnv* env) { |
1642 return RegisterNativesImpl(env); | 1665 return RegisterNativesImpl(env); |
1643 } | 1666 } |
1644 | 1667 |
1645 } // namespace content | 1668 } // namespace content |
OLD | NEW |