Update V8 to version 4.6.54.
[chromium-blink-merge.git] / android_webview / renderer / aw_content_renderer_client.cc
blobe424a27135598e3b058d3a347238d8b728894d52
1 // Copyright 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 <vector>
9 #include "android_webview/common/aw_resource.h"
10 #include "android_webview/common/render_view_messages.h"
11 #include "android_webview/common/url_constants.h"
12 #include "android_webview/grit/aw_renderer_resources.h"
13 #include "android_webview/renderer/aw_content_settings_client.h"
14 #include "android_webview/renderer/aw_key_systems.h"
15 #include "android_webview/renderer/aw_message_port_client.h"
16 #include "android_webview/renderer/aw_print_web_view_helper_delegate.h"
17 #include "android_webview/renderer/aw_render_frame_ext.h"
18 #include "android_webview/renderer/aw_render_view_ext.h"
19 #include "android_webview/renderer/print_render_frame_observer.h"
20 #include "base/i18n/rtl.h"
21 #include "base/message_loop/message_loop.h"
22 #include "base/strings/string_util.h"
23 #include "base/strings/utf_string_conversions.h"
24 #include "components/autofill/content/renderer/autofill_agent.h"
25 #include "components/autofill/content/renderer/password_autofill_agent.h"
26 #include "components/printing/renderer/print_web_view_helper.h"
27 #include "components/visitedlink/renderer/visitedlink_slave.h"
28 #include "content/public/common/url_constants.h"
29 #include "content/public/renderer/render_frame.h"
30 #include "content/public/renderer/render_thread.h"
31 #include "content/public/renderer/render_view.h"
32 #include "net/base/escape.h"
33 #include "net/base/net_errors.h"
34 #include "third_party/WebKit/public/platform/WebString.h"
35 #include "third_party/WebKit/public/platform/WebURL.h"
36 #include "third_party/WebKit/public/platform/WebURLError.h"
37 #include "third_party/WebKit/public/platform/WebURLRequest.h"
38 #include "third_party/WebKit/public/web/WebFrame.h"
39 #include "third_party/WebKit/public/web/WebSecurityPolicy.h"
40 #include "ui/base/l10n/l10n_util.h"
41 #include "ui/base/resource/resource_bundle.h"
42 #include "url/gurl.h"
43 #include "url/url_constants.h"
45 using content::RenderThread;
47 namespace android_webview {
49 AwContentRendererClient::AwContentRendererClient() {
52 AwContentRendererClient::~AwContentRendererClient() {
55 void AwContentRendererClient::RenderThreadStarted() {
56 blink::WebString content_scheme(base::ASCIIToUTF16(url::kContentScheme));
57 blink::WebSecurityPolicy::registerURLSchemeAsLocal(content_scheme);
59 blink::WebString aw_scheme(
60 base::ASCIIToUTF16(android_webview::kAndroidWebViewVideoPosterScheme));
61 blink::WebSecurityPolicy::registerURLSchemeAsSecure(aw_scheme);
63 RenderThread* thread = RenderThread::Get();
65 aw_render_process_observer_.reset(new AwRenderProcessObserver);
66 thread->AddObserver(aw_render_process_observer_.get());
68 visited_link_slave_.reset(new visitedlink::VisitedLinkSlave);
69 thread->AddObserver(visited_link_slave_.get());
72 void AwContentRendererClient::RenderFrameCreated(
73 content::RenderFrame* render_frame) {
74 new AwContentSettingsClient(render_frame);
75 new PrintRenderFrameObserver(render_frame);
76 new AwRenderFrameExt(render_frame);
77 new AwMessagePortClient(render_frame);
79 // TODO(jam): when the frame tree moves into content and parent() works at
80 // RenderFrame construction, simplify this by just checking parent().
81 content::RenderFrame* parent_frame =
82 render_frame->GetRenderView()->GetMainRenderFrame();
83 if (parent_frame && parent_frame != render_frame) {
84 // Avoid any race conditions from having the browser's UI thread tell the IO
85 // thread that a subframe was created.
86 RenderThread::Get()->Send(new AwViewHostMsg_SubFrameCreated(
87 parent_frame->GetRoutingID(), render_frame->GetRoutingID()));
90 // TODO(sgurun) do not create a password autofill agent (change
91 // autofill agent to store a weakptr).
92 autofill::PasswordAutofillAgent* password_autofill_agent =
93 new autofill::PasswordAutofillAgent(render_frame);
94 new autofill::AutofillAgent(render_frame, password_autofill_agent, NULL);
97 void AwContentRendererClient::RenderViewCreated(
98 content::RenderView* render_view) {
99 AwRenderViewExt::RenderViewCreated(render_view);
101 new printing::PrintWebViewHelper(
102 render_view,
103 scoped_ptr<printing::PrintWebViewHelper::Delegate>(
104 new AwPrintWebViewHelperDelegate()));
107 bool AwContentRendererClient::HasErrorPage(int http_status_code,
108 std::string* error_domain) {
109 return http_status_code >= 400;
112 void AwContentRendererClient::GetNavigationErrorStrings(
113 content::RenderView* /* render_view */,
114 blink::WebFrame* /* frame */,
115 const blink::WebURLRequest& failed_request,
116 const blink::WebURLError& error,
117 std::string* error_html,
118 base::string16* error_description) {
119 if (error_html) {
120 std::string url =
121 net::EscapeForHTML(GURL(failed_request.url()).possibly_invalid_spec());
122 std::string err =
123 base::UTF16ToUTF8(base::StringPiece16(error.localizedDescription));
125 std::vector<std::string> replacements;
126 replacements.push_back(
127 l10n_util::GetStringUTF8(IDS_AW_WEBPAGE_NOT_AVAILABLE));
128 if (err.empty()) {
129 replacements.push_back(l10n_util::GetStringFUTF8(
130 IDS_AW_WEBPAGE_TEMPORARILY_DOWN, base::UTF8ToUTF16(url)));
131 replacements.push_back(
132 l10n_util::GetStringUTF8(IDS_AW_WEBPAGE_DOWN_SUGGESTIONS));
133 } else {
134 replacements.push_back(l10n_util::GetStringFUTF8(
135 IDS_AW_WEBPAGE_CAN_NOT_BE_LOADED, base::UTF8ToUTF16(url)));
136 replacements.push_back(err);
138 if (base::i18n::IsRTL())
139 replacements.push_back("direction: rtl;");
140 else
141 replacements.push_back("");
142 *error_html = base::ReplaceStringPlaceholders(
143 ResourceBundle::GetSharedInstance().GetRawDataResource(
144 IDR_AW_LOAD_ERROR_HTML),
145 replacements, nullptr);
147 if (error_description) {
148 if (error.localizedDescription.isEmpty())
149 *error_description = base::ASCIIToUTF16(net::ErrorToString(error.reason));
150 else
151 *error_description = error.localizedDescription;
155 unsigned long long AwContentRendererClient::VisitedLinkHash(
156 const char* canonical_url,
157 size_t length) {
158 return visited_link_slave_->ComputeURLFingerprint(canonical_url, length);
161 bool AwContentRendererClient::IsLinkVisited(unsigned long long link_hash) {
162 return visited_link_slave_->IsVisited(link_hash);
165 void AwContentRendererClient::AddKeySystems(
166 std::vector<media::KeySystemInfo>* key_systems) {
167 AwAddKeySystems(key_systems);
170 bool AwContentRendererClient::ShouldOverridePageVisibilityState(
171 const content::RenderFrame* render_frame,
172 blink::WebPageVisibilityState* override_state) {
173 // webview is always visible due to rendering requirements.
174 *override_state = blink::WebPageVisibilityStateVisible;
175 return true;
178 } // namespace android_webview