Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: content/browser/android/content_view_core_impl.cc

Issue 387113003: Add a content API to create a message channel. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: removed unintentional log line Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/json/json_writer.h" 12 #include "base/json/json_writer.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/metrics/histogram.h" 14 #include "base/metrics/histogram.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "cc/layers/layer.h" 17 #include "cc/layers/layer.h"
18 #include "cc/layers/solid_color_layer.h" 18 #include "cc/layers/solid_color_layer.h"
19 #include "cc/output/begin_frame_args.h" 19 #include "cc/output/begin_frame_args.h"
20 #include "content/browser/android/gesture_event_type.h" 20 #include "content/browser/android/gesture_event_type.h"
21 #include "content/browser/android/interstitial_page_delegate_android.h" 21 #include "content/browser/android/interstitial_page_delegate_android.h"
22 #include "content/browser/android/java/gin_java_bridge_dispatcher_host.h" 22 #include "content/browser/android/java/gin_java_bridge_dispatcher_host.h"
23 #include "content/browser/android/load_url_params.h" 23 #include "content/browser/android/load_url_params.h"
24 #include "content/browser/frame_host/interstitial_page_impl.h" 24 #include "content/browser/frame_host/interstitial_page_impl.h"
25 #include "content/browser/frame_host/navigation_controller_impl.h" 25 #include "content/browser/frame_host/navigation_controller_impl.h"
26 #include "content/browser/frame_host/navigation_entry_impl.h" 26 #include "content/browser/frame_host/navigation_entry_impl.h"
27 #include "content/browser/geolocation/geolocation_dispatcher_host.h" 27 #include "content/browser/geolocation/geolocation_dispatcher_host.h"
28 #include "content/browser/media/media_web_contents_observer.h" 28 #include "content/browser/media/media_web_contents_observer.h"
29 #include "content/browser/message_port_service.h"
29 #include "content/browser/renderer_host/compositor_impl_android.h" 30 #include "content/browser/renderer_host/compositor_impl_android.h"
30 #include "content/browser/renderer_host/input/motion_event_android.h" 31 #include "content/browser/renderer_host/input/motion_event_android.h"
31 #include "content/browser/renderer_host/input/web_input_event_builders_android.h " 32 #include "content/browser/renderer_host/input/web_input_event_builders_android.h "
32 #include "content/browser/renderer_host/input/web_input_event_util.h" 33 #include "content/browser/renderer_host/input/web_input_event_util.h"
33 #include "content/browser/renderer_host/render_view_host_impl.h" 34 #include "content/browser/renderer_host/render_view_host_impl.h"
34 #include "content/browser/renderer_host/render_widget_host_impl.h" 35 #include "content/browser/renderer_host/render_widget_host_impl.h"
35 #include "content/browser/renderer_host/render_widget_host_view_android.h" 36 #include "content/browser/renderer_host/render_widget_host_view_android.h"
36 #include "content/browser/screen_orientation/screen_orientation_dispatcher_host. h" 37 #include "content/browser/screen_orientation/screen_orientation_dispatcher_host. h"
37 #include "content/browser/ssl/ssl_host_state.h" 38 #include "content/browser/ssl/ssl_host_state.h"
38 #include "content/browser/transition_request_manager.h" 39 #include "content/browser/transition_request_manager.h"
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 return -1; 152 return -1;
152 }; 153 };
153 } 154 }
154 155
155 float GetPrimaryDisplayDeviceScaleFactor() { 156 float GetPrimaryDisplayDeviceScaleFactor() {
156 const gfx::Display& display = 157 const gfx::Display& display =
157 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); 158 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay();
158 return display.device_scale_factor(); 159 return display.device_scale_factor();
159 } 160 }
160 161
162 void CreateMessageChannelOnIOThread(
163 MessagePortMessageFilter* filter,
164 int routing_id,
165 int* port1, int* port2) {
166
167 *port1 = 0;
168 *port2 = 0;
169 MessagePortService* msp = MessagePortService::GetInstance();
170 msp->Create(routing_id, filter, port1);
171 msp->Create(routing_id, filter, port2);
172 msp->QueueMessages(*port1);
173 msp->QueueMessages(*port2);
174 }
175
176 void OnMessageChannelCreated(
177 ScopedJavaGlobalRef<jobject>* callback,
mnaganov (inactive) 2014/07/14 16:06:22 Who owns the scoped callback ref? Do we need to de
sgurun-gerrit only 2014/07/15 22:19:54 We pass it as a owned_ptr. It is deleted once calb
178 int* port1, int* port2) {
179 JNIEnv* env = AttachCurrentThread();
180 Java_ContentViewCore_onMessageChannelCreated(env, *port1, *port2,
181 callback->obj());
182 }
183
161 } // namespace 184 } // namespace
162 185
163 // Enables a callback when the underlying WebContents is destroyed, to enable 186 // Enables a callback when the underlying WebContents is destroyed, to enable
164 // nulling the back-pointer. 187 // nulling the back-pointer.
165 class ContentViewCoreImpl::ContentViewUserData 188 class ContentViewCoreImpl::ContentViewUserData
166 : public base::SupportsUserData::Data { 189 : public base::SupportsUserData::Data {
167 public: 190 public:
168 explicit ContentViewUserData(ContentViewCoreImpl* content_view_core) 191 explicit ContentViewUserData(ContentViewCoreImpl* content_view_core)
169 : content_view_core_(content_view_core) { 192 : content_view_core_(content_view_core) {
170 } 193 }
(...skipping 1245 matching lines...) Expand 10 before | Expand all | Expand 10 after
1416 ScopedJavaGlobalRef<jobject> j_callback; 1439 ScopedJavaGlobalRef<jobject> j_callback;
1417 j_callback.Reset(env, callback); 1440 j_callback.Reset(env, callback);
1418 content::RenderFrameHost::JavaScriptResultCallback c_callback = 1441 content::RenderFrameHost::JavaScriptResultCallback c_callback =
1419 base::Bind(&JavaScriptResultCallback, j_callback); 1442 base::Bind(&JavaScriptResultCallback, j_callback);
1420 1443
1421 web_contents_->GetMainFrame()->ExecuteJavaScript( 1444 web_contents_->GetMainFrame()->ExecuteJavaScript(
1422 ConvertJavaStringToUTF16(env, script), 1445 ConvertJavaStringToUTF16(env, script),
1423 c_callback); 1446 c_callback);
1424 } 1447 }
1425 1448
1449 // TODO(sgurun) check which thread this has to run on.
1450 void ContentViewCoreImpl::CreateMessageChannel(JNIEnv* env, jobject obj,
1451 jobject callback) {
1452
1453 ScopedJavaGlobalRef<jobject>* j_callback = new ScopedJavaGlobalRef<jobject>();
1454 j_callback->Reset(env, callback);
1455 RenderProcessHostImpl* rph =
1456 static_cast<RenderProcessHostImpl*>(
1457 web_contents_->GetRenderProcessHost());
1458 MessagePortMessageFilter* mf = rph->message_port_message_filter();
1459
1460 int port1;
1461 int port2;
1462 // Create message channel on IO thread
1463 BrowserThread::PostTaskAndReply(
1464 BrowserThread::IO,
1465 FROM_HERE,
1466 base::Bind(&CreateMessageChannelOnIOThread,
1467 mf,
1468 GetWebContents()->GetRoutingID(),
1469 &port1, &port2),
1470 base::Bind(&OnMessageChannelCreated,
1471 base::Owned(j_callback),
1472 &port1, &port2));
1473 }
1474
1426 bool ContentViewCoreImpl::GetUseDesktopUserAgent( 1475 bool ContentViewCoreImpl::GetUseDesktopUserAgent(
1427 JNIEnv* env, jobject obj) { 1476 JNIEnv* env, jobject obj) {
1428 NavigationEntry* entry = web_contents_->GetController().GetVisibleEntry(); 1477 NavigationEntry* entry = web_contents_->GetController().GetVisibleEntry();
1429 return entry && entry->GetIsOverridingUserAgent(); 1478 return entry && entry->GetIsOverridingUserAgent();
1430 } 1479 }
1431 1480
1432 void ContentViewCoreImpl::UpdateImeAdapter(long native_ime_adapter, 1481 void ContentViewCoreImpl::UpdateImeAdapter(long native_ime_adapter,
1433 int text_input_type, 1482 int text_input_type,
1434 const std::string& text, 1483 const std::string& text,
1435 int selection_start, 1484 int selection_start,
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
1657 reinterpret_cast<ui::WindowAndroid*>(window_android), 1706 reinterpret_cast<ui::WindowAndroid*>(window_android),
1658 retained_objects_set); 1707 retained_objects_set);
1659 return reinterpret_cast<intptr_t>(view); 1708 return reinterpret_cast<intptr_t>(view);
1660 } 1709 }
1661 1710
1662 bool RegisterContentViewCore(JNIEnv* env) { 1711 bool RegisterContentViewCore(JNIEnv* env) {
1663 return RegisterNativesImpl(env); 1712 return RegisterNativesImpl(env);
1664 } 1713 }
1665 1714
1666 } // namespace content 1715 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698