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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/debug/crash_logging.h" | 12 #include "base/debug/crash_logging.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
17 #include "base/trace_event/trace_event.h" | 17 #include "base/trace_event/trace_event.h" |
18 #include "build/build_config.h" | 18 #include "build/build_config.h" |
19 #include "chrome/common/chrome_constants.h" | |
20 #include "chrome/common/crash_keys.h" | 19 #include "chrome/common/crash_keys.h" |
21 #include "chrome/common/render_messages.h" | 20 #include "chrome/common/render_messages.h" |
22 #include "chrome/common/url_constants.h" | 21 #include "chrome/common/url_constants.h" |
23 #include "chrome/renderer/prerender/prerender_helper.h" | 22 #include "chrome/renderer/prerender/prerender_helper.h" |
24 #include "chrome/renderer/web_apps.h" | |
25 #include "components/web_cache/renderer/web_cache_impl.h" | 23 #include "components/web_cache/renderer/web_cache_impl.h" |
26 #include "content/public/common/bindings_policy.h" | 24 #include "content/public/common/bindings_policy.h" |
27 #include "content/public/renderer/content_renderer_client.h" | 25 #include "content/public/renderer/content_renderer_client.h" |
28 #include "content/public/renderer/render_frame.h" | 26 #include "content/public/renderer/render_frame.h" |
29 #include "content/public/renderer/render_view.h" | 27 #include "content/public/renderer/render_view.h" |
30 #include "content/public/renderer/window_features_converter.h" | 28 #include "content/public/renderer/window_features_converter.h" |
31 #include "extensions/features/features.h" | 29 #include "extensions/features/features.h" |
32 #include "third_party/WebKit/public/web/WebDocument.h" | 30 #include "third_party/WebKit/public/web/WebDocument.h" |
33 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 31 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
34 #include "third_party/WebKit/public/web/WebView.h" | 32 #include "third_party/WebKit/public/web/WebView.h" |
(...skipping 19 matching lines...) Expand all Loading... | |
54 bool ChromeRenderViewObserver::OnMessageReceived(const IPC::Message& message) { | 52 bool ChromeRenderViewObserver::OnMessageReceived(const IPC::Message& message) { |
55 bool handled = true; | 53 bool handled = true; |
56 IPC_BEGIN_MESSAGE_MAP(ChromeRenderViewObserver, message) | 54 IPC_BEGIN_MESSAGE_MAP(ChromeRenderViewObserver, message) |
57 #if !defined(OS_ANDROID) | 55 #if !defined(OS_ANDROID) |
58 IPC_MESSAGE_HANDLER(ChromeViewMsg_WebUIJavaScript, OnWebUIJavaScript) | 56 IPC_MESSAGE_HANDLER(ChromeViewMsg_WebUIJavaScript, OnWebUIJavaScript) |
59 #endif | 57 #endif |
60 #if defined(OS_ANDROID) | 58 #if defined(OS_ANDROID) |
61 IPC_MESSAGE_HANDLER(ChromeViewMsg_UpdateBrowserControlsState, | 59 IPC_MESSAGE_HANDLER(ChromeViewMsg_UpdateBrowserControlsState, |
62 OnUpdateBrowserControlsState) | 60 OnUpdateBrowserControlsState) |
63 #endif | 61 #endif |
64 IPC_MESSAGE_HANDLER(ChromeViewMsg_GetWebApplicationInfo, | |
65 OnGetWebApplicationInfo) | |
66 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetWindowFeatures, OnSetWindowFeatures) | 62 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetWindowFeatures, OnSetWindowFeatures) |
67 IPC_MESSAGE_UNHANDLED(handled = false) | 63 IPC_MESSAGE_UNHANDLED(handled = false) |
68 IPC_END_MESSAGE_MAP() | 64 IPC_END_MESSAGE_MAP() |
69 | 65 |
70 return handled; | 66 return handled; |
71 } | 67 } |
72 | 68 |
73 #if !defined(OS_ANDROID) | 69 #if !defined(OS_ANDROID) |
74 void ChromeRenderViewObserver::OnWebUIJavaScript( | 70 void ChromeRenderViewObserver::OnWebUIJavaScript( |
75 const base::string16& javascript) { | 71 const base::string16& javascript) { |
76 webui_javascript_.push_back(javascript); | 72 webui_javascript_.push_back(javascript); |
77 } | 73 } |
78 #endif | 74 #endif |
79 | 75 |
80 #if defined(OS_ANDROID) | 76 #if defined(OS_ANDROID) |
81 void ChromeRenderViewObserver::OnUpdateBrowserControlsState( | 77 void ChromeRenderViewObserver::OnUpdateBrowserControlsState( |
82 content::BrowserControlsState constraints, | 78 content::BrowserControlsState constraints, |
83 content::BrowserControlsState current, | 79 content::BrowserControlsState current, |
84 bool animate) { | 80 bool animate) { |
85 render_view()->UpdateBrowserControlsState(constraints, current, animate); | 81 render_view()->UpdateBrowserControlsState(constraints, current, animate); |
86 } | 82 } |
87 #endif | 83 #endif |
88 | 84 |
89 void ChromeRenderViewObserver::OnGetWebApplicationInfo() { | |
90 WebFrame* main_frame = render_view()->GetWebView()->MainFrame(); | |
91 DCHECK(main_frame); | |
92 | |
93 WebApplicationInfo web_app_info; | |
94 web_apps::ParseWebAppFromWebDocument(main_frame, &web_app_info); | |
95 | |
96 // The warning below is specific to mobile but it doesn't hurt to show it even | |
97 // if the Chromium build is running on a desktop. It will get more exposition. | |
98 // TODO(mlamouri): Associate this message with an actual frame, to avoid the | |
99 // need to check whether or not the main frame is local. | |
Łukasz Anforowicz
2017/06/15 04:05:39
This is the TODO being addressed by this CL.
| |
100 if (web_app_info.mobile_capable == WebApplicationInfo::MOBILE_CAPABLE_APPLE && | |
101 main_frame->IsWebLocalFrame()) { | |
102 blink::WebConsoleMessage message( | |
103 blink::WebConsoleMessage::kLevelWarning, | |
104 "<meta name=\"apple-mobile-web-app-capable\" content=\"yes\"> is " | |
105 "deprecated. Please include <meta name=\"mobile-web-app-capable\" " | |
106 "content=\"yes\"> - " | |
107 "http://developers.google.com/chrome/mobile/docs/installtohomescreen"); | |
108 main_frame->ToWebLocalFrame()->AddMessageToConsole(message); | |
Łukasz Anforowicz
2017/06/15 04:05:39
After this CL, we can avoid ToWebLocalFrame "cast"
| |
109 } | |
110 | |
111 // Prune out any data URLs in the set of icons. The browser process expects | |
112 // any icon with a data URL to have originated from a favicon. We don't want | |
113 // to decode arbitrary data URLs in the browser process. See | |
114 // http://b/issue?id=1162972 | |
115 for (std::vector<WebApplicationInfo::IconInfo>::iterator it = | |
116 web_app_info.icons.begin(); it != web_app_info.icons.end();) { | |
117 if (it->url.SchemeIs(url::kDataScheme)) | |
118 it = web_app_info.icons.erase(it); | |
119 else | |
120 ++it; | |
121 } | |
122 | |
123 // Truncate the strings we send to the browser process. | |
124 web_app_info.title = | |
125 web_app_info.title.substr(0, chrome::kMaxMetaTagAttributeLength); | |
126 web_app_info.description = | |
127 web_app_info.description.substr(0, chrome::kMaxMetaTagAttributeLength); | |
128 | |
129 Send(new ChromeViewHostMsg_DidGetWebApplicationInfo( | |
130 routing_id(), web_app_info)); | |
131 } | |
132 | |
133 void ChromeRenderViewObserver::OnSetWindowFeatures( | 85 void ChromeRenderViewObserver::OnSetWindowFeatures( |
134 const blink::mojom::WindowFeatures& window_features) { | 86 const blink::mojom::WindowFeatures& window_features) { |
135 render_view()->GetWebView()->SetWindowFeatures( | 87 render_view()->GetWebView()->SetWindowFeatures( |
136 content::ConvertMojoWindowFeaturesToWebWindowFeatures(window_features)); | 88 content::ConvertMojoWindowFeaturesToWebWindowFeatures(window_features)); |
137 } | 89 } |
138 | 90 |
139 void ChromeRenderViewObserver::Navigate(const GURL& url) { | 91 void ChromeRenderViewObserver::Navigate(const GURL& url) { |
140 // Execute cache clear operations that were postponed until a navigation | 92 // Execute cache clear operations that were postponed until a navigation |
141 // event (including tab reload). | 93 // event (including tab reload). |
142 if (web_cache_impl_) | 94 if (web_cache_impl_) |
143 web_cache_impl_->ExecutePendingClearCache(); | 95 web_cache_impl_->ExecutePendingClearCache(); |
144 } | 96 } |
145 | 97 |
146 void ChromeRenderViewObserver::DidCommitProvisionalLoad( | 98 void ChromeRenderViewObserver::DidCommitProvisionalLoad( |
147 blink::WebLocalFrame* frame, | 99 blink::WebLocalFrame* frame, |
148 bool is_new_navigation) { | 100 bool is_new_navigation) { |
149 auto* render_frame = content::RenderFrame::FromWebFrame(frame); | 101 auto* render_frame = content::RenderFrame::FromWebFrame(frame); |
150 if (render_frame->IsMainFrame() && | 102 if (render_frame->IsMainFrame() && |
151 (render_frame->GetEnabledBindings() & content::BINDINGS_POLICY_WEB_UI) && | 103 (render_frame->GetEnabledBindings() & content::BINDINGS_POLICY_WEB_UI) && |
152 !webui_javascript_.empty()) { | 104 !webui_javascript_.empty()) { |
153 for (const auto& script : webui_javascript_) | 105 for (const auto& script : webui_javascript_) |
154 render_view()->GetMainRenderFrame()->ExecuteJavaScript(script); | 106 render_view()->GetMainRenderFrame()->ExecuteJavaScript(script); |
155 webui_javascript_.clear(); | 107 webui_javascript_.clear(); |
156 } | 108 } |
157 } | 109 } |
158 | 110 |
159 void ChromeRenderViewObserver::OnDestruct() { | 111 void ChromeRenderViewObserver::OnDestruct() { |
160 delete this; | 112 delete this; |
161 } | 113 } |
OLD | NEW |