Update incognito mode ewk API 95/49995/7
authorKamil Nowac <k.nowac@samsung.com>
Thu, 22 Oct 2015 09:45:59 +0000 (11:45 +0200)
committerKamil Nowa? <k.nowac@samsung.com>
Wed, 28 Oct 2015 07:38:50 +0000 (00:38 -0700)
[Issue] https://bugs.tizen.org/jira/browse/TT-230
[Problem] Using deprecated function
[Solution] Added new function and reorganization of
of current incognito mode solution
[Verification]
1. Open page in incognito mode
2. Type URL that do not exist it the history
3. Type enter

New URL shouldn't be inserted into history.

4. Close browser with ctrl+c
5. Open browser again

Browser should open without the tab last opened
in incognito mode.

Change-Id: Ia4548e628b30d57e58f9aeee3c4563e39705ab27

core/AbstractWebEngine/AbstractWebEngine.h
services/SimpleUI/SimpleUI.cpp
services/SimpleUI/SimpleUI.h
services/WebKitEngineService/WebKitEngineService.cpp
services/WebKitEngineService/WebKitEngineService.h
services/WebKitEngineService/WebView.cpp
services/WebKitEngineService/WebView.h

index 91da16c..bbbc8d8 100644 (file)
@@ -147,10 +147,16 @@ public:
     /**
      * Adds new tab
      * @param uri if not empty opens specified uri
+     * @param openerId
      * @param desktopMode true if desktop mode, false if mobile mode
+     * @param incognitoMode true if incognito mode, false if not
      * @return TabId of created tab
      */
-    virtual TabId addTab(const std::string & uri = std::string(), const TabId * openerId = NULL, bool desktopMode = true) = 0;
+    virtual TabId addTab(
+            const std::string & uri = std::string(),
+            const TabId * openerId = NULL,
+            bool desktopMode = true,
+            bool incognitoMode = false) = 0;
 
     /**
      * @param tab id
@@ -208,34 +214,12 @@ public:
     virtual std::shared_ptr<tizen_browser::tools::BrowserImage> getSnapshotData(TabId id, int width, int height) = 0;
 
     /**
-     * Set private mode on/off
-     * \param private mode on when true, off otherwise
-     */
-    virtual void setPrivateMode(bool) = 0;
-
-    /**
-     * Set the state of private mode for a specific tab
-     *
-     * \param id of snapshot
-     * \param state to set
-     */
-    virtual void setPrivateMode(const TabId&, bool) = 0;
-
-    /**
-     * Get the state of private mode
-     */
-    virtual bool isPrivateMode() const = 0;
-
-    /**
      * Get the state of private mode for a specific tab
      *
      * /param id of snapshot
-     * /return state of private mode where:
-     *     -1 is "Not set"
-     *      0 is "False"
-     *      1 is "True"
+     * /return state of private mode
      */
-    virtual int isPrivateMode(const TabId&) = 0;
+    virtual bool isPrivateMode(const TabId&) = 0;
 
     virtual bool isLoadError() const = 0;
 
index ab890cb..1e436f1 100644 (file)
@@ -71,7 +71,6 @@ SimpleUI::SimpleUI()
     , m_tabUI()
     , m_initialised(false)
     , m_wvIMEStatus(false)
-    , m_incognito(false)
     , m_ewkContext(ewk_context_new())
 {
     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
@@ -137,7 +136,6 @@ int SimpleUI::exec(const std::string& _url)
 
             loadUIServices();
             loadModelServices();
-            createActions();
 
             // initModelServices() needs to be called after initUIServices()
             initUIServices();
@@ -146,7 +144,6 @@ int SimpleUI::exec(const std::string& _url)
 
             connectModelSignals();
             connectUISignals();
-            connectActions();
 
             //Push first view to stack.
             m_viewManager->pushViewToStack(m_webPageUI.get());
@@ -267,11 +264,9 @@ void SimpleUI::connectUISignals()
     m_tabUI->closeTabUIClicked.connect(boost::bind(&SimpleUI::closeTabUI, this));
     m_tabUI->closeTabUIClicked.connect(boost::bind(&ZoomUI::showNavigation, m_zoomUI.get()));
     m_tabUI->newTabClicked.connect(boost::bind(&SimpleUI::newTabClicked, this));
-    m_tabUI->newTabClicked.connect(boost::bind(&SimpleUI::settingsPrivateModeSwitch, this, false));
     m_tabUI->tabClicked.connect(boost::bind(&SimpleUI::tabClicked, this,_1));
     m_tabUI->closeTabsClicked.connect(boost::bind(&SimpleUI::closeTabsClicked, this,_1));
-    m_tabUI->newIncognitoTabClicked.connect(boost::bind(&SimpleUI::settingsPrivateModeSwitch, this, true));
-    m_tabUI->newIncognitoTabClicked.connect(boost::bind(&SimpleUI::switchViewToIncognitoPage, this));
+    m_tabUI->newIncognitoTabClicked.connect(boost::bind(&SimpleUI::openNewTab, this, "", false, true));
     m_tabUI->tabsCount.connect(boost::bind(&SimpleUI::tabsCount, this));
 
     M_ASSERT(m_historyUI.get());
@@ -420,24 +415,6 @@ void SimpleUI::connectModelSignals()
 
 }
 
