Chromium Code Reviews| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 10 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
| 11 #include "base/android/jni_string.h" | 11 #include "base/android/jni_string.h" |
| 12 #include "base/android/scoped_java_ref.h" | 12 #include "base/android/scoped_java_ref.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
| 17 #include "base/strings/string_util.h" | |
| 17 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 18 #include "base/values.h" | 19 #include "base/values.h" |
| 19 #include "cc/layers/layer.h" | 20 #include "cc/layers/layer.h" |
| 20 #include "cc/layers/solid_color_layer.h" | 21 #include "cc/layers/solid_color_layer.h" |
| 21 #include "cc/output/begin_frame_args.h" | 22 #include "cc/output/begin_frame_args.h" |
| 22 #include "content/browser/accessibility/browser_accessibility_manager_android.h" | 23 #include "content/browser/accessibility/browser_accessibility_manager_android.h" |
| 23 #include "content/browser/accessibility/browser_accessibility_state_impl.h" | 24 #include "content/browser/accessibility/browser_accessibility_state_impl.h" |
| 24 #include "content/browser/android/gesture_event_type.h" | 25 #include "content/browser/android/gesture_event_type.h" |
| 25 #include "content/browser/android/interstitial_page_delegate_android.h" | 26 #include "content/browser/android/interstitial_page_delegate_android.h" |
| 26 #include "content/browser/android/java/gin_java_bridge_dispatcher_host.h" | 27 #include "content/browser/android/java/gin_java_bridge_dispatcher_host.h" |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 48 #include "content/public/browser/ssl_host_state_delegate.h" | 49 #include "content/public/browser/ssl_host_state_delegate.h" |
| 49 #include "content/public/browser/web_contents.h" | 50 #include "content/public/browser/web_contents.h" |
| 50 #include "content/public/common/content_client.h" | 51 #include "content/public/common/content_client.h" |
| 51 #include "content/public/common/content_switches.h" | 52 #include "content/public/common/content_switches.h" |
| 52 #include "content/public/common/menu_item.h" | 53 #include "content/public/common/menu_item.h" |
| 53 #include "content/public/common/user_agent.h" | 54 #include "content/public/common/user_agent.h" |
| 54 #include "jni/ContentViewCore_jni.h" | 55 #include "jni/ContentViewCore_jni.h" |
| 55 #include "third_party/WebKit/public/web/WebInputEvent.h" | 56 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 56 #include "ui/android/view_android.h" | 57 #include "ui/android/view_android.h" |
| 57 #include "ui/android/window_android.h" | 58 #include "ui/android/window_android.h" |
| 59 #include "ui/base/clipboard/clipboard.h" | |
| 58 #include "ui/events/android/motion_event_android.h" | 60 #include "ui/events/android/motion_event_android.h" |
| 59 #include "ui/events/blink/blink_event_util.h" | 61 #include "ui/events/blink/blink_event_util.h" |
| 60 #include "ui/events/event_utils.h" | 62 #include "ui/events/event_utils.h" |
| 61 #include "ui/gfx/android/java_bitmap.h" | 63 #include "ui/gfx/android/java_bitmap.h" |
| 62 #include "ui/gfx/geometry/point_conversions.h" | 64 #include "ui/gfx/geometry/point_conversions.h" |
| 63 #include "ui/gfx/geometry/size_conversions.h" | 65 #include "ui/gfx/geometry/size_conversions.h" |
| 64 #include "ui/gfx/geometry/size_f.h" | 66 #include "ui/gfx/geometry/size_f.h" |
| 65 | 67 |
| 66 using base::android::AttachCurrentThread; | 68 using base::android::AttachCurrentThread; |
| 67 using base::android::ConvertJavaStringToUTF16; | 69 using base::android::ConvertJavaStringToUTF16; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 84 // Popup item is of type group | 86 // Popup item is of type group |
| 85 POPUP_ITEM_TYPE_GROUP, | 87 POPUP_ITEM_TYPE_GROUP, |
| 86 | 88 |
| 87 // Popup item is disabled | 89 // Popup item is disabled |
| 88 POPUP_ITEM_TYPE_DISABLED, | 90 POPUP_ITEM_TYPE_DISABLED, |
| 89 | 91 |
| 90 // Popup item is enabled | 92 // Popup item is enabled |
| 91 POPUP_ITEM_TYPE_ENABLED, | 93 POPUP_ITEM_TYPE_ENABLED, |
| 92 }; | 94 }; |
| 93 | 95 |
| 96 // A copy of possible DragEvent.getActions(). | |
| 97 // https://developer.android.com/reference/android/view/DragEvent.html | |
| 98 enum DragEventActions { | |
| 99 ACTION_DRAG_STARTED = 1, | |
|
Ted C
2016/06/30 00:15:42
any reason we don't generate these the same way we
hush (inactive)
2016/06/30 18:19:06
Didn't know we could do that.
Done
| |
| 100 ACTION_DRAG_LOCATION, | |
| 101 ACTION_DROP, | |
| 102 ACTION_DRAG_ENDED, | |
| 103 ACTION_DRAG_ENTERED, | |
| 104 ACTION_DRAG_EXITED, | |
| 105 }; | |
| 106 | |
| 94 const void* const kContentViewUserDataKey = &kContentViewUserDataKey; | 107 const void* const kContentViewUserDataKey = &kContentViewUserDataKey; |
| 95 | 108 |
| 96 int GetRenderProcessIdFromRenderViewHost(RenderViewHost* host) { | 109 int GetRenderProcessIdFromRenderViewHost(RenderViewHost* host) { |
| 97 DCHECK(host); | 110 DCHECK(host); |
| 98 RenderProcessHost* render_process = host->GetProcess(); | 111 RenderProcessHost* render_process = host->GetProcess(); |
| 99 DCHECK(render_process); | 112 DCHECK(render_process); |
| 100 if (render_process->HasConnection()) | 113 if (render_process->HasConnection()) |
| 101 return render_process->GetHandle(); | 114 return render_process->GetHandle(); |
| 102 return 0; | 115 return 0; |
| 103 } | 116 } |
| (...skipping 1362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1466 const JavaParamRef<jobject>& jobj, | 1479 const JavaParamRef<jobject>& jobj, |
| 1467 jboolean opaque) { | 1480 jboolean opaque) { |
| 1468 if (GetRenderWidgetHostViewAndroid()) { | 1481 if (GetRenderWidgetHostViewAndroid()) { |
| 1469 if (opaque) | 1482 if (opaque) |
| 1470 GetRenderWidgetHostViewAndroid()->SetBackgroundColorToDefault(); | 1483 GetRenderWidgetHostViewAndroid()->SetBackgroundColorToDefault(); |
| 1471 else | 1484 else |
| 1472 GetRenderWidgetHostViewAndroid()->SetBackgroundColor(SK_ColorTRANSPARENT); | 1485 GetRenderWidgetHostViewAndroid()->SetBackgroundColor(SK_ColorTRANSPARENT); |
| 1473 } | 1486 } |
| 1474 } | 1487 } |
| 1475 | 1488 |
| 1489 void ContentViewCoreImpl::OnDragEvent( | |
| 1490 JNIEnv* env, | |
| 1491 const base::android::JavaParamRef<jobject>& jobj, | |
| 1492 jint action, | |
| 1493 jint x, | |
| 1494 jint y, | |
| 1495 jint screen_x, | |
| 1496 jint screen_y, | |
| 1497 const base::android::JavaParamRef<jobjectArray>& j_mimeTypes, | |
| 1498 const base::android::JavaParamRef<jstring>& j_content) { | |
| 1499 WebContentsViewAndroid* wcva = static_cast<WebContentsViewAndroid*>( | |
| 1500 static_cast<WebContentsImpl*>(web_contents())->GetView()); | |
| 1501 | |
| 1502 const gfx::Point location(x, y); | |
| 1503 const gfx::Point screen_location(screen_x, screen_y); | |
| 1504 | |
| 1505 std::vector<base::string16> mime_types; | |
| 1506 base::android::AppendJavaStringArrayToStringVector(env, j_mimeTypes, | |
| 1507 &mime_types); | |
| 1508 switch (action) { | |
| 1509 case ACTION_DRAG_ENTERED: { | |
| 1510 std::vector<DropData::Metadata> metadata; | |
| 1511 for (const base::string16& mime_type : mime_types) { | |
| 1512 metadata.push_back(DropData::Metadata::CreateForMimeType( | |
| 1513 DropData::Kind::STRING, mime_type)); | |
| 1514 } | |
| 1515 wcva->OnDragEntered(metadata, location, screen_location); | |
| 1516 break; | |
| 1517 } | |
| 1518 case ACTION_DRAG_LOCATION: { | |
| 1519 wcva->OnDragUpdated(location, screen_location); | |
| 1520 break; | |
| 1521 } | |
| 1522 case ACTION_DROP: { | |
| 1523 base::string16 text_to_drop = ConvertJavaStringToUTF16(env, j_content); | |
| 1524 DropData drop_data; | |
| 1525 drop_data.did_originate_from_renderer = false; | |
| 1526 for (const base::string16& mime_type : mime_types) { | |
| 1527 if (base::EqualsASCII(mime_type, ui::Clipboard::kMimeTypeURIList)) { | |
| 1528 drop_data.url = GURL(text_to_drop); | |
| 1529 } else if (base::EqualsASCII(mime_type, ui::Clipboard::kMimeTypeText)) { | |
| 1530 drop_data.text = base::NullableString16(text_to_drop, false); | |
| 1531 } else { | |
| 1532 drop_data.html = base::NullableString16(text_to_drop, false); | |
| 1533 } | |
| 1534 } | |
| 1535 | |
| 1536 wcva->OnPerformDrop(&drop_data, location, screen_location); | |
| 1537 break; | |
| 1538 } | |
| 1539 case ACTION_DRAG_EXITED: | |
| 1540 wcva->OnDragExited(); | |
| 1541 break; | |
| 1542 default: // STARTED and ENDED. Nothing meaningful to do. | |
| 1543 break; | |
| 1544 } | |
| 1545 } | |
| 1546 | |
| 1476 void ContentViewCoreImpl::RequestTextSurroundingSelection( | 1547 void ContentViewCoreImpl::RequestTextSurroundingSelection( |
| 1477 int max_length, | 1548 int max_length, |
| 1478 const base::Callback< | 1549 const base::Callback< |
| 1479 void(const base::string16& content, int start_offset, int end_offset)>& | 1550 void(const base::string16& content, int start_offset, int end_offset)>& |
| 1480 callback) { | 1551 callback) { |
| 1481 DCHECK(!callback.is_null()); | 1552 DCHECK(!callback.is_null()); |
| 1482 RenderFrameHost* focused_frame = web_contents_->GetFocusedFrame(); | 1553 RenderFrameHost* focused_frame = web_contents_->GetFocusedFrame(); |
| 1483 if (!focused_frame) | 1554 if (!focused_frame) |
| 1484 return; | 1555 return; |
| 1485 if (GetRenderWidgetHostViewAndroid()) { | 1556 if (GetRenderWidgetHostViewAndroid()) { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1581 return ScopedJavaLocalRef<jobject>(); | 1652 return ScopedJavaLocalRef<jobject>(); |
| 1582 | 1653 |
| 1583 return view->GetJavaObject(); | 1654 return view->GetJavaObject(); |
| 1584 } | 1655 } |
| 1585 | 1656 |
| 1586 bool RegisterContentViewCore(JNIEnv* env) { | 1657 bool RegisterContentViewCore(JNIEnv* env) { |
| 1587 return RegisterNativesImpl(env); | 1658 return RegisterNativesImpl(env); |
| 1588 } | 1659 } |
| 1589 | 1660 |
| 1590 } // namespace content | 1661 } // namespace content |
| OLD | NEW |