X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=webdvd.cpp;h=26e426062bd6aaa1bca1924cf443dc5f7a88a4ad;hb=72534f81da76c6c731c5d688d8485e6d9c9e2c9a;hp=d0f2e05f3e8dd2f9718f4f47e9636f119828ee3d;hpb=51e4ad8512a2b11da8737f345676b03d94e0fa2a;p=videolink.git diff --git a/webdvd.cpp b/webdvd.cpp index d0f2e05..26e4260 100644 --- a/webdvd.cpp +++ b/webdvd.cpp @@ -142,6 +142,36 @@ namespace return result; } + + std::string xml_escape(const std::string & str) + { + std::string result; + std::size_t begin = 0; + + for (;;) + { + std::size_t end = str.find_first_of("\"&'<>", begin); + result.append(str, begin, end - begin); + if (end == std::string::npos) + return result; + + const char * entity = NULL; + switch (str[end]) + { + case '"': entity = """; break; + case '&': entity = "&"; break; + case '\'': entity = "'"; break; + case '<': entity = "<"; break; + case '>': entity = ">"; break; + } + assert(entity); + result.append(entity); + + begin = end + 1; + } + } + + struct dvd_contents { enum pgc_type { menu_pgc, title_pgc }; @@ -171,7 +201,7 @@ namespace std::vector menus; std::vector titles; }; - + class webdvd_window : public Gtk::Window { public: @@ -185,6 +215,10 @@ namespace dvd_contents::pgc_ref add_title(const std::string & uri); void load_next_page(); void on_net_state_change(const char * uri, gint flags, guint status); + bool browser_is_busy() const + { + return pending_window_update_ || pending_req_count_; + } bool process_page(); void save_screenshot(); void process_links(nsIPresShell * pres_shell, @@ -280,8 +314,7 @@ namespace filename + " is missing or not a regular file"); vob_list .append("<vob file='") - // FIXME: Should XML-escape the path - .append(filename) + .append(xml_escape(filename)) .append("'/>\n"); } else @@ -378,7 +411,7 @@ namespace pending_window_update_ = false; } - if (pending_req_count_ == 0 && !pending_window_update_) + if (!browser_is_busy()) { try { @@ -426,7 +459,7 @@ namespace // Might need to wait a while for things to load or more // likely for a re-layout. - if (pending_req_count_ > 0) + if (browser_is_busy()) return true; } @@ -685,7 +718,7 @@ namespace // We may have to exit and wait for image loading // to complete, at which point we will be called // again. - if (pending_req_count_ > 0) + if (browser_is_busy()) { state->link_changing = true; page_state_ = state; @@ -1000,16 +1033,17 @@ namespace void set_browser_preferences() { - // Disable IE-compatibility kluge that causes backgrounds to - // sometimes/usually be missing from snapshots. This is only - // effective from Mozilla 1.8 onward. -# if MOZ_VERSION_MAJOR > 1 \ - || (MOZ_VERSION_MAJOR == 1 && MOZ_VERSION_MINOR >= 8) nsCOMPtr<nsIPrefService> pref_service; static const nsCID pref_service_cid = NS_PREFSERVICE_CID; check(CallGetService<nsIPrefService>(pref_service_cid, getter_AddRefs(pref_service))); nsCOMPtr<nsIPrefBranch> pref_branch; + + // Disable IE-compatibility kluge that causes backgrounds to + // sometimes/usually be missing from snapshots. This is only + // effective from Mozilla 1.8 onward. +# if MOZ_VERSION_MAJOR > 1 \ + || (MOZ_VERSION_MAJOR == 1 && MOZ_VERSION_MINOR >= 8) check(pref_service->GetDefaultBranch("layout", getter_AddRefs(pref_branch))); check(pref_branch->SetBoolPref( @@ -1017,9 +1051,17 @@ namespace true)); # endif - // TODO: Set display resolution? Unfortunately Mozilla doesn't - // support non-square pixels (and neither do fontconfig or Xft - // anyway). + // Set display resolution. With standard-definition video we + // will be fitting ~600 pixels across a screen typically + // ranging from 10 to 25 inches wide, for a resolution of + // 24-60 dpi. I therefore declare the average horizontal + // resolution to be 40 dpi. The vertical resolution will be + // slightly higher (PAL/SECAM) or lower (NTSC), but + // unfortunately Mozilla doesn't support non-square pixels + // (and neither do fontconfig or Xft anyway). + check(pref_service->GetDefaultBranch("browser.display", + getter_AddRefs(pref_branch))); + check(pref_branch->SetIntPref("screen_resolution", 40)); } } // namespace