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>
27 #include <widget_model.h>
29 #include <common/scheme_action_map.h>
34 #include "view_logic_utils.h"
37 char const * const TIZEN_SCHEME = "tizen";
38 char const * const TIZEN_EXIT = "tizen://exit";
39 char const * const TIZEN_HIDE = "tizen://hide";
40 char const * const TIZEN_ORIENTATION_LANDSCAPE =
41 "tizen://orientation.landscape";
42 char const * const TIZEN_ORIENTATION_PORTAIT = "tizen://orientation.portrait";
43 char const * const TIZEN_ORIENTATION_RESET = "tizen://orientation.reset";
44 char const * const TIZEN_CHANGE_USERAGNET = "tizen://changeUA";
46 const int ORIENTATION_LANDSCAPE_ANGLE = 270;
47 const int ORIENTATION_PORTAIT_ANGLE = 0;
49 static Eina_Bool exitAppIdlerCallback(void* /*data*/)
53 return ECORE_CALLBACK_CANCEL;
58 bool SchemeSupport::HandleUri(
60 ViewModule::SchemeActionMap::NavigationContext context)
62 return ViewModule::SchemeActionMap::HandleUri(uri,
67 bool SchemeSupport::HandleTizenScheme(const char* uri,
71 LogInfo("HandleTizenScheme called");
73 LogError("Empty uri");
77 LogError("Empty window data");
81 if (strncmp(uri, TIZEN_EXIT, strlen(TIZEN_EXIT)) == 0) {
82 LogInfo("Tizen scheme: " << uri << " exit");
83 ecore_idler_add(exitAppIdlerCallback, NULL);
85 } else if (strncmp(uri, TIZEN_HIDE, strlen(TIZEN_HIDE)) == 0) {
86 LogInfo("Tizen scheme: " << uri << " hide");
87 elm_win_lower(window);
89 } else if (strncmp(uri,
90 TIZEN_ORIENTATION_LANDSCAPE,
91 strlen(TIZEN_ORIENTATION_LANDSCAPE)) == 0)
93 LogInfo("Tizen scheme: " << uri << " orientation landscape");
94 elm_win_rotation_with_resize_set(window, ORIENTATION_LANDSCAPE_ANGLE);
96 } else if (strncmp(uri,
97 TIZEN_ORIENTATION_PORTAIT,
98 strlen(TIZEN_ORIENTATION_PORTAIT)) == 0)
100 LogInfo("Tizen scheme: " << uri << " orientation portait");
101 elm_win_rotation_with_resize_set(window, ORIENTATION_PORTAIT_ANGLE);
103 } else if (strncmp(uri,
104 TIZEN_ORIENTATION_RESET,
105 strlen(TIZEN_ORIENTATION_RESET)) == 0)
107 LogInfo("Tizen scheme: " << uri << " reset");
108 elm_win_rotation_with_resize_set(window, ORIENTATION_PORTAIT_ANGLE);
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, "=") + 1;
116 if (NULL == userAgentString) {
117 LogDebug("UA string is NULL");
119 LogDebug("Setting custom user agent as: " << userAgentString);
120 WKStringRef userAgentStringRef =
121 WKStringCreateWithUTF8CString(userAgentString);
122 WKPageSetCustomUserAgent(page, userAgentStringRef);
123 WKRelease(userAgentStringRef);
130 bool SchemeSupport::filterURIByScheme(WKPageRef page,
132 WKURLRequestRef request,
137 LogDebug("filterURIByScheme called");
139 DPL::OptionalString requestOptionalString =
140 ViewModule::Utils::toString(request);
141 if (requestOptionalString.IsNull()) {
143 // There is no reason, security by scheme block null uri
147 std::string url = DPL::ToUTF8String(*requestOptionalString);
148 bool mainFrame = WKFrameIsMainFrame(frame);
150 using namespace ViewModule::SchemeActionMap;
151 if (HandleTizenScheme(url.c_str(), window, page))
153 LogDebug("Scheme is tizen scheme");
157 NavigationContext ctx;
158 ctx = (mainFrame ? TOP_LEVEL : FRAME_LEVEL);
160 if (model->Type.Get().appType ==
161 WrtDB::APP_TYPE_TIZENWEBAPP)
164 // policy of new window should be applied,
165 // regardless level of this frame
167 } else if (model->Type.Get().appType ==
168 WrtDB::APP_TYPE_WAC20)
171 // policy of new window should be applied,
172 // only top level frame (this may be changed by WAC spec)
173 if (ctx == TOP_LEVEL) {
179 return HandleUri(url.c_str(), ctx);