OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifdef _MSC_VER | 5 #ifdef _MSC_VER |
6 // Do not warn about use of std::copy with raw pointers. | 6 // Do not warn about use of std::copy with raw pointers. |
7 #pragma warning(disable : 4996) | 7 #pragma warning(disable : 4996) |
8 #endif | 8 #endif |
9 | 9 |
10 #include "native_client/src/trusted/plugin/plugin.h" | 10 #include "native_client/src/trusted/plugin/plugin.h" |
(...skipping 848 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
859 // destroyed. | 859 // destroyed. |
860 const char* event_type_; | 860 const char* event_type_; |
861 nacl::string url_; | 861 nacl::string url_; |
862 Plugin::LengthComputable length_computable_; | 862 Plugin::LengthComputable length_computable_; |
863 uint64_t loaded_bytes_; | 863 uint64_t loaded_bytes_; |
864 uint64_t total_bytes_; | 864 uint64_t total_bytes_; |
865 }; | 865 }; |
866 | 866 |
867 const char* const Plugin::kNaClMIMEType = "application/x-nacl"; | 867 const char* const Plugin::kNaClMIMEType = "application/x-nacl"; |
868 | 868 |
869 bool Plugin::IsForeignMIMEType() const { | 869 bool Plugin::NexeIsContentHandler() const { |
| 870 // Tests if the MIME type is not a NaCl MIME type. |
| 871 // If the MIME type is foreign, then this NEXE is being used as a content |
| 872 // type handler rather than directly by an HTML document. |
870 return | 873 return |
871 !mime_type().empty() && | 874 !mime_type().empty() && |
872 mime_type() != kNaClMIMEType; | 875 mime_type() != kNaClMIMEType; |
873 } | 876 } |
874 | 877 |
875 | 878 |
876 Plugin* Plugin::New(PP_Instance pp_instance) { | 879 Plugin* Plugin::New(PP_Instance pp_instance) { |
877 PLUGIN_PRINTF(("Plugin::New (pp_instance=%"NACL_PRId32")\n", pp_instance)); | 880 PLUGIN_PRINTF(("Plugin::New (pp_instance=%"NACL_PRId32")\n", pp_instance)); |
878 #if NACL_WINDOWS && !defined(NACL_STANDALONE) | 881 #if NACL_WINDOWS && !defined(NACL_STANDALONE) |
879 if (!NaClHandlePassBrowserCtor()) { | 882 if (!NaClHandlePassBrowserCtor()) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
929 enable_dev_interfaces_ = (dev_settings != NULL); | 932 enable_dev_interfaces_ = (dev_settings != NULL); |
930 | 933 |
931 const char* type_attr = LookupArgument(kTypeAttribute); | 934 const char* type_attr = LookupArgument(kTypeAttribute); |
932 if (type_attr != NULL) { | 935 if (type_attr != NULL) { |
933 mime_type_ = nacl::string(type_attr); | 936 mime_type_ = nacl::string(type_attr); |
934 std::transform(mime_type_.begin(), mime_type_.end(), mime_type_.begin(), | 937 std::transform(mime_type_.begin(), mime_type_.end(), mime_type_.begin(), |
935 tolower); | 938 tolower); |
936 } | 939 } |
937 | 940 |
938 const char* manifest_url = LookupArgument(kSrcManifestAttribute); | 941 const char* manifest_url = LookupArgument(kSrcManifestAttribute); |
939 // If the MIME type is foreign, then 'src' will be the URL for the content | 942 if (NexeIsContentHandler()) { |
940 // and 'nacl' will be the URL for the manifest. | 943 // For content handlers 'src' will be the URL for the content |
941 if (IsForeignMIMEType()) { | 944 // and 'nacl' will be the URL for the manifest. |
942 manifest_url = LookupArgument(kNaClManifestAttribute); | 945 manifest_url = LookupArgument(kNaClManifestAttribute); |
| 946 // For content handlers the NEXE runs in the security context of the |
| 947 // content it is rendering and the NEXE itself appears to be a |
| 948 // cross-origin resource stored in a Chrome extension. We request |
| 949 // universal access during the NEXE load so that we can read the NEXE. |
943 } | 950 } |
944 // Use the document URL as the base for resolving relative URLs to find the | 951 // Use the document URL as the base for resolving relative URLs to find the |
945 // manifest. This takes into account the setting of <base> tags that | 952 // manifest. This takes into account the setting of <base> tags that |
946 // precede the embed/object. | 953 // precede the embed/object. |
947 CHECK(url_util_ != NULL); | 954 CHECK(url_util_ != NULL); |
948 pp::Var base_var = url_util_->GetDocumentURL(*this); | 955 pp::Var base_var = url_util_->GetDocumentURL(*this); |
949 if (!base_var.is_string()) { | 956 if (!base_var.is_string()) { |
950 PLUGIN_PRINTF(("Plugin::Init (unable to find document url)\n")); | 957 PLUGIN_PRINTF(("Plugin::Init (unable to find document url)\n")); |
951 return false; | 958 return false; |
952 } | 959 } |
(...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1629 program_url, | 1636 program_url, |
1630 translate_callback)); | 1637 translate_callback)); |
1631 return; | 1638 return; |
1632 } else { | 1639 } else { |
1633 pp::CompletionCallback open_callback = | 1640 pp::CompletionCallback open_callback = |
1634 callback_factory_.NewRequiredCallback(&Plugin::NexeFileDidOpen); | 1641 callback_factory_.NewRequiredCallback(&Plugin::NexeFileDidOpen); |
1635 // Will always call the callback on success or failure. | 1642 // Will always call the callback on success or failure. |
1636 CHECK( | 1643 CHECK( |
1637 nexe_downloader_.Open(program_url, | 1644 nexe_downloader_.Open(program_url, |
1638 DOWNLOAD_TO_FILE, | 1645 DOWNLOAD_TO_FILE, |
| 1646 NexeIsContentHandler(), |
1639 open_callback, | 1647 open_callback, |
1640 &UpdateDownloadProgress)); | 1648 &UpdateDownloadProgress)); |
1641 return; | 1649 return; |
1642 } | 1650 } |
1643 } | 1651 } |
1644 // Failed to select the program and/or the translator. | 1652 // Failed to select the program and/or the translator. |
1645 ReportLoadError(error_info); | 1653 ReportLoadError(error_info); |
1646 } | 1654 } |
1647 | 1655 |
1648 void Plugin::RequestNaClManifest(const nacl::string& url) { | 1656 void Plugin::RequestNaClManifest(const nacl::string& url) { |
(...skipping 21 matching lines...) Expand all Loading... |
1670 set_nacl_ready_state(OPENED); | 1678 set_nacl_ready_state(OPENED); |
1671 EnqueueProgressEvent(kProgressEventLoadStart); | 1679 EnqueueProgressEvent(kProgressEventLoadStart); |
1672 bool is_data_uri = GetUrlScheme(nmf_resolved_url.AsString()) == SCHEME_DATA; | 1680 bool is_data_uri = GetUrlScheme(nmf_resolved_url.AsString()) == SCHEME_DATA; |
1673 HistogramEnumerateManifestIsDataURI(static_cast<int>(is_data_uri)); | 1681 HistogramEnumerateManifestIsDataURI(static_cast<int>(is_data_uri)); |
1674 if (is_data_uri) { | 1682 if (is_data_uri) { |
1675 pp::CompletionCallback open_callback = | 1683 pp::CompletionCallback open_callback = |
1676 callback_factory_.NewRequiredCallback(&Plugin::NaClManifestBufferReady); | 1684 callback_factory_.NewRequiredCallback(&Plugin::NaClManifestBufferReady); |
1677 // Will always call the callback on success or failure. | 1685 // Will always call the callback on success or failure. |
1678 CHECK(nexe_downloader_.Open(nmf_resolved_url.AsString(), | 1686 CHECK(nexe_downloader_.Open(nmf_resolved_url.AsString(), |
1679 DOWNLOAD_TO_BUFFER, | 1687 DOWNLOAD_TO_BUFFER, |
| 1688 NexeIsContentHandler(), |
1680 open_callback, | 1689 open_callback, |
1681 NULL)); | 1690 NULL)); |
1682 } else { | 1691 } else { |
1683 pp::CompletionCallback open_callback = | 1692 pp::CompletionCallback open_callback = |
1684 callback_factory_.NewRequiredCallback(&Plugin::NaClManifestFileDidOpen); | 1693 callback_factory_.NewRequiredCallback(&Plugin::NaClManifestFileDidOpen); |
1685 // Will always call the callback on success or failure. | 1694 // Will always call the callback on success or failure. |
1686 CHECK(nexe_downloader_.Open(nmf_resolved_url.AsString(), | 1695 CHECK(nexe_downloader_.Open(nmf_resolved_url.AsString(), |
1687 DOWNLOAD_TO_FILE, | 1696 DOWNLOAD_TO_FILE, |
| 1697 NexeIsContentHandler(), |
1688 open_callback, | 1698 open_callback, |
1689 NULL)); | 1699 NULL)); |
1690 } | 1700 } |
1691 } | 1701 } |
1692 | 1702 |
1693 | 1703 |
1694 bool Plugin::SetManifestObject(const nacl::string& manifest_json, | 1704 bool Plugin::SetManifestObject(const nacl::string& manifest_json, |
1695 ErrorInfo* error_info) { | 1705 ErrorInfo* error_info) { |
1696 PLUGIN_PRINTF(("Plugin::SetManifestObject(): manifest_json='%s'.\n", | 1706 PLUGIN_PRINTF(("Plugin::SetManifestObject(): manifest_json='%s'.\n", |
1697 manifest_json.c_str())); | 1707 manifest_json.c_str())); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1748 PLUGIN_PRINTF(("Plugin::GetFileDesc (url=%s)\n", url.c_str())); | 1758 PLUGIN_PRINTF(("Plugin::GetFileDesc (url=%s)\n", url.c_str())); |
1749 int32_t file_desc_ok_to_close = NACL_NO_FILE_DESC; | 1759 int32_t file_desc_ok_to_close = NACL_NO_FILE_DESC; |
1750 std::map<nacl::string, int32_t>::iterator it = url_fd_map_.find(url); | 1760 std::map<nacl::string, int32_t>::iterator it = url_fd_map_.find(url); |
1751 if (it != url_fd_map_.end()) | 1761 if (it != url_fd_map_.end()) |
1752 file_desc_ok_to_close = DUP(it->second); | 1762 file_desc_ok_to_close = DUP(it->second); |
1753 return file_desc_ok_to_close; | 1763 return file_desc_ok_to_close; |
1754 } | 1764 } |
1755 | 1765 |
1756 | 1766 |
1757 bool Plugin::StreamAsFile(const nacl::string& url, | 1767 bool Plugin::StreamAsFile(const nacl::string& url, |
| 1768 bool permits_extension_urls, |
1758 PP_CompletionCallback callback) { | 1769 PP_CompletionCallback callback) { |
1759 PLUGIN_PRINTF(("Plugin::StreamAsFile (url='%s')\n", url.c_str())); | 1770 PLUGIN_PRINTF(("Plugin::StreamAsFile (url='%s', permits_extension_urls=%d)\n", |
| 1771 url.c_str(), permits_extension_urls)); |
1760 FileDownloader* downloader = new FileDownloader(); | 1772 FileDownloader* downloader = new FileDownloader(); |
1761 downloader->Initialize(this); | 1773 downloader->Initialize(this); |
1762 url_downloaders_.insert(downloader); | 1774 url_downloaders_.insert(downloader); |
1763 pp::CompletionCallback open_callback = | 1775 pp::CompletionCallback open_callback = |
1764 callback_factory_.NewRequiredCallback( | 1776 callback_factory_.NewRequiredCallback( |
1765 &Plugin::UrlDidOpenForStreamAsFile, downloader, callback); | 1777 &Plugin::UrlDidOpenForStreamAsFile, downloader, callback); |
1766 // Untrusted loads are always relative to the page's origin. | 1778 // Untrusted loads are always relative to the page's origin. |
1767 CHECK(url_util_ != NULL); | 1779 CHECK(url_util_ != NULL); |
1768 pp::Var resolved_url = | 1780 pp::Var resolved_url = |
1769 url_util_->ResolveRelativeToURL(pp::Var(plugin_base_url()), url); | 1781 url_util_->ResolveRelativeToURL(pp::Var(plugin_base_url()), url); |
1770 if (!resolved_url.is_string()) { | 1782 if (!resolved_url.is_string()) { |
1771 PLUGIN_PRINTF(("Plugin::StreamAsFile: " | 1783 PLUGIN_PRINTF(("Plugin::StreamAsFile: " |
1772 "could not resolve url \"%s\" relative to plugin \"%s\".", | 1784 "could not resolve url \"%s\" relative to plugin \"%s\".", |
1773 url.c_str(), | 1785 url.c_str(), |
1774 plugin_base_url().c_str())); | 1786 plugin_base_url().c_str())); |
1775 return false; | 1787 return false; |
1776 } | 1788 } |
1777 // If true, will always call the callback on success or failure. | 1789 // If true, will always call the callback on success or failure. |
1778 return downloader->Open(url, | 1790 return downloader->Open(url, |
1779 DOWNLOAD_TO_FILE, | 1791 DOWNLOAD_TO_FILE, |
| 1792 permits_extension_urls || NexeIsContentHandler(), |
1780 open_callback, | 1793 open_callback, |
1781 &UpdateDownloadProgress); | 1794 &UpdateDownloadProgress); |
1782 } | 1795 } |
1783 | 1796 |
1784 #ifndef HACK_FOR_MACOS_HANG_REMOVED | 1797 #ifndef HACK_FOR_MACOS_HANG_REMOVED |
1785 // The following is needed to avoid a plugin startup hang in the | 1798 // The following is needed to avoid a plugin startup hang in the |
1786 // MacOS "chrome_browser_tests under gyp" stage. | 1799 // MacOS "chrome_browser_tests under gyp" stage. |
1787 // TODO(sehr,mseaborn): remove this hack. | 1800 // TODO(sehr,mseaborn): remove this hack. |
1788 void (plugin::Plugin::*pmem)(int32_t, | 1801 void (plugin::Plugin::*pmem)(int32_t, |
1789 plugin::FileDownloader*&, | 1802 plugin::FileDownloader*&, |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2044 std::string scheme = canonicalized.AsString().substr(comps.scheme.begin, | 2057 std::string scheme = canonicalized.AsString().substr(comps.scheme.begin, |
2045 comps.scheme.len); | 2058 comps.scheme.len); |
2046 if (scheme == kChromeExtensionUriScheme) | 2059 if (scheme == kChromeExtensionUriScheme) |
2047 return SCHEME_CHROME_EXTENSION; | 2060 return SCHEME_CHROME_EXTENSION; |
2048 if (scheme == kDataUriScheme) | 2061 if (scheme == kDataUriScheme) |
2049 return SCHEME_DATA; | 2062 return SCHEME_DATA; |
2050 return SCHEME_OTHER; | 2063 return SCHEME_OTHER; |
2051 } | 2064 } |
2052 | 2065 |
2053 } // namespace plugin | 2066 } // namespace plugin |
OLD | NEW |