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 18 matching lines...) Expand all Loading... |
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/screen_orientation_dispatcher_host.h" | 48 #include "content/public/browser/screen_orientation_dispatcher_host.h" |
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" |
| 56 #include "jni/DragEvent_jni.h" |
55 #include "third_party/WebKit/public/web/WebInputEvent.h" | 57 #include "third_party/WebKit/public/web/WebInputEvent.h" |
56 #include "ui/android/view_android.h" | 58 #include "ui/android/view_android.h" |
57 #include "ui/android/window_android.h" | 59 #include "ui/android/window_android.h" |
| 60 #include "ui/base/clipboard/clipboard.h" |
58 #include "ui/events/android/motion_event_android.h" | 61 #include "ui/events/android/motion_event_android.h" |
59 #include "ui/events/blink/blink_event_util.h" | 62 #include "ui/events/blink/blink_event_util.h" |
60 #include "ui/events/event_utils.h" | 63 #include "ui/events/event_utils.h" |
61 #include "ui/gfx/android/java_bitmap.h" | 64 #include "ui/gfx/android/java_bitmap.h" |
62 #include "ui/gfx/geometry/point_conversions.h" | 65 #include "ui/gfx/geometry/point_conversions.h" |
63 #include "ui/gfx/geometry/size_conversions.h" | 66 #include "ui/gfx/geometry/size_conversions.h" |
64 #include "ui/gfx/geometry/size_f.h" | 67 #include "ui/gfx/geometry/size_f.h" |
65 | 68 |
66 using base::android::AttachCurrentThread; | 69 using base::android::AttachCurrentThread; |
67 using base::android::ConvertJavaStringToUTF16; | 70 using base::android::ConvertJavaStringToUTF16; |
(...skipping 1398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1466 const JavaParamRef<jobject>& jobj, | 1469 const JavaParamRef<jobject>& jobj, |
1467 jboolean opaque) { | 1470 jboolean opaque) { |
1468 if (GetRenderWidgetHostViewAndroid()) { | 1471 if (GetRenderWidgetHostViewAndroid()) { |
1469 if (opaque) | 1472 if (opaque) |
1470 GetRenderWidgetHostViewAndroid()->SetBackgroundColorToDefault(); | 1473 GetRenderWidgetHostViewAndroid()->SetBackgroundColorToDefault(); |
1471 else | 1474 else |
1472 GetRenderWidgetHostViewAndroid()->SetBackgroundColor(SK_ColorTRANSPARENT); | 1475 GetRenderWidgetHostViewAndroid()->SetBackgroundColor(SK_ColorTRANSPARENT); |
1473 } | 1476 } |
1474 } | 1477 } |
1475 | 1478 |
| 1479 void ContentViewCoreImpl::OnDragEvent( |
| 1480 JNIEnv* env, |
| 1481 const base::android::JavaParamRef<jobject>& jobj, |
| 1482 jint action, |
| 1483 jint x, |
| 1484 jint y, |
| 1485 jint screen_x, |
| 1486 jint screen_y, |
| 1487 const base::android::JavaParamRef<jobjectArray>& j_mimeTypes, |
| 1488 const base::android::JavaParamRef<jstring>& j_content) { |
| 1489 WebContentsViewAndroid* wcva = static_cast<WebContentsViewAndroid*>( |
| 1490 static_cast<WebContentsImpl*>(web_contents())->GetView()); |
| 1491 |
| 1492 const gfx::Point location(x, y); |
| 1493 const gfx::Point screen_location(screen_x, screen_y); |
| 1494 |
| 1495 std::vector<base::string16> mime_types; |
| 1496 base::android::AppendJavaStringArrayToStringVector(env, j_mimeTypes, |
| 1497 &mime_types); |
| 1498 switch (action) { |
| 1499 case JNI_DragEvent::ACTION_DRAG_ENTERED: { |
| 1500 std::vector<DropData::Metadata> metadata; |
| 1501 for (const base::string16& mime_type : mime_types) { |
| 1502 metadata.push_back(DropData::Metadata::CreateForMimeType( |
| 1503 DropData::Kind::STRING, mime_type)); |
| 1504 } |
| 1505 wcva->OnDragEntered(metadata, location, screen_location); |
| 1506 break; |
| 1507 } |
| 1508 case JNI_DragEvent::ACTION_DRAG_LOCATION: { |
| 1509 wcva->OnDragUpdated(location, screen_location); |
| 1510 break; |
| 1511 } |
| 1512 case JNI_DragEvent::ACTION_DROP: { |
| 1513 base::string16 text_to_drop = ConvertJavaStringToUTF16(env, j_content); |
| 1514 DropData drop_data; |
| 1515 drop_data.did_originate_from_renderer = false; |
| 1516 for (const base::string16& mime_type : mime_types) { |
| 1517 if (base::EqualsASCII(mime_type, ui::Clipboard::kMimeTypeURIList)) { |
| 1518 drop_data.url = GURL(text_to_drop); |
| 1519 } else if (base::EqualsASCII(mime_type, ui::Clipboard::kMimeTypeText)) { |
| 1520 drop_data.text = base::NullableString16(text_to_drop, false); |
| 1521 } else { |
| 1522 drop_data.html = base::NullableString16(text_to_drop, false); |
| 1523 } |
| 1524 } |
| 1525 |
| 1526 wcva->OnPerformDrop(&drop_data, location, screen_location); |
| 1527 break; |
| 1528 } |
| 1529 case JNI_DragEvent::ACTION_DRAG_EXITED: |
| 1530 wcva->OnDragExited(); |
| 1531 break; |
| 1532 default: // STARTED and ENDED. Nothing meaningful to do. |
| 1533 break; |
| 1534 } |
| 1535 } |
| 1536 |
1476 void ContentViewCoreImpl::RequestTextSurroundingSelection( | 1537 void ContentViewCoreImpl::RequestTextSurroundingSelection( |
1477 int max_length, | 1538 int max_length, |
1478 const base::Callback< | 1539 const base::Callback< |
1479 void(const base::string16& content, int start_offset, int end_offset)>& | 1540 void(const base::string16& content, int start_offset, int end_offset)>& |
1480 callback) { | 1541 callback) { |
1481 DCHECK(!callback.is_null()); | 1542 DCHECK(!callback.is_null()); |
1482 RenderFrameHost* focused_frame = web_contents_->GetFocusedFrame(); | 1543 RenderFrameHost* focused_frame = web_contents_->GetFocusedFrame(); |
1483 if (!focused_frame) | 1544 if (!focused_frame) |
1484 return; | 1545 return; |
1485 if (GetRenderWidgetHostViewAndroid()) { | 1546 if (GetRenderWidgetHostViewAndroid()) { |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1577 return ScopedJavaLocalRef<jobject>(); | 1638 return ScopedJavaLocalRef<jobject>(); |
1578 | 1639 |
1579 ContentViewCore* view = ContentViewCore::FromWebContents(web_contents); | 1640 ContentViewCore* view = ContentViewCore::FromWebContents(web_contents); |
1580 if (!view) | 1641 if (!view) |
1581 return ScopedJavaLocalRef<jobject>(); | 1642 return ScopedJavaLocalRef<jobject>(); |
1582 | 1643 |
1583 return view->GetJavaObject(); | 1644 return view->GetJavaObject(); |
1584 } | 1645 } |
1585 | 1646 |
1586 bool RegisterContentViewCore(JNIEnv* env) { | 1647 bool RegisterContentViewCore(JNIEnv* env) { |
1587 return RegisterNativesImpl(env); | 1648 return RegisterNativesImpl(env) && JNI_DragEvent::RegisterNativesImpl(env); |
1588 } | 1649 } |
1589 | 1650 |
1590 } // namespace content | 1651 } // namespace content |
OLD | NEW |