1 // Copyright (c) 2013 Intel Corporation. All rights reserved.
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
6 #include "xwalk/runtime/renderer/tizen/xwalk_content_renderer_client_tizen.h"
10 #include "base/files/file_path.h"
11 #include "base/strings/stringprintf.h"
12 #include "net/base/filename_util.h"
13 #include "net/base/net_errors.h"
15 #include "xwalk/application/common/constants.h"
16 #include "third_party/WebKit/public/platform/WebURLError.h"
17 #include "third_party/WebKit/public/web/WebFrame.h"
18 #include "third_party/WebKit/public/web/WebDocument.h"
24 const base::FilePath kTizenWebUiFwPath("/usr/share/tizen-web-ui-fw/");
25 const std::string kTizenWebUiFw = "/tizen-web-ui-fw/";
27 bool HasKnownExtension(const base::FilePath& path) {
28 if (path.MatchesExtension(".js"))
30 if (path.MatchesExtension(".css"))
32 if (path.MatchesExtension(".png"))
37 size_t GetRootPathLength(const GURL& first_party_for_cookies) {
38 const std::string& path = first_party_for_cookies.PathForRequest();
39 return path.rfind('/');
42 bool URLHasAppOrFileScheme(const GURL& url) {
43 if (url.SchemeIs("app"))
45 if (url.SchemeIsFile())
52 bool XWalkContentRendererClientTizen::WillSendRequest(
53 blink::WebFrame* frame, content::PageTransition transition_type,
54 const GURL& url, const GURL& first_party_for_cookies, GURL* new_url) {
57 if (XWalkContentRendererClient::WillSendRequest(
58 frame, transition_type, url, first_party_for_cookies, new_url))
61 if (!URLHasAppOrFileScheme(first_party_for_cookies))
64 const size_t root_path_length = GetRootPathLength(first_party_for_cookies);
65 if (root_path_length == std::string::npos)
68 const std::string& relative_path = url.path();
69 size_t tizen_web_ui_fw_pos = relative_path.find(kTizenWebUiFw,
71 if (tizen_web_ui_fw_pos == std::string::npos)
74 tizen_web_ui_fw_pos += kTizenWebUiFw.length();
75 const base::FilePath& resource_path = kTizenWebUiFwPath.Append(
76 relative_path.substr(tizen_web_ui_fw_pos));
78 // FIXME(leandro): base::NormalizeFilePath(resource_path) should be called
79 // here to make sure files are really beneath kTizenWebUiFwPath, but the
80 // sandbox prevents the Render process from calling realpath().
81 if (!kTizenWebUiFwPath.IsParent(resource_path))
84 if (!HasKnownExtension(resource_path))
87 GURL replacement_url = net::FilePathToFileURL(resource_path);
88 if (!replacement_url.is_valid())
91 new_url->Swap(&replacement_url);
95 bool XWalkContentRendererClientTizen::HasErrorPage(int http_status_code,
96 std::string* error_domain) {
100 void XWalkContentRendererClientTizen::GetNavigationErrorStrings(
101 content::RenderView* render_view,
102 blink::WebFrame* frame,
103 const blink::WebURLRequest& failed_request,
104 const blink::WebURLError& error,
105 std::string* error_html,
106 base::string16* error_description) {
109 base::StringPrintf("<html><body style=\"text-align: center;\">"
110 "<h1>NET ERROR : %s</h1></body></html>",
111 net::ErrorToString(error.reason).c_str());
115 std::string XWalkContentRendererClientTizen::GetOverridenUserAgent() const {
116 if (!xwalk_render_process_observer_)
118 return xwalk_render_process_observer_->GetOverridenUserAgent();