00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00026
00027
00028
00029
00030 #include <sys/types.h>
00031 #include <sys/stat.h>
00032 #include <unistd.h>
00033 #include <stdlib.h>
00034 #include "nsMemory.h"
00035 #include "browserTypes.h"
00036 #include "mozEmbedCallbacks.h"
00037 #include "indexFileHandler.h"
00038 #include "mozilla_api.h"
00039 #include "selection.h"
00040 #include "timingInfo.h"
00041 #include "browser.h"
00042 #include "pagebar.h"
00043 #include "displayUpdate.h"
00044 #include "browserLog.h"
00045 #include "erbusy.h"
00046
00047 #ifdef ENABLE_LOGGING
00048 #include <liberlog/erlog.h>
00049 #endif
00050
00051 gint open_uri_cb (GtkMozEmbed *embed, const char *uri, gpointer data)
00052 {
00053 struct stat statbuf;
00054 char *path;
00055
00056 BR_PAGEBARPRINTF("Going to load: %s\n", uri);
00057
00058 path = mozilla_uri_to_path(uri);
00059
00060
00061 if (path != NULL && stat(path, &statbuf) != 0)
00062 {
00063 BR_ERRORPRINTF("Not jumping to non-existing page: %s [%s]\n", uri, path);
00064 erbusy_off();
00065 free(path);
00066 return TRUE;
00067 }
00068 else if (path != NULL)
00069 {
00070 free(path);
00071 }
00072
00073 #ifdef ENABLE_LOGGING
00074
00075 char * load = (char*)malloc(strlen(uri)+1);
00076 strcpy(load, uri);
00077 erlog_event_open(load);
00078 free(load);
00079 #endif
00080
00081
00082 erbusy_blink();
00083
00084 return FALSE;
00085 }
00086
00087 void status_change_cb(GtkMozEmbed * embed, gpointer request, gint status, gpointer message)
00088 {
00089 BR_PAGEBARPRINTF("entry status %d", status);
00090 }
00091
00092 void progress_change_cb(GtkMozEmbed * embed, gint cur, gint max, Ereader * browser)
00093 {
00094 BR_PAGEBARPRINTF("entry cur %d max %d", cur, max);
00095 }
00096
00097
00098 void location_changed_cb(GtkMozEmbed * embed, gpointer data)
00099 {
00100 BR_PAGEBARPRINTF("________________BROWSER - location_changed_cb _____________");
00101
00102
00103 display_update_increase_level(MOZEMBED_UPDATE_LEVEL);
00104
00105 #ifdef TIMING_INFORMATION_ENABLED
00106 timing_display_time_elapsed();
00107 #endif //TIMING_INFORMATION_ENABLED
00108 }
00109
00110 void visibility_cb(GtkMozEmbed * embed, gboolean visibility, Ereader * browser)
00111 {
00112 BR_PAGEBARPRINTF("visibility_cb entry");
00113 set_browser_visibility(browser, visibility);
00114 }
00115
00116 void load_finished_cb(GtkMozEmbed * embed, Ereader * browser)
00117 {
00118 gchar *type = NULL;
00119 gboolean pagebar_update_needed = FALSE;
00120 gboolean page_type_known = FALSE;
00121 int pageCount;
00122 int page;
00123 int offset;
00124 gchar *url = NULL;
00125
00126 BR_PAGEBARPRINTF("________________BROWSER - load_finished _____________");
00127 #ifdef TIMING_INFORMATION_ENABLED
00128 timing_display_time_elapsed();
00129 #endif //TIMING_INFORMATION_ENABLED
00130
00131 BR_PAGEBARPRINTF("0x%x -- mozembed 0x%x -- pagestatus 0x%x", browser, embed, browser->pageStatus);
00132
00133
00134
00135
00136
00137 page_type_known = mozilla_get_page_type(GTK_MOZ_EMBED(browser->mozEmbed), &type);
00138
00139
00140 if (!page_type_known)
00141 {
00142 BR_PAGEBARPRINTF("---- mozilla_get_page_type returned unknown page type ----");
00143 type = g_strdup(INVALID_PAGE_TYPE);
00144 pageCount = DEFAULT_PAGE_COUNT;
00145 page = DEFAULT_PAGE;
00146 }
00147 else
00148 {
00149 if ( (pageCount = index_file_get_page_count(&browser->pageStatus->index, type)) == INVALID_PAGE_COUNT )
00150 {
00151 BR_WARNPRINTF("index_file_get_page_count() returned INVALID_PAGE_COUNT");
00152 pageCount = DEFAULT_PAGE_COUNT;
00153 page = DEFAULT_PAGE;
00154 }
00155 else
00156 {
00157 BR_PAGEBARPRINTF("---- mozilla_get_page_type returned %s (count %d) ----", type, pageCount);
00158
00159 url = gtk_moz_embed_get_location(GTK_MOZ_EMBED(browser->mozEmbed));
00160 BR_PAGEBARPRINTF("load_finished_cb -- location %s", url);
00161
00162 page = index_file_get_page_number(&browser->pageStatus->index, type, url);
00163 BR_PAGEBARPRINTF("index_file_get_page_number returned %d", page);
00164 }
00165
00166 }
00167
00168 browser->pageStatus->pageCount = pageCount;
00169 browser->pageStatus->currentPage = page;
00170
00171 offset = mozilla_determine_page_offset(GTK_MOZ_EMBED(browser->mozEmbed));
00172 BR_PAGEBARPRINTF("mozilla_determine_page_offset returned %d", offset);
00173
00174
00175
00176 BR_PAGEBARPRINTF("---- mozilla_get_page_type -- page_status_handle_type_update %s [0x%x]----", type, browser->pageStatus);
00177 pagebar_update_needed = page_status_handle_type_update(browser->pageStatus, type);
00178
00179 if (!pagebar_update_needed)
00180 {
00181 BR_PAGEBARPRINTF("---- no pagebar_update_needed => select page %d ----", page);
00182 pagebar_goto_page(page);
00183 pagebar_set_offset(offset);
00184 pagebar_redraw();
00185 }
00186 else
00187 {
00188 BR_PAGEBARPRINTF("---- pagebar_update_needed => redraw pagebar %d select page %d ----", pageCount, page);
00189 pagebar_set_pagecount(pageCount);
00190 pagebar_goto_page(page);
00191 pagebar_set_offset(offset);
00192 pagebar_redraw();
00193 }
00194
00195
00196 if (type)
00197 {
00198 g_free(type);
00199 type = NULL;
00200 }
00201
00202 if (url)
00203 {
00204 g_free(url);
00205 url = NULL;
00206 }
00207
00208 #ifdef SELECTION_ENABLED
00209
00210 selection_set_current_page_selections(GTK_MOZ_EMBED(embed));
00211 #endif // SELECTION_ENABLED
00212
00213
00214 BR_DISPLAYPRINTF("________________BROWSER - set idle callback _____________");
00215
00216 #ifdef TIMING_INFORMATION_ENABLED
00217 timing_display_time_elapsed();
00218 #endif //TIMING_INFORMATION_ENABLED
00219
00220 display_update_request_screen_refresh(MOZEMBED_UPDATE_LEVEL, NULL);
00221
00222 }
00223
00224