1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
|
/*
* Copyright 2012 Samsung Electronics Co., Ltd
*
* Licensed under the Flora License, Version 1.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.tizenopensource.org/license
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
extern "C" {
#include <ITapiSat.h>
#include <TapiUtility.h>
}
#include <app.h>
#include "browser-config.h"
#include "browser-class.h"
struct browser_data {
Evas_Object *main_win;
Evas_Object *bg;
Evas_Object *main_layout;
Evas_Object *navi_bar;
Elm_Theme *browser_theme;
Browser_Class *browser_instance;
Eina_Bool is_paused;
};
static void __br_set_env(void)
{
#if !defined(TIZEN_PUBLIC)
/* manual enabling of CoreGL fastpath */
setenv("COREGL_FASTPATH", "1", 1);
#endif
/* set image cache suze */
if (setenv("ELM_IMAGE_CACHE", "0", 1))
BROWSER_LOGD("ELM_IMAGE_CACHE is set to 1MB");
/* This is because of showing navigation bar more quickly. */
if (setenv("ELM_BRING_IN_SCROLL_FRICTION", "0.2", 1))
BROWSER_LOGD("ELM_BRING_IN_SCROLL_FRICTION is set");
if (setenv("ELM_PAGE_SCROLL_FRICTION", "0.4", 1))
BROWSER_LOGD("ELM_PAGE_SCROLL_FRICTION is set");
if (setenv("ELM_THUMBSCROLL_BOUNCE_FRICTION", "0.2", 1))
BROWSER_LOGD("ELM_THUMBSCROLL_BOUNCE_FRICTION is set");
}
static void __br_destroy(void *data)
{
BROWSER_LOGD("[%s]", __func__);
elm_exit();
}
static void __main_win_del_cb(void *data, Evas_Object *obj, void *event)
{
BROWSER_LOGD("[Browser-Launching time measure]<< window delete callback >>");
}
static bool __init_preference()
{
BROWSER_LOGD("[%s]", __func__);
if (!br_preference_create_bool(SHOW_MY_SITES_GUIDE, true))
return false;
if (!br_preference_create_str(LAST_VISITED_URL_KEY, ""))
return false;
#if defined(FEATURE_MOST_VISITED_SITES)
if (!br_preference_create_str(HOMEPAGE_KEY, MOST_VISITED_SITES))
return false;
#else
if (!br_preference_create_str(HOMEPAGE_KEY, USER_HOMEPAGE))
return false;
#endif
if (!br_preference_create_str(USER_HOMEPAGE_KEY, BROWSER_DEFAULT_USER_HOMEPAGE))
return false;
if (!br_preference_create_str(SEARCHURL_KEY, "http://search.yahoo.com/search?p="))
return false;
if (!br_preference_create_str(DEFAULT_VIEW_LEVEL_KEY, READABLE))
return false;
if (!br_preference_create_bool(RUN_JAVASCRIPT_KEY, true))
return false;
if (!br_preference_create_bool(DISPLAY_IMAGES_KEY, true))
return false;
if (!br_preference_create_bool(BLOCK_POPUP_KEY, true))
return false;
if (!br_preference_create_bool(SHOW_SECURITY_WARNINGS_KEY, true))
return false;
if (!br_preference_create_bool(ACCEPT_COOKIES_KEY, true))
return false;
if (!br_preference_create_bool(ENABLE_LOCATION_KEY, true))
return false;
#ifdef ZOOM_BUTTON
if (!br_preference_create_bool(ZOOM_BUTTON_KEY, true))
return false;
#endif
return true;
}
static Evas_Object *__create_main_win(void *app_data)
{
Evas_Object *window = elm_win_add(NULL, BROWSER_PACKAGE_NAME, ELM_WIN_BASIC);
if (window) {
int w;
int h;
elm_win_title_set(window, BROWSER_PACKAGE_NAME);
elm_win_borderless_set(window, EINA_TRUE);
elm_win_conformant_set(window, EINA_TRUE);
evas_object_smart_callback_add(window, "delete,request",
__main_win_del_cb, app_data);
ecore_x_window_size_get(ecore_x_window_root_first_get(),
&w, &h);
evas_object_resize(window, w, h);
elm_win_indicator_mode_set(window, ELM_WIN_INDICATOR_SHOW);
evas_object_show(window);
}
return window;
}
static Evas_Object *__create_bg(Evas_Object *win)
{
Evas_Object *bg;
bg = elm_bg_add(win);
if (!bg)
return NULL;
evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
elm_win_resize_object_add(win, bg);
evas_object_show(bg);
return bg;
}
static Evas_Object *__create_main_layout(Evas_Object *win)
{
Evas_Object *layout;
layout = elm_layout_add(win);
if (!layout)
return NULL;
if (!elm_layout_theme_set(layout, "layout", "application", "default"))
BROWSER_LOGE("elm_layout_theme_set is failed.\n");
evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
elm_win_resize_object_add(win, layout);
edje_object_signal_emit(elm_layout_edje_get(layout), "elm,state,show,indicator", "elm");
evas_object_show(layout);
return layout;
}
static Evas_Object *__create_navi_bar(void *app_data)
{
BROWSER_LOGD("[%s]", __func__);
Evas_Object *navi_bar;
struct browser_data *ad = (struct browser_data *)app_data;
navi_bar = elm_naviframe_add(ad->main_layout);
if (navi_bar) {
elm_object_theme_set(navi_bar, ad->browser_theme);
elm_object_style_set(navi_bar, "browser");
elm_object_part_content_set(ad->main_layout, "elm.swallow.content", navi_bar);
evas_object_show(navi_bar);
}
return navi_bar;
}
static Eina_Bool __process_app_service(service_h service, void *app_data)
{
BROWSER_LOGD("[%s]", __func__);
struct browser_data *ad = (struct browser_data *)app_data;
char *operation = NULL;
char *request_uri = NULL;
char *request_mime_type = NULL;
if (service_get_operation(service, &operation) != SERVICE_ERROR_NONE) {
BROWSER_LOGD("get service operation failed");
return EINA_FALSE;
}
if (service_get_uri(service, &request_uri) != SERVICE_ERROR_NONE) {
BROWSER_LOGD("get service uri failed");
}
if (service_get_mime(service, &request_mime_type) != SERVICE_ERROR_NONE) {
BROWSER_LOGD("get service mime failed");
}
if (!operation && !request_uri && !request_mime_type) {
BROWSER_LOGD("Not app svc");
return EINA_FALSE;
}
BROWSER_LOGD("operation[%s], request_uri[%s], request_mime_type[%s]", operation, request_uri, request_mime_type);
std::string full_path;
if (request_mime_type) {
if (!strncmp(request_mime_type, "application/x-shockwave-flash", strlen("application/x-shockwave-flash"))
|| !strncmp(request_mime_type, "image/svg+xml", strlen("image/svg+xml"))
|| !strncmp(request_mime_type, "text/html", strlen("text/html"))
|| !strncmp(request_mime_type, "application/xml", strlen("application/xml"))) {
if (request_uri)
full_path = std::string(request_uri);
} else {
BROWSER_LOGD("Not allowed mime type : [%s]", request_mime_type);
return EINA_FALSE;
}
} else if (request_uri) {
full_path = std::string(request_uri);
}
BROWSER_LOGD("url=[%s]", full_path.c_str());
if (ad->main_win)
elm_win_activate(ad->main_win);
ad->browser_instance->launch(full_path.c_str(), EINA_TRUE);
return EINA_TRUE;
}
static void __br_load_url(service_h service, void *app_data)
{
BROWSER_LOGD("[%s]", __func__);
struct browser_data *ad = (struct browser_data *)app_data;
if (__process_app_service(service, app_data)) {
BROWSER_LOGD("app service");
return;
}
std::string full_path;
char *mime_type = NULL;
char *search_keyword = NULL;
char *goto_url = NULL;
char *url = NULL;
if (service_get_uri(service, &url) != SERVICE_ERROR_NONE) {
BROWSER_LOGD("get service uri failed");
}
if (service_get_mime(service, &mime_type) != SERVICE_ERROR_NONE) {
BROWSER_LOGD("get service mime failed");
}
if (service_get_extra_data(service, "search_keyword", &search_keyword) != SERVICE_ERROR_NONE) {
BROWSER_LOGD("get service extra data(search keyword) failed");
}
if (service_get_extra_data(service, "goto_url", &search_keyword) != SERVICE_ERROR_NONE) {
BROWSER_LOGD("get service extra data(search keyword) failed");
}
if (mime_type && url) {
BROWSER_LOGD("mime type=[%s], url=[%s]", mime_type, url);
if (!strcmp(mime_type, "application/x-shockwave-flash")
|| !strcmp(mime_type, "image/svg+xml")
|| !strcmp(mime_type, "text/html")
|| !strcmp(mime_type, "application/xml")) {
full_path = std::string(url);
}
} else if (search_keyword) {
BROWSER_LOGD("search_keyword=[%s]", search_keyword);
if (search_keyword) {
char *search_url = NULL;
if (br_preference_get_str(SEARCHURL_KEY, &search_url) == false) {
BROWSER_LOGE("failed to get %s preference\n", SEARCHURL_KEY);
return;
}
if (search_url) {
full_path = std::string(search_url) + std::string(search_keyword);
free(search_url);
}
}
} else if (goto_url || url) {
BROWSER_LOGD("goto_url=[%s], url=[%s]", goto_url, url);
if (goto_url)
full_path = goto_url;
else
full_path = url;
}
BROWSER_LOGD("url=[%s]", full_path.c_str());
if (ad->main_win)
elm_win_activate(ad->main_win);
ad->browser_instance->launch(full_path.c_str(), EINA_TRUE);
}
static Eina_Bool __br_keydown_event(void *data, int type, void *event)
{
BROWSER_LOGD("[%s]", __func__);
Ecore_Event_Key *ev = (Ecore_Event_Key *)event;
if (!strcmp(ev->keyname, KEY_END)) {
__br_destroy(data);
}
return EXIT_FAILURE;
}
#if defined(HORIZONTAL_UI)
static void __br_rotate_cb(app_device_orientation_e mode, void *data)
{
BROWSER_LOGD("[%s] rotation mode = %d", __func__, mode);
struct browser_data *ad = (struct browser_data *)data;
int rotation_value;
switch (mode) {
case APP_DEVICE_ORIENTATION_0:
rotation_value = 0;
ug_send_event(UG_EVENT_ROTATE_PORTRAIT);
break;
case APP_DEVICE_ORIENTATION_90:
rotation_value = 90;
ug_send_event(UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN);
break;
case APP_DEVICE_ORIENTATION_180:
rotation_value = 180;
ug_send_event(UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN);
break;
case APP_DEVICE_ORIENTATION_270:
rotation_value = 270;
ug_send_event(UG_EVENT_ROTATE_LANDSCAPE);
break;
default:
rotation_value = -1;
break;
}
if (rotation_value >= 0 && ad->browser_instance) {
if (ad->browser_instance->is_available_to_rotate()) {
elm_win_rotation_with_resize_set(ad->main_win, rotation_value);
ad->browser_instance->rotate(rotation_value);
}
}
}
#endif
static void __br_low_memory_cb(void* data)
{
BROWSER_LOGD("[%s]", __func__);
/* To do */
struct browser_data *ad = (struct browser_data *)data;
if (ad && ad->browser_instance)
ad->browser_instance->clean_up_windows();
}
static void __br_low_battery_cb(void* data)
{
BROWSER_LOGD("[%s]", __func__);
/* To do */
return;
}
static void __br_lang_changed_cb(void *data)
{
BROWSER_LOGD("[%s]", __func__);
/* To do */
return;
}
static void __br_region_changed_cb(void *data)
{
BROWSER_LOGD("[%s]", __func__);
/* To do */
return;
}
static void __br_register_system_event(void *app_data)
{
/* To do */
struct browser_data *ad = (struct browser_data *)app_data;
}
static int __browser_set_i18n(const char *domain, const char *dir)
{
char *r = NULL;
if (domain == NULL) {
BROWSER_LOGE("domain is NULL");
return -1;
}
r = setlocale(LC_ALL, "");
/* if locale is not set properly, try again to set as language base */
if (r == NULL) {
char *lang_set = vconf_get_str(VCONFKEY_LANGSET);
if (!lang_set && strlen(lang_set) > 0)
r = setlocale(LC_ALL, lang_set);
BROWSER_LOGE("setlocale as [%s]", r);
if (lang_set)
free(lang_set);
}
if (r == NULL) {
BROWSER_LOGE("setlocale failed");
return -1;
}
r = bindtextdomain(domain, dir);
if (r == NULL) {
BROWSER_LOGE("bindtextdomain failed");
return -1;
}
r = textdomain(domain);
if (r == NULL) {
BROWSER_LOGE("textdomain failed");
return -1;
}
return 0;
}
static bool __br_app_create(void *app_data)
{
BROWSER_LOGD("[Browser-Launching time measure] << theme extenstion >>");
struct browser_data *ad = (struct browser_data *)app_data;
elm_config_preferred_engine_set("opengl_x11");
if(!__init_preference())
return false;
ad->browser_theme = elm_theme_new();
elm_theme_ref_set(ad->browser_theme, NULL);
elm_theme_extension_add(ad->browser_theme, BROWSER_NAVIFRAME_THEME);
elm_theme_extension_add(ad->browser_theme, BROWSER_CONTROLBAR_THEME);
elm_theme_extension_add(ad->browser_theme, BROWSER_BUTTON_THEME);
elm_theme_extension_add(ad->browser_theme, BROWSER_PROGRESSBAR_THEME);
elm_theme_extension_add(ad->browser_theme, BROWSER_URL_LAYOUT_THEME);
elm_theme_extension_add(ad->browser_theme, BROWSER_PREDICTIVE_HISTORY_THEME);
elm_theme_extension_add(ad->browser_theme, BROWSER_SETTINGS_THEME);
elm_theme_extension_add(ad->browser_theme, BROWSER_BOOKMARK_THEME);
elm_theme_extension_add(ad->browser_theme, BROWSER_FIND_WORD_LAYOUT_THEME);
BROWSER_LOGD("[Browser-Launching time measure] << create main window >>");
ad->main_win = __create_main_win(ad);
if (!ad->main_win) {
BROWSER_LOGE("fail to create window");
return false;
}
BROWSER_LOGD("[Browser-Launching time measure] << create background >>");
ad->bg = __create_bg(ad->main_win);
if (!ad->bg) {
BROWSER_LOGE("fail to create bg");
return false;
}
BROWSER_LOGD("[Browser-Launching time measure] << create layout main >>");
ad->main_layout = __create_main_layout(ad->main_win);
if (!ad->main_layout) {
BROWSER_LOGE("fail to create main layout");
return false;
}
ad->navi_bar = __create_navi_bar(ad);
if (!ad->navi_bar) {
BROWSER_LOGE("fail to create navi bar");
return false;
}
/* create browser instance & init */
ad->browser_instance = new(nothrow) Browser_Class(ad->main_win, ad->navi_bar, ad->bg);
if (!ad->browser_instance) {
BROWSER_LOGE("fail to Browser_Class");
return false;
}
if (ad->browser_instance->init() == EINA_FALSE) {
BROWSER_LOGE("fail to browser init");
return false;
}
/* init internationalization */
int ret = __browser_set_i18n(BROWSER_PACKAGE_NAME, BROWSER_LOCALE_DIR);
if (ret) {
BROWSER_LOGE("fail to __browser_set_i18n");
return false;
}
#if defined(HORIZONTAL_UI)
app_device_orientation_e rotation_value = app_get_device_orientation();
if (rotation_value != APP_DEVICE_ORIENTATION_0) {
elm_win_rotation_with_resize_set(ad->main_win, rotation_value);
ad->browser_instance->rotate(rotation_value);
}
#endif
return true;
}
/* GCF test requirement */
static void __send_termination_event_to_tapi(void)
{
BROWSER_LOGD("[%s]", __func__);
int ret = TAPI_API_SUCCESS;
int request_id = -1;
TelSatEventDownloadReqInfo_t event_data;
event_data.eventDownloadType = TAPI_EVENT_SAT_DW_TYPE_BROWSER_TERMINATION;
event_data.u.browserTerminationEventReqInfo.browserTerminationCause = TAPI_SAT_BROWSER_TERMINATED_BY_USER;
TapiHandle *handle = NULL;
handle = tel_init(NULL);
ret = tel_download_sat_event(handle, &event_data, NULL, NULL);
if(ret != TAPI_API_SUCCESS && ret != TAPI_API_SAT_EVENT_NOT_REQUIRED_BY_USIM)
BROWSER_LOGE("failed to tel_download_sat_event");
tel_deinit(handle);
}
static void __br_app_terminate(void *app_data)
{
BROWSER_LOGD("[%s]", __func__);
struct browser_data *ad = (struct browser_data *)app_data;
elm_theme_extension_del(ad->browser_theme, BROWSER_NAVIFRAME_THEME);
elm_theme_extension_del(ad->browser_theme, BROWSER_CONTROLBAR_THEME);
elm_theme_extension_del(ad->browser_theme, BROWSER_BUTTON_THEME);
elm_theme_extension_del(ad->browser_theme, BROWSER_URL_LAYOUT_THEME);
elm_theme_extension_del(ad->browser_theme, BROWSER_PROGRESSBAR_THEME);
elm_theme_extension_del(ad->browser_theme, BROWSER_PREDICTIVE_HISTORY_THEME);
elm_theme_extension_del(ad->browser_theme, BROWSER_SETTINGS_THEME);
elm_theme_extension_del(ad->browser_theme, BROWSER_BOOKMARK_THEME);
elm_theme_extension_del(ad->browser_theme, BROWSER_FIND_WORD_LAYOUT_THEME);
elm_theme_free(ad->browser_theme);
/* GCF test requirement */
__send_termination_event_to_tapi();
if (ad->main_win);
evas_object_del(ad->main_win);
if (ad->browser_instance)
delete ad->browser_instance;
BROWSER_LOGD("[Browser-Launching time measure] << __br_app_terminate ends >>");
}
static void __br_app_pause(void *app_data)
{
BROWSER_LOGD("[%s]", __func__);
struct browser_data *ad = (struct browser_data *)app_data;
if (!ad || !ad->browser_instance)
return;
ad->browser_instance->pause();
ad->is_paused = EINA_TRUE;
}
static void __br_app_resume(void *app_data)
{
BROWSER_LOGD("[%s]", __func__);
struct browser_data *ad = (struct browser_data *)app_data;
if (!ad || !ad->browser_instance)
return;
ad->browser_instance->resume();
ad->is_paused = EINA_FALSE;
}
static void __br_app_reset(service_h service, void *app_data)
{
struct browser_data *ad = (struct browser_data *)app_data;
BROWSER_LOGD("[%s]", __func__);
ad->browser_instance->reset();
__br_load_url(service, app_data);
ad->is_paused = EINA_FALSE;
}
int main(int argc, char *argv[])
{
__br_set_env();
app_event_callback_s ops;
memset(&ops, 0x0, sizeof(app_event_callback_s));
ops.create = __br_app_create;
ops.terminate = __br_app_terminate;
ops.pause = __br_app_pause;
ops.resume = __br_app_resume;
ops.service = __br_app_reset;
ops.low_memory = __br_low_memory_cb;
ops.low_battery = __br_low_battery_cb;
#if defined(HORIZONTAL_UI)
ops.device_orientation = __br_rotate_cb;
#endif
ops.language_changed = __br_lang_changed_cb;
ops.region_format_changed = __br_region_changed_cb;
struct browser_data ad;
memset(&ad, 0x0, sizeof(struct browser_data));
int ret = app_efl_main(&argc, &argv, &ops, &ad);
return ret;
}
|