From 83a450cac21fd43b4e52b876f637cb9e22ebcf86 Mon Sep 17 00:00:00 2001 From: Piotr Tworek Date: Tue, 24 Jun 2014 16:47:11 -0700 Subject: [PATCH] Implement support for overriding content mime type. This adds EFL port implementation of ResourceDispatcherHostDelegate's ShouldOverrideMimeType function. The code exposes this interface via EWK context object. Due to the fact chromium resource dispatcher host delegate is a singleton object the interface is exposed as a static function in WebContext. Issue-Id: CBWEBCORE-306 Change-Id: I1de8e03c5d5bd529901cb2e6ac05fa4e1d35d231 Conflicts: impl/content_main_delegate_efl.cc --- .../resource_dispatcher_host_delegate_efl.cc | 2 +- tizen_src/impl/content_browser_client_efl.cc | 2 +- tizen_src/impl/eweb_context.cc | 23 ++++++++++++++++++++++ tizen_src/impl/eweb_context.h | 4 ++++ tizen_src/impl/tizen_webview/public/tw_callbacks.h | 1 + .../impl/tizen_webview/public/tw_web_context.cc | 4 ++++ .../impl/tizen_webview/public/tw_web_context.h | 3 +++ 7 files changed, 37 insertions(+), 2 deletions(-) diff --git a/tizen_src/impl/browser/resource_dispatcher_host_delegate_efl.cc b/tizen_src/impl/browser/resource_dispatcher_host_delegate_efl.cc index 0b0d8e2..9c01d24 100644 --- a/tizen_src/impl/browser/resource_dispatcher_host_delegate_efl.cc +++ b/tizen_src/impl/browser/resource_dispatcher_host_delegate_efl.cc @@ -144,7 +144,7 @@ void ResourceDispatcherHostDelegateEfl::TriggerNewDownloadStartCallback( bool ResourceDispatcherHostDelegateEfl::ShouldOverrideMimeType( const GURL& url, std::string& mime_type) { - return false; + return EWebContext::ShouldOverrideMimeForURL(url, mime_type); } } // namespace content diff --git a/tizen_src/impl/content_browser_client_efl.cc b/tizen_src/impl/content_browser_client_efl.cc index f44e71a..090ecf7 100644 --- a/tizen_src/impl/content_browser_client_efl.cc +++ b/tizen_src/impl/content_browser_client_efl.cc @@ -50,7 +50,7 @@ using tizen_webview::Security_Origin; namespace content { ContentBrowserClientEfl::ContentBrowserClientEfl() - : browser_main_parts_efl_(NULL) { + : web_context_(NULL), browser_main_parts_efl_(NULL) { } BrowserMainParts* ContentBrowserClientEfl::CreateBrowserMainParts( diff --git a/tizen_src/impl/eweb_context.cc b/tizen_src/impl/eweb_context.cc index a6360fc..8b3e2f3 100644 --- a/tizen_src/impl/eweb_context.cc +++ b/tizen_src/impl/eweb_context.cc @@ -60,6 +60,8 @@ using tizen_webview::Security_Origin; using tizen_webview::GetGURL; using tizen_webview::GetURL; +tizen_webview::Mime_Override_Callback EWebContext::mime_override_callback_ = 0; + namespace { /** @@ -207,6 +209,27 @@ void EWebContext::SendWrtMessage(const tizen_webview::WrtIpcMessageData& data) { } } +void EWebContext::SetMimeOverrideCallback( + tizen_webview::Mime_Override_Callback callback) { + mime_override_callback_ = callback; +} + +bool EWebContext::ShouldOverrideMimeForURL( + const GURL& url, std::string& mime_type) { + if (mime_override_callback_) { + char *new_mime = NULL; + bool overriden = mime_override_callback_( + url.spec().c_str(), mime_type.c_str(), &new_mime); + if (overriden) { + DCHECK(new_mime); + mime_type.assign(new_mime); + ::free(new_mime); + return true; + } + } + return false; +} + EWebContext::EWebContext() : m_pixmap(0) { EwkGlobalData::Ensure(); diff --git a/tizen_src/impl/eweb_context.h b/tizen_src/impl/eweb_context.h index c92044f..0a88036 100644 --- a/tizen_src/impl/eweb_context.h +++ b/tizen_src/impl/eweb_context.h @@ -102,6 +102,9 @@ class EWebContext { void SendWidgetInfo(int widget_id, double scale, const std::string &theme, const std::string &encoded_bundle); void SendWrtMessage(const tizen_webview::WrtIpcMessageData& message); + static void SetMimeOverrideCallback(tizen_webview::Mime_Override_Callback callback); + static bool ShouldOverrideMimeForURL(const GURL& url, std::string& mime_type); + void SetPixmap(int pixmap) { m_pixmap = pixmap; } int Pixmap() const { return m_pixmap; } @@ -111,6 +114,7 @@ class EWebContext { friend class tizen_webview::WebContext; static EWebContext* default_context_; + static tizen_webview::Mime_Override_Callback mime_override_callback_; scoped_ptr web_cache_manager_; scoped_ptr browser_context_; HTTPCustomHeadersEflMap http_custom_headers_; diff --git a/tizen_src/impl/tizen_webview/public/tw_callbacks.h b/tizen_src/impl/tizen_webview/public/tw_callbacks.h index 37a8eec..8a433d9 100644 --- a/tizen_src/impl/tizen_webview/public/tw_callbacks.h +++ b/tizen_src/impl/tizen_webview/public/tw_callbacks.h @@ -20,6 +20,7 @@ typedef void (*Web_Storage_Origins_Get_Callback)(Eina_List* origins, void* user_ typedef void (*Context_Did_Start_Download_Callback)(const char* download_url, void* user_data); typedef void (*Vibration_Client_Vibrate_Cb)(uint64_t vibration_time, void *user_data); typedef void (*Vibration_Client_Vibration_Cancel_Cb)(void *user_data); +typedef Eina_Bool (*Mime_Override_Callback)(const char *url, const char *current_mime, char **new_mime); /** * Callback for ewk_view_web_app_capable_get diff --git a/tizen_src/impl/tizen_webview/public/tw_web_context.cc b/tizen_src/impl/tizen_webview/public/tw_web_context.cc index ce8c5aa..960ec23 100644 --- a/tizen_src/impl/tizen_webview/public/tw_web_context.cc +++ b/tizen_src/impl/tizen_webview/public/tw_web_context.cc @@ -189,4 +189,8 @@ void WebContext::SetPixmap(int pixmap) { impl->SetPixmap( pixmap); } +void WebContext::SetMimeOverrideCallback(Mime_Override_Callback callback) { + EWebContext::SetMimeOverrideCallback(callback); +} + } // namespace tizen_webview diff --git a/tizen_src/impl/tizen_webview/public/tw_web_context.h b/tizen_src/impl/tizen_webview/public/tw_web_context.h index 1a94c9d..3a209d5 100644 --- a/tizen_src/impl/tizen_webview/public/tw_web_context.h +++ b/tizen_src/impl/tizen_webview/public/tw_web_context.h @@ -108,6 +108,9 @@ struct WebContext : public tizen_webview::RefCounted { int Pixmap() const; void SetPixmap(int pixmap); + // Set MIME override callback + static void SetMimeOverrideCallback(Mime_Override_Callback callback); + // Note: Do not use outside chromium EWebContext* GetImpl() { return impl; } -- 2.7.4