From ffa2a6b25345f83cb4d12c81e47bf14a5da1bbca Mon Sep 17 00:00:00 2001 From: Alexis Menard Date: Mon, 19 May 2014 15:45:32 -0300 Subject: [PATCH] [Next][Android] M36 Gardening : Refactor the notification system The notification code needs to be refactored due to upstream changes. Few methods names were renamed or removed and the biggest change was the removal of the notification id that we were using. This patch essentially adapt to the changes (notably passing the delegate instead of process_id and route_id) and it rolls our own way to manage notifications ids. Upstream CL : https://codereview.chromium.org/241553002 --- .../xwalk/core/XWalkContentsClientBridge.java | 36 ++--- .../xwalk/core/XWalkNotificationService.java | 4 +- .../core/XWalkNotificationServiceImpl.java | 38 ++--- .../android/xwalk_contents_client_bridge.cc | 145 ++++++++---------- .../android/xwalk_contents_client_bridge.h | 30 ++-- .../xwalk_contents_client_bridge_base.cc | 10 ++ .../xwalk_contents_client_bridge_base.h | 15 +- .../browser/xwalk_content_browser_client.cc | 8 +- 8 files changed, 136 insertions(+), 150 deletions(-) diff --git a/runtime/android/core/src/org/xwalk/core/XWalkContentsClientBridge.java b/runtime/android/core/src/org/xwalk/core/XWalkContentsClientBridge.java index 37bbb4a929..ad3784505c 100644 --- a/runtime/android/core/src/org/xwalk/core/XWalkContentsClientBridge.java +++ b/runtime/android/core/src/org/xwalk/core/XWalkContentsClientBridge.java @@ -552,16 +552,16 @@ private void updateNotificationIcon(int notificationId, Bitmap icon) { @CalledByNative private void showNotification(String title, String message, String replaceId, - int notificationId, int processId, int routeId) { + int notificationId, long delegate) { // FIXME(wang16): use replaceId to replace exist notification. It happens when // a notification with same name and tag fires. mNotificationService.showNotification( - title, message, notificationId, processId, routeId); + title, message, notificationId, delegate); } @CalledByNative - private void cancelNotification(int notificationId, int processId, int routeId) { - mNotificationService.cancelNotification(notificationId, processId, routeId); + private void cancelNotification(int notificationId, long delegate) { + mNotificationService.cancelNotification(notificationId, delegate); } void confirmJsResult(int id, String prompt) { @@ -579,24 +579,24 @@ void exitFullscreen(long nativeWebContents) { nativeExitFullscreen(mNativeContentsClientBridge, nativeWebContents); } - public void notificationDisplayed(int id, int processId, int routeId) { + public void notificationDisplayed(long delegate) { if (mNativeContentsClientBridge == 0) return; - nativeNotificationDisplayed(mNativeContentsClientBridge, id, processId, routeId); + nativeNotificationDisplayed(mNativeContentsClientBridge, delegate); } - public void notificationError(int id, String error, int processId, int routeId) { + public void notificationError(long delegate) { if (mNativeContentsClientBridge == 0) return; - nativeNotificationError(mNativeContentsClientBridge, id, error, processId, routeId); + nativeNotificationError(mNativeContentsClientBridge, delegate); } - public void notificationClicked(int id, int processId, int routeId) { + public void notificationClicked(int id, long delegate) { if (mNativeContentsClientBridge == 0) return; - nativeNotificationClicked(mNativeContentsClientBridge, id, processId, routeId); + nativeNotificationClicked(mNativeContentsClientBridge, id, delegate); } - public void notificationClosed(int id, boolean byUser, int processId, int routeId) { + public void notificationClosed(int id, boolean byUser, long delegate) { if (mNativeContentsClientBridge == 0) return; - nativeNotificationClosed(mNativeContentsClientBridge, id, byUser, processId, routeId); + nativeNotificationClosed(mNativeContentsClientBridge, id, byUser, delegate); } void setDownloadListener(DownloadListener listener) { @@ -627,14 +627,10 @@ private native void nativeConfirmJsResult(long nativeXWalkContentsClientBridge, String prompt); private native void nativeCancelJsResult(long nativeXWalkContentsClientBridge, int id); private native void nativeExitFullscreen(long nativeXWalkContentsClientBridge, long nativeWebContents); - private native void nativeNotificationDisplayed(long nativeXWalkContentsClientBridge, int id, - int processId, int routeId); - private native void nativeNotificationError(long nativeXWalkContentsClientBridge, int id, - String error, int processId, int routeId); - private native void nativeNotificationClicked(long nativeXWalkContentsClientBridge, int id, - int processId, int routeId); - private native void nativeNotificationClosed(long nativeXWalkContentsClientBridge, int id, - boolean byUser, int processId, int routeId); + private native void nativeNotificationDisplayed(long nativeXWalkContentsClientBridge, long delegate); + private native void nativeNotificationError(long nativeXWalkContentsClientBridge, long delegate); + private native void nativeNotificationClicked(long nativeXWalkContentsClientBridge, int id, long delegate); + private native void nativeNotificationClosed(long nativeXWalkContentsClientBridge, int id, boolean byUser, long delegate); private native void nativeOnFilesSelected(long nativeXWalkContentsClientBridge, int processId, int renderId, int mode_flags, String filepath, String displayName); private native void nativeOnFilesNotSelected(long nativeXWalkContentsClientBridge, diff --git a/runtime/android/core/src/org/xwalk/core/XWalkNotificationService.java b/runtime/android/core/src/org/xwalk/core/XWalkNotificationService.java index ce08b54f9c..bd06aad61c 100644 --- a/runtime/android/core/src/org/xwalk/core/XWalkNotificationService.java +++ b/runtime/android/core/src/org/xwalk/core/XWalkNotificationService.java @@ -10,9 +10,9 @@ interface XWalkNotificationService { public void setBridge(XWalkContentsClientBridge bridge); public void showNotification( - String title, String message, int notificationId, int processId, int routeId); + String title, String message, int notificationId, long delegate); public void updateNotificationIcon(int notificationId, Bitmap icon); - public void cancelNotification(int notificationId, int processId, int routeId); + public void cancelNotification(int notificationId, long delegate); public void shutdown(); public boolean maybeHandleIntent(Intent intent); } diff --git a/runtime/android/core/src/org/xwalk/core/XWalkNotificationServiceImpl.java b/runtime/android/core/src/org/xwalk/core/XWalkNotificationServiceImpl.java index 3e796a1f16..e860f0c36f 100644 --- a/runtime/android/core/src/org/xwalk/core/XWalkNotificationServiceImpl.java +++ b/runtime/android/core/src/org/xwalk/core/XWalkNotificationServiceImpl.java @@ -32,8 +32,7 @@ public class XWalkNotificationServiceImpl implements XWalkNotificationService { private static final String XWALK_ACTION_CLICK_NOTIFICATION_SUFFIX = ".notification.click"; private static final String XWALK_ACTION_CLOSE_NOTIFICATION_SUFFIX = ".notification.close"; private static final String XWALK_INTENT_EXTRA_KEY_NOTIFICATION_ID = "xwalk.NOTIFICATION_ID"; - private static final String XWALK_INTENT_EXTRA_KEY_PROCESS_ID = "xwalk.PROCESS_ID"; - private static final String XWALK_INTENT_EXTRA_KEY_ROUTE_ID = "xwalk.ROUTE_ID"; + private static final String XWALK_INTENT_EXTRA_KEY_DELEGATE = "xwalk.DELEGATE"; private static final String XWALK_INTENT_CATEGORY_NOTIFICATION_PREFIX = "notification_"; private Context mContext; @@ -112,16 +111,15 @@ public void shutdown() { public boolean maybeHandleIntent(Intent intent) { if (intent.getAction() == null) return false; int notificationId = intent.getIntExtra(XWALK_INTENT_EXTRA_KEY_NOTIFICATION_ID, -1); - int processId = intent.getIntExtra(XWALK_INTENT_EXTRA_KEY_PROCESS_ID, -1); - int routeId = intent.getIntExtra(XWALK_INTENT_EXTRA_KEY_ROUTE_ID, -1); - if (notificationId < 0) return false; + long delegate = intent.getLongExtra(XWALK_INTENT_EXTRA_KEY_DELEGATE, -1); + if (notificationId <= 0) return false; if (intent.getAction().equals( mView.getActivity().getPackageName() + XWALK_ACTION_CLOSE_NOTIFICATION_SUFFIX)) { - onNotificationClose(notificationId, true, processId, routeId); + onNotificationClose(notificationId, true, delegate); return true; } else if (intent.getAction().equals( mView.getActivity().getPackageName() + XWALK_ACTION_CLICK_NOTIFICATION_SUFFIX)) { - onNotificationClick(notificationId, processId, routeId); + onNotificationClick(notificationId, delegate); return true; } return false; @@ -163,14 +161,13 @@ public void updateNotificationIcon(int notificationId, Bitmap icon) { @Override @SuppressWarnings("deprecation") public void showNotification(String title, String message, - int notificationId, int processId, int routeId) { + int notificationId, long delegate) { Context activity = mView.getActivity(); String category = getCategoryFromNotificationId(notificationId); Intent clickIntent = new Intent(activity, activity.getClass()); clickIntent.setAction(activity.getPackageName() + XWALK_ACTION_CLICK_NOTIFICATION_SUFFIX); clickIntent.putExtra(XWALK_INTENT_EXTRA_KEY_NOTIFICATION_ID, notificationId); - clickIntent.putExtra(XWALK_INTENT_EXTRA_KEY_PROCESS_ID, processId); - clickIntent.putExtra(XWALK_INTENT_EXTRA_KEY_ROUTE_ID, routeId); + clickIntent.putExtra(XWALK_INTENT_EXTRA_KEY_DELEGATE, delegate); clickIntent.setFlags( Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY | Intent.FLAG_ACTIVITY_SINGLE_TOP); clickIntent.addCategory(category); @@ -179,8 +176,7 @@ public void showNotification(String title, String message, Intent closeIntent = new Intent(activity.getPackageName() + XWALK_ACTION_CLOSE_NOTIFICATION_SUFFIX); closeIntent.putExtra(XWALK_INTENT_EXTRA_KEY_NOTIFICATION_ID, notificationId); - closeIntent.putExtra(XWALK_INTENT_EXTRA_KEY_PROCESS_ID, processId); - closeIntent.putExtra(XWALK_INTENT_EXTRA_KEY_ROUTE_ID, routeId); + closeIntent.putExtra(XWALK_INTENT_EXTRA_KEY_DELEGATE, delegate); closeIntent.addCategory(category); PendingIntent pendingCloseIntent = PendingIntent.getBroadcast(activity, 0, closeIntent, PendingIntent.FLAG_UPDATE_CURRENT); @@ -202,42 +198,42 @@ public void showNotification(String title, String message, doShowNotification(notificationId, notification); mExistNotificationIds.put(notificationId, builder); notificationChanged(); - onNotificationShown(notificationId, processId, routeId); + onNotificationShown(notificationId, delegate); } @Override - public void cancelNotification(int notificationId, int processId, int routeId) { + public void cancelNotification(int notificationId, long delegate) { mNotificationManager.cancel(notificationId); - onNotificationClose(notificationId, false, processId, routeId); + onNotificationClose(notificationId, false, delegate); } public void doShowNotification(int id, Notification notification) { mNotificationManager.notify(id, notification); } - public void onNotificationShown(int notificationId, int processId, int routeId) { + public void onNotificationShown(int notificationId, long delegate) { if (mExistNotificationIds.containsKey(notificationId) && mBridge != null) { - mBridge.notificationDisplayed(notificationId, processId, routeId); + mBridge.notificationDisplayed(delegate); } } - public void onNotificationClick(int notificationId, int processId, int routeId) { + public void onNotificationClick(int notificationId, long delegate) { if (mExistNotificationIds.containsKey(notificationId)) { mExistNotificationIds.remove(notificationId); notificationChanged(); if (mBridge != null) { - mBridge.notificationClicked(notificationId, processId, routeId); + mBridge.notificationClicked(notificationId, delegate); } } } public void onNotificationClose( - int notificationId, boolean byUser, int processId, int routeId) { + int notificationId, boolean byUser, long delegate) { if (mExistNotificationIds.containsKey(notificationId)) { mExistNotificationIds.remove(notificationId); notificationChanged(); if (mBridge != null) { - mBridge.notificationClosed(notificationId, byUser, processId, routeId); + mBridge.notificationClosed(notificationId, byUser, delegate); } } } diff --git a/runtime/browser/android/xwalk_contents_client_bridge.cc b/runtime/browser/android/xwalk_contents_client_bridge.cc index 0450dad696..c8da571050 100644 --- a/runtime/browser/android/xwalk_contents_client_bridge.cc +++ b/runtime/browser/android/xwalk_contents_client_bridge.cc @@ -10,7 +10,11 @@ #include "base/android/jni_array.h" #include "base/android/jni_string.h" #include "base/callback.h" +#include "base/guid.h" #include "content/public/browser/browser_thread.h" +#include "content/public/browser/desktop_notification_delegate.h" +#include "content/public/browser/render_frame_host.h" +#include "content/public/browser/render_process_host.h" #include "content/public/browser/render_view_host.h" #include "content/public/browser/web_contents.h" #include "content/public/common/file_chooser_params.h" @@ -39,17 +43,18 @@ namespace { void RunUpdateNotificationIconOnUIThread( int notification_id, - int process_id, - int route_id, + content::RenderFrameHost* render_frame_host, const SkBitmap& icon) { XWalkContentsClientBridgeBase* bridge = - XWalkContentsClientBridgeBase::FromRenderViewID(process_id, route_id); + XWalkContentsClientBridgeBase::FromRenderFrameHost(render_frame_host); if (bridge) bridge->UpdateNotificationIcon(notification_id, icon); } } // namespace +static IDMap notifications_; + XWalkContentsClientBridge::XWalkContentsClientBridge(JNIEnv* env, jobject obj) : java_ref_(env, obj) { DCHECK(obj); @@ -210,13 +215,11 @@ void XWalkContentsClientBridge::OnNotificationIconDownloaded( } else { NotificationDownloadRequestIdMap::iterator iter = downloading_icon_notifications_.find(id); - if (iter == downloading_icon_notifications_.end() || - iter->second.size() != 3) { + if (iter == downloading_icon_notifications_.end()) return; - } - int notification_id = iter->second[0]; - int process_id = iter->second[1]; - int route_id = iter->second[2]; + + int notification_id = iter->second.first; + content::RenderFrameHost* render_frame_host = iter->second.second; // This will lead to a second call of ShowNotification for the // same notification id to update the icon. On Android, when // the notification which is already shown is fired again, it will @@ -226,8 +229,7 @@ void XWalkContentsClientBridge::OnNotificationIconDownloaded( FROM_HERE, base::Bind(&RunUpdateNotificationIconOnUIThread, notification_id, - process_id, - route_id, + render_frame_host, bitmaps[0])); } downloading_icon_notifications_.erase(id); @@ -247,11 +249,24 @@ void XWalkContentsClientBridge::UpdateNotificationIcon( env, obj.obj(), notification_id, jicon.obj()); } +static void CancelNotification( + JavaObjectWeakGlobalRef java_ref, + int notification_id, content::DesktopNotificationDelegate* delegate) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + JNIEnv* env = AttachCurrentThread(); + ScopedJavaLocalRef obj = java_ref.get(env); + if (obj.is_null()) + return; + + Java_XWalkContentsClientBridge_cancelNotification( + env, obj.obj(), notification_id, reinterpret_cast(delegate)); +} + void XWalkContentsClientBridge::ShowNotification( const content::ShowDesktopNotificationHostMsgParams& params, - bool worker, - int process_id, - int route_id) { + content::RenderFrameHost* render_frame_host, + content::DesktopNotificationDelegate* delegate, + base::Closure* cancel_callback) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); JNIEnv* env = AttachCurrentThread(); @@ -266,49 +281,34 @@ void XWalkContentsClientBridge::ShowNotification( ScopedJavaLocalRef jreplace_id( ConvertUTF16ToJavaString(env, params.replace_id)); + int notification_id = notifications_.Add(delegate); Java_XWalkContentsClientBridge_showNotification( env, obj.obj(), jtitle.obj(), jbody.obj(), - jreplace_id.obj(), params.notification_id, - process_id, route_id); + jreplace_id.obj(), notification_id, + reinterpret_cast(delegate)); + + if (cancel_callback) + *cancel_callback = + base::Bind(&CancelNotification, java_ref_, notification_id, delegate); if (params.icon_url.is_valid()) { - RenderViewHost* rvh = RenderViewHost::FromID(process_id, route_id); - if (rvh) { - WebContents* web_contents = WebContents::FromRenderViewHost(rvh); - if (web_contents) { - int download_request_id = web_contents->DownloadImage( - params.icon_url, - false, - 0, - base::Bind( - &XWalkContentsClientBridge::OnNotificationIconDownloaded, - base::Unretained(this))); - std::vector ids; - ids.push_back(params.notification_id); - ids.push_back(process_id); - ids.push_back(route_id); - downloading_icon_notifications_[download_request_id] = ids; - } + WebContents* web_contents = + WebContents::FromRenderFrameHost(render_frame_host); + if (web_contents) { + int download_request_id = web_contents->DownloadImage( + params.icon_url, + false, + 0, + base::Bind( + &XWalkContentsClientBridge::OnNotificationIconDownloaded, + base::Unretained(this))); + NotificationDownloadRequestInfos info = + std::make_pair(notification_id, render_frame_host); + downloading_icon_notifications_[download_request_id] = info; } } } -void XWalkContentsClientBridge::CancelNotification( - int notification_id, - int process_id, - int route_id) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - JNIEnv* env = AttachCurrentThread(); - - ScopedJavaLocalRef obj = java_ref_.get(env); - if (obj.is_null()) - return; - - Java_XWalkContentsClientBridge_cancelNotification( - env, obj.obj(), notification_id, - process_id, route_id); -} - void XWalkContentsClientBridge::ConfirmJsResult(JNIEnv* env, jobject, int id, @@ -346,48 +346,37 @@ void XWalkContentsClientBridge::ExitFullscreen( } void XWalkContentsClientBridge::NotificationDisplayed( - JNIEnv*, jobject, int id, int process_id, int route_id) { + JNIEnv*, jobject, jlong delegate) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - RenderViewHost* rvh = RenderViewHost::FromID( - process_id, route_id); - if (!rvh) - return; - rvh->DesktopNotificationPostDisplay(id); + content::DesktopNotificationDelegate* notification_delegate = + reinterpret_cast (delegate); + notification_delegate->NotificationDisplayed(); } void XWalkContentsClientBridge::NotificationError( - JNIEnv* env, jobject, int id, jstring error, - int process_id, int route_id) { + JNIEnv* env, jobject, jlong delegate) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - RenderViewHost* rvh = RenderViewHost::FromID( - process_id, route_id); - if (!rvh) - return; - base::string16 error_text; - if (error) - error_text = ConvertJavaStringToUTF16(env, error); - rvh->DesktopNotificationPostError(id, error_text); + content::DesktopNotificationDelegate* notification_delegate = + reinterpret_cast (delegate); + notification_delegate->NotificationError(); } void XWalkContentsClientBridge::NotificationClicked( - JNIEnv*, jobject, int id, int process_id, int route_id) { + JNIEnv*, jobject, jint id, jlong delegate) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - RenderViewHost* rvh = RenderViewHost::FromID( - process_id, route_id); - if (!rvh) - return; - rvh->DesktopNotificationPostClick(id); + notifications_.Remove(id); + content::DesktopNotificationDelegate* notification_delegate = + reinterpret_cast (delegate); + notification_delegate->NotificationClick(); } void XWalkContentsClientBridge::NotificationClosed( - JNIEnv*, jobject, int id, bool by_user, - int process_id, int route_id) { + JNIEnv*, jobject, jint id, bool by_user, jlong delegate) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - RenderViewHost* rvh = RenderViewHost::FromID( - process_id, route_id); - if (!rvh) - return; - rvh->DesktopNotificationPostClose(id, by_user); + notifications_.Remove(id); + content::DesktopNotificationDelegate* notification_delegate = + reinterpret_cast (delegate); + notification_delegate->NotificationClosed(by_user); } void XWalkContentsClientBridge::OnFilesSelected( diff --git a/runtime/browser/android/xwalk_contents_client_bridge.h b/runtime/browser/android/xwalk_contents_client_bridge.h index 7f8bdc87a3..d4fd47991b 100644 --- a/runtime/browser/android/xwalk_contents_client_bridge.h +++ b/runtime/browser/android/xwalk_contents_client_bridge.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #include "base/android/jni_weak_ref.h" @@ -62,19 +63,14 @@ class XWalkContentsClientBridge : public XWalkContentsClientBridgeBase { OVERRIDE; virtual void ShowNotification( const content::ShowDesktopNotificationHostMsgParams& params, - bool worker, - int process_id, - int route_id) + content::RenderFrameHost* render_frame_host, + content::DesktopNotificationDelegate* delegate, + base::Closure* cancel_callback) OVERRIDE; virtual void UpdateNotificationIcon( int notification_id, const SkBitmap& icon) OVERRIDE; - virtual void CancelNotification( - int notification_id, - int process_id, - int route_id) - OVERRIDE; bool OnReceivedHttpAuthRequest(const base::android::JavaRef& handler, const std::string& host, @@ -92,14 +88,11 @@ class XWalkContentsClientBridge : public XWalkContentsClientBridgeBase { void ConfirmJsResult(JNIEnv*, jobject, int id, jstring prompt); void CancelJsResult(JNIEnv*, jobject, int id); void ExitFullscreen(JNIEnv*, jobject, jlong web_contents); - void NotificationDisplayed( - JNIEnv*, jobject, int id, int process_id, int route_id); - void NotificationError( - JNIEnv*, jobject, int id, jstring error, int process_id, int route_id); - void NotificationClicked( - JNIEnv*, jobject, int id, int process_id, int route_id); - void NotificationClosed( - JNIEnv*, jobject, int id, bool by_user, int process_id, int route_id); + void NotificationDisplayed(JNIEnv*, jobject, jlong delegate); + void NotificationError(JNIEnv*, jobject, jlong delegate); + void NotificationClicked(JNIEnv*, jobject, jint id, jlong delegate); + void NotificationClosed(JNIEnv*, jobject, jint id, bool by_user, + jlong delegate); void OnFilesSelected( JNIEnv*, jobject, int process_id, int render_id, int mode, jstring filepath, jstring display_name); @@ -114,7 +107,10 @@ class XWalkContentsClientBridge : public XWalkContentsClientBridgeBase { IDMap pending_js_dialog_callbacks_; - typedef std::map > NotificationDownloadRequestIdMap; + typedef std::pair + NotificationDownloadRequestInfos; + typedef std::map + NotificationDownloadRequestIdMap; NotificationDownloadRequestIdMap downloading_icon_notifications_; }; diff --git a/runtime/browser/android/xwalk_contents_client_bridge_base.cc b/runtime/browser/android/xwalk_contents_client_bridge_base.cc index 4481431c4f..6d6174d0ad 100644 --- a/runtime/browser/android/xwalk_contents_client_bridge_base.cc +++ b/runtime/browser/android/xwalk_contents_client_bridge_base.cc @@ -81,6 +81,16 @@ XWalkContentsClientBridgeBase* XWalkContentsClientBridgeBase::FromRenderFrameID( return UserData::GetContents(web_contents); } +// static +XWalkContentsClientBridgeBase* + XWalkContentsClientBridgeBase::FromRenderFrameHost( + content::RenderFrameHost* render_frame_host) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + content::WebContents* web_contents = + content::WebContents::FromRenderFrameHost(render_frame_host); + return UserData::GetContents(web_contents); +} + XWalkContentsClientBridgeBase::~XWalkContentsClientBridgeBase() { } diff --git a/runtime/browser/android/xwalk_contents_client_bridge_base.h b/runtime/browser/android/xwalk_contents_client_bridge_base.h index a9675487cf..deec85156d 100644 --- a/runtime/browser/android/xwalk_contents_client_bridge_base.h +++ b/runtime/browser/android/xwalk_contents_client_bridge_base.h @@ -13,6 +13,8 @@ class GURL; class SkBitmap; namespace content { +class DesktopNotificationDelegate; +class RenderFrameHost; struct ShowDesktopNotificationHostMsgParams; class WebContents; } @@ -39,6 +41,8 @@ class XWalkContentsClientBridgeBase { int render_view_id); static XWalkContentsClientBridgeBase* FromRenderFrameID(int render_process_id, int render_frame_id); + static XWalkContentsClientBridgeBase* FromRenderFrameHost( + content::RenderFrameHost* render_frame_host); virtual ~XWalkContentsClientBridgeBase(); @@ -62,19 +66,14 @@ class XWalkContentsClientBridgeBase { = 0; virtual void ShowNotification( const content::ShowDesktopNotificationHostMsgParams& params, - bool worker, - int process_id, - int route_id) + content::RenderFrameHost* render_frame_host, + content::DesktopNotificationDelegate* delegate, + base::Closure* cancel_callback) = 0; virtual void UpdateNotificationIcon( int notification_id, const SkBitmap& icon) = 0; - virtual void CancelNotification( - int notification_id, - int process_id, - int route_id) - = 0; }; } // namespace xwalk diff --git a/runtime/browser/xwalk_content_browser_client.cc b/runtime/browser/xwalk_content_browser_client.cc index 9f8cca05a5..f17644d253 100644 --- a/runtime/browser/xwalk_content_browser_client.cc +++ b/runtime/browser/xwalk_content_browser_client.cc @@ -14,6 +14,7 @@ #include "content/public/browser/browser_main_parts.h" #include "content/public/browser/browser_ppapi_host.h" #include "content/public/browser/child_process_data.h" +#include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_process_host.h" #include "content/public/browser/resource_context.h" #include "content/public/browser/storage_partition.h" @@ -285,11 +286,10 @@ void XWalkContentBrowserClient::ShowDesktopNotification( content::DesktopNotificationDelegate* delegate, base::Closure* cancel_callback) { #if defined(OS_ANDROID) - content::RenderProcessHost* process = render_frame_host->GetProcess(); XWalkContentsClientBridgeBase* bridge = - XWalkContentsClientBridgeBase::FromRenderViewID(process->GetID(), - render_view_id); - bridge->ShowNotification(params, worker, process->GetID(), cancel_callback); + XWalkContentsClientBridgeBase::FromRenderFrameHost(render_frame_host); + bridge->ShowNotification(params, render_frame_host, + delegate, cancel_callback); #endif }