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
3 // found in the LICENSE file.
5 #include "android_webview/renderer/aw_content_renderer_client.h"
7 #include "android_webview/common/aw_resource.h"
8 #include "android_webview/common/url_constants.h"
9 #include "android_webview/renderer/aw_render_view_ext.h"
10 #include "base/utf_string_conversions.h"
11 #include "content/public/renderer/render_thread.h"
12 #include "googleurl/src/gurl.h"
13 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
14 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLError.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRequest.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
19 namespace android_webview
{
21 AwContentRendererClient::AwContentRendererClient() {
24 AwContentRendererClient::~AwContentRendererClient() {
27 void AwContentRendererClient::RenderThreadStarted() {
28 WebKit::WebString
content_scheme(
29 ASCIIToUTF16(android_webview::kContentScheme
));
30 WebKit::WebSecurityPolicy::registerURLSchemeAsLocal(content_scheme
);
32 aw_render_process_observer_
.reset(new AwRenderProcessObserver
);
33 content::RenderThread::Get()->AddObserver(
34 aw_render_process_observer_
.get());
37 void AwContentRendererClient::RenderViewCreated(
38 content::RenderView
* render_view
) {
39 AwRenderViewExt::RenderViewCreated(render_view
);
42 std::string
AwContentRendererClient::GetDefaultEncoding() {
43 return AwResource::GetDefaultTextEncoding();
46 WebKit::WebPlugin
* AwContentRendererClient::CreatePluginReplacement(
47 content::RenderView
* render_view
,
48 const FilePath
& plugin_path
) {
49 // TODO(boliu): Call WebViewPlugin::Create with appropriate html for missing
50 // plugin placeholder.
54 bool AwContentRendererClient::HasErrorPage(int http_status_code
,
55 std::string
* error_domain
) {
56 return http_status_code
>= 400;
59 void AwContentRendererClient::GetNavigationErrorStrings(
60 const WebKit::WebURLRequest
& failed_request
,
61 const WebKit::WebURLError
& error
,
62 std::string
* error_html
,
63 string16
* error_description
) {
65 GURL
error_url(failed_request
.url());
66 std::string err
= UTF16ToUTF8(error
.localizedDescription
);
69 contents
= AwResource::GetNoDomainPageContent();
71 contents
= AwResource::GetLoadErrorPageContent();
72 ReplaceSubstringsAfterOffset(&contents
, 0, "%e", err
);
75 ReplaceSubstringsAfterOffset(&contents
, 0, "%s",
76 error_url
.possibly_invalid_spec());
77 *error_html
= contents
;
81 unsigned long long AwContentRendererClient::VisitedLinkHash(
82 const char* canonical_url
,
84 // TODO(boliu): Implement a visited link solution for Android WebView.
85 // Perhaps componentize chrome implementation or move to content/?
89 bool AwContentRendererClient::IsLinkVisited(unsigned long long link_hash
) {
90 // TODO(boliu): Implement a visited link solution for Android WebView.
91 // Perhaps componentize chrome implementation or move to content/?
95 void AwContentRendererClient::PrefetchHostName(const char* hostname
,
97 // TODO(boliu): Implement hostname prefetch for Android WebView.
98 // Perhaps componentize chrome implementation or move to content/?
101 } // namespace android_webview