Add Tizen-specific implementation of PolicyResponseDelegateEfl
authorSeungSeop Park <sns.park@samsung.com>
Fri, 30 May 2014 16:02:19 +0000 (12:02 -0400)
committerYoungsoo Choi <kenshin.choi@samsung.com>
Tue, 10 Jul 2018 06:57:09 +0000 (06:57 +0000)
Change-Id: I05bf734660d22886e73b0da1ce7c2ab351ffef8c

tizen_src/impl/browser/policy_response_delegate_efl.cc [new file with mode: 0644]
tizen_src/impl/browser/policy_response_delegate_efl.h [new file with mode: 0644]
tizen_src/impl/chromium-efl.gyp

diff --git a/tizen_src/impl/browser/policy_response_delegate_efl.cc b/tizen_src/impl/browser/policy_response_delegate_efl.cc
new file mode 100644 (file)
index 0000000..7b891f3
--- /dev/null
@@ -0,0 +1,88 @@
+#include "browser/policy_response_delegate_efl.h"
+
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/render_view_host.h"
+#include "content/public/browser/render_frame_host.h"
+#include "content/public/browser/resource_dispatcher_host.h"
+#include "content/public/browser/resource_request_info.h"
+#include "content/public/browser/web_contents.h"
+#include "net/url_request/url_request.h"
+
+#include "web_contents_delegate_efl.h"
+#include "common/web_contents_utils.h"
+
+using content::BrowserThread;
+using content::RenderViewHost;
+using content::RenderFrameHost;
+using content::ResourceDispatcherHost;
+using content::ResourceRequestInfo;
+using content::WebContents;
+
+using web_contents_utils::WebContentsFromFrameID;
+
+PolicyResponseDelegateEfl::PolicyResponseDelegateEfl(net::URLRequest* request,
+    const net::CompletionCallback& callback,
+    const net::HttpResponseHeaders* original_response_headers)
+    : original_headers_(original_response_headers),
+      callback_(callback),
+      url_(request->url()),
+      render_process_id_(0),
+      render_frame_id_(0),
+      url_request_id_(request->identifier()),
+      processed_(false) {
+  ResourceRequestInfo::GetRenderFrameForRequest(request, &render_process_id_, &render_frame_id_);
+  BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
+      base::Bind(&PolicyResponseDelegateEfl::HandlePolicyResponseOnUIThread, this));
+}
+
+void PolicyResponseDelegateEfl::HandlePolicyResponseOnUIThread() {
+  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
+  WebContents* web_contents = WebContentsFromFrameID(render_process_id_, render_frame_id_);
+  if (!web_contents) {
+    UseResponse();
+    return;
+  }
+
+  content::WebContentsDelegateEfl* delegate =
+          static_cast<content::WebContentsDelegateEfl*>(web_contents->GetDelegate());
+  DCHECK(delegate);
+  // | original_headers_ | is thread safe. We can use it on UI thread.
+  delegate->OnHeadersReceived(this, url_, original_headers_);
+}
+
+void PolicyResponseDelegateEfl::UseResponse() {
+  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+  BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
+        base::Bind(&PolicyResponseDelegateEfl::UseResponseOnIOThread, this));
+}
+
+void PolicyResponseDelegateEfl::IgnoreResponse() {
+  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+  BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
+      base::Bind(&PolicyResponseDelegateEfl::IgnoreResponseOnIOThread, this));
+}
+
+void PolicyResponseDelegateEfl::UseResponseOnIOThread() {
+  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+  if (processed_)
+    return;
+
+  callback_.Run(net::OK);
+  processed_ = true;
+}
+
+void PolicyResponseDelegateEfl::IgnoreResponseOnIOThread() {
+  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+  if (processed_)
+    return;
+
+  callback_.Run(net::ERR_BLOCKED_BY_CLIENT);
+  processed_ = true;
+}
+
+void PolicyResponseDelegateEfl::HandleURLRequestDestroyedOnIOThread() {
+  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+  // The request has gone so don't try to do anything about it further.
+  processed_ = true;
+}
diff --git a/tizen_src/impl/browser/policy_response_delegate_efl.h b/tizen_src/impl/browser/policy_response_delegate_efl.h
new file mode 100644 (file)
index 0000000..25d2b55
--- /dev/null
@@ -0,0 +1,39 @@
+#ifndef POLICY_RESPONSE_DELEGATE_EFL_H_
+#define POLICY_RESPONSE_DELEGATE_EFL_H_
+
+#include "base/memory/ref_counted.h"
+#include "net/base/completion_callback.h"
+#include "url/gurl.h"
+
+namespace net {
+class URLRequest;
+class HttpResponseHeaders;
+}
+
+class PolicyResponseDelegateEfl: public base::RefCountedThreadSafe<PolicyResponseDelegateEfl> {
+ public:
+  PolicyResponseDelegateEfl(net::URLRequest* request,
+                            const net::CompletionCallback& callback,
+                            const net::HttpResponseHeaders* original_response_headers);
+  virtual void UseResponse();
+  virtual void IgnoreResponse();
+  void HandleURLRequestDestroyedOnIOThread();
+
+ private:
+  friend class base::RefCountedThreadSafe<PolicyResponseDelegateEfl>;
+
+  void HandlePolicyResponseOnUIThread();
+  void UseResponseOnIOThread();
+  void IgnoreResponseOnIOThread();
+
+  const net::HttpResponseHeaders* original_headers_;
+  net::CompletionCallback callback_;
+  GURL url_;
+  int render_process_id_;
+  int render_frame_id_;
+  uint64 url_request_id_;
+  // Should be accessed only on IO thread.
+  bool processed_;
+};
+
+#endif /* POLICY_RESPONSE_DELEGATE_EFL_H_ */
index 659d38315e717dd90ab9cbdb8514ff3fad006be7..6d9402c7a2dcb333424dfb95a3f7fa702ae51ab4 100644 (file)
@@ -58,6 +58,8 @@
       'browser/javascript_dialog_manager_efl.h',
       'browser/javascript_modal_dialog_efl.cc',
       'browser/javascript_modal_dialog_efl.h',
+      'browser/policy_response_delegate_efl.cc',
+      'browser/policy_response_delegate_efl.h',
       # [M37] backing store support removed from chromium. Efl implementations should probably also be removed
       #'browser/renderer_host/backing_store_efl.cc',
       #'browser/renderer_host/backing_store_efl.h',