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/content_settings_observer.h" | 5 #include "chrome/renderer/content_settings_observer.h" |
6 | 6 |
7 #include "chrome/common/render_messages.h" | 7 #include "chrome/common/render_messages.h" |
8 #include "chrome/common/ssl_insecure_content.h" | 8 #include "chrome/common/ssl_insecure_content.h" |
9 #include "content/public/common/url_constants.h" | 9 #include "content/public/common/url_constants.h" |
10 #include "content/public/renderer/document_state.h" | 10 #include "content/public/renderer/document_state.h" |
11 #include "content/public/renderer/render_frame.h" | 11 #include "content/public/renderer/render_frame.h" |
12 #include "content/public/renderer/render_view.h" | 12 #include "content/public/renderer/render_view.h" |
13 #include "extensions/features/features.h" | 13 #include "extensions/features/features.h" |
| 14 #include "services/service_manager/public/cpp/interface_registry.h" |
14 #include "third_party/WebKit/public/platform/URLConversion.h" | 15 #include "third_party/WebKit/public/platform/URLConversion.h" |
15 #include "third_party/WebKit/public/platform/WebContentSettingCallbacks.h" | 16 #include "third_party/WebKit/public/platform/WebContentSettingCallbacks.h" |
16 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" | 17 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" |
17 #include "third_party/WebKit/public/platform/WebURL.h" | 18 #include "third_party/WebKit/public/platform/WebURL.h" |
18 #include "third_party/WebKit/public/web/WebDataSource.h" | 19 #include "third_party/WebKit/public/web/WebDataSource.h" |
19 #include "third_party/WebKit/public/web/WebDocument.h" | 20 #include "third_party/WebKit/public/web/WebDocument.h" |
20 #include "third_party/WebKit/public/web/WebFrameClient.h" | 21 #include "third_party/WebKit/public/web/WebFrameClient.h" |
21 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 22 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
22 #include "third_party/WebKit/public/web/WebView.h" | 23 #include "third_party/WebKit/public/web/WebView.h" |
23 #include "url/origin.h" | 24 #include "url/origin.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 extension_dispatcher_(extension_dispatcher), | 98 extension_dispatcher_(extension_dispatcher), |
98 #endif | 99 #endif |
99 allow_running_insecure_content_(false), | 100 allow_running_insecure_content_(false), |
100 content_setting_rules_(NULL), | 101 content_setting_rules_(NULL), |
101 is_interstitial_page_(false), | 102 is_interstitial_page_(false), |
102 current_request_id_(0), | 103 current_request_id_(0), |
103 should_whitelist_(should_whitelist) { | 104 should_whitelist_(should_whitelist) { |
104 ClearBlockedContentSettings(); | 105 ClearBlockedContentSettings(); |
105 render_frame->GetWebFrame()->setContentSettingsClient(this); | 106 render_frame->GetWebFrame()->setContentSettingsClient(this); |
106 | 107 |
| 108 render_frame->GetInterfaceRegistry()->AddInterface( |
| 109 base::Bind(&ContentSettingsObserver::OnInsecureContentRendererRequest, |
| 110 base::Unretained(this))); |
| 111 |
107 content::RenderFrame* main_frame = | 112 content::RenderFrame* main_frame = |
108 render_frame->GetRenderView()->GetMainRenderFrame(); | 113 render_frame->GetRenderView()->GetMainRenderFrame(); |
109 // TODO(nasko): The main frame is not guaranteed to be in the same process | 114 // TODO(nasko): The main frame is not guaranteed to be in the same process |
110 // with this frame with --site-per-process. This code needs to be updated | 115 // with this frame with --site-per-process. This code needs to be updated |
111 // to handle this case. See https://crbug.com/496670. | 116 // to handle this case. See https://crbug.com/496670. |
112 if (main_frame && main_frame != render_frame) { | 117 if (main_frame && main_frame != render_frame) { |
113 // Copy all the settings from the main render frame to avoid race conditions | 118 // Copy all the settings from the main render frame to avoid race conditions |
114 // when initializing this data. See https://crbug.com/333308. | 119 // when initializing this data. See https://crbug.com/333308. |
115 ContentSettingsObserver* parent = ContentSettingsObserver::Get(main_frame); | 120 ContentSettingsObserver* parent = ContentSettingsObserver::Get(main_frame); |
116 allow_running_insecure_content_ = parent->allow_running_insecure_content_; | 121 allow_running_insecure_content_ = parent->allow_running_insecure_content_; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 blocked = true; | 156 blocked = true; |
152 Send(new ChromeViewHostMsg_ContentBlocked(routing_id(), settings_type, | 157 Send(new ChromeViewHostMsg_ContentBlocked(routing_id(), settings_type, |
153 details)); | 158 details)); |
154 } | 159 } |
155 } | 160 } |
156 | 161 |
157 bool ContentSettingsObserver::OnMessageReceived(const IPC::Message& message) { | 162 bool ContentSettingsObserver::OnMessageReceived(const IPC::Message& message) { |
158 bool handled = true; | 163 bool handled = true; |
159 IPC_BEGIN_MESSAGE_MAP(ContentSettingsObserver, message) | 164 IPC_BEGIN_MESSAGE_MAP(ContentSettingsObserver, message) |
160 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAsInterstitial, OnSetAsInterstitial) | 165 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAsInterstitial, OnSetAsInterstitial) |
161 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAllowRunningInsecureContent, | |
162 OnSetAllowRunningInsecureContent) | |
163 IPC_MESSAGE_HANDLER(ChromeViewMsg_ReloadFrame, OnReloadFrame); | |
164 IPC_MESSAGE_HANDLER(ChromeViewMsg_RequestFileSystemAccessAsyncResponse, | 166 IPC_MESSAGE_HANDLER(ChromeViewMsg_RequestFileSystemAccessAsyncResponse, |
165 OnRequestFileSystemAccessAsyncResponse) | 167 OnRequestFileSystemAccessAsyncResponse) |
166 IPC_MESSAGE_UNHANDLED(handled = false) | 168 IPC_MESSAGE_UNHANDLED(handled = false) |
167 IPC_END_MESSAGE_MAP() | 169 IPC_END_MESSAGE_MAP() |
168 if (handled) | 170 if (handled) |
169 return true; | 171 return true; |
170 | 172 |
171 // Don't swallow LoadBlockedPlugins messages, as they're sent to every | 173 // Don't swallow LoadBlockedPlugins messages, as they're sent to every |
172 // blocked plugin. | 174 // blocked plugin. |
173 IPC_BEGIN_MESSAGE_MAP(ContentSettingsObserver, message) | 175 IPC_BEGIN_MESSAGE_MAP(ContentSettingsObserver, message) |
(...skipping 24 matching lines...) Expand all Loading... |
198 // If we start failing this DCHECK, please makes sure we don't regress | 200 // If we start failing this DCHECK, please makes sure we don't regress |
199 // this bug: http://code.google.com/p/chromium/issues/detail?id=79304 | 201 // this bug: http://code.google.com/p/chromium/issues/detail?id=79304 |
200 DCHECK(frame->document().getSecurityOrigin().toString() == "null" || | 202 DCHECK(frame->document().getSecurityOrigin().toString() == "null" || |
201 !url.SchemeIs(url::kDataScheme)); | 203 !url.SchemeIs(url::kDataScheme)); |
202 } | 204 } |
203 | 205 |
204 void ContentSettingsObserver::OnDestruct() { | 206 void ContentSettingsObserver::OnDestruct() { |
205 delete this; | 207 delete this; |
206 } | 208 } |
207 | 209 |
| 210 void ContentSettingsObserver::SetAllowRunningInsecureContent() { |
| 211 allow_running_insecure_content_ = true; |
| 212 |
| 213 // Reload if we are the main frame. |
| 214 blink::WebLocalFrame* frame = render_frame()->GetWebFrame(); |
| 215 if (!frame->parent()) |
| 216 frame->reload(blink::WebFrameLoadType::ReloadMainResource); |
| 217 } |
| 218 |
| 219 void ContentSettingsObserver::OnInsecureContentRendererRequest( |
| 220 chrome::mojom::InsecureContentRendererRequest request) { |
| 221 insecure_content_renderer_bindings_.AddBinding(this, std::move(request)); |
| 222 } |
| 223 |
208 bool ContentSettingsObserver::allowDatabase(const WebString& name, | 224 bool ContentSettingsObserver::allowDatabase(const WebString& name, |
209 const WebString& display_name, | 225 const WebString& display_name, |
210 unsigned estimated_size) { | 226 unsigned estimated_size) { |
211 WebFrame* frame = render_frame()->GetWebFrame(); | 227 WebFrame* frame = render_frame()->GetWebFrame(); |
212 if (frame->getSecurityOrigin().isUnique() || | 228 if (frame->getSecurityOrigin().isUnique() || |
213 frame->top()->getSecurityOrigin().isUnique()) | 229 frame->top()->getSecurityOrigin().isUnique()) |
214 return false; | 230 return false; |
215 | 231 |
216 bool result = false; | 232 bool result = false; |
217 Send(new ChromeViewHostMsg_AllowDatabase( | 233 Send(new ChromeViewHostMsg_AllowDatabase( |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 | 443 |
428 void ContentSettingsObserver::OnLoadBlockedPlugins( | 444 void ContentSettingsObserver::OnLoadBlockedPlugins( |
429 const std::string& identifier) { | 445 const std::string& identifier) { |
430 temporarily_allowed_plugins_.insert(identifier); | 446 temporarily_allowed_plugins_.insert(identifier); |
431 } | 447 } |
432 | 448 |
433 void ContentSettingsObserver::OnSetAsInterstitial() { | 449 void ContentSettingsObserver::OnSetAsInterstitial() { |
434 is_interstitial_page_ = true; | 450 is_interstitial_page_ = true; |
435 } | 451 } |
436 | 452 |
437 void ContentSettingsObserver::OnSetAllowRunningInsecureContent(bool allow) { | |
438 allow_running_insecure_content_ = allow; | |
439 } | |
440 | |
441 void ContentSettingsObserver::OnReloadFrame() { | |
442 DCHECK(!render_frame()->GetWebFrame()->parent()) << | |
443 "Should only be called on the main frame"; | |
444 render_frame()->GetWebFrame()->reload( | |
445 blink::WebFrameLoadType::ReloadMainResource); | |
446 } | |
447 | |
448 void ContentSettingsObserver::OnRequestFileSystemAccessAsyncResponse( | 453 void ContentSettingsObserver::OnRequestFileSystemAccessAsyncResponse( |
449 int request_id, | 454 int request_id, |
450 bool allowed) { | 455 bool allowed) { |
451 PermissionRequestMap::iterator it = permission_requests_.find(request_id); | 456 PermissionRequestMap::iterator it = permission_requests_.find(request_id); |
452 if (it == permission_requests_.end()) | 457 if (it == permission_requests_.end()) |
453 return; | 458 return; |
454 | 459 |
455 WebContentSettingCallbacks callbacks = it->second; | 460 WebContentSettingCallbacks callbacks = it->second; |
456 permission_requests_.erase(it); | 461 permission_requests_.erase(it); |
457 | 462 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 #endif | 535 #endif |
531 | 536 |
532 // If the scheme is file:, an empty file name indicates a directory listing, | 537 // If the scheme is file:, an empty file name indicates a directory listing, |
533 // which requires JavaScript to function properly. | 538 // which requires JavaScript to function properly. |
534 if (protocol == url::kFileScheme && | 539 if (protocol == url::kFileScheme && |
535 document_url.protocolIs(url::kFileScheme)) { | 540 document_url.protocolIs(url::kFileScheme)) { |
536 return GURL(document_url).ExtractFileName().empty(); | 541 return GURL(document_url).ExtractFileName().empty(); |
537 } | 542 } |
538 return false; | 543 return false; |
539 } | 544 } |
OLD | NEW |