From bc5a675ad94a6ed4a188880782c11a1f69e4f46c Mon Sep 17 00:00:00 2001
From: Piotr Pruski
Date: Wed, 11 Feb 2015 16:21:22 +0100
Subject: [PATCH] Implementation for ewk_settings_private_browsing
Implementation of set and get functions to use private browsing mode.
Implementation replaces current webcontext to new one with private settings.
The old one is held till user goes back to normal browsing.
Bug: http://107.108.218.239/bugzilla/show_bug.cgi?id=11110
Reviewed by: Antonio Gomes, DONGJUN KiM
Change-Id: I922a1e674be01024e55622c0d1822c414dd17bbf
Signed-off-by: Piotr Pruski
---
.../ewk/efl_integration/public/ewk_settings.cc | 18 +++-----
.../ewk/efl_integration/public/ewk_settings.h | 4 +-
tizen_src/ewk/unittest/ewk-tests.gypi | 2 +
..._settings_private_browsing_enabled_get_func.cpp | 36 ++++++++++++++++
..._settings_private_browsing_enabled_set_func.cpp | 50 ++++++++++++++++++++++
tizen_src/impl/eweb_context.cc | 5 +--
tizen_src/impl/eweb_context.h | 1 -
tizen_src/impl/eweb_view.cc | 23 ++++++++++
tizen_src/impl/eweb_view.h | 3 ++
tizen_src/impl/tizen_webview/public/tw_webview.cc | 8 ++++
tizen_src/impl/tizen_webview/public/tw_webview.h | 2 +
11 files changed, 134 insertions(+), 18 deletions(-)
create mode 100644 tizen_src/ewk/unittest/utc_blink_ewk_settings_private_browsing_enabled_get_func.cpp
create mode 100755 tizen_src/ewk/unittest/utc_blink_ewk_settings_private_browsing_enabled_set_func.cpp
diff --git a/tizen_src/ewk/efl_integration/public/ewk_settings.cc b/tizen_src/ewk/efl_integration/public/ewk_settings.cc
index 41d4218..e1bf842 100644
--- a/tizen_src/ewk/efl_integration/public/ewk_settings.cc
+++ b/tizen_src/ewk/efl_integration/public/ewk_settings.cc
@@ -209,22 +209,16 @@ const char* ewk_settings_default_encoding_get(const Ewk_Settings* settings)
Eina_Bool ewk_settings_private_browsing_enabled_set(Ewk_Settings* settings, Eina_Bool enable)
{
- // This API is not supported by blink engine because it does not support toggling of private browsing mode
- // Chromium allows to create new WebContext with private browsing enabled for whole lifespan of WebContext
- // To support private browsing we need to add new ewk API that allows us to create either context or view with
- // private browsing enabled
- LOG_EWK_API_MOCKUP("Not supported by chromium");
- return EINA_FALSE;
+ EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
+ WebView* impl = WebView::FromEvasObject(settings->getEvasObject());
+ return impl->SetPrivateBrowsing(enable);
}
Eina_Bool ewk_settings_private_browsing_enabled_get(const Ewk_Settings* settings)
{
- // This API is not supported by blink engine because it does not support toggling of private browsing mode
- // Chromium allows to create new WebContext with private browsing enabled for whole lifespan of WebContext
- // To support private browsing we need to add new ewk API that allows us to create either context or view with
- // private browsing enabled
- LOG_EWK_API_MOCKUP("Not supported by chromium");
- return EINA_FALSE;
+ EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
+ EWK_VIEW_IMPL_GET_OR_RETURN(const_cast(settings)->getEvasObject(), webview, EINA_FALSE);
+ return webview->GetPrivateBrowsing();
}
Eina_Bool ewk_settings_editable_link_behavior_set(Ewk_Settings* settings, Ewk_Editable_Link_Behavior behavior)
diff --git a/tizen_src/ewk/efl_integration/public/ewk_settings.h b/tizen_src/ewk/efl_integration/public/ewk_settings.h
index 6ad3c71..3fe210a 100644
--- a/tizen_src/ewk/efl_integration/public/ewk_settings.h
+++ b/tizen_src/ewk/efl_integration/public/ewk_settings.h
@@ -272,7 +272,7 @@ EAPI const char* ewk_settings_default_encoding_get(const Ewk_Settings *settings)
*
* @return @c EINA_TRUE on success or @c EINA_FALSE on failure
*/
-EAPI Eina_Bool ewk_settings_private_browsing_enabled_set(Ewk_Settings *settings, Eina_Bool enable);
+EINA_DEPRECATED EAPI Eina_Bool ewk_settings_private_browsing_enabled_set(Ewk_Settings *settings, Eina_Bool enable);
/**
* Returns enables/disables private browsing.
@@ -282,7 +282,7 @@ EAPI Eina_Bool ewk_settings_private_browsing_enabled_set(Ewk_Settings *settings,
* @return @c EINA_TRUE if private browsing was enabled
* @c EINA_FALSE if not or on failure
*/
-EAPI Eina_Bool ewk_settings_private_browsing_enabled_get(const Ewk_Settings *settings);
+EINA_DEPRECATED EAPI Eina_Bool ewk_settings_private_browsing_enabled_get(const Ewk_Settings *settings);
/**
* Requests to set editable link behavior.
diff --git a/tizen_src/ewk/unittest/ewk-tests.gypi b/tizen_src/ewk/unittest/ewk-tests.gypi
index 37b8fff..4b3f6bd 100644
--- a/tizen_src/ewk/unittest/ewk-tests.gypi
+++ b/tizen_src/ewk/unittest/ewk-tests.gypi
@@ -225,6 +225,8 @@
'utc_blink_ewk_settings_link_effect_enabled_set_func.cpp',
'utc_blink_ewk_settings_link_magnifier_enabled_get_func.cpp',
'utc_blink_ewk_settings_link_magnifier_enabled_set_func.cpp',
+ 'utc_blink_ewk_settings_private_browsing_enabled_get_func.cpp',
+ 'utc_blink_ewk_settings_private_browsing_enabled_set_func.cpp',
'utc_blink_ewk_settings_load_remote_images_set_func.cpp',
'utc_blink_ewk_settings_loads_images_automatically_set_func.cpp',
'utc_blink_ewk_settings_paste_image_uri_mode_set_func.cpp',
diff --git a/tizen_src/ewk/unittest/utc_blink_ewk_settings_private_browsing_enabled_get_func.cpp b/tizen_src/ewk/unittest/utc_blink_ewk_settings_private_browsing_enabled_get_func.cpp
new file mode 100644
index 0000000..7a0ff42
--- /dev/null
+++ b/tizen_src/ewk/unittest/utc_blink_ewk_settings_private_browsing_enabled_get_func.cpp
@@ -0,0 +1,36 @@
+// Copyright 2014 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 "utc_blink_ewk_base.h"
+
+class utc_blink_ewk_settings_private_browsing_enabled_get_func : public utc_blink_ewk_base
+{
+};
+
+
+/**
+ * @brief Tests getting private browsing enabled.
+ */
+TEST_F(utc_blink_ewk_settings_private_browsing_enabled_get_func, POS_TEST_TRUE)
+{
+ Ewk_Settings* settings = ewk_view_settings_get(GetEwkWebView());
+ ASSERT_TRUE(settings);
+
+ ewk_settings_private_browsing_enabled_set(settings, EINA_TRUE);
+ ASSERT_TRUE(ewk_settings_private_browsing_enabled_get(settings));
+}
+
+/**
+ * @brief Tests if getting private browsing enabled with NULL settings fails.
+ */
+TEST_F(utc_blink_ewk_settings_private_browsing_enabled_get_func, NEG_TEST)
+{
+
+ Ewk_Settings* settings = ewk_view_settings_get(GetEwkWebView());
+ ASSERT_TRUE(settings);
+ ewk_settings_private_browsing_enabled_set(settings, EINA_TRUE);
+ ASSERT_TRUE(ewk_settings_private_browsing_enabled_get(settings));
+
+ ASSERT_FALSE(ewk_settings_private_browsing_enabled_get(NULL));
+}
diff --git a/tizen_src/ewk/unittest/utc_blink_ewk_settings_private_browsing_enabled_set_func.cpp b/tizen_src/ewk/unittest/utc_blink_ewk_settings_private_browsing_enabled_set_func.cpp
new file mode 100755
index 0000000..0ba0bbb
--- /dev/null
+++ b/tizen_src/ewk/unittest/utc_blink_ewk_settings_private_browsing_enabled_set_func.cpp
@@ -0,0 +1,50 @@
+// Copyright 2014 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 "utc_blink_ewk_base.h"
+
+class utc_blink_ewk_settings_private_browsing_enabled_set_func : public utc_blink_ewk_base
+{
+};
+
+
+/**
+ * @brief Tests setting private browsing enabled to TRUE.
+ */
+TEST_F(utc_blink_ewk_settings_private_browsing_enabled_set_func, POS_TEST_TRUE)
+{
+ Ewk_Settings* settings = ewk_view_settings_get(GetEwkWebView());
+ ASSERT_TRUE(settings);
+
+ ewk_settings_private_browsing_enabled_set(settings, EINA_TRUE);
+ ASSERT_TRUE(ewk_settings_private_browsing_enabled_get(settings));
+}
+
+/**
+ * @brief Tests setting private browsing enabled to FALSE.
+ */
+TEST_F(utc_blink_ewk_settings_private_browsing_enabled_set_func, POS_TEST_FALSE)
+{
+ Ewk_Settings* settings = ewk_view_settings_get(GetEwkWebView());
+ ASSERT_TRUE(settings);
+
+ ewk_settings_private_browsing_enabled_set(settings, EINA_FALSE);
+ ASSERT_FALSE(ewk_settings_private_browsing_enabled_get(settings));
+}
+
+/**
+ * @brief Tests if setting private browsing enabled with NULL settings fails.
+ */
+TEST_F(utc_blink_ewk_settings_private_browsing_enabled_set_func, NEG_TEST)
+{
+
+ Ewk_Settings* settings = ewk_view_settings_get(GetEwkWebView());
+ ASSERT_TRUE(settings);
+ ewk_settings_private_browsing_enabled_set(settings, EINA_TRUE);
+ ASSERT_TRUE(ewk_settings_private_browsing_enabled_get(settings));
+
+ ewk_settings_private_browsing_enabled_set(NULL, EINA_FALSE);
+
+ ASSERT_TRUE(ewk_settings_private_browsing_enabled_get(settings));;
+}
diff --git a/tizen_src/impl/eweb_context.cc b/tizen_src/impl/eweb_context.cc
index 320c310..e168686 100644
--- a/tizen_src/impl/eweb_context.cc
+++ b/tizen_src/impl/eweb_context.cc
@@ -232,11 +232,10 @@ bool EWebContext::OverrideMimeForURL(const std::string& url_spec,
EWebContext::EWebContext(bool incognito)
: m_pixmap(0),
- inspector_server_(NULL),
- incognito_(incognito) {
+ inspector_server_(NULL) {
CHECK(EwkGlobalData::GetInstance());
- browser_context_.reset(new BrowserContextEfl(this));
+ browser_context_.reset(new BrowserContextEfl(this, incognito));
// Notification Service gets init in BrowserMainRunner init,
// so cache manager can register for notifications only after that.
web_cache_manager_.reset(new WebCacheManagerEfl(browser_context_.get()));
diff --git a/tizen_src/impl/eweb_context.h b/tizen_src/impl/eweb_context.h
index 2e049f2..902fca7 100644
--- a/tizen_src/impl/eweb_context.h
+++ b/tizen_src/impl/eweb_context.h
@@ -131,7 +131,6 @@ class EWebContext {
scoped_ptr mime_override_callback_;
int m_pixmap;
content::DevToolsDelegateEfl* inspector_server_;
- bool incognito_;
};
#endif
diff --git a/tizen_src/impl/eweb_view.cc b/tizen_src/impl/eweb_view.cc
index e76f5b9..d98554c 100644
--- a/tizen_src/impl/eweb_view.cc
+++ b/tizen_src/impl/eweb_view.cc
@@ -1030,6 +1030,29 @@ bool EWebView::SetUserAgentAppName(const char* application_name) {
return true;
}
+bool EWebView::SetPrivateBrowsing(bool incognito) {
+ if (context_->GetImpl()->browser_context()->IsOffTheRecord() == incognito)
+ return false;
+
+ GURL url = web_contents_->GetVisibleURL();
+ if (old_context_.get()) {
+ context_ = old_context_;
+ old_context_ = NULL;
+ } else {
+ old_context_ = context_;
+ context_ = tizen_webview::WebContext::Create(incognito);
+ }
+
+ InitializeContent();
+ NavigationController::LoadURLParams params(url);
+ web_contents_->GetController().LoadURLWithParams(params);
+ return true;
+}
+
+bool EWebView::GetPrivateBrowsing() const {
+ return context_->GetImpl()->browser_context()->IsOffTheRecord();
+}
+
void EWebView::set_magnifier(bool status) {
rwhv()->set_magnifier(status);
}
diff --git a/tizen_src/impl/eweb_view.h b/tizen_src/impl/eweb_view.h
index d58e5d3..60bd950 100644
--- a/tizen_src/impl/eweb_view.h
+++ b/tizen_src/impl/eweb_view.h
@@ -290,6 +290,8 @@ class EWebView {
bool ExecuteJavaScript(const char* script, tizen_webview::View_Script_Execute_Callback callback, void* userdata);
bool SetUserAgent(const char* userAgent);
bool SetUserAgentAppName(const char* application_name);
+ bool SetPrivateBrowsing(bool incognito);
+ bool GetPrivateBrowsing() const;
const char* GetUserAgent() const;
const char* GetUserAgentAppName() const;
const char* GetSelectedText() const;
@@ -512,6 +514,7 @@ class EWebView {
tizen_webview::WebView* public_webview_;
tizen_webview::WebViewEvasEventHandler* evas_event_handler_;
scoped_refptr context_;
+ scoped_refptr old_context_;
scoped_ptr web_contents_;
scoped_ptr web_contents_delegate_;
std::string pending_url_request_;
diff --git a/tizen_src/impl/tizen_webview/public/tw_webview.cc b/tizen_src/impl/tizen_webview/public/tw_webview.cc
index a9608f04..8ae00bf 100644
--- a/tizen_src/impl/tizen_webview/public/tw_webview.cc
+++ b/tizen_src/impl/tizen_webview/public/tw_webview.cc
@@ -61,6 +61,14 @@ WebContext* WebView::GetWebContext() {
return impl_->context();
}
+bool WebView::SetPrivateBrowsing(bool incognito) {
+ return impl_->SetPrivateBrowsing(incognito);
+}
+
+bool WebView::GetPrivateBrowsing() const {
+ return impl_->GetPrivateBrowsing();
+}
+
Ewk_Settings* WebView::GetSettings() {
return impl_->GetSettings();
}
diff --git a/tizen_src/impl/tizen_webview/public/tw_webview.h b/tizen_src/impl/tizen_webview/public/tw_webview.h
index 059b6fc..19e360d 100644
--- a/tizen_src/impl/tizen_webview/public/tw_webview.h
+++ b/tizen_src/impl/tizen_webview/public/tw_webview.h
@@ -56,6 +56,8 @@ class WebView {
Evas_Object* AsEvasObject();
static WebView* FromEvasObject(Evas_Object* eo);
WebContext* GetWebContext();
+ bool SetPrivateBrowsing(bool incognito);
+ bool GetPrivateBrowsing() const;
Ewk_Settings* GetSettings();
SelectionController* GetSelectionController();
WebViewEvasEventHandler* GetEvasEventHandler();
--
2.7.4