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 <p.pruski@samsung.com>
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<Ewk_Settings *>(settings)->getEvasObject(), webview, EINA_FALSE);
+ return webview->GetPrivateBrowsing();
}
Eina_Bool ewk_settings_editable_link_behavior_set(Ewk_Settings* settings, Ewk_Editable_Link_Behavior behavior)
*
* @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.
* @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.
'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',
--- /dev/null
+// 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));
+}
--- /dev/null
+// 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));;
+}
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()));
scoped_ptr<EwkMimeOverrideCallback> mime_override_callback_;
int m_pixmap;
content::DevToolsDelegateEfl* inspector_server_;
- bool incognito_;
};
#endif
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);
}
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;
tizen_webview::WebView* public_webview_;
tizen_webview::WebViewEvasEventHandler* evas_event_handler_;
scoped_refptr<tizen_webview::WebContext> context_;
+ scoped_refptr<tizen_webview::WebContext> old_context_;
scoped_ptr<content::WebContents> web_contents_;
scoped_ptr<content::WebContentsDelegateEfl> web_contents_delegate_;
std::string pending_url_request_;
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();
}
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();