1 // Copyright (c) 2013 Intel Corporation. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "xwalk/runtime/renderer/tizen/xwalk_content_renderer_client_tizen.h"
9 #include "base/files/file_path.h"
10 #include "net/base/filename_util.h"
12 #include "xwalk/application/common/constants.h"
13 #include "third_party/WebKit/public/web/WebFrame.h"
14 #include "third_party/WebKit/public/web/WebDocument.h"
20 const base::FilePath kTizenWebUiFwPath("/usr/share/tizen-web-ui-fw/");
21 const std::string kTizenWebUiFw = "/tizen-web-ui-fw/";
23 bool HasKnownExtension(const base::FilePath& path) {
24 if (path.MatchesExtension(".js"))
26 if (path.MatchesExtension(".css"))
28 if (path.MatchesExtension(".png"))
33 size_t GetRootPathLength(const GURL& first_party_for_cookies) {
34 const std::string& path = first_party_for_cookies.PathForRequest();
35 return path.rfind('/');
38 bool URLHasAppOrFileScheme(const GURL& url) {
39 if (url.SchemeIs("app"))
41 if (url.SchemeIsFile())
48 bool XWalkContentRendererClientTizen::WillSendRequest(
49 blink::WebFrame* frame, content::PageTransition transition_type,
50 const GURL& url, const GURL& first_party_for_cookies, GURL* new_url) {
53 if (XWalkContentRendererClient::WillSendRequest(
54 frame, transition_type, url, first_party_for_cookies, new_url))
57 if (!URLHasAppOrFileScheme(first_party_for_cookies))
60 const size_t root_path_length = GetRootPathLength(first_party_for_cookies);
61 if (root_path_length == std::string::npos)
64 const std::string& relative_path = url.path();
65 size_t tizen_web_ui_fw_pos = relative_path.find(kTizenWebUiFw,
67 if (tizen_web_ui_fw_pos == std::string::npos)
70 tizen_web_ui_fw_pos += kTizenWebUiFw.length();
71 const base::FilePath& resource_path = kTizenWebUiFwPath.Append(
72 relative_path.substr(tizen_web_ui_fw_pos));
74 // FIXME(leandro): base::NormalizeFilePath(resource_path) should be called
75 // here to make sure files are really beneath kTizenWebUiFwPath, but the
76 // sandbox prevents the Render process from calling realpath().
77 if (!kTizenWebUiFwPath.IsParent(resource_path))
80 if (!HasKnownExtension(resource_path))
83 GURL replacement_url = net::FilePathToFileURL(resource_path);
84 if (!replacement_url.is_valid())
87 new_url->Swap(&replacement_url);