[Release] wrt_0.8.251
[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 <appcore-common.h>
25 #include <dpl/log/log.h>
26 #include <widget_model.h>
27 #include <common/scheme_action_map.h>
28 #include <EWebKit2.h>
29
30 namespace {
31 char const * const TIZEN_SCHEME = "tizen";
32 char const * const TIZEN_EXIT = "tizen://exit";
33 char const * const TIZEN_HIDE = "tizen://hide";
34 char const * const TIZEN_CHANGE_USERAGNET = "tizen://changeUA";
35
36 static Eina_Bool exitAppIdlerCallback(void* /*data*/)
37 {
38     // webapp termination
39     ewk_shutdown();
40     elm_exit();
41     return ECORE_CALLBACK_CANCEL;
42 }
43 } // namespace
44
45 bool SchemeSupport::HandleUri(
46     const char* uri,
47     ViewModule::SchemeActionMap::NavigationContext context)
48 {
49     return ViewModule::SchemeActionMap::HandleUri(uri,
50                                                   context,
51                                                   m_type);
52 }
53
54 bool SchemeSupport::HandleTizenScheme(const char* uri,
55                                       Evas_Object* window,
56                                       Evas_Object* wkView)
57 {
58     LogDebug("HandleTizenScheme called");
59     if (!uri) {
60         LogError("Empty uri");
61         return false;
62     }
63     if (!window) {
64         LogError("Empty window data");
65         return false;
66     }
67
68     if (strncmp(uri, TIZEN_EXIT, strlen(TIZEN_EXIT)) == 0) {
69         LogDebug("Tizen scheme: " << uri << " exit");
70         ecore_idler_add(exitAppIdlerCallback, NULL);
71         return true;
72     } else if (strncmp(uri, TIZEN_HIDE, strlen(TIZEN_HIDE)) == 0) {
73         LogDebug("Tizen scheme: " << uri << " hide");
74         elm_win_lower(window);
75         return true;
76     } else if (strncmp(uri,
77                        TIZEN_CHANGE_USERAGNET,
78                        strlen(TIZEN_CHANGE_USERAGNET)) == 0)
79     {
80         LogDebug("Tizen scheme: " << uri << " change UA");
81         const char* userAgentString = strstr(uri, "=");
82         if (NULL == userAgentString) {
83             LogDebug("UA string is NULL");
84         } else {
85             userAgentString++;
86             LogDebug("Setting custom user agent as: " << userAgentString);
87             ewk_view_user_agent_set(wkView, userAgentString);
88         }
89         return true;
90     }
91     return false;
92 }
93
94 bool SchemeSupport::filterURIByScheme(Ewk_Policy_Decision* policyDecision,
95                                       bool newWindow,
96                                       WidgetModel* model,
97                                       Evas_Object* window,
98                                       Evas_Object* wkView)
99 {
100     LogDebug("filterURIByScheme called");
101     Assert(policyDecision);
102     Assert(model);
103
104     const char* url = ewk_policy_decision_url_get(policyDecision);
105     if (NULL == url) {
106         // URI is null
107         // There is no reason, security by scheme block null uri
108         return true;
109     }
110
111     bool mainFrame =
112         ewk_frame_is_main_frame(ewk_policy_decision_frame_get(policyDecision));
113
114     using namespace ViewModule::SchemeActionMap;
115     if (HandleTizenScheme(url, window, wkView)) {
116         LogDebug("Scheme is tizen scheme");
117         return false;
118     }
119
120     NavigationContext ctx;
121     ctx = (mainFrame ? TOP_LEVEL : FRAME_LEVEL);
122     if (newWindow) {
123         if (model->Type.Get().appType ==
124             WrtDB::APP_TYPE_TIZENWEBAPP)
125         {
126             // In case of Tizen,
127             // policy of new window should be applied,
128             // regardless level of this frame
129             ctx = NEW_WINDOW;
130         }
131     }
132
133     return HandleUri(url, ctx);
134 }
135