-void SimpleUI::createActions()
-{
-    BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
-    ///\todo Add MulitStateAction. and convert m_stopLoading and m_reload actons to it?
-
-    m_settingPrivateBrowsing = sharedAction(new Action("Private browsing"));
-    m_settingPrivateBrowsing->setToolTip("On exit from private mode all cookies, history, and stored data will be deleted");
-    m_settingPrivateBrowsing->setCheckable(true);
-    m_settingPrivateBrowsing->setChecked(m_webEngine->isPrivateMode());
-    m_settingPrivateBrowsing->setEnabled(true);
-}
-
-void SimpleUI::connectActions()
-{
-    BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
-    m_settingPrivateBrowsing->toggled.connect(boost::bind(&SimpleUI::settingsPrivateModeSwitch, this, _1));
-}
-
 void SimpleUI::switchViewToWebPage()
 {
     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
@@ -490,17 +467,19 @@ void SimpleUI::switchViewToIncognitoPage()
 {
     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
     M_ASSERT(m_viewManager);
-    openNewTab("");
+    m_webPageUI->toIncognito(true);
     m_webPageUI->switchViewToIncognitoPage();
     m_viewManager->popStackTo(m_webPageUI.get());
 }
 
-void SimpleUI::openNewTab(const std::string &uri, bool desktopMode)
+void SimpleUI::openNewTab(const std::string &uri, bool desktopMode, bool incognitoMode)
 {
     BROWSER_LOGD("[%s:%d] uri =%s", __PRETTY_FUNCTION__, __LINE__, uri.c_str());
-    tizen_browser::basic_webengine::TabId tab = m_webEngine->addTab(uri, nullptr, desktopMode);
-    applyPrivateModeToTab(tab);
+    tizen_browser::basic_webengine::TabId tab = m_webEngine->addTab(uri, nullptr, desktopMode, incognitoMode);
     switchToTab(tab);
+    m_webPageUI->toIncognito(incognitoMode);
+    if (incognitoMode)
+        switchViewToIncognitoPage();
 }
 
 void SimpleUI::closeTab()
@@ -592,11 +571,11 @@ void SimpleUI::onBookmarkClicked(std::shared_ptr<tizen_browser::services::Bookma
 {
     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
     M_ASSERT(m_viewManager);
-    std::string bookmarkAddress = bookmarkItem->getAddress();
     m_viewManager->popStackTo(m_webPageUI.get());
-    if (!m_incognito) {
+    std::string bookmarkAddress = bookmarkItem->getAddress();
+    if (!m_webEngine->isPrivateMode(m_webEngine->currentTabId()))
         openNewTab(bookmarkAddress);
-    else {
+    else {
         std::string bookmarkTitle = bookmarkItem->getTittle();
         m_webPageUI->switchViewToWebPage(m_webEngine->getLayout(), bookmarkAddress, bookmarkTitle);
         m_webEngine->setURI(bookmarkAddress);
@@ -660,9 +639,8 @@ void SimpleUI::stopEnable(bool enable)
 void SimpleUI::loadStarted()
 {
     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
-    if(!m_webEngine->isPrivateMode()){
+    if (!m_webEngine->isPrivateMode(m_webEngine->currentTabId()))
         m_currentSession.updateItem(m_webEngine->currentTabId().toString(), m_webEngine->getURI());
-    }
     m_webPageUI->loadStarted();
 }
 
@@ -675,11 +653,13 @@ void SimpleUI::loadFinished()
 {
     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
 
-    if(!m_webEngine->isPrivateMode()){
-        m_historyService->addHistoryItem(std::make_shared<tizen_browser::services::HistoryItem> (m_webEngine->getURI(),
+    if (!m_webEngine->isPrivateMode(m_webEngine->currentTabId()))
+        m_historyService->addHistoryItem(std::make_shared<tizen_browser::services::HistoryItem>(m_webEngine->getURI(),
                                                                                                 m_webEngine->getTitle(),
-                                                                                                m_webEngine->getFavicon()), m_webEngine->getSnapshotData(QuickAccess::MAX_THUMBNAIL_WIDTH, QuickAccess::MAX_THUMBNAIL_HEIGHT));
-    }
+                                                                                                m_webEngine->getFavicon()),
+                                                                                                m_webEngine->getSnapshotData(
+                                                                                                    QuickAccess::MAX_THUMBNAIL_WIDTH,
+                                                                                                    QuickAccess::MAX_THUMBNAIL_HEIGHT));
     m_webPageUI->loadFinished();
 }
 
@@ -687,7 +667,7 @@ void SimpleUI::loadStopped()
 {
     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
 
-    if (!m_webEngine->isPrivateMode()) {
+    if (!m_webEngine->isPrivateMode(m_webEngine->currentTabId())) {
         m_historyService->addHistoryItem(std::make_shared<tizen_browser::services::HistoryItem>(
                                              m_webEngine->getURI(),
                                              m_webEngine->getURI(),
@@ -725,7 +705,7 @@ void SimpleUI::filterURL(const std::string& url)
         else
             m_webEngine->setURI(url);
 
-        if (m_incognito)
+        if (m_webEngine->isPrivateMode(m_webEngine->currentTabId()))
             switchViewToWebPage();
     }
     m_webPageUI->getURIEntry().clearFocus();
@@ -818,6 +798,7 @@ void SimpleUI::newTabClicked()
         return;
 
     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
+    m_webPageUI->toIncognito(false);
     switchViewToQuickAccess();
 }
 
@@ -825,7 +806,7 @@ void SimpleUI::tabClicked(const tizen_browser::basic_webengine::TabId& tabId)
 {
     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
     m_viewManager->popStackTo(m_webPageUI.get());
-    applyPrivateModeToTab(tabId);
+    m_webPageUI->toIncognito(m_webEngine->isPrivateMode(tabId));
     switchToTab(tabId);
 }
 
@@ -1025,23 +1006,6 @@ void SimpleUI::closeBookmarkManagerUI()
     m_viewManager->popTheStack();
 }
 
-void SimpleUI::settingsPrivateModeSwitch(bool newState)
-{
-    BROWSER_LOGD("%s: Setting Private mode to: %s", __func__, (newState ? "true" : "false"));
-    m_incognito = newState;
-}
-
-void SimpleUI::applyPrivateModeToTab(const tizen_browser::basic_webengine::TabId& tabId)
-{
-    if (m_webEngine->isPrivateMode(tabId) < 0) {
-        m_webEngine->setPrivateMode(tabId, m_incognito);
-        m_webPageUI->toIncognito(m_incognito);
-    } else {
-        m_webEngine->setPrivateMode(tabId, m_webEngine->isPrivateMode(tabId));
-        m_webPageUI->toIncognito(m_webEngine->isPrivateMode(tabId));
-    }
-}
-
 void SimpleUI::settingsDeleteSelectedData(const std::string& str)
 {
     BROWSER_LOGD("[%s]: Deleting selected data", __func__);
index 1539a19..4924296 100644 (file)
@@ -77,8 +77,6 @@ public:
     void destroyUI();
 private:
     // setup functions
-    void createActions();
-    void connectActions();
     void loadUIServices();
     void connectUISignals();
     void loadModelServices();
@@ -111,7 +109,7 @@ private:
     void switchViewToWebPage();
     void updateView();
 
-    void openNewTab(const std::string &uri, bool desktopMode = true);
+    void openNewTab(const std::string &uri, bool desktopMode = true, bool incognitoMode = false);
     void switchToTab(const tizen_browser::basic_webengine::TabId& tabId);
     void newTabClicked();
     void tabClicked(const tizen_browser::basic_webengine::TabId& tabId);
@@ -151,7 +149,6 @@ private:
     void setwvIMEStatus(bool status);
 
     sharedAction m_showBookmarkManagerUI;
-    sharedAction m_settingPrivateBrowsing;
 
     /**
      * \brief filters URL before it is passed to WebEngine.
@@ -220,8 +217,6 @@ private:
     void closeTab();
     void closeTab(const tizen_browser::basic_webengine::TabId& id);
 
-    void settingsPrivateModeSwitch(bool newState);
-    void applyPrivateModeToTab(const tizen_browser::basic_webengine::TabId& id);
     void settingsDeleteSelectedData(const std::string& str);
     void settingsResetMostVisited();
     void settingsResetBrowser();
@@ -260,7 +255,6 @@ private:
     int m_tabLimit;
     int m_favoritesLimit;
     bool m_wvIMEStatus;
-    bool m_incognito;
 
     //helper object used to view management
     ViewManager* m_viewManager;
index 0e7a6ef..62e7fb4 100644 (file)
@@ -42,7 +42,6 @@ EXPORT_SERVICE(WebKitEngineService, "org.tizen.browser.webkitengineservice")
 
 WebKitEngineService::WebKitEngineService()
     : m_initialised(false)
-    , m_privateMode(false)
     , m_stopped(false)
     , m_guiParent(nullptr)
     , m_currentTabId(TabId::NONE)
@@ -303,7 +302,7 @@ std::vector<std::shared_ptr<TabContent> > WebKitEngineService::getTabContents()
     return result;
 }
 
-TabId WebKitEngineService::addTab(const std::string & uri, const TabId * openerId, bool desktopMode)
+TabId WebKitEngineService::addTab(const std::string & uri, const TabId * openerId, bool desktopMode, bool incognitoMode)
 {
     AbstractWebEngine::checkIfCreate();
 
@@ -317,7 +316,7 @@ TabId WebKitEngineService::addTab(const std::string & uri, const TabId * openerI
 
     // searching for next available tabId
     TabId newTabId;
-    WebViewPtr p = std::make_shared<WebView>(reinterpret_cast<Evas_Object *>(m_guiParent), newTabId);
+    WebViewPtr p = std::make_shared<WebView>(reinterpret_cast<Evas_Object *>(m_guiParent), newTabId, incognitoMode);
     if (openerId)
         p->init(desktopMode, getTabView(*openerId));
     else
@@ -425,38 +424,12 @@ void WebKitEngineService::confirmationResult(WebConfirmationPtr c)
     m_tabs[c->getTabId()]->confirmationResult(c);
 }
 
-void WebKitEngineService::setPrivateMode(bool state)
-{
-    BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
-
-    if (m_privateMode == state) {
-        BROWSER_LOGD("%s:%d %s new privateMode is the same", __FILE__, __LINE__, __func__);
-        return;
-    }
-
-    m_privateMode = state;
-
-    for(std::map<TabId, WebViewPtr>::iterator it = m_tabs.begin(), end = m_tabs.end(); it != end; ++it)
-        it->second->setPrivateMode(state);
-}
-
-void WebKitEngineService::setPrivateMode(const TabId& id, bool state)
-{
-    BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
-    m_tabs[id]->setPrivateMode(state);
-}
-
-int WebKitEngineService::isPrivateMode(const TabId& id)
+bool WebKitEngineService::isPrivateMode(const TabId& id)
 {
     BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
     return m_tabs[id]->isPrivateMode();
 }
 
-bool WebKitEngineService::isPrivateMode() const
-{
-    return m_privateMode;
-}
-
 std::shared_ptr<tizen_browser::tools::BrowserImage> WebKitEngineService::getSnapshotData(int width, int height)
 {
     M_ASSERT(m_currentWebView);
index a60af08..beb9053 100644 (file)
@@ -81,7 +81,7 @@ public:
      * @param uri
      * @return TabId of created tab
      */
-    TabId addTab(const std::string & uri = std::string(), const TabId * openerId = NULL, bool desktopMode = true);
+    TabId addTab(const std::string & uri = std::string(), const TabId * openerId = NULL, bool desktopMode = true, bool incognitoMode = false);
     Evas_Object* getTabView(TabId id);
     bool switchToTab(TabId);
     bool closeTab();
@@ -111,10 +111,6 @@ public:
 
     std::shared_ptr<tizen_browser::tools::BrowserImage> getSnapshotData(TabId id, int width, int height);
 
-    void setPrivateMode(bool);
-    void setPrivateMode(const TabId& id, bool state);
-    bool isPrivateMode() const;
-
     /**
      * @brief Get the state of private mode for a specific tab
      *
@@ -124,7 +120,7 @@ public:
      *      0 is "False"
      *      1 is "True"
      */
-    int isPrivateMode(const TabId& id);
+    bool isPrivateMode(const TabId& id);
 
 
     /**
@@ -213,7 +209,6 @@ private:
 
 private:
     bool m_initialised;
-    bool m_privateMode;
     void * m_guiParent;
     bool m_stopped;
 
index b81a334..988d24d 100644 (file)
@@ -63,7 +63,7 @@ namespace webkitengine_service {
 
 const std::string WebView::COOKIES_PATH = "cookies";
 
-WebView::WebView(Evas_Object * obj, TabId tabId)
+WebView::WebView(Evas_Object * obj, TabId tabId, bool incognitoMode)
     : m_parent(obj)
     , m_tabId(tabId)
     , m_ewkView(nullptr)
@@ -72,7 +72,7 @@ WebView::WebView(Evas_Object * obj, TabId tabId)
     , m_isLoading(false)
     , m_loadError(false)
     , m_suspended(false)
-    , m_private(-1)
+    , m_private(incognitoMode)
 {
     config.load("whatever");
 }
@@ -92,7 +92,14 @@ void WebView::init(bool desktopMode, Evas_Object*)
 {
 #if defined(USE_EWEBKIT)
     M_ASSERT(m_ewkContext);
-    m_ewkView = ewk_view_add_with_context(evas_object_evas_get(m_parent), m_ewkContext);
+
+    m_ewkView = m_private ? ewk_view_add_in_incognito_mode(evas_object_evas_get(m_parent)) :
+                            ewk_view_add_with_context(evas_object_evas_get(m_parent), m_ewkContext);
+
+    Ewk_Context *context = ewk_view_context_get(m_ewkView);
+    if (context)
+        m_private ? ewk_cookie_manager_accept_policy_set(ewk_context_cookie_manager_get(context), EWK_COOKIE_ACCEPT_POLICY_NEVER) :
+                    ewk_cookie_manager_accept_policy_set(ewk_context_cookie_manager_get(context), EWK_COOKIE_ACCEPT_POLICY_ALWAYS);
 
     evas_object_data_set(m_ewkView, "_container", this);
     BROWSER_LOGD("%s:%d %s self=%p", __FILE__, __LINE__, __func__, this);
@@ -311,38 +318,6 @@ bool WebView::isLoadError() const
     return m_loadError;
 }
 
-void WebView::setPrivateMode(bool state)
-{
-    BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
-    M_ASSERT(m_ewkView);
-    if(m_private < 0){
-#if defined(USE_EWEBKIT)
-#if PLATFORM(TIZEN)
-        Ewk_Settings * settings = ewk_view_settings_get(m_ewkView);
-#else
-        Ewk_Settings * settings = ewk_page_group_settings_get(ewk_view_page_group_get(m_ewkView));
-#endif
-        ewk_settings_private_browsing_enabled_set(settings, state);
-        if (m_ewkView)
-        {
-            Ewk_Context *context = ewk_view_context_get(m_ewkView);
-            if (context)
-            {
-                if(state)
-                {
-                    ewk_cookie_manager_accept_policy_set(ewk_context_cookie_manager_get(context), EWK_COOKIE_ACCEPT_POLICY_NEVER);
-                }
-                else
-                {
-                    ewk_cookie_manager_accept_policy_set(ewk_context_cookie_manager_get(context), EWK_COOKIE_ACCEPT_POLICY_ALWAYS);
-                }
-            }
-        }
-#endif
-        m_private = static_cast<unsigned int>(state);
-    }
-}
-
 void WebView::confirmationResult(WebConfirmationPtr confirmation)
 {
     BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
index f6aa423..f73919a 100644 (file)
@@ -39,7 +39,7 @@ namespace webkitengine_service {
 class WebView
 {
 public:
-    WebView(Evas_Object *, TabId);
+    WebView(Evas_Object *, TabId, bool incognitoMode);
     virtual ~WebView();
     void init(bool desktopMode, Evas_Object * opener = NULL);
 
@@ -68,17 +68,12 @@ public:
 
     void confirmationResult(WebConfirmationPtr);
 
-    void setPrivateMode(bool);
-
     /**
      * @brief Get the state of private mode
      *
-     * @return state of private mode where:
-     *     -1 is "Not set"
-     *      0 is "False"
-     *      1 is "True"
+     * @return state of private mode
      */
-    int isPrivateMode() {return m_private;}
+    bool isPrivateMode() {return m_private;}
 
     std::shared_ptr<tizen_browser::tools::BrowserImage> captureSnapshot(int width, int height);
      /**
@@ -227,7 +222,7 @@ private:
     // true if desktop view is enabled, false if mobile
     bool m_desktopMode;
     bool m_suspended;
-    int m_private;
+    bool m_private;
 
     config::DefaultConfig config;