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 "base/strings/stringprintf.h"
11 #include "net/base/filename_util.h"
12 #include "net/base/net_errors.h"
14 #include "xwalk/application/common/constants.h"
15 #include "third_party/WebKit/public/platform/WebURLError.h"
16 #include "third_party/WebKit/public/web/WebFrame.h"
17 #include "third_party/WebKit/public/web/WebDocument.h"
23 const base::FilePath kTizenWebUiFwPath("/usr/share/tizen-web-ui-fw/");
24 const std::string kTizenWebUiFw = "/tizen-web-ui-fw/";
26 bool HasKnownExtension(const base::FilePath& path) {
27 if (path.MatchesExtension(".js"))
29 if (path.MatchesExtension(".css"))
31 if (path.MatchesExtension(".png"))
36 size_t GetRootPathLength(const GURL& first_party_for_cookies) {
37 const std::string& path = first_party_for_cookies.PathForRequest();
38 return path.rfind('/');
41 bool URLHasAppOrFileScheme(const GURL& url) {
42 if (url.SchemeIs("app"))
44 if (url.SchemeIsFile())
51 bool XWalkContentRendererClientTizen::WillSendRequest(
52 blink::WebFrame* frame, content::PageTransition transition_type,
53 const GURL& url, const GURL& first_party_for_cookies, GURL* new_url) {
56 if (XWalkContentRendererClient::WillSendRequest(
57 frame, transition_type, url, first_party_for_cookies, new_url))
60 if (!URLHasAppOrFileScheme(first_party_for_cookies))
63 const size_t root_path_length = GetRootPathLength(first_party_for_cookies);
64 if (root_path_length == std::string::npos)
67 const std::string& relative_path = url.path();
68 size_t tizen_web_ui_fw_pos = relative_path.find(kTizenWebUiFw,
70 if (tizen_web_ui_fw_pos == std::string::npos)
73 tizen_web_ui_fw_pos += kTizenWebUiFw.length();
74 const base::FilePath& resource_path = kTizenWebUiFwPath.Append(
75 relative_path.substr(tizen_web_ui_fw_pos));
77 // FIXME(leandro): base::NormalizeFilePath(resource_path) should be called
78 // here to make sure files are really beneath kTizenWebUiFwPath, but the
79 // sandbox prevents the Render process from calling realpath().
80 if (!kTizenWebUiFwPath.IsParent(resource_path))
83 if (!HasKnownExtension(resource_path))
86 GURL replacement_url = net::FilePathToFileURL(resource_path);
87 if (!replacement_url.is_valid())
90 new_url->Swap(&replacement_url);
94 bool XWalkContentRendererClientTizen::HasErrorPage(int http_status_code,
95 std::string* error_domain) {
99 void XWalkContentRendererClientTizen::GetNavigationErrorStrings(
100 content::RenderView* render_view,
101 blink::WebFrame* frame,
102 const blink::WebURLRequest& failed_request,
103 const blink::WebURLError& error,
104 std::string* error_html,
105 base::string16* error_description) {
108 base::StringPrintf("<html><body style=\"text-align: center;\">"
109 "<h1>NET ERROR : %s</h1></body></html>",
110 net::ErrorToString(error.reason).c_str());