Changeset 99200 in webkit
- Timestamp:
- Nov 3, 2011 9:10:42 AM (12 years ago)
- Location:
- trunk/Tools
- Files:
-
- 1 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Tools/ChangeLog
r99193 r99200 1 2011-11-03 Carlos Garcia Campos <cgarcia@igalia.com> 2 3 [GTK] Remove WebKit2 C API from MiniBrowser 4 https://bugs.webkit.org/show_bug.cgi?id=71459 5 6 Reviewed by Martin Robinson. 7 8 Use the GTK+ API instead to add minimum functionality. The other 9 features will be ported to GTK+ API in following patches. 10 11 * MiniBrowser/gtk/BrowserWindow.c: 12 (activateUriEntryCallback): Use webkit_web_view_load_uri(). 13 (goBackCallback): Use webkit_web_view_go_back(). 14 (goForwardCallback): Use webkit_web_view_go_forward(). 15 (webViewURIChanged): Update location entry with current uri using 16 webkit_web_view_get_uri(). 17 (browserWindowFinalize): 18 (browserWindowGetProperty): 19 (browserWindowSetProperty): 20 (browser_window_init): 21 (browserWindowConstructed): Connect to notify::uri signal of 22 WebView to be notified when the URI changes. 23 (browser_window_class_init): 24 (browser_window_new): Use WebKitWebView. 25 (browser_window_get_view): Use WebKitWebView 26 * MiniBrowser/gtk/BrowserWindow.h: 27 * MiniBrowser/gtk/GNUmakefile.am: 28 * MiniBrowser/gtk/WebBundle/WebBundleMain.c: Removed. 29 * MiniBrowser/gtk/main.c: 30 (loadURI): Use webkit_web_view_new(). 31 (main): 32 1 33 2011-11-03 Simon Hausmann <simon.hausmann@nokia.com> 2 34 -
trunk/Tools/MiniBrowser/gtk/BrowserWindow.c
r98351 r99200 39 39 GtkWidget *mainBox; 40 40 GtkWidget *uriEntry; 41 GtkWidget *statusBar;42 41 GtkWidget *backItem; 43 42 GtkWidget *forwardItem; 44 WKViewRef webView; 45 46 guint statusBarContextId; 47 WKBackForwardListRef history; 48 49 gchar *title; 50 gdouble loadProgress; 43 WebKitWebView *webView; 44 51 45 }; 52 46 … … 55 49 }; 56 50 57 static void browserWindowLoaderClientInit(BrowserWindow*);58 static void browserWindowUIClientInit(BrowserWindow*);59 static void browserWindowPolicyClientInit(BrowserWindow*);60 61 51 static gint windowCount = 0; 62 52 63 53 G_DEFINE_TYPE(BrowserWindow, browser_window, GTK_TYPE_WINDOW) 64 54 65 static void activateUriEntryCallback(BrowserWindow* window) 66 { 67 WKURLRef url = WKURLCreateWithUTF8CString(gtk_entry_get_text(GTK_ENTRY(window->uriEntry))); 68 WKPageLoadURL(WKViewGetPage(window->webView), url); 69 WKRelease(url); 70 } 71 72 static void goBackCallback(BrowserWindow* window) 73 { 74 WKPageGoBack(WKViewGetPage(window->webView)); 75 } 76 77 static void goForwardCallback(BrowserWindow* window) 78 { 79 WKPageGoForward(WKViewGetPage(window->webView)); 80 } 81 82 static void browserWindowFinalize(GObject* gObject) 83 { 84 BrowserWindow* window = BROWSER_WINDOW(gObject); 85 86 g_free(window->title); 87 55 static void activateUriEntryCallback(BrowserWindow *window) 56 { 57 webkit_web_view_load_uri(window->webView, gtk_entry_get_text(GTK_ENTRY(window->uriEntry))); 58 } 59 60 static void goBackCallback(BrowserWindow *window) 61 { 62 webkit_web_view_go_back(window->webView); 63 } 64 65 static void goForwardCallback(BrowserWindow *window) 66 { 67 webkit_web_view_go_forward(window->webView); 68 } 69 70 static void webViewURIChanged(WebKitWebView *webView, GParamSpec *pspec, BrowserWindow *window) 71 { 72 gtk_entry_set_text(GTK_ENTRY(window->uriEntry), webkit_web_view_get_uri(webView)); 73 } 74 75 static void browserWindowFinalize(GObject *gObject) 76 { 88 77 G_OBJECT_CLASS(browser_window_parent_class)->finalize(gObject); 89 78 … … 92 81 } 93 82 94 static void browserWindowGetProperty(GObject * object, guint propId, GValue* value, GParamSpec*pspec)95 { 96 BrowserWindow *window = BROWSER_WINDOW(object);83 static void browserWindowGetProperty(GObject *object, guint propId, GValue *value, GParamSpec *pspec) 84 { 85 BrowserWindow *window = BROWSER_WINDOW(object); 97 86 98 87 switch (propId) { 99 88 case PROP_VIEW: 100 g_value_set_object(value, (gpointer)browser_window_get_view(window));89 g_value_set_object(value, browser_window_get_view(window)); 101 90 break; 102 91 default: … … 105 94 } 106 95 107 static void browserWindowSetProperty(GObject * object, guint propId, const GValue* value, GParamSpec*pspec)96 static void browserWindowSetProperty(GObject *object, guint propId, const GValue *value, GParamSpec *pspec) 108 97 { 109 98 BrowserWindow* window = BROWSER_WINDOW(object); … … 118 107 } 119 108 120 static void browser_window_init(BrowserWindow *window)109 static void browser_window_init(BrowserWindow *window) 121 110 { 122 111 g_atomic_int_inc(&windowCount); … … 128 117 129 118 GtkWidget *toolbar = gtk_toolbar_new(); 130 #if GTK_CHECK_VERSION(2, 15, 0)131 119 gtk_orientable_set_orientation(GTK_ORIENTABLE(toolbar), GTK_ORIENTATION_HORIZONTAL); 132 #else133 gtk_toolbar_set_orientation(GTK_TOOLBAR(toolbar), GTK_ORIENTATION_HORIZONTAL);134 #endif135 120 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_BOTH_HORIZ); 136 121 … … 170 155 } 171 156 172 static void browserWindowConstructed(GObject* gObject) 173 { 174 BrowserWindow* window = BROWSER_WINDOW(gObject); 157 static void browserWindowConstructed(GObject *gObject) 158 { 159 BrowserWindow *window = BROWSER_WINDOW(gObject); 160 161 g_signal_connect(window->webView, "notify::uri", G_CALLBACK(webViewURIChanged), window); 175 162 176 163 gtk_box_pack_start(GTK_BOX(window->mainBox), GTK_WIDGET(window->webView), TRUE, TRUE, 0); 177 164 gtk_widget_show(GTK_WIDGET(window->webView)); 178 179 window->statusBar = gtk_statusbar_new(); 180 window->statusBarContextId = gtk_statusbar_get_context_id(GTK_STATUSBAR(window->statusBar), "Link Hover"); 181 gtk_box_pack_start(GTK_BOX(window->mainBox), window->statusBar, FALSE, FALSE, 0); 182 gtk_widget_show(window->statusBar); 183 184 window->history = WKPageGetBackForwardList(WKViewGetPage(window->webView)); 185 186 browserWindowLoaderClientInit(window); 187 browserWindowUIClientInit(window); 188 browserWindowPolicyClientInit(window); 189 190 WKPageGroupRef groupRef = WKPageGetPageGroup(WKViewGetPage(window->webView)); 191 WKPreferencesRef preferencesRef = WKPageGroupGetPreferences(groupRef); 192 WKPreferencesSetDeveloperExtrasEnabled(preferencesRef, true); 193 } 194 195 static void browser_window_class_init(BrowserWindowClass* klass) 196 { 197 GObjectClass* gobjectClass = G_OBJECT_CLASS(klass); 165 } 166 167 static void browser_window_class_init(BrowserWindowClass *klass) 168 { 169 GObjectClass *gobjectClass = G_OBJECT_CLASS(klass); 170 198 171 gobjectClass->constructed = browserWindowConstructed; 199 172 gobjectClass->get_property = browserWindowGetProperty; … … 206 179 "View", 207 180 "The web view of this window", 208 GTK_TYPE_WIDGET,181 WEBKIT_TYPE_WEB_VIEW, 209 182 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); 210 183 } 211 184 212 static char* WKStringGetCString(WKStringRef string)213 {214 size_t length = WKStringGetMaximumUTF8CStringSize(string);215 char *buffer = (char *) g_malloc(length);216 WKStringGetUTF8CString(string, buffer, length);217 return buffer;218 }219 220 static char* WKURLGetCString(WKURLRef url)221 {222 WKStringRef urlString = WKURLCopyString(url);223 char *urlText = WKStringGetCString(urlString);224 WKRelease(urlString);225 return urlText;226 }227 228 static void browserWindowUpdateTitle(BrowserWindow* window)229 {230 GString *string = g_string_new(window->title);231 gdouble loadProgress = window->loadProgress * 100;232 g_string_append(string, " - WebKit Launcher");233 if (loadProgress < 100)234 g_string_append_printf(string, " (%f%%)", loadProgress);235 gchar *title = g_string_free(string, FALSE);236 gtk_window_set_title(GTK_WINDOW(window), title);237 g_free(title);238 }239 240 static void browserWindowSetTitle(BrowserWindow* window, const gchar* title)241 {242 if (!g_strcmp0(window->title, title))243 return;244 245 g_free(window->title);246 window->title = g_strdup(title);247 browserWindowUpdateTitle(window);248 }249 250 static void browserWindowSetLoadProgress(BrowserWindow* window, gdouble progress)251 {252 window->loadProgress = progress;253 browserWindowUpdateTitle(window);254 }255 256 static void browserWindowUpdateURL(BrowserWindow* window, WKURLRef url)257 {258 if (!url) {259 gtk_entry_set_text(GTK_ENTRY(window->uriEntry), "");260 return;261 }262 263 char *urlText = WKURLGetCString(url);264 gtk_entry_set_text(GTK_ENTRY(window->uriEntry), urlText);265 g_free(urlText);266 }267 268 static void browserWindowHistoryItemActivated(BrowserWindow *window, GtkAction *action)269 {270 WKBackForwardListItemRef item = g_object_get_data(G_OBJECT(action), "back-forward-list-item");271 if (!item)272 return;273 274 WKPageGoToBackForwardListItem(WKViewGetPage(window->webView), item);275 }276 277 static void browserWindowHistoryItemSelected(BrowserWindow *window, GtkMenuItem *item)278 {279 gtk_statusbar_pop(GTK_STATUSBAR(window->statusBar), window->statusBarContextId);280 281 GtkAction *action = gtk_activatable_get_related_action(GTK_ACTIVATABLE(item));282 if (!action)283 return;284 285 gtk_statusbar_push(GTK_STATUSBAR(window->statusBar), window->statusBarContextId, gtk_action_get_name(action));286 }287 288 static GtkAction *createGtkActionFromBackForwardItem(WKBackForwardListItemRef item)289 {290 if (!item)291 return 0;292 293 WKURLRef url = WKBackForwardListItemCopyURL(item);294 char *name = WKURLGetCString(url);295 WKRelease(url);296 297 WKStringRef title = WKBackForwardListItemCopyTitle(item);298 char *label = WKStringGetCString(title);299 WKRelease(title);300 301 GtkAction *action = gtk_action_new(name, label, 0, 0);302 g_free(name);303 g_free(label);304 305 return action;306 }307 308 static GtkWidget *browserWindowCreateMenuItemFromBackForwardItem(BrowserWindow *window, WKBackForwardListItemRef item)309 {310 GtkAction *action = createGtkActionFromBackForwardItem(item);311 if (!action)312 return 0;313 314 g_object_set_data_full(G_OBJECT(action), "back-forward-list-item", (gpointer)WKRetain(item), (GDestroyNotify)WKRelease);315 g_signal_connect_swapped(action, "activate", G_CALLBACK(browserWindowHistoryItemActivated), window);316 317 GtkWidget *menuItem = gtk_action_create_menu_item(action);318 g_signal_connect_swapped(menuItem, "select", G_CALLBACK(browserWindowHistoryItemSelected), window);319 g_object_unref(action);320 321 return menuItem;322 }323 324 static GtkWidget *browserWindowCreateBackForwardMenu(BrowserWindow *window, WKArrayRef list)325 {326 if (!list)327 return 0;328 329 guint listCount = WKArrayGetSize(list);330 if (!listCount)331 return 0;332 333 GtkWidget *menu = gtk_menu_new();334 gboolean hasItems = FALSE;335 guint i;336 for (i = 0; i < listCount; i++) {337 WKBackForwardListItemRef item = WKArrayGetItemAtIndex(list, i);338 GtkWidget *menuItem = browserWindowCreateMenuItemFromBackForwardItem(window, item);339 if (!menuItem)340 continue;341 342 gtk_menu_shell_prepend(GTK_MENU_SHELL(menu), menuItem);343 gtk_widget_show(menuItem);344 hasItems = TRUE;345 }346 347 if (!hasItems) {348 gtk_widget_destroy(menu);349 return 0;350 }351 352 return menu;353 }354 355 static void browserWindowUpdateNavigationActions(BrowserWindow* window)356 {357 gtk_widget_set_sensitive(window->backItem, WKPageCanGoBack(WKViewGetPage(window->webView)));358 gtk_widget_set_sensitive(window->forwardItem, WKPageCanGoForward(WKViewGetPage(window->webView)));359 360 WKArrayRef list = WKBackForwardListCopyBackListWithLimit(window->history, 10);361 GtkWidget *menu = browserWindowCreateBackForwardMenu(window, list);362 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(window->backItem), menu);363 if (list)364 WKRelease(list);365 366 list = WKBackForwardListCopyForwardListWithLimit(window->history, 10);367 menu = browserWindowCreateBackForwardMenu(window, list);368 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(window->forwardItem), menu);369 if (list)370 WKRelease(list);371 }372 373 // Loader client.374 static void didStartProvisionalLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo)375 {376 if (!WKFrameIsMainFrame(frame))377 return;378 379 WKURLRef url = WKFrameCopyProvisionalURL(frame);380 browserWindowUpdateURL(BROWSER_WINDOW(clientInfo), url);381 if (url)382 WKRelease(url);383 }384 385 static void didReceiveServerRedirectForProvisionalLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo)386 {387 if (!WKFrameIsMainFrame(frame))388 return;389 390 WKURLRef url = WKFrameCopyProvisionalURL(frame);391 browserWindowUpdateURL(BROWSER_WINDOW(clientInfo), url);392 if (url)393 WKRelease(url);394 }395 396 static void didFailProvisionalLoadWithErrorForFrame(WKPageRef page, WKFrameRef frame, WKErrorRef error, WKTypeRef userData, const void* clientInfo)397 {398 if (!WKFrameIsMainFrame(frame))399 return;400 401 WKURLRef url = WKFrameCopyProvisionalURL(frame);402 browserWindowUpdateURL(BROWSER_WINDOW(clientInfo), url);403 if (url)404 WKRelease(url);405 }406 407 static void didCommitLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo)408 {409 if (!WKFrameIsMainFrame(frame))410 return;411 412 WKURLRef url = WKFrameCopyURL(frame);413 browserWindowUpdateURL(BROWSER_WINDOW(clientInfo), url);414 if (url)415 WKRelease(url);416 }417 418 static void didFinishDocumentLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo)419 {420 if (!WKFrameIsMainFrame(frame))421 return;422 }423 424 static void didFinishLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo)425 {426 if (!WKFrameIsMainFrame(frame))427 return;428 429 BrowserWindow* window = BROWSER_WINDOW(clientInfo);430 gtk_widget_grab_focus(GTK_WIDGET(window->webView));431 }432 433 static void didFailLoadWithErrorForFrame(WKPageRef page, WKFrameRef frame, WKErrorRef error, WKTypeRef userData, const void* clientInfo)434 {435 if (!WKFrameIsMainFrame(frame))436 return;437 }438 439 static void didReceiveTitleForFrame(WKPageRef page, WKStringRef title, WKFrameRef frame, WKTypeRef userData, const void* clientInfo)440 {441 if (!WKFrameIsMainFrame(frame))442 return;443 444 char *titleText = WKStringGetCString(title);445 browserWindowSetTitle(BROWSER_WINDOW(clientInfo), titleText);446 g_free(titleText);447 }448 449 static void didFirstLayoutForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo)450 {451 if (!WKFrameIsMainFrame(frame))452 return;453 }454 455 static void didFirstVisuallyNonEmptyLayoutForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo)456 {457 if (!WKFrameIsMainFrame(frame))458 return;459 }460 461 static void didRemoveFrameFromHierarchy(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo)462 {463 if (!WKFrameIsMainFrame(frame))464 return;465 }466 467 static void didStartProgress(WKPageRef page, const void* clientInfo)468 {469 browserWindowSetLoadProgress(BROWSER_WINDOW(clientInfo), 0.);470 }471 472 static void didChangeProgress(WKPageRef page, const void* clientInfo)473 {474 browserWindowSetLoadProgress(BROWSER_WINDOW(clientInfo), WKPageGetEstimatedProgress(page));475 }476 477 static void didFinishProgress(WKPageRef page, const void* clientInfo)478 {479 browserWindowSetLoadProgress(BROWSER_WINDOW(clientInfo), 1.);480 }481 482 static void didBecomeUnresponsive(WKPageRef page, const void* clientInfo)483 {484 }485 486 static void didBecomeResponsive(WKPageRef page, const void* clientInfo)487 {488 }489 490 static void didChangeBackForwardList(WKPageRef page, WKBackForwardListItemRef addedItem, WKArrayRef removedItems, const void *clientInfo)491 {492 browserWindowUpdateNavigationActions(BROWSER_WINDOW(clientInfo));493 }494 495 static void browserWindowLoaderClientInit(BrowserWindow* window)496 {497 WKPageLoaderClient loadClient = {498 kWKPageLoaderClientCurrentVersion,499 window, /* clientInfo */500 didStartProvisionalLoadForFrame,501 didReceiveServerRedirectForProvisionalLoadForFrame,502 didFailProvisionalLoadWithErrorForFrame,503 didCommitLoadForFrame,504 didFinishDocumentLoadForFrame,505 didFinishLoadForFrame,506 didFailLoadWithErrorForFrame,507 0, /* didSameDocumentNavigationForFrame */508 didReceiveTitleForFrame,509 didFirstLayoutForFrame,510 didFirstVisuallyNonEmptyLayoutForFrame,511 didRemoveFrameFromHierarchy,512 0, /* didDisplayInsecureContentForFrame */513 0, /* didRunInsecureContentForFrame */514 0, /* canAuthenticateAgainstProtectionSpaceInFrame */515 0, /* didReceiveAuthenticationChallengeInFrame */516 didStartProgress,517 didChangeProgress,518 didFinishProgress,519 didBecomeUnresponsive,520 didBecomeResponsive,521 0, /* processDidCrash */522 didChangeBackForwardList,523 0, /* shouldGoToBackForwardListItem */524 0 /* didFailToInitializePlugin */525 };526 WKPageSetPageLoaderClient(WKViewGetPage(window->webView), &loadClient);527 }528 529 // UI Client.530 static WKPageRef createNewPage(WKPageRef page, WKURLRequestRef request, WKDictionaryRef features, WKEventModifiers modifiers, WKEventMouseButton button, const void *clientInfo)531 {532 WKViewRef webView = WKViewCreate(WKPageGetContext(page), 0);533 BrowserWindow* window = BROWSER_WINDOW(browser_window_new(webView));534 return WKRetain(WKViewGetPage(window->webView));535 }536 537 static void showPage(WKPageRef page, const void *clientInfo)538 {539 gtk_widget_show(GTK_WIDGET(clientInfo));540 }541 542 static void closePage(WKPageRef page, const void *clientInfo)543 {544 gtk_widget_destroy(GTK_WIDGET(clientInfo));545 }546 547 static GtkWidget* createMessageDialog(GtkWindow *parent, GtkMessageType type, GtkButtonsType buttons, gint defaultResponse, WKStringRef message, WKFrameRef frame)548 {549 char *messageText = WKStringGetCString(message);550 GtkWidget *dialog = gtk_message_dialog_new(parent, GTK_DIALOG_DESTROY_WITH_PARENT, type, buttons, "%s", messageText);551 g_free(messageText);552 553 WKURLRef url = WKFrameCopyURL(frame);554 char *urlText = WKURLGetCString(url);555 WKRelease(url);556 gchar *title = g_strdup_printf("JavaScript - %s", urlText);557 g_free(urlText);558 gtk_window_set_title(GTK_WINDOW(dialog), title);559 g_free(title);560 561 gtk_dialog_set_default_response(GTK_DIALOG(dialog), defaultResponse);562 563 return dialog;564 }565 566 static void focus(WKPageRef page, const void *clientInfo)567 {568 BrowserWindow *window = BROWSER_WINDOW(clientInfo);569 gtk_widget_grab_focus(GTK_WIDGET(window->webView));570 }571 572 static void unfocus(WKPageRef page, const void *clientInfo)573 {574 BrowserWindow *window = BROWSER_WINDOW(clientInfo);575 if (gtk_widget_is_toplevel(GTK_WIDGET(window)))576 gtk_window_set_focus(GTK_WINDOW(window), NULL);577 }578 579 static void runJavaScriptAlert(WKPageRef page, WKStringRef message, WKFrameRef frame, const void *clientInfo)580 {581 GtkWidget *dialog = createMessageDialog(GTK_WINDOW(clientInfo), GTK_MESSAGE_WARNING, GTK_BUTTONS_CLOSE, GTK_RESPONSE_CLOSE, message, frame);582 gtk_dialog_run(GTK_DIALOG(dialog));583 gtk_widget_destroy(dialog);584 }585 586 static bool runJavaScriptConfirm(WKPageRef page, WKStringRef message, WKFrameRef frame, const void* clientInfo)587 {588 GtkWidget *dialog = createMessageDialog(GTK_WINDOW(clientInfo), GTK_MESSAGE_QUESTION, GTK_BUTTONS_OK_CANCEL, GTK_RESPONSE_OK, message, frame);589 bool returnValue = (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK);590 gtk_widget_destroy(dialog);591 592 return returnValue;593 }594 595 static WKStringRef runJavaScriptPrompt(WKPageRef page, WKStringRef message, WKStringRef defaultValue, WKFrameRef frame, const void* clientInfo)596 {597 GtkWidget *dialog = createMessageDialog(GTK_WINDOW(clientInfo), GTK_MESSAGE_QUESTION, GTK_BUTTONS_OK_CANCEL, GTK_RESPONSE_OK, message, frame);598 599 GtkWidget *entry = gtk_entry_new();600 char *value = WKStringGetCString(defaultValue);601 gtk_entry_set_text(GTK_ENTRY(entry), value);602 g_free(value);603 gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), entry);604 gtk_entry_set_activates_default(GTK_ENTRY(entry), TRUE);605 gtk_widget_show(entry);606 607 WKStringRef returnValue = (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) ? WKStringCreateWithUTF8CString(gtk_entry_get_text(GTK_ENTRY(entry))) : 0;608 gtk_widget_destroy(dialog);609 610 return returnValue;611 }612 613 static void mouseDidMoveOverElement(WKPageRef page, WKHitTestResultRef hitTestResult, WKEventModifiers modifiers, WKTypeRef userData, const void *clientInfo)614 {615 BrowserWindow *window = BROWSER_WINDOW(clientInfo);616 gtk_statusbar_pop(GTK_STATUSBAR(window->statusBar), window->statusBarContextId);617 618 WKURLRef linkUrlRef = WKHitTestResultCopyAbsoluteLinkURL(hitTestResult);619 if (!linkUrlRef)620 return;621 622 gchar *link = WKURLGetCString(linkUrlRef);623 WKRelease(linkUrlRef);624 gtk_statusbar_push(GTK_STATUSBAR(window->statusBar), window->statusBarContextId, link);625 g_free(link);626 }627 628 static void browserWindowUIClientInit(BrowserWindow *window)629 {630 WKPageUIClient uiClient = {631 kWKPageUIClientCurrentVersion,632 window, /* clientInfo */633 0, /* createNewPage_deprecatedForUseWithV0 */634 showPage,635 closePage,636 0, /* takeFocus */637 focus,638 unfocus,639 runJavaScriptAlert,640 runJavaScriptConfirm,641 runJavaScriptPrompt,642 0, /* setStatusText */643 0, /* mouseDidMoveOverElement_deprecatedForUseWithV0 */644 0, /* missingPluginButtonClicked */645 0, /* didNotHandleKeyEvent */646 0, /* didNotHandleWheelEvent */647 0, /* toolbarsAreVisible */648 0, /* setToolbarsAreVisible */649 0, /* menuBarIsVisible */650 0, /* setMenuBarIsVisible */651 0, /* statusBarIsVisible */652 0, /* setStatusBarIsVisible */653 0, /* isResizable */654 0, /* setIsResizable */655 0, /* getWindowFrame */656 0, /* setWindowFrame */657 0, /* runBeforeUnloadConfirmPanel */658 0, /* didDraw */659 0, /* pageDidScroll */660 0, /* exceededDatabaseQuota */661 0, /* runOpenPanel */662 0, /* decidePolicyForGeolocationPermissionRequest */663 0, /* headerHeight */664 0, /* footerHeight */665 0, /* drawHeader */666 0, /* drawFooter */667 0, /* printFrame */668 0, /* runModal */669 0, /* didCompleteRubberBandForMainFrame */670 0, /* saveDataToFileInDownloadsFolder */671 0, /* shouldInterruptJavaScript */672 createNewPage,673 mouseDidMoveOverElement674 };675 WKPageSetPageUIClient(WKViewGetPage(window->webView), &uiClient);676 }677 678 static void decidePolicyForNavigationAction(WKPageRef page, WKFrameRef frame, WKFrameNavigationType navigationType, WKEventModifiers modifiers, WKEventMouseButton mouseButton, WKURLRequestRef request, WKFramePolicyListenerRef listener, WKTypeRef userData, const void* clientInfo)679 {680 if (navigationType != kWKFrameNavigationTypeLinkClicked || mouseButton != kWKEventMouseButtonMiddleButton) {681 WKFramePolicyListenerUse(listener);682 return;683 }684 685 WKViewRef webView = WKViewCreate(WKPageGetContext(page), 0);686 GtkWidget *window = browser_window_new(webView);687 WKURLRef url = WKURLRequestCopyURL(request);688 WKPageLoadURL(WKViewGetPage(webView), url);689 WKRelease(url);690 gtk_widget_grab_focus(GTK_WIDGET(webView));691 gtk_widget_show(window);692 693 WKFramePolicyListenerIgnore(listener);694 }695 696 static void browserWindowPolicyClientInit(BrowserWindow* window)697 {698 WKPagePolicyClient policyClient = {699 kWKPagePolicyClientCurrentVersion,700 window, /* clientInfo */701 decidePolicyForNavigationAction,702 0, /* decidePolicyForNewWindowAction */703 0, /* decidePolicyForResponse */704 0 /* unableToImplementPolicy */705 };706 WKPageSetPagePolicyClient(WKViewGetPage(window->webView), &policyClient);707 }708 709 185 // Public API. 710 GtkWidget * browser_window_new(WKViewRefview)711 { 712 g_return_val_if_fail( GTK_IS_WIDGET(view), 0);186 GtkWidget *browser_window_new(WebKitWebView *view) 187 { 188 g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(view), 0); 713 189 714 190 return GTK_WIDGET(g_object_new(BROWSER_TYPE_WINDOW, … … 717 193 } 718 194 719 W KViewRef browser_window_get_view(BrowserWindow*window)195 WebKitWebView *browser_window_get_view(BrowserWindow *window) 720 196 { 721 197 g_return_val_if_fail(BROWSER_IS_WINDOW(window), 0); -
trunk/Tools/MiniBrowser/gtk/BrowserWindow.h
r85311 r99200 27 27 #define BrowserWindow_h 28 28 29 #include < WebKit2/WebKit2.h>29 #include <webkit2/webkit2.h> 30 30 #include <gtk/gtk.h> 31 31 … … 44 44 GType browser_window_get_type(void); 45 45 46 GtkWidget* browser_window_new(W KViewRef);47 W KViewRefbrowser_window_get_view(BrowserWindow*);46 GtkWidget* browser_window_new(WebKitWebView*); 47 WebKitWebView* browser_window_get_view(BrowserWindow*); 48 48 49 49 G_END_DECLS -
trunk/Tools/MiniBrowser/gtk/GNUmakefile.am
r92273 r99200 1 bin_PROGRAMS += \1 noinst_PROGRAMS += \ 2 2 Programs/MiniBrowser 3 3 4 4 Programs_MiniBrowser_CPPFLAGS = \ 5 5 -I$(srcdir)/Source \ 6 -I$(top_builddir)/DerivedSources/WebKit2/include \ 6 -I$(top_builddir)/DerivedSources/WebKit2/webkit2gtk \ 7 -I$(top_builddir)/DerivedSources/WebKit2/webkit2gtk/include \ 7 8 -DWEBKIT_EXEC_PATH=\"${shell pwd}/$(top_builddir)/Programs/\" \ 8 9 $(global_cppflags) \ … … 14 15 Tools/MiniBrowser/gtk/BrowserWindow.c \ 15 16 Tools/MiniBrowser/gtk/main.c 16 17 BUILT_SOURCES += \18 generate-minibrowser-forward-headers19 20 MiniBrowser := $(srcdir)/Tools/MiniBrowser/gtk21 MiniBrowserFwdHeaders := $(GENSOURCES_WEBKIT2)/include22 generate-minibrowser-forward-headers: $(WebKit2)/Scripts/generate-forwarding-headers.pl $(Programs_MiniBrowser_SOURCES)23 $(AM_V_GEN)$(PERL) $< $(MiniBrowser) $(MiniBrowserFwdHeaders) gtk24 $(AM_V_GEN)$(PERL) $< $(MiniBrowser) $(MiniBrowserFwdHeaders) soup25 17 26 18 Programs_MiniBrowser_LDADD = \ … … 36 28 $(top_builddir)/Programs/MiniBrowser 37 29 38 # Injected bundle39 noinst_LTLIBRARIES += Libraries/libMiniBrowserWebBundle.la40 Libraries_libMiniBrowserWebBundle_la_SOURCES = \41 Tools/MiniBrowser/gtk/WebBundle/WebBundleMain.c42 43 Libraries_libMiniBrowserWebBundle_la_LDFLAGS = \44 -rpath ${shell pwd}/$(top_builddir)/../unix/TestNetscapePlugin/.libs \45 $(no_undefined) \46 -avoid-version \47 -module48 49 Libraries_libMiniBrowserWebBundle_la_CPPFLAGS = \50 -I$(top_builddir)/DerivedSources/InjectedBundle \51 -I$(top_builddir)/DerivedSources/WebKit2/include \52 $(global_cppflags) \53 $(javascriptcore_cppflags) \54 $(GLIB_CFLAGS) -
trunk/Tools/MiniBrowser/gtk/main.c
r98239 r99200 27 27 28 28 #include "BrowserWindow.h" 29 #include < WebKit2/WebKit2.h>29 #include <webkit2/webkit2.h> 30 30 #include <gtk/gtk.h> 31 31 32 32 static const gchar **uriArguments = NULL; 33 34 static WKContextRef createWKContextWithInjectedBundle()35 {36 WKStringRef bundlePath = WKStringCreateWithUTF8CString("Libraries/.libs/libMiniBrowserWebBundle.so");37 WKContextRef processContext = WKContextCreateWithInjectedBundlePath(bundlePath);38 WKContextInjectedBundleClient bundleClient = {39 kWKContextInjectedBundleClientCurrentVersion,40 0, /* clientInfo */41 0, /* didRecieveMessageFromInjectedBundle,*/42 043 };44 WKContextSetInjectedBundleClient(processContext, &bundleClient);45 WKRelease(bundlePath);46 47 return processContext;48 }49 33 50 34 static gchar *argumentToURL(const char *filename) … … 57 41 } 58 42 59 static void loadURI(const gchar *uri , WKContextRef processContext)43 static void loadURI(const gchar *uri) 60 44 { 61 WKViewRef webView = WKViewCreate(processContext, 0);62 GtkWidget *mainWindow = browser_window_new( webView);45 GtkWidget *webView = webkit_web_view_new(); 46 GtkWidget *mainWindow = browser_window_new(WEBKIT_WEB_VIEW(webView)); 63 47 gchar *url = argumentToURL(uri); 64 WKURLRef wkURL = WKURLCreateWithUTF8CString(url);48 webkit_web_view_load_uri(WEBKIT_WEB_VIEW(webView), url); 65 49 g_free(url); 66 WKPageLoadURL(WKViewGetPage(webView), wkURL);67 WKRelease(wkURL);68 50 69 gtk_widget_grab_focus( GTK_WIDGET(webView));51 gtk_widget_grab_focus(webView); 70 52 gtk_widget_show(mainWindow); 71 53 } … … 98 80 g_setenv("WEBKIT_EXEC_PATH", WEBKIT_EXEC_PATH, FALSE); 99 81 100 WKContextRef processContext = createWKContextWithInjectedBundle();101 102 82 if (uriArguments) { 103 83 int i; 104 84 105 85 for (i = 0; uriArguments[i]; i++) 106 loadURI(uriArguments[i] , processContext);86 loadURI(uriArguments[i]); 107 87 } else 108 loadURI("http://www.webkitgtk.org/" , processContext);88 loadURI("http://www.webkitgtk.org/"); 109 89 110 90 gtk_main();
Note: See TracChangeset
for help on using the changeset viewer.