OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/renderer/chrome_render_view_observer.h" | 5 #include "chrome/renderer/chrome_render_view_observer.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "chrome/common/chrome_constants.h" | 15 #include "chrome/common/chrome_constants.h" |
16 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
17 #include "chrome/common/prerender_messages.h" | 17 #include "chrome/common/prerender_messages.h" |
18 #include "chrome/common/render_messages.h" | 18 #include "chrome/common/render_messages.h" |
19 #include "chrome/common/url_constants.h" | 19 #include "chrome/common/url_constants.h" |
20 #include "chrome/renderer/prerender/prerender_helper.h" | 20 #include "chrome/renderer/prerender/prerender_helper.h" |
21 #include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h" | 21 #include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h" |
22 #include "chrome/renderer/translate/translate_helper.h" | 22 #include "chrome/renderer/translate/translate_helper.h" |
23 #include "chrome/renderer/web_apps.h" | |
23 #include "chrome/renderer/webview_color_overlay.h" | 24 #include "chrome/renderer/webview_color_overlay.h" |
24 #include "components/web_cache/renderer/web_cache_render_process_observer.h" | 25 #include "components/web_cache/renderer/web_cache_render_process_observer.h" |
25 #include "content/public/common/bindings_policy.h" | 26 #include "content/public/common/bindings_policy.h" |
26 #include "content/public/renderer/content_renderer_client.h" | 27 #include "content/public/renderer/content_renderer_client.h" |
27 #include "content/public/renderer/render_frame.h" | 28 #include "content/public/renderer/render_frame.h" |
28 #include "content/public/renderer/render_view.h" | 29 #include "content/public/renderer/render_view.h" |
29 #include "extensions/common/constants.h" | 30 #include "extensions/common/constants.h" |
30 #include "net/base/data_url.h" | 31 #include "net/base/data_url.h" |
31 #include "skia/ext/platform_canvas.h" | 32 #include "skia/ext/platform_canvas.h" |
32 #include "third_party/WebKit/public/platform/WebCString.h" | 33 #include "third_party/WebKit/public/platform/WebCString.h" |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
174 #if !defined(OS_ANDROID) && !defined(OS_IOS) | 175 #if !defined(OS_ANDROID) && !defined(OS_IOS) |
175 IPC_MESSAGE_HANDLER(ChromeViewMsg_WebUIJavaScript, OnWebUIJavaScript) | 176 IPC_MESSAGE_HANDLER(ChromeViewMsg_WebUIJavaScript, OnWebUIJavaScript) |
176 #endif | 177 #endif |
177 #if defined(ENABLE_EXTENSIONS) | 178 #if defined(ENABLE_EXTENSIONS) |
178 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetVisuallyDeemphasized, | 179 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetVisuallyDeemphasized, |
179 OnSetVisuallyDeemphasized) | 180 OnSetVisuallyDeemphasized) |
180 #endif | 181 #endif |
181 #if defined(OS_ANDROID) | 182 #if defined(OS_ANDROID) |
182 IPC_MESSAGE_HANDLER(ChromeViewMsg_UpdateTopControlsState, | 183 IPC_MESSAGE_HANDLER(ChromeViewMsg_UpdateTopControlsState, |
183 OnUpdateTopControlsState) | 184 OnUpdateTopControlsState) |
184 IPC_MESSAGE_HANDLER(ChromeViewMsg_RetrieveWebappInformation, | |
185 OnRetrieveWebappInformation) | |
186 IPC_MESSAGE_HANDLER(ChromeViewMsg_RetrieveMetaTagContent, | 185 IPC_MESSAGE_HANDLER(ChromeViewMsg_RetrieveMetaTagContent, |
187 OnRetrieveMetaTagContent) | 186 OnRetrieveMetaTagContent) |
188 #endif | 187 #endif |
188 IPC_MESSAGE_HANDLER(ChromeViewMsg_GetWebApplicationInfo, | |
189 OnGetWebApplicationInfo) | |
189 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetClientSidePhishingDetection, | 190 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetClientSidePhishingDetection, |
190 OnSetClientSidePhishingDetection) | 191 OnSetClientSidePhishingDetection) |
191 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetWindowFeatures, OnSetWindowFeatures) | 192 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetWindowFeatures, OnSetWindowFeatures) |
192 IPC_MESSAGE_UNHANDLED(handled = false) | 193 IPC_MESSAGE_UNHANDLED(handled = false) |
193 IPC_END_MESSAGE_MAP() | 194 IPC_END_MESSAGE_MAP() |
194 | 195 |
195 return handled; | 196 return handled; |
196 } | 197 } |
197 | 198 |
198 #if !defined(OS_ANDROID) && !defined(OS_IOS) | 199 #if !defined(OS_ANDROID) && !defined(OS_IOS) |
199 void ChromeRenderViewObserver::OnWebUIJavaScript( | 200 void ChromeRenderViewObserver::OnWebUIJavaScript( |
200 const base::string16& javascript) { | 201 const base::string16& javascript) { |
201 webui_javascript_.push_back(javascript); | 202 webui_javascript_.push_back(javascript); |
202 } | 203 } |
203 #endif | 204 #endif |
204 | 205 |
205 #if defined(OS_ANDROID) | 206 #if defined(OS_ANDROID) |
206 void ChromeRenderViewObserver::OnUpdateTopControlsState( | 207 void ChromeRenderViewObserver::OnUpdateTopControlsState( |
207 content::TopControlsState constraints, | 208 content::TopControlsState constraints, |
208 content::TopControlsState current, | 209 content::TopControlsState current, |
209 bool animate) { | 210 bool animate) { |
210 render_view()->UpdateTopControlsState(constraints, current, animate); | 211 render_view()->UpdateTopControlsState(constraints, current, animate); |
211 } | 212 } |
212 | 213 |
213 void ChromeRenderViewObserver::OnRetrieveWebappInformation( | |
214 const GURL& expected_url) { | |
215 WebFrame* main_frame = render_view()->GetWebView()->mainFrame(); | |
216 bool found_tag; | |
217 std::string content_str; | |
218 | |
219 // Search for the "mobile-web-app-capable" tag. | |
220 bool mobile_parse_success = RetrieveMetaTagContent( | |
221 main_frame, | |
222 expected_url, | |
223 "mobile-web-app-capable", | |
224 &found_tag, | |
225 &content_str); | |
226 bool is_mobile_webapp_capable = mobile_parse_success && found_tag && | |
227 LowerCaseEqualsASCII(content_str, "yes"); | |
228 | |
229 // Search for the "apple-mobile-web-app-capable" tag. | |
230 bool apple_parse_success = RetrieveMetaTagContent( | |
231 main_frame, | |
232 expected_url, | |
233 "apple-mobile-web-app-capable", | |
234 &found_tag, | |
235 &content_str); | |
236 bool is_apple_mobile_webapp_capable = apple_parse_success && found_tag && | |
237 LowerCaseEqualsASCII(content_str, "yes"); | |
238 | |
239 bool is_only_apple_mobile_webapp_capable = | |
240 is_apple_mobile_webapp_capable && !is_mobile_webapp_capable; | |
241 if (main_frame && is_only_apple_mobile_webapp_capable) { | |
242 blink::WebConsoleMessage message( | |
243 blink::WebConsoleMessage::LevelWarning, | |
244 "<meta name=\"apple-mobile-web-app-capable\" content=\"yes\"> is " | |
245 "deprecated. Please include <meta name=\"mobile-web-app-capable\" " | |
246 "content=\"yes\"> - " | |
247 "http://developers.google.com/chrome/mobile/docs/installtohomescreen"); | |
248 main_frame->addMessageToConsole(message); | |
249 } | |
250 | |
251 Send(new ChromeViewHostMsg_DidRetrieveWebappInformation( | |
252 routing_id(), | |
253 mobile_parse_success && apple_parse_success, | |
254 is_mobile_webapp_capable, | |
255 is_apple_mobile_webapp_capable, | |
256 expected_url)); | |
257 } | |
258 | |
259 void ChromeRenderViewObserver::OnRetrieveMetaTagContent( | 214 void ChromeRenderViewObserver::OnRetrieveMetaTagContent( |
260 const GURL& expected_url, | 215 const GURL& expected_url, |
261 const std::string tag_name) { | 216 const std::string tag_name) { |
262 bool found_tag; | 217 bool found_tag; |
263 std::string content_str; | 218 std::string content_str; |
264 bool parsed_successfully = RetrieveMetaTagContent( | 219 bool parsed_successfully = RetrieveMetaTagContent( |
265 render_view()->GetWebView()->mainFrame(), | 220 render_view()->GetWebView()->mainFrame(), |
266 expected_url, | 221 expected_url, |
267 tag_name, | 222 tag_name, |
268 &found_tag, | 223 &found_tag, |
269 &content_str); | 224 &content_str); |
270 | 225 |
271 Send(new ChromeViewHostMsg_DidRetrieveMetaTagContent( | 226 Send(new ChromeViewHostMsg_DidRetrieveMetaTagContent( |
272 routing_id(), | 227 routing_id(), |
273 parsed_successfully && found_tag, | 228 parsed_successfully && found_tag, |
274 tag_name, | 229 tag_name, |
275 content_str, | 230 content_str, |
276 expected_url)); | 231 expected_url)); |
277 } | 232 } |
278 #endif | 233 #endif |
279 | 234 |
235 void ChromeRenderViewObserver::OnGetWebApplicationInfo() { | |
236 WebFrame* main_frame = render_view()->GetWebView()->mainFrame(); | |
237 DCHECK(main_frame); | |
238 | |
239 WebApplicationInfo web_app_info; | |
240 web_apps::ParseWebAppFromWebDocument(main_frame, &web_app_info); | |
241 | |
242 // The warning below is specific to mobile but it doesn't hurt to show it even | |
243 // if the Chromium build is running on a desktop. It will get more exposition. | |
244 if (web_app_info.mobile_capable == | |
245 WebApplicationInfo::MOBILE_CAPABLE_APPLE) { | |
246 blink::WebConsoleMessage message( | |
247 blink::WebConsoleMessage::LevelWarning, | |
248 "<meta name=\"apple-mobile-web-app-capable\" content=\"yes\"> is " | |
249 "deprecated. Please include <meta name=\"mobile-web-app-capable\" " | |
250 "content=\"yes\"> - " | |
251 "http://developers.google.com/chrome/mobile/docs/installtohomescreen"); | |
252 main_frame->addMessageToConsole(message); | |
253 } | |
254 | |
255 // Prune out any data URLs in the set of icons. The browser process expects | |
256 // any icon with a data URL to have originated from a favicon. We don't want | |
257 // to decode arbitrary data URLs in the browser process. See | |
258 // http://b/issue?id=1162972 | |
259 for (std::vector<WebApplicationInfo::IconInfo>::iterator it = | |
260 web_app_info.icons.begin(); it != web_app_info.icons.end();) { | |
261 it->url.SchemeIs(url::kDataScheme) ? it = web_app_info.icons.erase(it) | |
sky
2014/09/16 18:07:30
Ternary operator is good for assignments and param
mlamouri (slow - plz ping)
2014/09/16 18:29:00
Done.
| |
262 : ++it; | |
263 } | |
264 | |
265 // Truncate the strings we send to the browser process. | |
266 web_app_info.title = | |
267 web_app_info.title.substr(0, chrome::kMaxMetaTagAttributeLength); | |
268 web_app_info.description = | |
269 web_app_info.description.substr(0, chrome::kMaxMetaTagAttributeLength); | |
270 | |
271 Send(new ChromeViewHostMsg_DidGetWebApplicationInfo( | |
272 routing_id(), web_app_info)); | |
273 } | |
274 | |
280 void ChromeRenderViewObserver::OnSetWindowFeatures( | 275 void ChromeRenderViewObserver::OnSetWindowFeatures( |
281 const WebWindowFeatures& window_features) { | 276 const WebWindowFeatures& window_features) { |
282 render_view()->GetWebView()->setWindowFeatures(window_features); | 277 render_view()->GetWebView()->setWindowFeatures(window_features); |
283 } | 278 } |
284 | 279 |
285 void ChromeRenderViewObserver::Navigate(const GURL& url) { | 280 void ChromeRenderViewObserver::Navigate(const GURL& url) { |
286 // Execute cache clear operations that were postponed until a navigation | 281 // Execute cache clear operations that were postponed until a navigation |
287 // event (including tab reload). | 282 // event (including tab reload). |
288 if (web_cache_render_process_observer_) | 283 if (web_cache_render_process_observer_) |
289 web_cache_render_process_observer_->ExecutePendingClearCache(); | 284 web_cache_render_process_observer_->ExecutePendingClearCache(); |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
462 WebElement element = node.to<WebElement>(); | 457 WebElement element = node.to<WebElement>(); |
463 if (!element.hasHTMLTagName(tag_name)) | 458 if (!element.hasHTMLTagName(tag_name)) |
464 continue; | 459 continue; |
465 WebString value = element.getAttribute(attribute_name); | 460 WebString value = element.getAttribute(attribute_name); |
466 if (value.isNull() || !LowerCaseEqualsASCII(value, "refresh")) | 461 if (value.isNull() || !LowerCaseEqualsASCII(value, "refresh")) |
467 continue; | 462 continue; |
468 return true; | 463 return true; |
469 } | 464 } |
470 return false; | 465 return false; |
471 } | 466 } |
OLD | NEW |