 +  // the file doesn't match some conditions to be served from a CDN or static
 +  // file server, or because the file has not yet been synced to the CDN or
 +  // static file server.
-+  if (!$is_in_files_directory) {
++
++  // Shipped files.
++  if (strpos($path, file_directory_path() . '/') !== 0) {
 +    return base_path() . $path;
 +  }
++  // Created files.
 +  else {
-+    // Strip file_directory_path from $path. We only include relative paths in urls.
-+    if (strpos($path, file_directory_path() .'/') === 0) {
-+      $path = trim(substr($path, strlen(file_directory_path())), '\\/');
-+    }
-+
 +    switch (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC)) {
 +      case FILE_DOWNLOADS_PUBLIC:
-+        return $GLOBALS['base_url'] .'/'. file_directory_path() .'/'. str_replace('\\', '/', $path);
++        return $GLOBALS['base_url'] . '/' . $path;
 +      case FILE_DOWNLOADS_PRIVATE:
-+        return url('system/files/'. $path, array('absolute' => TRUE));
++        // Strip file_directory_path from $path. Private downloads' URLs are
++        // rewritten to be served relatively to system/files (which is a menu
++        // callback that streams the file) instead of relatively to the file
++        // directory path.
++        $path = trim(substr($path, strlen(file_directory_path())), '/');
++        return url('system/files/' . $path, array('absolute' => TRUE));
 +    }
    }
  }

retrieving revision 1.496
diff -u -F^f -r1.496 theme.inc
--- includes/theme.inc	18 Jun 2009 21:19:02 -0000	1.496
+++ includes/theme.inc	22 Jun 2009 22:32:34 -0000
@@ -1086,24 +1086,24 @@ function theme_get_setting($setting_name
 
     if ($settings['toggle_logo']) {

retrieving revision 1.171
diff -u -F^f -r1.171 file.inc
--- includes/file.inc	9 Jun 2009 21:33:12 -0000	1.171
+++ includes/file.inc	23 Jun 2009 20:36:46 -0000
@@ -79,20 +79,62 @@
 /**
  * Create the download path to a file.
  *
- * @param $path A string containing the path of the file to generate URL for.
- * @return A string containing a URL that can be used to download the file.
+ * There are two kinds of files:
+ * - "created files", i.e. those in the files directory (which is stored in
+ *   the file_directory_path variable and can be retrieved using
+ *   file_directory_path()). These are files that have either been uploaded by
+ *   users or were generated automatically (for example through CSS
+ *   aggregation).
+ * - "shipped files", i.e. those outside of the files directory, which ship as
+ *   part of Drupal core or contributed modules or themes.
+ * When the custom_file_url_rewrite() function is defined and returns a
+ * rewritten path (and not FALSE), then that rewritten path is used instead of
+ * creating a URL for the file at the given path.
+ *
+ * @param $path
+ *   A string containing the Drupal path (i.e. path relative to the Drupal
+ *   root directory) of the file to generate the URL for.
+ * @return
+ *   A string containing a URL that can be used to download the file.
  */
 function file_create_url($path) {
-  // Strip file_directory_path from $path. We only include relative paths in
