Apply mime_override_callback for specific mimetype 73/43673/2
authorYongseop Kim <yons.kim@samsung.com>
Mon, 13 Jul 2015 07:10:11 +0000 (16:10 +0900)
committeryons.kim <yons.kim@samsung.com>
Thu, 16 Jul 2015 01:26:01 +0000 (10:26 +0900)
Change-Id: Iccac998196d35452238291b934cb8233dc936ef0

src/common/resource_manager.cc
src/runtime/web_application.cc
src/runtime/web_view.cc
src/runtime/web_view.h
src/runtime/web_view_impl.cc
src/runtime/web_view_impl.h

index d219710..df68bf3 100755 (executable)
@@ -195,11 +195,9 @@ ResourceManager::GetDefaultResource() {
   auto content_info = application_data_->content_info();
   if (content_info) {
     default_src = content_info->src();
-    // TODO(yons.kim): uncomment below codes after implementing
-    //                 content info handler
-    // type = content_info->type();
-    // encoding = (!content_info->encoding().empty())
-    //            ? content_info->encoding() : kDefaultEncoding;
+    type = content_info->type();
+    encoding = (!content_info->encoding().empty())
+               ? content_info->encoding() : kDefaultEncoding;
   }
 
   if (!default_src.empty()) {
index 3b556a5..76a218e 100755 (executable)
@@ -374,7 +374,7 @@ void WebApplication::Launch(std::unique_ptr<wrt::AppControl> appcontrol) {
   std::unique_ptr<ResourceManager::Resource> res =
     resource_manager_->GetStartResource(appcontrol.get());
   view->SetDefaultEncoding(res->encoding());
-  view->LoadUrl(res->uri());
+  view->LoadUrl(res->uri(), res->mime());
   view_stack_.push_front(view);
   window_->SetContent(view->evas_object());
 
@@ -401,7 +401,7 @@ void WebApplication::AppControl(std::unique_ptr<wrt::AppControl> appcontrol) {
     WebView* view = new WebView(window_, ewk_context_);
     SetupWebView(view);
     view->SetDefaultEncoding(res->encoding());
-    view->LoadUrl(res->uri());
+    view->LoadUrl(res->uri(), res->mime());
     view_stack_.push_front(view);
     window_->SetContent(view->evas_object());
   } else {
index 14bd331..5210db8 100755 (executable)
@@ -34,8 +34,8 @@ WebView::~WebView() {
   delete impl_;
 }
 
-void WebView::LoadUrl(const std::string& url) {
-  impl_->LoadUrl(url);
+void WebView::LoadUrl(const std::string& url, const std::string& mime) {
+  impl_->LoadUrl(url, mime);
 }
 
 std::string WebView::GetUrl() {
index bef4241..75afea3 100755 (executable)
@@ -90,7 +90,7 @@ class WebView {
   WebView(wrt::NativeWindow* window, Ewk_Context* context);
   virtual ~WebView();
 
-  void LoadUrl(const std::string& url);
+  void LoadUrl(const std::string& url, const std::string& mime = std::string());
   std::string GetUrl();
 
   void Suspend();
index cf31f75..8f52a04 100755 (executable)
@@ -75,7 +75,22 @@ WebViewImpl::~WebViewImpl() {
   evas_object_del(ewk_view_);
 }
 
-void WebViewImpl::LoadUrl(const std::string& url) {
+void WebViewImpl::LoadUrl(const std::string& url, const std::string& mime) {
+  if (!mime.empty()) {
+    mime_ = mime;
+    auto mime_override_cb = [](const char* url, const char* mime,
+                               char** new_mime, void* data) -> Eina_Bool{
+      WebViewImpl* view = static_cast<WebViewImpl*>(data);
+      if (view != nullptr
+          && utils::BaseName(url) == utils::BaseName(view->GetUrl())) {
+        *new_mime = strdup(view->mime().c_str());
+        LOGGER(DEBUG) << "ewk's new_mime: " << *new_mime;
+        return EINA_TRUE;
+      }
+      return EINA_FALSE;
+    };
+    ewk_context_mime_override_callback_set(context_, mime_override_cb, this);
+  }
   ewk_view_url_set(ewk_view_, url.c_str());
 }
 
index f9cdc7e..8b00082 100755 (executable)
@@ -25,6 +25,7 @@
 #include <map>
 
 #include "runtime/web_view.h"
+#include "common/url.h"
 
 class Ewk_Context;
 
@@ -35,7 +36,7 @@ class WebViewImpl {
   WebViewImpl(WebView* view, wrt::NativeWindow* window, Ewk_Context* context);
   virtual ~WebViewImpl();
 
-  void LoadUrl(const std::string& url);
+  void LoadUrl(const std::string& url, const std::string& mime = std::string());
   std::string GetUrl();
 
   void Suspend();
@@ -50,6 +51,7 @@ class WebViewImpl {
 
   void SetEventListener(WebView::EventListener* listener);
   Evas_Object* evas_object() const;
+  std::string mime() const { return mime_; }
 
  private:
   void OnKeyEvent(Ea_Callback_Type key_type);
@@ -81,6 +83,7 @@ class WebViewImpl {
   WebView* view_;
   std::map<const std::string, Evas_Smart_Cb> smart_callbacks_;
   bool fullscreen_;
+  std::string mime_;
 };
 }  // namespace wrt