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 static Eina_Bool exitAppIdlerCallback(void* /*data*/)
48 return ECORE_CALLBACK_CANCEL;}
52 bool SchemeSupport::HandleUri(
54 ViewModule::SchemeActionMap::NavigationContext context)
56 return ViewModule::SchemeActionMap::HandleUri(uri,
61 bool SchemeSupport::HandleTizenScheme(const char* uri,
65 LogInfo("HandleTizenScheme called");
67 LogError("Empty uri");
71 LogError("Empty window data");
75 if (strncmp(uri, TIZEN_EXIT, strlen(TIZEN_EXIT)) == 0) {
76 LogInfo("Tizen scheme: " << uri << " exit");
77 ecore_idler_add(exitAppIdlerCallback, NULL);
79 } else if (strncmp(uri, TIZEN_HIDE, strlen(TIZEN_HIDE)) == 0) {
80 LogInfo("Tizen scheme: " << uri << " hide");
81 elm_win_lower(window);
83 } else if (strncmp(uri,
84 TIZEN_ORIENTATION_LANDSCAPE,
85 strlen(TIZEN_ORIENTATION_LANDSCAPE)) == 0)
87 LogInfo("Tizen scheme: " << uri << " orientation landscape");
88 elm_win_rotation_with_resize_set(window, ORIENTATION_LANDSCAPE_ANGLE);
90 } else if (strncmp(uri,
91 TIZEN_ORIENTATION_PORTAIT,
92 strlen(TIZEN_ORIENTATION_PORTAIT)) == 0)
94 LogInfo("Tizen scheme: " << uri << " orientation portait");
95 elm_win_rotation_with_resize_set(window, ORIENTATION_PORTAIT_ANGLE);
97 } else if (strncmp(uri,
98 TIZEN_ORIENTATION_RESET,
99 strlen(TIZEN_ORIENTATION_RESET)) == 0)
101 LogInfo("Tizen scheme: " << uri << " reset");
102 elm_win_rotation_with_resize_set(window, ORIENTATION_PORTAIT_ANGLE);
104 } else if (strncmp(uri,
105 TIZEN_CHANGE_USERAGNET,
106 strlen(TIZEN_CHANGE_USERAGNET)) == 0)
108 LogInfo("Tizen scheme: " << uri << " change UA");
109 const char* userAgentString = strstr(uri, "=");
110 if (NULL == userAgentString) {
111 LogDebug("UA string is NULL");
114 LogDebug("Setting custom user agent as: " << userAgentString);
115 ewk_view_user_agent_set(wkView, userAgentString);
122 bool SchemeSupport::filterURIByScheme(Ewk_Policy_Decision* policyDecision,
128 LogDebug("filterURIByScheme called");
129 Assert(policyDecision);
132 const char* url = ewk_policy_decision_url_get(policyDecision);
135 // There is no reason, security by scheme block null uri
140 ewk_frame_is_main_frame(ewk_policy_decision_frame_get(policyDecision));
142 using namespace ViewModule::SchemeActionMap;
143 if (HandleTizenScheme(url, window, wkView))
145 LogDebug("Scheme is tizen scheme");
149 NavigationContext ctx;
150 ctx = (mainFrame ? TOP_LEVEL : FRAME_LEVEL);
152 if (model->Type.Get().appType ==
153 WrtDB::APP_TYPE_TIZENWEBAPP)
156 // policy of new window should be applied,
157 // regardless level of this frame
159 } else if (model->Type.Get().appType ==
160 WrtDB::APP_TYPE_WAC20)
163 // policy of new window should be applied,
164 // only top level frame (this may be changed by WAC spec)
165 if (ctx == TOP_LEVEL) {
171 return HandleUri(url, ctx);