Fix mouse warp with 2x displays
[chromium-blink-merge.git] / android_webview / renderer / aw_content_renderer_client.cc
blobf1ccc5d9331defe26d68da50811dd0cb2dd8f83e
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 "android_webview/common/aw_resource.h"
8 #include "android_webview/common/render_view_messages.h"
9 #include "android_webview/common/url_constants.h"
10 #include "android_webview/renderer/aw_content_settings_client.h"
11 #include "android_webview/renderer/aw_key_systems.h"
12 #include "android_webview/renderer/aw_message_port_client.h"
13 #include "android_webview/renderer/aw_print_web_view_helper_delegate.h"
14 #include "android_webview/renderer/aw_render_frame_ext.h"
15 #include "android_webview/renderer/aw_render_view_ext.h"
16 #include "android_webview/renderer/print_render_frame_observer.h"
17 #include "base/message_loop/message_loop.h"
18 #include "base/strings/utf_string_conversions.h"
19 #include "components/autofill/content/renderer/autofill_agent.h"
20 #include "components/autofill/content/renderer/password_autofill_agent.h"
21 #include "components/printing/renderer/print_web_view_helper.h"
22 #include "components/visitedlink/renderer/visitedlink_slave.h"
23 #include "content/public/common/url_constants.h"
24 #include "content/public/renderer/render_frame.h"
25 #include "content/public/renderer/render_thread.h"
26 #include "content/public/renderer/render_view.h"
27 #include "net/base/escape.h"
28 #include "net/base/net_errors.h"
29 #include "third_party/WebKit/public/platform/WebString.h"
30 #include "third_party/WebKit/public/platform/WebURL.h"
31 #include "third_party/WebKit/public/platform/WebURLError.h"
32 #include "third_party/WebKit/public/platform/WebURLRequest.h"
33 #include "third_party/WebKit/public/web/WebFrame.h"
34 #include "third_party/WebKit/public/web/WebSecurityPolicy.h"
35 #include "url/gurl.h"
37 using content::RenderThread;
39 namespace android_webview {
41 AwContentRendererClient::AwContentRendererClient() {
44 AwContentRendererClient::~AwContentRendererClient() {
47 void AwContentRendererClient::RenderThreadStarted() {
48 blink::WebString content_scheme(
49 base::ASCIIToUTF16(android_webview::kContentScheme));
50 blink::WebSecurityPolicy::registerURLSchemeAsLocal(content_scheme);
52 blink::WebString aw_scheme(
53 base::ASCIIToUTF16(android_webview::kAndroidWebViewVideoPosterScheme));
54 blink::WebSecurityPolicy::registerURLSchemeAsSecure(aw_scheme);
56 RenderThread* thread = RenderThread::Get();
58 aw_render_process_observer_.reset(new AwRenderProcessObserver);
59 thread->AddObserver(aw_render_process_observer_.get());
61 visited_link_slave_.reset(new visitedlink::VisitedLinkSlave);
62 thread->AddObserver(visited_link_slave_.get());
65 void AwContentRendererClient::RenderFrameCreated(
66 content::RenderFrame* render_frame) {
67 new AwContentSettingsClient(render_frame);
68 new PrintRenderFrameObserver(render_frame);
69 new AwRenderFrameExt(render_frame);
70 new AwMessagePortClient(render_frame);
72 // TODO(jam): when the frame tree moves into content and parent() works at
73 // RenderFrame construction, simplify this by just checking parent().
74 content::RenderFrame* parent_frame =
75 render_frame->GetRenderView()->GetMainRenderFrame();
76 if (parent_frame && parent_frame != render_frame) {
77 // Avoid any race conditions from having the browser's UI thread tell the IO
78 // thread that a subframe was created.
79 RenderThread::Get()->Send(new AwViewHostMsg_SubFrameCreated(
80 parent_frame->GetRoutingID(), render_frame->GetRoutingID()));
83 // TODO(sgurun) do not create a password autofill agent (change
84 // autofill agent to store a weakptr).
85 autofill::PasswordAutofillAgent* password_autofill_agent =
86 new autofill::PasswordAutofillAgent(render_frame);
87 new autofill::AutofillAgent(render_frame, password_autofill_agent, NULL);
90 void AwContentRendererClient::RenderViewCreated(
91 content::RenderView* render_view) {
92 AwRenderViewExt::RenderViewCreated(render_view);
94 new printing::PrintWebViewHelper(
95 render_view,
96 scoped_ptr<printing::PrintWebViewHelper::Delegate>(
97 new AwPrintWebViewHelperDelegate()));
100 bool AwContentRendererClient::HasErrorPage(int http_status_code,
101 std::string* error_domain) {
102 return http_status_code >= 400;
105 void AwContentRendererClient::GetNavigationErrorStrings(
106 content::RenderView* /* render_view */,
107 blink::WebFrame* /* frame */,
108 const blink::WebURLRequest& failed_request,
109 const blink::WebURLError& error,
110 std::string* error_html,
111 base::string16* error_description) {
112 if (error_html) {
113 GURL error_url(failed_request.url());
114 std::string err =
115 base::UTF16ToUTF8(base::StringPiece16(error.localizedDescription));
116 std::string contents;
117 if (err.empty()) {
118 contents = AwResource::GetNoDomainPageContent();
119 } else {
120 contents = AwResource::GetLoadErrorPageContent();
121 base::ReplaceSubstringsAfterOffset(&contents, 0, "%e", err);
124 base::ReplaceSubstringsAfterOffset(&contents, 0, "%s",
125 net::EscapeForHTML(error_url.possibly_invalid_spec()));
126 *error_html = contents;
128 if (error_description) {
129 if (error.localizedDescription.isEmpty())
130 *error_description = base::ASCIIToUTF16(net::ErrorToString(error.reason));
131 else
132 *error_description = error.localizedDescription;
136 unsigned long long AwContentRendererClient::VisitedLinkHash(
137 const char* canonical_url,
138 size_t length) {
139 return visited_link_slave_->ComputeURLFingerprint(canonical_url, length);
142 bool AwContentRendererClient::IsLinkVisited(unsigned long long link_hash) {
143 return visited_link_slave_->IsVisited(link_hash);
146 void AwContentRendererClient::AddKeySystems(
147 std::vector<media::KeySystemInfo>* key_systems) {
148 AwAddKeySystems(key_systems);
151 bool AwContentRendererClient::ShouldOverridePageVisibilityState(
152 const content::RenderFrame* render_frame,
153 blink::WebPageVisibilityState* override_state) {
154 // webview is always visible due to rendering requirements.
155 *override_state = blink::WebPageVisibilityStateVisible;
156 return true;
159 } // namespace android_webview