[M40 Merge] Provide a way to set injected-bundle so name [ewk_context_new_with_inject...
authorKrzysztof Czech <k.czech@samsung.com>
Fri, 13 Mar 2015 12:26:56 +0000 (13:26 +0100)
committerYoungsoo Choi <kenshin.choi@samsung.com>
Tue, 10 Jul 2018 06:57:09 +0000 (06:57 +0000)
API that will be used by the WRT web apps to inject specific bundle to perform some
additional operations directly on JS context. Currently libwrt-injected-bundle.so
is injected by default.

Bug: http://107.108.218.239/bugzilla/show_bug.cgi?id=10976
Reviewed by: DONGJUN KiM, Piotr Tworek
Reviewed by: DONGJUN KiM, Hyunhak Kim, Piotr Tworek, arno renevier, commitbot

Change-Id: I86145ede4bd50bc7af7ee69b4a7a3f241ff4965a
Signed-off-by: yh106.jung <yh106.jung@samsung.com>
15 files changed:
tizen_src/ewk/efl_integration/common/content_switches_efl.cc
tizen_src/ewk/efl_integration/common/content_switches_efl.h
tizen_src/ewk/efl_integration/content_browser_client_efl.cc
tizen_src/ewk/efl_integration/eweb_context.cc
tizen_src/ewk/efl_integration/eweb_context.h
tizen_src/ewk/efl_integration/private/ewk_context_private.cc
tizen_src/ewk/efl_integration/private/ewk_context_private.h
tizen_src/ewk/efl_integration/public/ewk_context.cc
tizen_src/ewk/efl_integration/renderer/content_renderer_client_efl.cc
tizen_src/ewk/efl_integration/wrt/dynamicplugin.cc
tizen_src/ewk/unittest/ewk-tests.gypi
tizen_src/ewk/unittest/resources/ewk_context/injected_bundle/chromium/bundle_sample.cc [new file with mode: 0644]
tizen_src/ewk/unittest/resources/ewk_context/injected_bundle/webkit/bundle_sample.c [moved from tizen_src/ewk/unittest/resources/ewk_context/injected_bundle/bundle_sample.c with 89% similarity]
tizen_src/ewk/unittest/resources/ewk_context/injected_bundle/webkit/bundle_sample.so [moved from tizen_src/ewk/unittest/resources/ewk_context/injected_bundle/bundle_sample.so with 100% similarity]
tizen_src/ewk/unittest/utc_blink_ewk_context_new_with_injected_bundle_path_func.cc [new file with mode: 0644]

index 8901b0a..6ea914b 100644 (file)
@@ -11,6 +11,7 @@ namespace switches {
 // to web applications and thereby apply different styling based on these
 // different modes using CSS Media Queries.
 const char kEnableViewMode[]    = "enable-view-mode";
+const char kInjectedBundlePath[] = "injected-bundle-path";
 
 // Don't dump stuff here, follow the same order as the header.
 
index 11da214..6ece3a8 100644 (file)
@@ -17,6 +17,7 @@ namespace switches {
 // to web applications and thereby apply different styling based on these
 // different modes using CSS Media Queries.
 CONTENT_EXPORT extern const char kEnableViewMode[];
+CONTENT_EXPORT extern const char kInjectedBundlePath[];
 
 // DON'T ADD RANDOM STUFF HERE. Put it in the main section above in
 // alphabetical order, or in one of the ifdefs (also in order in each section).
index 4c5cdb7..c8d9618 100644 (file)
@@ -8,6 +8,7 @@
 #include "base/memory/scoped_ptr.h"
 #include "browser_main_parts_efl.h"
 #include "browser_context_efl.h"
+#include "eweb_context.h"
 #include "web_contents_delegate_efl.h"
 #include "web_contents_view_delegate_ewk.h"
 #include "devtools_manager_delegate_efl.h"
 #include "browser/render_message_filter_efl.h"
 #include "browser/resource_dispatcher_host_delegate_efl.h"
 #include "browser/web_view_browser_message_filter.h"
+#include "common/content_switches_efl.h"
 #include "content/browser/web_contents/web_contents_view_efl.h"
 #include "content/public/browser/browser_thread.h"
 #include "content/public/browser/render_widget_host.h"
 #include "content/public/browser/render_widget_host_iterator.h"
 #include "content/public/browser/resource_dispatcher_host.h"
 #include "content/public/browser/web_contents.h"
-#include "content/public/common/platform_notification_data.h"
+#include "content/public/common/content_switches.h"
 #include "common/web_contents_utils.h"
 
 #if defined(OS_TIZEN)
@@ -82,6 +84,23 @@ LocationProvider* ContentBrowserClientEfl::OverrideSystemLocationProvider() {
 
 void ContentBrowserClientEfl::AppendExtraCommandLineSwitches(base::CommandLine* command_line,
     int child_process_id) {
+  if (command_line->HasSwitch(switches::kProcessType)) {
+    std::string processType = command_line->
+        GetSwitchValueASCII(switches::kProcessType);
+    if (processType == switches::kRendererProcess) {
+      if (content::RenderProcessHost* host =
+              content::RenderProcessHost::FromID(child_process_id)) {
+        if (EWebContext* context = static_cast<BrowserContextEfl*>(
+                host->GetBrowserContext())->WebContext()) {
+          const std::string& injectedBundlePath =
+              context->GetInjectedBundlePath();
+          if (!injectedBundlePath.empty())
+            command_line->AppendSwitchASCII(
+                switches::kInjectedBundlePath, injectedBundlePath);
+        }
+      }
+    }
+  }
   CommandLineEfl::AppendProcessSpecificArgs(*command_line);
 }
 
index 17566b4..d659bc1 100644 (file)
@@ -233,6 +233,17 @@ EWebContext::EWebContext(bool incognito)
   web_cache_manager_.reset(new WebCacheManagerEfl(browser_context_.get()));
 }
 
+EWebContext::EWebContext(const std::string& injectedBundlePath)
+    : injected_bundle_path_(injectedBundlePath),
+      m_pixmap(0),
+      inspector_server_(NULL) {
+  CHECK(EwkGlobalData::GetInstance());
+
+  // WRT does not really care about incognito, so set it to false
+  browser_context_.reset(new BrowserContextEfl(this, false));
+  web_cache_manager_.reset(new WebCacheManagerEfl(browser_context_.get()));
+}
+
 EWebContext::~EWebContext() {
 }
 
index f95c4ef..46e27f0 100644 (file)
@@ -111,8 +111,11 @@ class EWebContext {
   unsigned int InspectorServerStart(unsigned int port);
   bool InspectorServerStop();
 
+  const std::string& GetInjectedBundlePath() const { return injected_bundle_path_; }
+
  private:
   EWebContext(bool incognito);
+  EWebContext(const std::string& injectedBundlePath);
   ~EWebContext();
   friend class Ewk_Context;
 
@@ -121,6 +124,7 @@ class EWebContext {
   scoped_ptr<content::BrowserContextEfl> browser_context_;
   scoped_ptr<Ewk_Cookie_Manager> ewk_cookie_manager_;
   std::string proxy_uri_;
+  std::string injected_bundle_path_;
   scoped_ptr<EwkDidStartDownloadCallback> start_download_callback_;
   scoped_ptr<EwkMimeOverrideCallback> mime_override_callback_;
   int m_pixmap;
index fba64c6..185ec9b 100644 (file)
@@ -56,6 +56,13 @@ Ewk_Context* Ewk_Context::Create(bool incognito) {
   return context;
 }
 
+//static
+Ewk_Context* Ewk_Context::Create(const std::string& injectedBundlePath) {
+  Ewk_Context* context = new Ewk_Context(injectedBundlePath);
+  context->AddRef();
+  return context;
+}
+
 // static
 void Ewk_Context::Delete(Ewk_Context* context) {
   if (context) {
@@ -73,6 +80,10 @@ void Ewk_Context::Delete(Ewk_Context* context) {
 Ewk_Context::Ewk_Context(bool incognito) : impl(new EWebContext(incognito)) {
 }
 
+Ewk_Context::Ewk_Context(const std::string& injectedBundlePath)
+    : impl(new EWebContext(injectedBundlePath)) {
+}
+
 Ewk_Context::~Ewk_Context() {
   if (this == default_context_)
     default_context_= NULL;
index bab5ad1..51f9ef1 100644 (file)
@@ -29,6 +29,7 @@ struct Ewk_Context : public base::RefCounted<Ewk_Context> {
   static Ewk_Context* DefaultContext();
   static void DefaultContextRelease();
   static Ewk_Context* Create(bool incognito = false);
+  static Ewk_Context* Create(const std::string& injectedBundlePath);
   static void Delete(Ewk_Context*);
 
   // Get related class
@@ -129,6 +130,7 @@ struct Ewk_Context : public base::RefCounted<Ewk_Context> {
   EWebContext* impl;
 
   Ewk_Context(bool incognito);
+  Ewk_Context(const std::string& injectedBundlePath);
   ~Ewk_Context();
   friend class base::RefCounted<Ewk_Context>;
 
index 90ab294..5658340 100644 (file)
@@ -47,10 +47,8 @@ Ewk_Context* ewk_context_new()
 
 Ewk_Context *ewk_context_new_with_injected_bundle_path(const char *path)
 {
-  //with chromium engine this API not used.
-  //returning default context
-  NOTIMPLEMENTED();
-  return NULL;
+  EINA_SAFETY_ON_NULL_RETURN_VAL(path, NULL);
+  return Ewk_Context::Create(std::string(path));
 }
 
 void ewk_context_delete(Ewk_Context* context)
index 232c812..e548eaf 100644 (file)
@@ -8,8 +8,9 @@
 #include <vconf/vconf.h>
 #endif
 
-#include "url/gurl.h"
+#include "base/command_line.h"
 #include "base/path_service.h"
+#include "common/content_switches_efl.h"
 #include "common/render_messages_ewk.h"
 #include "content/common/paths_efl.h"
 #include "content/public/renderer/render_thread.h"
@@ -26,6 +27,7 @@
 #include "third_party/WebKit/public/web/WebDocument.h"
 #include "third_party/WebKit/public/web/WebFrame.h"
 #include "third_party/WebKit/public/web/WebView.h"
+#include "url/gurl.h"
 
 #if defined(OS_TIZEN_MOBILE)
 #include "content/common/tts_messages_efl.h"
@@ -75,16 +77,17 @@ void ContentRendererClientEfl::RenderThreadStarted()
 {
   content::RenderThread* thread = content::RenderThread::Get();
 
-  wrt_widget_.reset(new WrtWidget);
-  thread->AddObserver(wrt_widget_->GetObserver());
+  if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kInjectedBundlePath)) {
+    wrt_widget_.reset(new WrtWidget);
+    thread->AddObserver(wrt_widget_->GetObserver());
+    wrt_url_parser_.reset(new WrtUrlParseImpl(wrt_widget_.get()));
+  }
 
   render_process_observer_.reset(new RenderProcessObserverEfl(this));
   thread->AddObserver(render_process_observer_.get());
 
   visited_link_slave_.reset(new visitedlink::VisitedLinkSlave());
   thread->AddObserver(visited_link_slave_.get());
-
-  wrt_url_parser_.reset(new WrtUrlParseImpl(wrt_widget_.get()));
 }
 
 void ContentRendererClientEfl::RenderFrameCreated(content::RenderFrame* render_frame) {
@@ -154,7 +157,12 @@ bool ContentRendererClientEfl::WillSendRequest(blink::WebFrame* frame,
                                                const GURL& url,
                                                const GURL& first_party_for_cookies,
                                                GURL* new_url) {
-  wrt_widget_->ParseUrl(url, *new_url);
+  if (wrt_widget_) {
+    wrt_widget_->ParseUrl(url, *new_url);
+  } else {
+    *new_url = url;
+  }
+
   return true;
 }
 
@@ -163,15 +171,16 @@ void ContentRendererClientEfl::DidCreateScriptContext(blink::WebFrame* frame,
                                                       int extension_group,
                                                       int world_id) {
   const content::RenderView* render_view = content::RenderView::FromWebView(frame->view());
-
-  wrt_widget_->StartSession(context, render_view->GetRoutingID(),
+  if (wrt_widget_)
+    wrt_widget_->StartSession(context, render_view->GetRoutingID(),
                             frame->document().baseURL().string().utf8());
 }
 
 void ContentRendererClientEfl::WillReleaseScriptContext(blink::WebFrame* frame,
                                                         v8::Handle<v8::Context> context,
                                                         int world_id) {
-  wrt_widget_->StopSession(context);
+  if (wrt_widget_)
+    wrt_widget_->StopSession(context);
 }
 
 unsigned long long ContentRendererClientEfl::VisitedLinkHash(const char* canonical_url,
index e0ba1e6..10b7c34 100644 (file)
@@ -5,10 +5,12 @@
 #include "dynamicplugin.h"
 
 #include <dlfcn.h>
-#include <base/logging.h>
+
+#include "base/command_line.h"
+#include "base/logging.h"
+#include "common/content_switches_efl.h"
 
 namespace {
-const char* const INJECTED_BUNDLE_LIBRARY = "/usr/lib/libwrt-injected-bundle.so";
 const char* const START_SESSION_FUNCTION = "DynamicPluginStartSession";
 const char* const URL_PARSING_FUNCTION = "DynamicUrlParsing";
 const char* const SET_WIDGET_INFO_FUNCTION = "DynamicSetWidgetInfo";
@@ -21,9 +23,14 @@ DynamicPlugin::DynamicPlugin()
     m_parseURL(0),
     m_setWidgetInfo(0),
     m_databaseAttach(0) {
-  m_handle = dlopen(INJECTED_BUNDLE_LIBRARY, RTLD_LAZY);
+  const base::CommandLine& commandLine = *base::CommandLine::ForCurrentProcess();
+  std::string injectedBundlePath =
+    commandLine.GetSwitchValueASCII(switches::kInjectedBundlePath);
+  if (injectedBundlePath.empty())
+    return;
+  m_handle = dlopen(injectedBundlePath.c_str(), RTLD_LAZY);
   if (!m_handle) {
-    LOG(ERROR) << "No handle to " << INJECTED_BUNDLE_LIBRARY <<  " " << dlerror() << "\n";
+    LOG(ERROR) << "No handle to " << injectedBundlePath.c_str() <<  " " << dlerror() << "\n";
     return;
   }
 
index 1b0af5f..fa504e6 100644 (file)
@@ -8,6 +8,7 @@
       '<(DEPTH)/tizen_src/build/system.gyp:edje',
       '<(DEPTH)/tizen_src/build/system.gyp:elementary',
       '<(DEPTH)/testing/gtest.gyp:gtest',
+      'bundle_sample',
       'chromium-ewk',
     ],
     'include_dirs': [
         'utc_blink_ewk_context_menu_item_tag_get_func.cpp',
         'utc_blink_ewk_context_menu_nth_item_get_func.cpp',
         'utc_blink_ewk_context_new_func.cpp',
+        'utc_blink_ewk_context_new_with_injected_bundle_path_func.cc',
         'utc_blink_ewk_context_notify_low_memory_func.cpp',
         'utc_blink_ewk_context_pixmap_set_func.cpp',
         'utc_blink_ewk_context_preferred_languages_set_func.cpp',
         '<!@(pkg-config --libs-only-l glib-2.0)',
       ],
     },
-
+    'copies': [{
+      'destination':'resources/ewk_context/injected_bundle/chromium/',
+      'files': [ '<(PRODUCT_DIR)/lib/libbundle_sample.so' ],
+    }],
     'conditions': [
      ['building_for_tizen==1', {
       'cflags': [
     }]
    ],
 
+  },
+  {
+    'target_name': 'bundle_sample',
+    'type': 'shared_library',
+    'sources': [
+      'resources/ewk_context/injected_bundle/chromium/bundle_sample.cc',
+    ],
+    'dependencies': [
+      '<(DEPTH)/v8/tools/gyp/v8.gyp:v8',
+    ],
+    'include_dirs': [
+      '.',
+      '<(DEPTH)/v8/include',
+    ],
   }]
 }
diff --git a/tizen_src/ewk/unittest/resources/ewk_context/injected_bundle/chromium/bundle_sample.cc b/tizen_src/ewk/unittest/resources/ewk_context/injected_bundle/chromium/bundle_sample.cc
new file mode 100644 (file)
index 0000000..86a643b
--- /dev/null
@@ -0,0 +1,26 @@
+// Copyright 2015 Samsung Electronics. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <v8.h>
+
+#define EXPORT __attribute__((__visibility__("default")))
+
+namespace {
+void Run(const char* source) {
+  v8::Script::Compile(v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), source))->Run();
+}
+} // namespace
+
+extern "C" EXPORT void DynamicPluginStartSession(int widget_id,
+                               v8::Handle<v8::Context> context,
+                               int routingHandle,
+                               double scale,
+                               const char* encodeBundle,
+                               const char* theme,
+                               const char* baseURL) {
+  Run("document.write(\"DynamicPluginStartSession\");");
+}
+
+extern "C" EXPORT void DynamicDatabaseAttach(int attach) {
+}
@@ -1,3 +1,7 @@
+// Copyright 2015 Samsung Electronics. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
 #include <WebKit2/WKBundle.h>
 #include <WebKit2/WKBundleInitialize.h>
 #include <WebKit2/WKBundlePage.h>
diff --git a/tizen_src/ewk/unittest/utc_blink_ewk_context_new_with_injected_bundle_path_func.cc b/tizen_src/ewk/unittest/utc_blink_ewk_context_new_with_injected_bundle_path_func.cc
new file mode 100644 (file)
index 0000000..10e2e46
--- /dev/null
@@ -0,0 +1,78 @@
+// Copyright 2015 Samsung Electronics. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// See README.md how to run this test in DESKTOP mode.
+
+#include "utc_blink_ewk_base.h"
+
+class utc_blink_ewk_context_new_with_injected_bundle_path_func : public utc_blink_ewk_base
+{
+protected:
+    utc_blink_ewk_context_new_with_injected_bundle_path_func()
+      : timer(NULL),
+        webview(NULL) {
+    }
+
+    Ecore_Timer* timer;
+    Evas_Object* webview;
+    static const std::string injectedBundlePath;
+
+    static void getPlainText(Evas_Object* webview, const char* plainText, void* data)
+    {
+      ASSERT_TRUE(data);
+      utc_blink_ewk_context_new_with_injected_bundle_path_func* owner =
+        static_cast<utc_blink_ewk_context_new_with_injected_bundle_path_func*>(data);
+      owner->EventLoopStop(Success);
+      if (!plainText)
+        utc_fail();
+
+      if (strcmp(plainText, "DynamicPluginStartSession"))
+        utc_fail();
+    }
+    static Eina_Bool timerCallback(void* data)
+    {
+      utc_blink_ewk_context_new_with_injected_bundle_path_func* owner =
+        static_cast<utc_blink_ewk_context_new_with_injected_bundle_path_func*>(data);
+      ewk_view_plain_text_get(owner->webview, getPlainText, owner);
+    }
+    void runWithTimer()
+    {
+      timer = ecore_timer_add(1, timerCallback, this);
+    }
+
+    Evas_Object* CreateWindow()
+    {
+      Evas_Object* window = elm_win_add(NULL, "TC Launcher", ELM_WIN_BASIC);
+      return ewk_view_add_with_context(evas_object_evas_get(window),
+        ewk_context_new_with_injected_bundle_path(GetResourcePath(injectedBundlePath.c_str()).c_str()));
+    }
+};
+
+const std::string utc_blink_ewk_context_new_with_injected_bundle_path_func::injectedBundlePath =
+    "ewk_context/injected_bundle/chromium/libbundle_sample.so";
+
+/**
+ * @brief Checking whether context with injected bundle path is returned
+ */
+TEST_F(utc_blink_ewk_context_new_with_injected_bundle_path_func, POS_TEST)
+{
+  ASSERT_TRUE(ewk_context_new_with_injected_bundle_path(
+              GetResourcePath(injectedBundlePath.c_str()).c_str()));
+}
+
+TEST_F(utc_blink_ewk_context_new_with_injected_bundle_path_func, POS_TEST1)
+{
+  webview = CreateWindow();
+  const char simpleHTML[] = "<html><body><script>document.write(\"\");</script></body></html>";
+  ASSERT_TRUE(ewk_view_html_string_load(webview, simpleHTML, NULL, NULL));
+  ewk_send_widget_info(ewk_view_context_get(webview), 1, 1.0, "theme", "encodeBundle");
+  runWithTimer();
+  ASSERT_EQ(Success, EventLoopStart());
+}
+
+TEST_F(utc_blink_ewk_context_new_with_injected_bundle_path_func, NEG_TEST)
+{
+  Ewk_Context* context = ewk_context_new_with_injected_bundle_path(0);
+  ASSERT_TRUE(!context);
+}