Fix crash in HandlePolicyResponseOnUIThread when WebContents is NULL
authorTomasz Czekala <t.czekala@partner.samsung.com>
Fri, 6 Feb 2015 12:25:13 +0000 (13:25 +0100)
committerYoungsoo Choi <kenshin.choi@samsung.com>
Tue, 10 Jul 2018 06:57:09 +0000 (06:57 +0000)
In some situtations it was possible that HandlePolicyResponseOnUIThread
was called after related WebContents was already gone or when there was
no WebContents assigned to the Response

Bug: http://107.108.218.239/bugzilla/show_bug.cgi?id=9527
Reviewed by: Jaesik Chang, Janusz Majnert, Kamil Klimek, Piotr Grad, Piotr Tworek

Change-Id: Idb65a2684373a6a21543591f857a53d544090ac7
Signed-off-by: Tomasz Czekala <t.czekala@partner.samsung.com>
tizen_src/impl/browser/policy_response_delegate_efl.cc

index fdec7f990ed0b6aba1b5bb37ee5679c5cd0aff64..7157aabda60b8c6f99824df7ad5125c5e753c6ad 100644 (file)
@@ -26,6 +26,7 @@ using content::WebContents;
 using content::ResourceController;
 
 using web_contents_utils::WebContentsFromFrameID;
+using web_contents_utils::WebContentsFromViewID;
 
 using web_contents_utils::WebViewFromWebContents;
 
@@ -53,23 +54,42 @@ PolicyResponseDelegateEfl::PolicyResponseDelegateEfl(
     ResourceRequestInfo::GetRenderFrameForRequest(request, &render_process_id_, &render_frame_id_);
   }
 
-  /*
-   * In some situations there is no render_process and render_frame associated with
-   * request. Such situation happens in TC utc_blink_ewk_geolocation_permission_request_suspend_func
-   */
-  //DCHECK(render_process_id_ > 0);
-  //DCHECK(render_frame_id_ > 0 || render_view_id_ > 0);
-  BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
+  // Chromium internal downloads are not associated with any frame or view, we should
+  // accept them without EWK-specific logic. For example notification icon is internal
+  // chromium download
+  if (render_process_id_ > 0 && (render_frame_id_ > 0 || render_view_id_ > 0)) {
+    BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
         base::Bind(&PolicyResponseDelegateEfl::HandlePolicyResponseOnUIThread, this));
+  } else {
+    // Async call required!
+    BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
+        base::Bind(&PolicyResponseDelegateEfl::UseResponseOnIOThread, this));
+  }
 }
 
 void PolicyResponseDelegateEfl::HandlePolicyResponseOnUIThread() {
   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
   DCHECK(policy_decision_.get());
 
-  WebContents* web_contents = WebContentsFromFrameID(
+  WebContents* web_contents = NULL;
+
+  DCHECK(render_process_id_ > 0);
+  DCHECK(render_frame_id_ > 0 || render_view_id_ > 0);
+
+  if (render_frame_id_ > 0) {
+    web_contents = WebContentsFromFrameID(
       render_process_id_, render_frame_id_);
-  DCHECK(web_contents);
+  } else {
+    web_contents = WebContentsFromViewID(render_process_id_, render_view_id_);
+  }
+
+  if (!web_contents) {
+    // this is a situation where we had frame/view info on IO thread but it
+    // does not exist now in UI. We'll ignore such responses
+    IgnoreResponse();
+    return;
+  }
+
   content::BrowserContextEfl* browser_context =
       static_cast<content::BrowserContextEfl*>(
           web_contents->GetBrowserContext());