2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * @file view_logic_scheme_support.cpp
18 * @author Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
22 #include "view_logic_scheme_support.h"
24 #include <appcore-common.h>
25 #include <dpl/log/log.h>
26 #include <widget_model.h>
27 #include <common/scheme_action_map.h>
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_ORIENTATION_LANDSCAPE =
35 "tizen://orientation.landscape";
36 char const * const TIZEN_ORIENTATION_PORTAIT = "tizen://orientation.portrait";
37 char const * const TIZEN_ORIENTATION_RESET = "tizen://orientation.reset";
38 char const * const TIZEN_CHANGE_USERAGNET = "tizen://changeUA";
40 const int ORIENTATION_LANDSCAPE_ANGLE = 270;
41 const int ORIENTATION_PORTAIT_ANGLE = 0;
43 const int W3C_SCREEN_ORI_PORTRAIT_PRIMARY = 0;
44 const int W3C_SCREEN_ORI_LANDSCAPE_PRIMARY = 90;
46 static Eina_Bool exitAppIdlerCallback(void* /*data*/)
51 return ECORE_CALLBACK_CANCEL;
55 bool SchemeSupport::HandleUri(
57 ViewModule::SchemeActionMap::NavigationContext context)
59 return ViewModule::SchemeActionMap::HandleUri(uri,
64 bool SchemeSupport::HandleTizenScheme(const char* uri,
68 LogInfo("HandleTizenScheme called");
70 LogError("Empty uri");
74 LogError("Empty window data");
78 if (strncmp(uri, TIZEN_EXIT, strlen(TIZEN_EXIT)) == 0) {
79 LogInfo("Tizen scheme: " << uri << " exit");
80 ecore_idler_add(exitAppIdlerCallback, NULL);
82 } else if (strncmp(uri, TIZEN_HIDE, strlen(TIZEN_HIDE)) == 0) {
83 LogInfo("Tizen scheme: " << uri << " hide");
84 elm_win_lower(window);
86 } else if (strncmp(uri,
87 TIZEN_ORIENTATION_LANDSCAPE,
88 strlen(TIZEN_ORIENTATION_LANDSCAPE)) == 0)
90 LogInfo("Tizen scheme: " << uri << " orientation landscape");
91 elm_win_rotation_with_resize_set(window, ORIENTATION_LANDSCAPE_ANGLE);
92 ewk_view_orientation_send(wkView, W3C_SCREEN_ORI_LANDSCAPE_PRIMARY);
94 } else if (strncmp(uri,
95 TIZEN_ORIENTATION_PORTAIT,
96 strlen(TIZEN_ORIENTATION_PORTAIT)) == 0)
98 LogInfo("Tizen scheme: " << uri << " orientation portait");
99 elm_win_rotation_with_resize_set(window, ORIENTATION_PORTAIT_ANGLE);
100 ewk_view_orientation_send(wkView, W3C_SCREEN_ORI_PORTRAIT_PRIMARY);
102 } else if (strncmp(uri,
103 TIZEN_ORIENTATION_RESET,
104 strlen(TIZEN_ORIENTATION_RESET)) == 0)
106 LogInfo("Tizen scheme: " << uri << " reset");
107 elm_win_rotation_with_resize_set(window, ORIENTATION_PORTAIT_ANGLE);
108 ewk_view_orientation_send(wkView, W3C_SCREEN_ORI_PORTRAIT_PRIMARY);
110 } else if (strncmp(uri,
111 TIZEN_CHANGE_USERAGNET,
112 strlen(TIZEN_CHANGE_USERAGNET)) == 0)
114 LogInfo("Tizen scheme: " << uri << " change UA");
115 const char* userAgentString = strstr(uri, "=");
116 if (NULL == userAgentString) {
117 LogDebug("UA string is NULL");
120 LogDebug("Setting custom user agent as: " << userAgentString);
121 ewk_view_user_agent_set(wkView, userAgentString);
128 bool SchemeSupport::filterURIByScheme(Ewk_Policy_Decision* policyDecision,
134 LogDebug("filterURIByScheme called");
135 Assert(policyDecision);
138 const char* url = ewk_policy_decision_url_get(policyDecision);
141 // There is no reason, security by scheme block null uri
146 ewk_frame_is_main_frame(ewk_policy_decision_frame_get(policyDecision));
148 using namespace ViewModule::SchemeActionMap;
149 if (HandleTizenScheme(url, window, wkView)) {
150 LogDebug("Scheme is tizen scheme");
154 NavigationContext ctx;
155 ctx = (mainFrame ? TOP_LEVEL : FRAME_LEVEL);
157 if (model->Type.Get().appType ==
158 WrtDB::APP_TYPE_TIZENWEBAPP)
161 // policy of new window should be applied,
162 // regardless level of this frame
164 } else if (model->Type.Get().appType ==
165 WrtDB::APP_TYPE_WAC20)
168 // policy of new window should be applied,
169 // only top level frame (this may be changed by WAC spec)
170 if (ctx == TOP_LEVEL) {
176 return HandleUri(url, ctx);