diff options
author | teravest@chromium.org <teravest@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-19 17:23:18 +0000 |
---|---|---|
committer | teravest@chromium.org <teravest@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-19 17:23:18 +0000 |
commit | 54642132e70c320e5eab25328065859e7335b597 (patch) | |
tree | 677d3d65214c35162dec4f7db88146fa0ff38819 /ppapi | |
parent | a213562240a57cab65feb37d26030a711e00d5d7 (diff) | |
download | chromium_src-54642132e70c320e5eab25328065859e7335b597.zip chromium_src-54642132e70c320e5eab25328065859e7335b597.tar.gz chromium_src-54642132e70c320e5eab25328065859e7335b597.tar.bz2 |
Pepper: Move GetUrlScheme to PPB_NaCl_Private.
This is part of a series of changes to clean up FileDownloader so that it's
less dependent on Plugin.
As an added benefit, the code for GetUrlScheme is much shorter once it's on the
Chromium side.
BUG=239656
R=dmichael@chromium.org
Review URL: https://codereview.chromium.org/203523003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@258027 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
-rw-r--r-- | ppapi/api/private/ppb_nacl_private.idl | 9 | ||||
-rw-r--r-- | ppapi/c/private/ppb_nacl_private.h | 10 | ||||
-rw-r--r-- | ppapi/native_client/src/trusted/plugin/file_downloader.cc | 11 | ||||
-rw-r--r-- | ppapi/native_client/src/trusted/plugin/file_downloader.h | 11 | ||||
-rw-r--r-- | ppapi/native_client/src/trusted/plugin/plugin.cc | 46 | ||||
-rw-r--r-- | ppapi/native_client/src/trusted/plugin/plugin.h | 4 | ||||
-rw-r--r-- | ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c | 8 |
7 files changed, 45 insertions, 54 deletions
diff --git a/ppapi/api/private/ppb_nacl_private.idl b/ppapi/api/private/ppb_nacl_private.idl index 3ad1637..94a3bea 100644 --- a/ppapi/api/private/ppb_nacl_private.idl +++ b/ppapi/api/private/ppb_nacl_private.idl @@ -115,6 +115,12 @@ enum PP_NaClEventType { PP_NACL_EVENT_CRASH }; +enum PP_UrlSchemeType { + PP_SCHEME_CHROME_EXTENSION, + PP_SCHEME_DATA, + PP_SCHEME_OTHER +}; + /* PPB_NaCl_Private */ interface PPB_NaCl_Private { /* Launches NaCl's sel_ldr process. Returns PP_EXTERNAL_PLUGIN_OK on success @@ -282,4 +288,7 @@ interface PPB_NaCl_Private { /* platform. */ str_t GetSandboxArch(); + + /* Returns the scheme type for a given url. */ + PP_UrlSchemeType GetUrlScheme([in] PP_Var url); }; diff --git a/ppapi/c/private/ppb_nacl_private.h b/ppapi/c/private/ppb_nacl_private.h index 5e83b98..cd20082 100644 --- a/ppapi/c/private/ppb_nacl_private.h +++ b/ppapi/c/private/ppb_nacl_private.h @@ -3,7 +3,7 @@ * found in the LICENSE file. */ -/* From private/ppb_nacl_private.idl modified Wed Mar 12 14:00:41 2014. */ +/* From private/ppb_nacl_private.idl modified Tue Mar 18 11:15:05 2014. */ #ifndef PPAPI_C_PRIVATE_PPB_NACL_PRIVATE_H_ #define PPAPI_C_PRIVATE_PPB_NACL_PRIVATE_H_ @@ -130,6 +130,12 @@ typedef enum { PP_NACL_EVENT_LOADEND, PP_NACL_EVENT_CRASH } PP_NaClEventType; + +typedef enum { + PP_SCHEME_CHROME_EXTENSION, + PP_SCHEME_DATA, + PP_SCHEME_OTHER +} PP_UrlSchemeType; /** * @} */ @@ -286,6 +292,8 @@ struct PPB_NaCl_Private_1_0 { * platform. */ const char* (*GetSandboxArch)(void); + /* Returns the scheme type for a given url. */ + PP_UrlSchemeType (*GetUrlScheme)(struct PP_Var url); }; typedef struct PPB_NaCl_Private_1_0 PPB_NaCl_Private; diff --git a/ppapi/native_client/src/trusted/plugin/file_downloader.cc b/ppapi/native_client/src/trusted/plugin/file_downloader.cc index 9df21b3..3666808 100644 --- a/ppapi/native_client/src/trusted/plugin/file_downloader.cc +++ b/ppapi/native_client/src/trusted/plugin/file_downloader.cc @@ -149,9 +149,10 @@ bool FileDownloader::Open( // Note that we have the only reference to the underlying objects, so // this will implicitly close any pending IO and destroy them. url_loader_ = pp::URLLoader(instance_); - url_scheme_ = instance_->GetUrlScheme(url); + pp::Var url_var = pp::Var(url); + url_scheme_ = instance_->nacl_interface()->GetUrlScheme(url_var.pp_var()); bool grant_universal_access = false; - if (url_scheme_ == SCHEME_DATA) { + if (url_scheme_ == PP_SCHEME_DATA) { // TODO(elijahtaylor) Remove this when data URIs can be read without // universal access. // https://bugs.webkit.org/show_bug.cgi?id=17352 @@ -268,17 +269,17 @@ bool FileDownloader::InitialResponseIsValid() { bool status_ok = false; status_code_ = url_response_.GetStatusCode(); switch (url_scheme_) { - case SCHEME_CHROME_EXTENSION: + case PP_SCHEME_CHROME_EXTENSION: PLUGIN_PRINTF(("FileDownloader::InitialResponseIsValid (chrome-extension " "response status_code=%" NACL_PRId32 ")\n", status_code_)); status_ok = (status_code_ == kExtensionUrlRequestStatusOk); break; - case SCHEME_DATA: + case PP_SCHEME_DATA: PLUGIN_PRINTF(("FileDownloader::InitialResponseIsValid (data URI " "response status_code=%" NACL_PRId32 ")\n", status_code_)); status_ok = (status_code_ == kDataUriRequestStatusOk); break; - case SCHEME_OTHER: + case PP_SCHEME_OTHER: PLUGIN_PRINTF(("FileDownloader::InitialResponseIsValid (HTTP response " "status_code=%" NACL_PRId32 ")\n", status_code_)); status_ok = (status_code_ == NACL_HTTP_STATUS_OK); diff --git a/ppapi/native_client/src/trusted/plugin/file_downloader.h b/ppapi/native_client/src/trusted/plugin/file_downloader.h index 66b6ba6..fd33509 100644 --- a/ppapi/native_client/src/trusted/plugin/file_downloader.h +++ b/ppapi/native_client/src/trusted/plugin/file_downloader.h @@ -12,6 +12,7 @@ #include "native_client/src/trusted/validator/nacl_file_info.h" #include "ppapi/c/private/pp_file_handle.h" #include "ppapi/c/private/ppb_file_io_private.h" +#include "ppapi/c/private/ppb_nacl_private.h" #include "ppapi/c/trusted/ppb_url_loader_trusted.h" #include "ppapi/cpp/file_io.h" #include "ppapi/cpp/instance.h" @@ -31,12 +32,6 @@ typedef enum { DOWNLOAD_NONE } DownloadMode; -typedef enum { - SCHEME_CHROME_EXTENSION, - SCHEME_DATA, - SCHEME_OTHER -} UrlSchemeType; - typedef std::vector<char>* FileStreamData; typedef CallbackSource<FileStreamData> StreamCallbackSource; typedef pp::CompletionCallbackWithOutput<FileStreamData> StreamCallback; @@ -86,7 +81,7 @@ class FileDownloader { url_loader_trusted_interface_(NULL), open_time_(-1), mode_(DOWNLOAD_NONE), - url_scheme_(SCHEME_OTHER), + url_scheme_(PP_SCHEME_OTHER), data_stream_callback_source_(NULL) {} ~FileDownloader() {} @@ -223,7 +218,7 @@ class FileDownloader { static const uint32_t kTempBufferSize = 16384; std::vector<char> temp_buffer_; std::deque<char> buffer_; - UrlSchemeType url_scheme_; + PP_UrlSchemeType url_scheme_; StreamCallbackSource* data_stream_callback_source_; NaClFileInfoAutoCloser file_info_; }; diff --git a/ppapi/native_client/src/trusted/plugin/plugin.cc b/ppapi/native_client/src/trusted/plugin/plugin.cc index 3fbb80e..6f79e02 100644 --- a/ppapi/native_client/src/trusted/plugin/plugin.cc +++ b/ppapi/native_client/src/trusted/plugin/plugin.cc @@ -70,10 +70,6 @@ const size_t kNaClManifestMaxFileBytes = 1024 * 1024; // collide with any user-defined HTML attribute, make the first character '@'. const char* const kDevAttribute = "@dev"; -// URL schemes that we treat in special ways. -const char* const kChromeExtensionUriScheme = "chrome-extension"; -const char* const kDataUriScheme = "data"; - // Up to 20 seconds const int64_t kTimeSmallMin = 1; // in ms const int64_t kTimeSmallMax = 20000; // in ms @@ -1050,7 +1046,9 @@ void Plugin::ProcessNaClManifest(const nacl::string& manifest_json) { bool uses_nonsfi_mode; if (manifest_->GetProgramURL( &program_url, &pnacl_options, &uses_nonsfi_mode, &error_info)) { - is_installed_ = GetUrlScheme(program_url) == SCHEME_CHROME_EXTENSION; + pp::Var program_url_var(program_url); + is_installed_ = (nacl_interface_->GetUrlScheme(program_url_var.pp_var()) == + PP_SCHEME_CHROME_EXTENSION); uses_nonsfi_mode_ = uses_nonsfi_mode; set_nacl_ready_state(LOADING); // Inform JavaScript that we found a nexe URL to load. @@ -1106,13 +1104,15 @@ void Plugin::RequestNaClManifest(const nacl::string& url) { } PLUGIN_PRINTF(("Plugin::RequestNaClManifest (resolved url='%s')\n", nmf_resolved_url.AsString().c_str())); - is_installed_ = GetUrlScheme(nmf_resolved_url.AsString()) == - SCHEME_CHROME_EXTENSION; + is_installed_ = (nacl_interface_->GetUrlScheme(nmf_resolved_url.pp_var()) == + PP_SCHEME_CHROME_EXTENSION); set_manifest_base_url(nmf_resolved_url.AsString()); // Inform JavaScript that a load is starting. set_nacl_ready_state(OPENED); EnqueueProgressEvent(PP_NACL_EVENT_LOADSTART); - bool is_data_uri = GetUrlScheme(nmf_resolved_url.AsString()) == SCHEME_DATA; + bool is_data_uri = + (nacl_interface_->GetUrlScheme(nmf_resolved_url.pp_var()) == + PP_SCHEME_DATA); HistogramEnumerateManifestIsDataURI(static_cast<int>(is_data_uri)); if (is_data_uri) { pp::CompletionCallback open_callback = @@ -1385,7 +1385,9 @@ void Plugin::EnqueueProgressEvent(PP_NaClEventType event_type, bool Plugin::OpenURLFast(const nacl::string& url, FileDownloader* downloader) { // Fast path only works for installed file URLs. - if (GetUrlScheme(url) != SCHEME_CHROME_EXTENSION) + pp::Var url_var(url); + if (nacl_interface_->GetUrlScheme(url_var.pp_var()) != + PP_SCHEME_CHROME_EXTENSION) return false; // IMPORTANT: Make sure the document can request the given URL. If we don't // check, a malicious app could probe the extension system. This enforces a @@ -1409,32 +1411,6 @@ bool Plugin::OpenURLFast(const nacl::string& url, return true; } -UrlSchemeType Plugin::GetUrlScheme(const std::string& url) { - CHECK(url_util_ != NULL); - PP_URLComponents_Dev comps; - pp::Var canonicalized = - url_util_->Canonicalize(pp::Var(url), &comps); - - if (canonicalized.is_null() || - (comps.scheme.begin == 0 && comps.scheme.len == -1)) { - // |url| was an invalid URL or has no scheme. - return SCHEME_OTHER; - } - - CHECK(comps.scheme.begin < - static_cast<int>(canonicalized.AsString().size())); - CHECK(comps.scheme.begin + comps.scheme.len < - static_cast<int>(canonicalized.AsString().size())); - - std::string scheme = canonicalized.AsString().substr(comps.scheme.begin, - comps.scheme.len); - if (scheme == kChromeExtensionUriScheme) - return SCHEME_CHROME_EXTENSION; - if (scheme == kDataUriScheme) - return SCHEME_DATA; - return SCHEME_OTHER; -} - bool Plugin::DocumentCanRequest(const std::string& url) { CHECK(url_util_ != NULL); return url_util_->DocumentCanRequest(this, pp::Var(url)); diff --git a/ppapi/native_client/src/trusted/plugin/plugin.h b/ppapi/native_client/src/trusted/plugin/plugin.h index 6801576..6d472d9 100644 --- a/ppapi/native_client/src/trusted/plugin/plugin.h +++ b/ppapi/native_client/src/trusted/plugin/plugin.h @@ -208,10 +208,6 @@ class Plugin : public pp::Instance { // descriptor. struct NaClFileInfo GetFileInfo(const nacl::string& url); - // A helper function that gets the scheme type for |url|. Uses URLUtil_Dev - // interface which this class has as a member. - UrlSchemeType GetUrlScheme(const std::string& url); - // A helper function that indicates if |url| can be requested by the document // under the same-origin policy. Strictly speaking, it may be possible for the // document to request the URL using CORS even if this function returns false. diff --git a/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c b/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c index 8423846..fbe2049 100644 --- a/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c +++ b/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c @@ -3181,6 +3181,11 @@ static const char* Pnacl_M25_PPB_NaCl_Private_GetSandboxArch(void) { return iface->GetSandboxArch(); } +static PP_UrlSchemeType Pnacl_M25_PPB_NaCl_Private_GetUrlScheme(struct PP_Var* url) { + const struct PPB_NaCl_Private_1_0 *iface = Pnacl_WrapperInfo_PPB_NaCl_Private_1_0.real_iface; + return iface->GetUrlScheme(*url); +} + /* End wrapper methods for PPB_NaCl_Private_1_0 */ /* Begin wrapper methods for PPB_NetAddress_Private_0_1 */ @@ -5069,7 +5074,8 @@ static const struct PPB_NaCl_Private_1_0 Pnacl_Wrappers_PPB_NaCl_Private_1_0 = { .ReportLoadError = (void (*)(PP_Instance instance, PP_NaClError error, PP_Bool is_installed))&Pnacl_M25_PPB_NaCl_Private_ReportLoadError, .InstanceDestroyed = (void (*)(PP_Instance instance))&Pnacl_M25_PPB_NaCl_Private_InstanceDestroyed, .NaClDebugStubEnabled = (PP_Bool (*)(void))&Pnacl_M25_PPB_NaCl_Private_NaClDebugStubEnabled, - .GetSandboxArch = (const char* (*)(void))&Pnacl_M25_PPB_NaCl_Private_GetSandboxArch + .GetSandboxArch = (const char* (*)(void))&Pnacl_M25_PPB_NaCl_Private_GetSandboxArch, + .GetUrlScheme = (PP_UrlSchemeType (*)(struct PP_Var url))&Pnacl_M25_PPB_NaCl_Private_GetUrlScheme }; static const struct PPB_NetAddress_Private_0_1 Pnacl_Wrappers_PPB_NetAddress_Private_0_1 = { |