| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 933 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 944 tolower); | 944 tolower); |
| 945 } | 945 } |
| 946 | 946 |
| 947 const char* manifest_url = LookupArgument(kSrcManifestAttribute); | 947 const char* manifest_url = LookupArgument(kSrcManifestAttribute); |
| 948 if (NexeIsContentHandler()) { | 948 if (NexeIsContentHandler()) { |
| 949 // For content handlers 'src' will be the URL for the content | 949 // For content handlers 'src' will be the URL for the content |
| 950 // and 'nacl' will be the URL for the manifest. | 950 // and 'nacl' will be the URL for the manifest. |
| 951 manifest_url = LookupArgument(kNaClManifestAttribute); | 951 manifest_url = LookupArgument(kNaClManifestAttribute); |
| 952 // For content handlers the NEXE runs in the security context of the | 952 // For content handlers the NEXE runs in the security context of the |
| 953 // content it is rendering and the NEXE itself appears to be a | 953 // content it is rendering and the NEXE itself appears to be a |
| 954 // cross-origin resource stored in a Chrome extension. We request | 954 // cross-origin resource stored in a Chrome extension. |
| 955 // universal access during the NEXE load so that we can read the NEXE. | |
| 956 } | 955 } |
| 957 // Use the document URL as the base for resolving relative URLs to find the | 956 // Use the document URL as the base for resolving relative URLs to find the |
| 958 // manifest. This takes into account the setting of <base> tags that | 957 // manifest. This takes into account the setting of <base> tags that |
| 959 // precede the embed/object. | 958 // precede the embed/object. |
| 960 CHECK(url_util_ != NULL); | 959 CHECK(url_util_ != NULL); |
| 961 pp::Var base_var = url_util_->GetDocumentURL(*this); | 960 pp::Var base_var = url_util_->GetDocumentURL(*this); |
| 962 if (!base_var.is_string()) { | 961 if (!base_var.is_string()) { |
| 963 PLUGIN_PRINTF(("Plugin::Init (unable to find document url)\n")); | 962 PLUGIN_PRINTF(("Plugin::Init (unable to find document url)\n")); |
| 964 return false; | 963 return false; |
| 965 } | 964 } |
| (...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1632 program_url, | 1631 program_url, |
| 1633 translate_callback)); | 1632 translate_callback)); |
| 1634 return; | 1633 return; |
| 1635 } else { | 1634 } else { |
| 1636 pp::CompletionCallback open_callback = | 1635 pp::CompletionCallback open_callback = |
| 1637 callback_factory_.NewRequiredCallback(&Plugin::NexeFileDidOpen); | 1636 callback_factory_.NewRequiredCallback(&Plugin::NexeFileDidOpen); |
| 1638 // Will always call the callback on success or failure. | 1637 // Will always call the callback on success or failure. |
| 1639 CHECK( | 1638 CHECK( |
| 1640 nexe_downloader_.Open(program_url, | 1639 nexe_downloader_.Open(program_url, |
| 1641 DOWNLOAD_TO_FILE, | 1640 DOWNLOAD_TO_FILE, |
| 1642 NexeIsContentHandler(), | |
| 1643 open_callback, | 1641 open_callback, |
| 1644 &UpdateDownloadProgress)); | 1642 &UpdateDownloadProgress)); |
| 1645 return; | 1643 return; |
| 1646 } | 1644 } |
| 1647 } | 1645 } |
| 1648 // Failed to select the program and/or the translator. | 1646 // Failed to select the program and/or the translator. |
| 1649 ReportLoadError(error_info); | 1647 ReportLoadError(error_info); |
| 1650 } | 1648 } |
| 1651 | 1649 |
| 1652 void Plugin::RequestNaClManifest(const nacl::string& url) { | 1650 void Plugin::RequestNaClManifest(const nacl::string& url) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1674 set_nacl_ready_state(OPENED); | 1672 set_nacl_ready_state(OPENED); |
| 1675 EnqueueProgressEvent(kProgressEventLoadStart); | 1673 EnqueueProgressEvent(kProgressEventLoadStart); |
| 1676 bool is_data_uri = GetUrlScheme(nmf_resolved_url.AsString()) == SCHEME_DATA; | 1674 bool is_data_uri = GetUrlScheme(nmf_resolved_url.AsString()) == SCHEME_DATA; |
| 1677 HistogramEnumerateManifestIsDataURI(static_cast<int>(is_data_uri)); | 1675 HistogramEnumerateManifestIsDataURI(static_cast<int>(is_data_uri)); |
| 1678 if (is_data_uri) { | 1676 if (is_data_uri) { |
| 1679 pp::CompletionCallback open_callback = | 1677 pp::CompletionCallback open_callback = |
| 1680 callback_factory_.NewRequiredCallback(&Plugin::NaClManifestBufferReady); | 1678 callback_factory_.NewRequiredCallback(&Plugin::NaClManifestBufferReady); |
| 1681 // Will always call the callback on success or failure. | 1679 // Will always call the callback on success or failure. |
| 1682 CHECK(nexe_downloader_.Open(nmf_resolved_url.AsString(), | 1680 CHECK(nexe_downloader_.Open(nmf_resolved_url.AsString(), |
| 1683 DOWNLOAD_TO_BUFFER, | 1681 DOWNLOAD_TO_BUFFER, |
| 1684 NexeIsContentHandler(), | |
| 1685 open_callback, | 1682 open_callback, |
| 1686 NULL)); | 1683 NULL)); |
| 1687 } else { | 1684 } else { |
| 1688 pp::CompletionCallback open_callback = | 1685 pp::CompletionCallback open_callback = |
| 1689 callback_factory_.NewRequiredCallback(&Plugin::NaClManifestFileDidOpen); | 1686 callback_factory_.NewRequiredCallback(&Plugin::NaClManifestFileDidOpen); |
| 1690 // Will always call the callback on success or failure. | 1687 // Will always call the callback on success or failure. |
| 1691 CHECK(nexe_downloader_.Open(nmf_resolved_url.AsString(), | 1688 CHECK(nexe_downloader_.Open(nmf_resolved_url.AsString(), |
| 1692 DOWNLOAD_TO_FILE, | 1689 DOWNLOAD_TO_FILE, |
| 1693 NexeIsContentHandler(), | |
| 1694 open_callback, | 1690 open_callback, |
| 1695 NULL)); | 1691 NULL)); |
| 1696 } | 1692 } |
| 1697 } | 1693 } |
| 1698 | 1694 |
| 1699 | 1695 |
| 1700 bool Plugin::SetManifestObject(const nacl::string& manifest_json, | 1696 bool Plugin::SetManifestObject(const nacl::string& manifest_json, |
| 1701 ErrorInfo* error_info) { | 1697 ErrorInfo* error_info) { |
| 1702 PLUGIN_PRINTF(("Plugin::SetManifestObject(): manifest_json='%s'.\n", | 1698 PLUGIN_PRINTF(("Plugin::SetManifestObject(): manifest_json='%s'.\n", |
| 1703 manifest_json.c_str())); | 1699 manifest_json.c_str())); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1754 PLUGIN_PRINTF(("Plugin::GetFileDesc (url=%s)\n", url.c_str())); | 1750 PLUGIN_PRINTF(("Plugin::GetFileDesc (url=%s)\n", url.c_str())); |
| 1755 int32_t file_desc_ok_to_close = NACL_NO_FILE_DESC; | 1751 int32_t file_desc_ok_to_close = NACL_NO_FILE_DESC; |
| 1756 std::map<nacl::string, int32_t>::iterator it = url_fd_map_.find(url); | 1752 std::map<nacl::string, int32_t>::iterator it = url_fd_map_.find(url); |
| 1757 if (it != url_fd_map_.end()) | 1753 if (it != url_fd_map_.end()) |
| 1758 file_desc_ok_to_close = DUP(it->second); | 1754 file_desc_ok_to_close = DUP(it->second); |
| 1759 return file_desc_ok_to_close; | 1755 return file_desc_ok_to_close; |
| 1760 } | 1756 } |
| 1761 | 1757 |
| 1762 | 1758 |
| 1763 bool Plugin::StreamAsFile(const nacl::string& url, | 1759 bool Plugin::StreamAsFile(const nacl::string& url, |
| 1764 bool permits_extension_urls, | |
| 1765 PP_CompletionCallback callback) { | 1760 PP_CompletionCallback callback) { |
| 1766 PLUGIN_PRINTF(("Plugin::StreamAsFile (url='%s', permits_extension_urls=%d)\n", | 1761 PLUGIN_PRINTF(("Plugin::StreamAsFile (url='%s')\n", url.c_str())); |
| 1767 url.c_str(), permits_extension_urls)); | |
| 1768 FileDownloader* downloader = new FileDownloader(); | 1762 FileDownloader* downloader = new FileDownloader(); |
| 1769 downloader->Initialize(this); | 1763 downloader->Initialize(this); |
| 1770 url_downloaders_.insert(downloader); | 1764 url_downloaders_.insert(downloader); |
| 1771 pp::CompletionCallback open_callback = | 1765 pp::CompletionCallback open_callback = |
| 1772 callback_factory_.NewRequiredCallback( | 1766 callback_factory_.NewRequiredCallback( |
| 1773 &Plugin::UrlDidOpenForStreamAsFile, downloader, callback); | 1767 &Plugin::UrlDidOpenForStreamAsFile, downloader, callback); |
| 1774 // Untrusted loads are always relative to the page's origin. | 1768 // Untrusted loads are always relative to the page's origin. |
| 1775 CHECK(url_util_ != NULL); | 1769 CHECK(url_util_ != NULL); |
| 1776 pp::Var resolved_url = | 1770 pp::Var resolved_url = |
| 1777 url_util_->ResolveRelativeToURL(pp::Var(plugin_base_url()), url); | 1771 url_util_->ResolveRelativeToURL(pp::Var(plugin_base_url()), url); |
| 1778 if (!resolved_url.is_string()) { | 1772 if (!resolved_url.is_string()) { |
| 1779 PLUGIN_PRINTF(("Plugin::StreamAsFile: " | 1773 PLUGIN_PRINTF(("Plugin::StreamAsFile: " |
| 1780 "could not resolve url \"%s\" relative to plugin \"%s\".", | 1774 "could not resolve url \"%s\" relative to plugin \"%s\".", |
| 1781 url.c_str(), | 1775 url.c_str(), |
| 1782 plugin_base_url().c_str())); | 1776 plugin_base_url().c_str())); |
| 1783 return false; | 1777 return false; |
| 1784 } | 1778 } |
| 1785 // If true, will always call the callback on success or failure. | 1779 // If true, will always call the callback on success or failure. |
| 1786 return downloader->Open(url, | 1780 return downloader->Open(url, |
| 1787 DOWNLOAD_TO_FILE, | 1781 DOWNLOAD_TO_FILE, |
| 1788 permits_extension_urls || NexeIsContentHandler(), | |
| 1789 open_callback, | 1782 open_callback, |
| 1790 &UpdateDownloadProgress); | 1783 &UpdateDownloadProgress); |
| 1791 } | 1784 } |
| 1792 | 1785 |
| 1793 #ifndef HACK_FOR_MACOS_HANG_REMOVED | 1786 #ifndef HACK_FOR_MACOS_HANG_REMOVED |
| 1794 // The following is needed to avoid a plugin startup hang in the | 1787 // The following is needed to avoid a plugin startup hang in the |
| 1795 // MacOS "chrome_browser_tests under gyp" stage. | 1788 // MacOS "chrome_browser_tests under gyp" stage. |
| 1796 // TODO(sehr,mseaborn): remove this hack. | 1789 // TODO(sehr,mseaborn): remove this hack. |
| 1797 void (plugin::Plugin::*pmem)(int32_t, | 1790 void (plugin::Plugin::*pmem)(int32_t, |
| 1798 plugin::FileDownloader*&, | 1791 plugin::FileDownloader*&, |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2053 std::string scheme = canonicalized.AsString().substr(comps.scheme.begin, | 2046 std::string scheme = canonicalized.AsString().substr(comps.scheme.begin, |
| 2054 comps.scheme.len); | 2047 comps.scheme.len); |
| 2055 if (scheme == kChromeExtensionUriScheme) | 2048 if (scheme == kChromeExtensionUriScheme) |
| 2056 return SCHEME_CHROME_EXTENSION; | 2049 return SCHEME_CHROME_EXTENSION; |
| 2057 if (scheme == kDataUriScheme) | 2050 if (scheme == kDataUriScheme) |
| 2058 return SCHEME_DATA; | 2051 return SCHEME_DATA; |
| 2059 return SCHEME_OTHER; | 2052 return SCHEME_OTHER; |
| 2060 } | 2053 } |
| 2061 | 2054 |
| 2062 } // namespace plugin | 2055 } // namespace plugin |
| OLD | NEW |