Elementary Web: add functions to set / get useragent
Patch by Steven Falken <btwotch@googlemail.com> with a few changes. SVN revision: 66938
This commit is contained in:
parent
04a6f780fb
commit
7677abd03a
|
@ -156,7 +156,8 @@ void test_video(void *data, Evas_Object *obj, void *event_info);
|
|||
void test_eio(void *data, Evas_Object *obj, void *event_info);
|
||||
#endif
|
||||
#ifdef HAVE_ELEMENTARY_WEB
|
||||
void test_web(void *data, Evas_Object *obj, void *event_info);
|
||||
void test_web_normal(void *data, Evas_Object *obj, void *event_info);
|
||||
void test_web_mobile(void *data, Evas_Object *obj, void *event_info);
|
||||
#endif
|
||||
|
||||
struct elm_test
|
||||
|
@ -412,7 +413,8 @@ add_tests:
|
|||
|
||||
//------------------------------//
|
||||
#ifdef HAVE_ELEMENTARY_WEB
|
||||
ADD_TEST(NULL, "Web", "Web", test_web);
|
||||
ADD_TEST(NULL, "Web", "Web", test_web_normal);
|
||||
ADD_TEST(NULL, "Web", "Web-mobile", test_web_mobile);
|
||||
#endif
|
||||
|
||||
//------------------------------//
|
||||
|
|
|
@ -11,6 +11,7 @@ typedef struct
|
|||
Evas_Object *btn_fwd;
|
||||
Evas_Object *url_entry;
|
||||
Eina_List *sub_wins;
|
||||
const char* user_agent;
|
||||
Eina_Bool js_hooks : 1;
|
||||
} Web_Test;
|
||||
|
||||
|
@ -102,6 +103,7 @@ _new_window_hook(void *data, Evas_Object *obj __UNUSED__, Eina_Bool js __UNUSED_
|
|||
evas_object_show(bg);
|
||||
|
||||
new_web = elm_web_add(new_win);
|
||||
elm_web_useragent_set(new_web, wt->user_agent);
|
||||
evas_object_size_hint_weight_set(new_web, EVAS_HINT_EXPAND,
|
||||
EVAS_HINT_EXPAND);
|
||||
elm_win_resize_object_add(new_win, new_web);
|
||||
|
@ -332,8 +334,10 @@ _main_web_del_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, vo
|
|||
}
|
||||
|
||||
void
|
||||
test_web(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
|
||||
test_web(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__, Eina_Bool mobile)
|
||||
{
|
||||
const char user_agent_firefox[] = "Mozilla/5.0 (X11; Linux x86_64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1";
|
||||
const char user_agent_mobile[] = "Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3";
|
||||
Evas_Object *win, *bg, *bx, *bx2, *bt, *web, *url;
|
||||
Web_Test *wt;
|
||||
|
||||
|
@ -342,7 +346,18 @@ test_web(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __
|
|||
wt = calloc(1, sizeof(*wt));
|
||||
|
||||
win = elm_win_add(NULL, "web", ELM_WIN_BASIC);
|
||||
elm_win_title_set(win, "Web");
|
||||
|
||||
if (mobile == EINA_TRUE)
|
||||
{
|
||||
wt->user_agent = user_agent_mobile;
|
||||
elm_win_title_set(win, "Web-mobile");
|
||||
}
|
||||
else
|
||||
{
|
||||
wt->user_agent = user_agent_firefox;
|
||||
elm_win_title_set(win, "Web");
|
||||
}
|
||||
|
||||
elm_win_autodel_set(win, EINA_TRUE);
|
||||
|
||||
bg = elm_bg_add(win);
|
||||
|
@ -363,6 +378,8 @@ test_web(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __
|
|||
evas_object_show(bx2);
|
||||
|
||||
web = elm_web_add(win);
|
||||
elm_web_useragent_set(web, wt->user_agent);
|
||||
printf("elm_web useragent: %s\n", elm_web_useragent_get(web));
|
||||
evas_object_size_hint_weight_set(web, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
||||
evas_object_size_hint_align_set(web, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
||||
elm_box_pack_end(bx, web);
|
||||
|
@ -481,4 +498,16 @@ test_web(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __
|
|||
evas_object_resize(win, 320, 480);
|
||||
evas_object_show(win);
|
||||
}
|
||||
|
||||
void
|
||||
test_web_normal(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
|
||||
{
|
||||
test_web(data, obj, event_info, EINA_FALSE);
|
||||
}
|
||||
|
||||
void
|
||||
test_web_mobile(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
|
||||
{
|
||||
test_web(data, obj, event_info, EINA_TRUE);
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1203,6 +1203,32 @@ elm_web_console_message_hook_set(Evas_Object *obj, Elm_Web_Console_Message func,
|
|||
#endif
|
||||
}
|
||||
|
||||
EAPI void
|
||||
elm_web_useragent_set(Evas_Object *obj, const char *user_agent)
|
||||
{
|
||||
ELM_CHECK_WIDTYPE(obj, widtype);
|
||||
#ifdef HAVE_ELEMENTARY_WEB
|
||||
Widget_Data *wd = elm_widget_data_get(obj);
|
||||
if (!wd) return;
|
||||
ewk_view_setting_user_agent_set(wd->ewk_view, user_agent);
|
||||
#else
|
||||
(void)user_agent;
|
||||
#endif
|
||||
}
|
||||
|
||||
EAPI const char*
|
||||
elm_web_useragent_get(const Evas_Object *obj)
|
||||
{
|
||||
ELM_CHECK_WIDTYPE(obj, widtype) NULL;
|
||||
#ifdef HAVE_ELEMENTARY_WEB
|
||||
Widget_Data *wd = elm_widget_data_get(obj);
|
||||
if (!wd) return NULL;
|
||||
return ewk_view_setting_user_agent_get(wd->ewk_view);
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
EAPI Eina_Bool
|
||||
elm_web_tab_propagate_get(const Evas_Object *obj)
|
||||
{
|
||||
|
|
|
@ -350,6 +350,24 @@ typedef void (*Elm_Web_Console_Message)(void *data, Evas_Object *obj, const char
|
|||
*/
|
||||
EAPI Evas_Object *elm_web_add(Evas_Object *parent);
|
||||
|
||||
/**
|
||||
* Change useragent of a elm_web object
|
||||
*
|
||||
* @param obj The object
|
||||
* @param useragent String for useragent
|
||||
*
|
||||
*/
|
||||
EAPI void elm_web_useragent_set(Evas_Object *obj, const char *user_agent);
|
||||
|
||||
/**
|
||||
* Return current useragent of elm_web object
|
||||
*
|
||||
* @param obj The object
|
||||
* @return Useragent string
|
||||
*
|
||||
*/
|
||||
EAPI const char* elm_web_useragent_get(const Evas_Object *obj);
|
||||
|
||||
/**
|
||||
* Get internal ewk_view object from web object.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue