Fix problem with native extension and package URLs

Cherry-picks 4bfdaa83b2c5c6f90f410e7eea4729f8f65d3440 and
7af8d6e5a4f981e06a29e28db180ca4badd2f0f9 to dev channel.

Review URL: https://codereview.chromium.org/2149193004 .
Review URL: https://codereview.chromium.org/2153203002 .
diff --git a/runtime/bin/extensions.cc b/runtime/bin/extensions.cc
index f4b921f..d319ce7 100644
--- a/runtime/bin/extensions.cc
+++ b/runtime/bin/extensions.cc
@@ -19,11 +19,6 @@
 Dart_Handle Extensions::LoadExtension(const char* extension_directory,
                                       const char* extension_name,
                                       Dart_Handle parent_library) {
-  if (strncmp(extension_directory, "http://", 7) == 0 ||
-      strncmp(extension_directory, "https://", 8) == 0) {
-    return Dart_NewApiError("Cannot load native extensions over http:");
-  }
-
   // For example on Linux: directory/libfoo-arm.so
   const char* library_strings[] = {
     extension_directory,  // directory/
diff --git a/runtime/bin/loader.cc b/runtime/bin/loader.cc
index 19150a7..6a99a4e 100644
--- a/runtime/bin/loader.cc
+++ b/runtime/bin/loader.cc
@@ -296,8 +296,20 @@
     ASSERT(library_uri != Dart_Null());
     Dart_Handle library = Dart_LookupLibrary(library_uri);
     ASSERT(!Dart_IsError(library));
-    const char* lib_path_str = reinterpret_cast<const char*>(result->payload);
+    const char* lib_uri = reinterpret_cast<const char*>(result->payload);
+    if (strncmp(lib_uri, "http://", 7) == 0 ||
+        strncmp(lib_uri, "https://", 8) == 0) {
+      loader->error_ =
+        Dart_NewApiError("Cannot load native extensions over http: or https:");
+        return false;
+    }
     const char* extension_uri = reinterpret_cast<const char*>(result->uri);
+    const char* lib_path = NULL;
+    if (strncmp(lib_uri, "file://", 7) == 0) {
+      lib_path = DartUtils::RemoveScheme(lib_uri);
+    } else {
+      lib_path = lib_uri;
+    }
     const char* extension_path = DartUtils::RemoveScheme(extension_uri);
     if (strchr(extension_path, '/') != NULL ||
         (IsWindowsHost() && strchr(extension_path, '\\') != NULL)) {
@@ -306,7 +318,7 @@
           extension_path);
       return false;
     }
-    Dart_Handle result = Extensions::LoadExtension(lib_path_str,
+    Dart_Handle result = Extensions::LoadExtension(lib_path,
                                                    extension_path,
                                                    library);
     if (Dart_IsError(result)) {