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 enum DragEventActions { | |
| 97 ACTION_DRAG_STARTED = 1, | |
|
dcheng
2016/06/24 23:07:53
Nit: enum class, and just call the members STARTED
hush (inactive)
2016/06/27 19:01:54
Sorry I can't use enum clas here. They have to be
| |
| 98 ACTION_DRAG_LOCATION, | |
| 99 ACTION_DROP, | |
| 100 ACTION_DRAG_ENDED, | |
| 101 ACTION_DRAG_ENTERED, | |
| 102 ACTION_DRAG_EXITED, | |
| 103 }; | |
| 104 | |
| 94 const void* const kContentViewUserDataKey = &kContentViewUserDataKey; | 105 const void* const kContentViewUserDataKey = &kContentViewUserDataKey; |
| 95 | 106 |
| 96 int GetRenderProcessIdFromRenderViewHost(RenderViewHost* host) { | 107 int GetRenderProcessIdFromRenderViewHost(RenderViewHost* host) { |
| 97 DCHECK(host); | 108 DCHECK(host); |
| 98 RenderProcessHost* render_process = host->GetProcess(); | 109 RenderProcessHost* render_process = host->GetProcess(); |
| 99 DCHECK(render_process); | 110 DCHECK(render_process); |
| 100 if (render_process->HasConnection()) | 111 if (render_process->HasConnection()) |
| 101 return render_process->GetHandle(); | 112 return render_process->GetHandle(); |
| 102 return 0; | 113 return 0; |
| 103 } | 114 } |
| (...skipping 1362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1466 const JavaParamRef<jobject>& jobj, | 1477 const JavaParamRef<jobject>& jobj, |
| 1467 jboolean opaque) { | 1478 jboolean opaque) { |
| 1468 if (GetRenderWidgetHostViewAndroid()) { | 1479 if (GetRenderWidgetHostViewAndroid()) { |
| 1469 if (opaque) | 1480 if (opaque) |
| 1470 GetRenderWidgetHostViewAndroid()->SetBackgroundColorToDefault(); | 1481 GetRenderWidgetHostViewAndroid()->SetBackgroundColorToDefault(); |
| 1471 else | 1482 else |
| 1472 GetRenderWidgetHostViewAndroid()->SetBackgroundColor(SK_ColorTRANSPARENT); | 1483 GetRenderWidgetHostViewAndroid()->SetBackgroundColor(SK_ColorTRANSPARENT); |
| 1473 } | 1484 } |
| 1474 } | 1485 } |
| 1475 | 1486 |
| 1487 void ContentViewCoreImpl::OnDragEvent( | |
| 1488 JNIEnv* env, | |
| 1489 const base::android::JavaParamRef<jobject>& jobj, | |
| 1490 int action, | |
| 1491 const JavaParamRef<jintArray>& j_locations, | |
| 1492 const base::android::JavaParamRef<jobjectArray>& j_mimeTypes, | |
| 1493 const base::android::JavaParamRef<jstring>& j_content) { | |
| 1494 WebContentsViewAndroid* wcva = static_cast<WebContentsViewAndroid*>( | |
| 1495 static_cast<WebContentsImpl*>(web_contents())->GetView()); | |
| 1496 | |
| 1497 std::vector<int> locations; | |
| 1498 base::android::JavaIntArrayToIntVector(env, j_locations, &locations); | |
| 1499 | |
| 1500 std::vector<base::string16> mime_types; | |
| 1501 base::android::AppendJavaStringArrayToStringVector(env, j_mimeTypes, | |
| 1502 &mime_types); | |
| 1503 switch (action) { | |
| 1504 case ACTION_DRAG_ENTERED: { | |
| 1505 std::vector<DropData::Metadata> metadata; | |
| 1506 for (base::string16 mime_type : mime_types) { | |
| 1507 metadata.push_back(DropData::Metadata::CreateForMimeType( | |
| 1508 DropData::Kind::STRING, mime_type)); | |
| 1509 } | |
| 1510 wcva->OnDragEntered(metadata, locations); | |
| 1511 break; | |
| 1512 } | |
| 1513 case ACTION_DRAG_LOCATION: { | |
| 1514 wcva->OnDragUpdated(locations); | |
| 1515 break; | |
| 1516 } | |
| 1517 case ACTION_DROP: { | |
| 1518 base::string16 text_to_drop = ConvertJavaStringToUTF16(env, j_content); | |
| 1519 DropData drop_data; | |
| 1520 drop_data.did_originate_from_renderer = false; | |
| 1521 for (base::string16 mime_type : mime_types) { | |
|
dcheng
2016/06/24 23:07:53
const base::string16, otherwise this copies each m
hush (inactive)
2016/06/27 19:01:54
Done.
| |
| 1522 if (base::EqualsASCII(mime_type, ui::Clipboard::kMimeTypeURIList)) { | |
| 1523 drop_data.url = GURL(text_to_drop); | |
| 1524 } else if (base::EqualsASCII(mime_type, ui::Clipboard::kMimeTypeText)) { | |
| 1525 drop_data.text = base::NullableString16(text_to_drop, false); | |
| 1526 } else { | |
| 1527 drop_data.html = base::NullableString16(text_to_drop, false); | |
| 1528 } | |
| 1529 } | |
| 1530 | |
| 1531 wcva->OnPerformDrop(drop_data, locations); | |
| 1532 break; | |
| 1533 } | |
| 1534 case ACTION_DRAG_EXITED: | |
| 1535 wcva->OnDragExited(); | |
| 1536 break; | |
| 1537 case ACTION_DRAG_ENDED: | |
| 1538 break; | |
| 1539 } | |
| 1540 } | |
| 1541 | |
| 1476 void ContentViewCoreImpl::RequestTextSurroundingSelection( | 1542 void ContentViewCoreImpl::RequestTextSurroundingSelection( |
| 1477 int max_length, | 1543 int max_length, |
| 1478 const base::Callback< | 1544 const base::Callback< |
| 1479 void(const base::string16& content, int start_offset, int end_offset)>& | 1545 void(const base::string16& content, int start_offset, int end_offset)>& |
| 1480 callback) { | 1546 callback) { |
| 1481 DCHECK(!callback.is_null()); | 1547 DCHECK(!callback.is_null()); |
| 1482 RenderFrameHost* focused_frame = web_contents_->GetFocusedFrame(); | 1548 RenderFrameHost* focused_frame = web_contents_->GetFocusedFrame(); |
| 1483 if (!focused_frame) | 1549 if (!focused_frame) |
| 1484 return; | 1550 return; |
| 1485 if (GetRenderWidgetHostViewAndroid()) { | 1551 if (GetRenderWidgetHostViewAndroid()) { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1581 return ScopedJavaLocalRef<jobject>(); | 1647 return ScopedJavaLocalRef<jobject>(); |
| 1582 | 1648 |
| 1583 return view->GetJavaObject(); | 1649 return view->GetJavaObject(); |
| 1584 } | 1650 } |
| 1585 | 1651 |
| 1586 bool RegisterContentViewCore(JNIEnv* env) { | 1652 bool RegisterContentViewCore(JNIEnv* env) { |
| 1587 return RegisterNativesImpl(env); | 1653 return RegisterNativesImpl(env); |
| 1588 } | 1654 } |
| 1589 | 1655 |
| 1590 } // namespace content | 1656 } // namespace content |
| OLD | NEW |