fix a pdf-viewer's parsing logic, and this should resolve the related issue at https://github.com/electron/electron/issues/10007

This commit is contained in:
Boik 2017-07-14 12:09:14 +08:00
parent 1d32f300f3
commit 9a7651a93f
2 changed files with 11 additions and 2 deletions

View file

@ -86,9 +86,10 @@ void OnPdfResourceIntercepted(
// The URL passes the original pdf resource url, that will be requested
// by the webui page.
// chrome://pdf-viewer/index.html?src=https://somepage/123.pdf
GURL escaped_url(net::EscapeUrlEncodedData(original_url.spec(), true));
content::NavigationController::LoadURLParams params(
GURL(base::StringPrintf("%sindex.html?%s=%s", kPdfViewerUIOrigin,
kPdfPluginSrc, original_url.spec().c_str())));
kPdfPluginSrc, escaped_url.spec().c_str())));
web_contents->GetController().LoadURLWithParams(params);
}

View file

@ -11,6 +11,7 @@
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "content/public/browser/web_contents.h"
#include "net/base/escape.h"
namespace atom {
@ -52,9 +53,16 @@ AtomWebUIControllerFactory::CreateWebUIControllerForURL(content::WebUI* web_ui,
base::StringPairs toplevel_params;
base::SplitStringIntoKeyValuePairs(url.query(), '=', '&', &toplevel_params);
std::string stream_id, src;
const net::UnescapeRule::Type unescape_rules =
net::UnescapeRule::SPOOFING_AND_CONTROL_CHARS |
net::UnescapeRule::SPACES | net::UnescapeRule::PATH_SEPARATORS |
net::UnescapeRule::URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS |
net::UnescapeRule::NORMAL | net::UnescapeRule::REPLACE_PLUS_WITH_SPACE;
for (const auto& param : toplevel_params) {
if (param.first == kPdfPluginSrc) {
src = param.second;
src = net::UnescapeURLComponent(param.second, unescape_rules);
}
}
if (url.has_ref()) {