OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "android_webview/native/aw_settings.h" | 5 #include "android_webview/native/aw_settings.h" |
6 | 6 |
7 #include "android_webview/browser/renderer_host/aw_render_view_host_ext.h" | 7 #include "android_webview/browser/renderer_host/aw_render_view_host_ext.h" |
8 #include "android_webview/native/aw_contents.h" | 8 #include "android_webview/native/aw_contents.h" |
| 9 #include "content/public/browser/render_view_host.h" |
| 10 #include "content/public/browser/web_contents.h" |
9 #include "jni/AwSettings_jni.h" | 11 #include "jni/AwSettings_jni.h" |
10 #include "webkit/glue/webkit_glue.h" | 12 #include "webkit/glue/webkit_glue.h" |
11 | 13 |
12 namespace android_webview { | 14 namespace android_webview { |
13 | 15 |
14 AwSettings::AwSettings(JNIEnv* env, jobject obj) | 16 AwSettings::AwSettings(JNIEnv* env, jobject obj) |
15 : java_ref_(env, obj), | 17 : java_ref_(env, obj), |
16 initial_page_scale_percent_(0), | 18 initial_page_scale_percent_(0), |
17 text_zoom_percent_(100) { | 19 text_zoom_percent_(100) { |
18 } | 20 } |
(...skipping 24 matching lines...) Expand all Loading... |
43 initial_page_scale_percent_ = page_scale_percent; | 45 initial_page_scale_percent_ = page_scale_percent; |
44 UpdateInitialPageScale(); | 46 UpdateInitialPageScale(); |
45 } | 47 } |
46 | 48 |
47 void AwSettings::SetTextZoom(JNIEnv* env, jobject obj, jint text_zoom_percent) { | 49 void AwSettings::SetTextZoom(JNIEnv* env, jobject obj, jint text_zoom_percent) { |
48 if (text_zoom_percent_ == text_zoom_percent) return; | 50 if (text_zoom_percent_ == text_zoom_percent) return; |
49 text_zoom_percent_ = text_zoom_percent; | 51 text_zoom_percent_ = text_zoom_percent; |
50 UpdateTextZoom(); | 52 UpdateTextZoom(); |
51 } | 53 } |
52 | 54 |
53 void AwSettings::SetWebContents(JNIEnv* env, jobject obj, jint web_contents) { | 55 void AwSettings::SetWebContents(JNIEnv* env, jobject obj, jint jweb_contents) { |
54 Observe(reinterpret_cast<content::WebContents*>(web_contents)); | 56 content::WebContents* web_contents = |
| 57 reinterpret_cast<content::WebContents*>(jweb_contents); |
| 58 Observe(web_contents); |
| 59 |
| 60 UpdateRenderViewHostExtSettings(); |
| 61 if (web_contents->GetRenderViewHost()) { |
| 62 UpdateRenderViewHostSettings(web_contents->GetRenderViewHost()); |
| 63 } |
55 } | 64 } |
56 | 65 |
57 void AwSettings::UpdateInitialPageScale() { | 66 void AwSettings::UpdateInitialPageScale() { |
58 AwRenderViewHostExt* rvhe = GetAwRenderViewHostExt(); | 67 AwRenderViewHostExt* rvhe = GetAwRenderViewHostExt(); |
59 if (!rvhe) return; | 68 if (!rvhe) return; |
60 if (initial_page_scale_percent_ == 0) { | 69 if (initial_page_scale_percent_ == 0) { |
61 rvhe->SetInitialPageScale(-1); | 70 rvhe->SetInitialPageScale(-1); |
62 } else { | 71 } else { |
63 rvhe->SetInitialPageScale(initial_page_scale_percent_ / 100.0f); | 72 rvhe->SetInitialPageScale(initial_page_scale_percent_ / 100.0f); |
64 } | 73 } |
65 } | 74 } |
66 | 75 |
67 void AwSettings::UpdateTextZoom() { | 76 void AwSettings::UpdateTextZoom() { |
68 AwRenderViewHostExt* rvhe = GetAwRenderViewHostExt(); | 77 AwRenderViewHostExt* rvhe = GetAwRenderViewHostExt(); |
69 if (!rvhe) return; | 78 if (!rvhe) return; |
70 if (text_zoom_percent_ > 0) { | 79 if (text_zoom_percent_ > 0) { |
71 rvhe->SetTextZoomLevel(webkit_glue::ZoomFactorToZoomLevel( | 80 rvhe->SetTextZoomLevel(webkit_glue::ZoomFactorToZoomLevel( |
72 text_zoom_percent_ / 100.0f)); | 81 text_zoom_percent_ / 100.0f)); |
73 } else { | 82 } else { |
74 // Use the default zoom level value when Text Autosizer is turned on. | 83 // Use the default zoom level value when Text Autosizer is turned on. |
75 rvhe->SetTextZoomLevel(0); | 84 rvhe->SetTextZoomLevel(0); |
76 } | 85 } |
77 } | 86 } |
78 | 87 |
79 void AwSettings::RenderViewCreated(content::RenderViewHost* render_view_host) { | 88 void AwSettings::UpdatePreferredSizeMode( |
| 89 content::RenderViewHost* render_view_host) { |
| 90 render_view_host->EnablePreferredSizeMode(); |
| 91 } |
| 92 |
| 93 void AwSettings::UpdateRenderViewHostExtSettings() { |
80 UpdateInitialPageScale(); | 94 UpdateInitialPageScale(); |
81 UpdateTextZoom(); | 95 UpdateTextZoom(); |
82 } | 96 } |
83 | 97 |
| 98 void AwSettings::UpdateRenderViewHostSettings( |
| 99 content::RenderViewHost* render_view_host) { |
| 100 UpdatePreferredSizeMode(render_view_host); |
| 101 } |
| 102 |
| 103 void AwSettings::RenderViewCreated(content::RenderViewHost* render_view_host) { |
| 104 // A single WebContents can normally have 0, 1 or 2 RenderViewHost instances |
| 105 // associated with it. |
| 106 // This is important since there is only one RenderViewHostExt instance per |
| 107 // WebContents (and not one RVHExt per RVH, as you might expect) and updating |
| 108 // settings via RVHExt only ever updates the 'current' RVH. |
| 109 // In android_webview we don't swap out the RVH on cross-site navigations, so |
| 110 // we shouldn't have to deal with the multiple RVH per WebContents case. That |
| 111 // in turn means that the newly created RVH is always the 'current' RVH |
| 112 // (since we only ever go from 0 to 1 RVH instances) and hence the DCHECK. |
| 113 DCHECK(web_contents()->GetRenderViewHost() == render_view_host); |
| 114 |
| 115 UpdateRenderViewHostExtSettings(); |
| 116 UpdateRenderViewHostSettings(render_view_host); |
| 117 } |
| 118 |
84 static jint Init(JNIEnv* env, | 119 static jint Init(JNIEnv* env, |
85 jobject obj, | 120 jobject obj, |
86 jint web_contents) { | 121 jint web_contents) { |
87 AwSettings* settings = new AwSettings(env, obj); | 122 AwSettings* settings = new AwSettings(env, obj); |
88 settings->SetWebContents(env, obj, web_contents); | 123 settings->SetWebContents(env, obj, web_contents); |
89 return reinterpret_cast<jint>(settings); | 124 return reinterpret_cast<jint>(settings); |
90 } | 125 } |
91 | 126 |
92 bool RegisterAwSettings(JNIEnv* env) { | 127 bool RegisterAwSettings(JNIEnv* env) { |
93 return RegisterNativesImpl(env) >= 0; | 128 return RegisterNativesImpl(env) >= 0; |
94 } | 129 } |
95 | 130 |
96 } // namespace android_webview | 131 } // namespace android_webview |
OLD | NEW |