Merge "fix: use EINA_* booleans instread of TRUE/FALSE" into tizen
[platform/framework/web/wrt.git] / src / view / webkit / view_logic_scheme_support.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 /*
17  * @file       view_logic_scheme_support.cpp
18  * @author     Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
19  * @version    1.0
20  */
21
22 #include "view_logic_scheme_support.h"
23
24 #include <dpl/assert.h>
25 #include <dpl/log/secure_log.h>
26 #include <common/scheme_action_map.h>
27 #include <Elementary.h>
28 #include <EWebKit2.h>
29
30 namespace ViewModule {
31 namespace {
32 char const * const TIZEN_SCHEME = "tizen";
33 char const * const TIZEN_EXIT = "tizen://exit";
34 char const * const TIZEN_HIDE = "tizen://hide";
35 char const * const TIZEN_CHANGE_USERAGNET = "tizen://changeUA";
36
37 static Eina_Bool exitAppIdlerCallback(void* /*data*/)
38 {
39     elm_exit();
40     return ECORE_CALLBACK_CANCEL;
41 }
42 } // namespace
43
44 bool SchemeSupport::HandleTizenScheme(const char* uri,
45                                       Evas_Object* window,
46                                       Evas_Object* wkView)
47 {
48     if (!uri) {
49         _W("Empty uri");
50         return false;
51     }
52     if (!window) {
53         _W("Empty window data");
54         return false;
55     }
56
57     if (strncmp(uri, TIZEN_EXIT, strlen(TIZEN_EXIT)) == 0) {
58         _D("%s : exit", uri);
59         ecore_idler_add(exitAppIdlerCallback, NULL);
60         return true;
61     } else if (strncmp(uri, TIZEN_HIDE, strlen(TIZEN_HIDE)) == 0) {
62         _D("%s : hide", uri);
63         elm_win_withdrawn_set(window, EINA_TRUE);
64         return true;
65     } else if (strncmp(uri,
66                        TIZEN_CHANGE_USERAGNET,
67                        strlen(TIZEN_CHANGE_USERAGNET)) == 0)
68     {
69         _D("%s : change UA", uri);
70         const char* userAgentString = strstr(uri, "=");
71         if (NULL == userAgentString) {
72             _W("UA string is NULL");
73         } else {
74             userAgentString++;
75             _D("Setting custom user agent as: %s", userAgentString);
76             ewk_view_user_agent_set(wkView, userAgentString);
77         }
78         return true;
79     }
80     return false;
81 }
82
83 bool SchemeSupport::filterURIByScheme(Ewk_Policy_Decision* policyDecision,
84                                       bool newWindow,
85                                       Evas_Object* window,
86                                       Evas_Object* wkView)
87 {
88     _D("called");
89     Assert(policyDecision);
90
91     const char* url = ewk_policy_decision_url_get(policyDecision);
92     if (NULL == url) {
93         // URI is null
94         // There is no reason, security by scheme block null uri
95         return true;
96     }
97
98     bool mainFrame =
99         ewk_frame_is_main_frame(ewk_policy_decision_frame_get(policyDecision));
100
101     using namespace ViewModule::SchemeActionMap;
102     if (HandleTizenScheme(url, window, wkView)) {
103         _D("Scheme is tizen scheme");
104         return false;
105     }
106
107     NavigationContext ctx;
108     ctx = (mainFrame ? TOP_LEVEL : FRAME_LEVEL);
109     if (newWindow) {
110         // In case of Tizen,
111         // policy of new window should be applied,
112         // regardless level of this frame
113         ctx = NEW_WINDOW;
114     }
115
116     return SchemeActionMap::HandleUri(url, ctx);
117 }
118 } // namespace ViewModule
119