Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Side by Side Diff: chrome/renderer/content_settings_observer.cc

Issue 273513005: Avoid sync IPCs for FileSystem API [chromium] (2/4) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "chrome/common/chrome_switches.h" 9 #include "chrome/common/chrome_switches.h"
10 #include "chrome/common/render_messages.h" 10 #include "chrome/common/render_messages.h"
11 #include "chrome/common/url_constants.h" 11 #include "chrome/common/url_constants.h"
12 #include "content/public/renderer/document_state.h" 12 #include "content/public/renderer/document_state.h"
13 #include "content/public/renderer/navigation_state.h" 13 #include "content/public/renderer/navigation_state.h"
14 #include "content/public/renderer/render_frame.h" 14 #include "content/public/renderer/render_frame.h"
15 #include "content/public/renderer/render_view.h" 15 #include "content/public/renderer/render_view.h"
16 #include "extensions/common/constants.h" 16 #include "extensions/common/constants.h"
17 #include "extensions/renderer/dispatcher.h" 17 #include "extensions/renderer/dispatcher.h"
18 #include "third_party/WebKit/public/platform/WebPermissionCallbacks.h"
18 #include "third_party/WebKit/public/platform/WebURL.h" 19 #include "third_party/WebKit/public/platform/WebURL.h"
19 #include "third_party/WebKit/public/web/WebDataSource.h" 20 #include "third_party/WebKit/public/web/WebDataSource.h"
20 #include "third_party/WebKit/public/web/WebDocument.h" 21 #include "third_party/WebKit/public/web/WebDocument.h"
21 #include "third_party/WebKit/public/web/WebFrame.h" 22 #include "third_party/WebKit/public/web/WebFrame.h"
22 #include "third_party/WebKit/public/web/WebFrameClient.h" 23 #include "third_party/WebKit/public/web/WebFrameClient.h"
23 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" 24 #include "third_party/WebKit/public/web/WebSecurityOrigin.h"
24 #include "third_party/WebKit/public/web/WebView.h" 25 #include "third_party/WebKit/public/web/WebView.h"
25 #include "webkit/child/weburlresponse_extradata_impl.h" 26 #include "webkit/child/weburlresponse_extradata_impl.h"
26 27
27 using blink::WebDataSource; 28 using blink::WebDataSource;
28 using blink::WebDocument; 29 using blink::WebDocument;
29 using blink::WebFrame; 30 using blink::WebFrame;
30 using blink::WebFrameClient; 31 using blink::WebPermissionCallbacks;
31 using blink::WebSecurityOrigin; 32 using blink::WebSecurityOrigin;
32 using blink::WebString; 33 using blink::WebString;
33 using blink::WebURL; 34 using blink::WebURL;
34 using blink::WebView; 35 using blink::WebView;
35 using content::DocumentState; 36 using content::DocumentState;
36 using content::NavigationState; 37 using content::NavigationState;
37 using extensions::APIPermission; 38 using extensions::APIPermission;
38 39
39 namespace { 40 namespace {
40 41
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 content::RenderFrame* render_frame, 147 content::RenderFrame* render_frame,
147 extensions::Dispatcher* extension_dispatcher) 148 extensions::Dispatcher* extension_dispatcher)
148 : content::RenderFrameObserver(render_frame), 149 : content::RenderFrameObserver(render_frame),
149 content::RenderFrameObserverTracker<ContentSettingsObserver>( 150 content::RenderFrameObserverTracker<ContentSettingsObserver>(
150 render_frame), 151 render_frame),
151 extension_dispatcher_(extension_dispatcher), 152 extension_dispatcher_(extension_dispatcher),
152 allow_displaying_insecure_content_(false), 153 allow_displaying_insecure_content_(false),
153 allow_running_insecure_content_(false), 154 allow_running_insecure_content_(false),
154 content_setting_rules_(NULL), 155 content_setting_rules_(NULL),
155 is_interstitial_page_(false), 156 is_interstitial_page_(false),
156 npapi_plugins_blocked_(false) { 157 npapi_plugins_blocked_(false),
158 current_request_id_(0) {
157 ClearBlockedContentSettings(); 159 ClearBlockedContentSettings();
158 render_frame->GetWebFrame()->setPermissionClient(this); 160 render_frame->GetWebFrame()->setPermissionClient(this);
159 161
160 if (render_frame->GetRenderView()->GetMainRenderFrame() != render_frame) { 162 if (render_frame->GetRenderView()->GetMainRenderFrame() != render_frame) {
161 // Copy all the settings from the main render frame to avoid race conditions 163 // Copy all the settings from the main render frame to avoid race conditions
162 // when initializing this data. See http://crbug.com/333308. 164 // when initializing this data. See http://crbug.com/333308.
163 ContentSettingsObserver* parent = ContentSettingsObserver::Get( 165 ContentSettingsObserver* parent = ContentSettingsObserver::Get(
164 render_frame->GetRenderView()->GetMainRenderFrame()); 166 render_frame->GetRenderView()->GetMainRenderFrame());
165 allow_displaying_insecure_content_ = 167 allow_displaying_insecure_content_ =
166 parent->allow_displaying_insecure_content_; 168 parent->allow_displaying_insecure_content_;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 bool ContentSettingsObserver::OnMessageReceived(const IPC::Message& message) { 202 bool ContentSettingsObserver::OnMessageReceived(const IPC::Message& message) {
201 bool handled = true; 203 bool handled = true;
202 IPC_BEGIN_MESSAGE_MAP(ContentSettingsObserver, message) 204 IPC_BEGIN_MESSAGE_MAP(ContentSettingsObserver, message)
203 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAsInterstitial, OnSetAsInterstitial) 205 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAsInterstitial, OnSetAsInterstitial)
204 IPC_MESSAGE_HANDLER(ChromeViewMsg_NPAPINotSupported, OnNPAPINotSupported) 206 IPC_MESSAGE_HANDLER(ChromeViewMsg_NPAPINotSupported, OnNPAPINotSupported)
205 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAllowDisplayingInsecureContent, 207 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAllowDisplayingInsecureContent,
206 OnSetAllowDisplayingInsecureContent) 208 OnSetAllowDisplayingInsecureContent)
207 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAllowRunningInsecureContent, 209 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAllowRunningInsecureContent,
208 OnSetAllowRunningInsecureContent) 210 OnSetAllowRunningInsecureContent)
209 IPC_MESSAGE_HANDLER(ChromeViewMsg_ReloadFrame, OnReloadFrame); 211 IPC_MESSAGE_HANDLER(ChromeViewMsg_ReloadFrame, OnReloadFrame);
212 IPC_MESSAGE_HANDLER(ChromeViewMsg_RequestFileSystemAccessResponse,
213 OnRequestFileSystemAccessResponse)
210 IPC_MESSAGE_UNHANDLED(handled = false) 214 IPC_MESSAGE_UNHANDLED(handled = false)
211 IPC_END_MESSAGE_MAP() 215 IPC_END_MESSAGE_MAP()
212 if (handled) 216 if (handled)
213 return true; 217 return true;
214 218
215 // Don't swallow LoadBlockedPlugins messages, as they're sent to every 219 // Don't swallow LoadBlockedPlugins messages, as they're sent to every
216 // blocked plugin. 220 // blocked plugin.
217 IPC_BEGIN_MESSAGE_MAP(ContentSettingsObserver, message) 221 IPC_BEGIN_MESSAGE_MAP(ContentSettingsObserver, message)
218 IPC_MESSAGE_HANDLER(ChromeViewMsg_LoadBlockedPlugins, OnLoadBlockedPlugins) 222 IPC_MESSAGE_HANDLER(ChromeViewMsg_LoadBlockedPlugins, OnLoadBlockedPlugins)
219 IPC_END_MESSAGE_MAP() 223 IPC_END_MESSAGE_MAP()
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 frame->top()->document().securityOrigin().isUnique()) 272 frame->top()->document().securityOrigin().isUnique())
269 return false; 273 return false;
270 274
271 bool result = false; 275 bool result = false;
272 Send(new ChromeViewHostMsg_AllowFileSystem( 276 Send(new ChromeViewHostMsg_AllowFileSystem(
273 routing_id(), GURL(frame->document().securityOrigin().toString()), 277 routing_id(), GURL(frame->document().securityOrigin().toString()),
274 GURL(frame->top()->document().securityOrigin().toString()), &result)); 278 GURL(frame->top()->document().securityOrigin().toString()), &result));
275 return result; 279 return result;
276 } 280 }
277 281
282 void ContentSettingsObserver::requestFileSystemAccess(
283 const WebPermissionCallbacks& callbacks) {
284 WebFrame* frame = render_frame()->GetWebFrame();
285 if (frame->document().securityOrigin().isUnique() ||
286 frame->top()->document().securityOrigin().isUnique()) {
287 WebPermissionCallbacks permissionCallbacks(callbacks);
288 permissionCallbacks.doDeny();
289 return;
290 }
291 ++current_request_id_;
292 std::pair<PermissionRequestMap::iterator, bool> insert_result =
293 permission_requests_.insert(
294 std::make_pair(current_request_id_, callbacks));
295
296 // Verify there are no duplicate insertions.
297 bool inserted = insert_result.second;
298 DCHECK(inserted);
299
300 Send(new ChromeViewHostMsg_RequestFileSystemAccess(
301 routing_id(),
302 current_request_id_,
303 GURL(frame->document().securityOrigin().toString()),
304 GURL(frame->top()->document().securityOrigin().toString())));
305 }
306
278 bool ContentSettingsObserver::allowImage(bool enabled_per_settings, 307 bool ContentSettingsObserver::allowImage(bool enabled_per_settings,
279 const WebURL& image_url) { 308 const WebURL& image_url) {
280 bool allow = enabled_per_settings; 309 bool allow = enabled_per_settings;
281 if (enabled_per_settings) { 310 if (enabled_per_settings) {
282 if (is_interstitial_page_) 311 if (is_interstitial_page_)
283 return true; 312 return true;
284 313
285 WebFrame* frame = render_frame()->GetWebFrame(); 314 WebFrame* frame = render_frame()->GetWebFrame();
286 if (IsWhitelistedForContentSettings(frame)) 315 if (IsWhitelistedForContentSettings(frame))
287 return true; 316 return true;
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 allow_running_insecure_content_ = allow; 627 allow_running_insecure_content_ = allow;
599 OnSetAllowDisplayingInsecureContent(allow); 628 OnSetAllowDisplayingInsecureContent(allow);
600 } 629 }
601 630
602 void ContentSettingsObserver::OnReloadFrame() { 631 void ContentSettingsObserver::OnReloadFrame() {
603 DCHECK(!render_frame()->GetWebFrame()->parent()) << 632 DCHECK(!render_frame()->GetWebFrame()->parent()) <<
604 "Should only be called on the main frame"; 633 "Should only be called on the main frame";
605 render_frame()->GetWebFrame()->reload(); 634 render_frame()->GetWebFrame()->reload();
606 } 635 }
607 636
637 void ContentSettingsObserver::OnRequestFileSystemAccessResponse(int request_id,
638 bool allowed) {
639 PermissionRequestMap::iterator it = permission_requests_.find(request_id);
640 if (it == permission_requests_.end())
641 return;
jochen (gone - plz use gerrit) 2014/05/08 07:38:53 when can this happen?
Xi Han 2014/05/08 19:48:30 I am not sure when it would happen, but it is bett
642
643 WebPermissionCallbacks callbacks = it->second;
644 permission_requests_.erase(it);
645
646 if (allowed) {
647 callbacks.doAllow();
648 return;
649 }
650 callbacks.doDeny();
651 }
652
608 void ContentSettingsObserver::ClearBlockedContentSettings() { 653 void ContentSettingsObserver::ClearBlockedContentSettings() {
609 for (size_t i = 0; i < arraysize(content_blocked_); ++i) 654 for (size_t i = 0; i < arraysize(content_blocked_); ++i)
610 content_blocked_[i] = false; 655 content_blocked_[i] = false;
611 cached_storage_permissions_.clear(); 656 cached_storage_permissions_.clear();
612 cached_script_permissions_.clear(); 657 cached_script_permissions_.clear();
613 } 658 }
614 659
615 const extensions::Extension* ContentSettingsObserver::GetExtension( 660 const extensions::Extension* ContentSettingsObserver::GetExtension(
616 const WebSecurityOrigin& origin) const { 661 const WebSecurityOrigin& origin) const {
617 if (!EqualsASCII(origin.protocol(), extensions::kExtensionScheme)) 662 if (!EqualsASCII(origin.protocol(), extensions::kExtensionScheme))
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 710
666 // If the scheme is file:, an empty file name indicates a directory listing, 711 // If the scheme is file:, an empty file name indicates a directory listing,
667 // which requires JavaScript to function properly. 712 // which requires JavaScript to function properly.
668 if (EqualsASCII(origin.protocol(), content::kFileScheme)) { 713 if (EqualsASCII(origin.protocol(), content::kFileScheme)) {
669 return document_url.SchemeIs(content::kFileScheme) && 714 return document_url.SchemeIs(content::kFileScheme) &&
670 document_url.ExtractFileName().empty(); 715 document_url.ExtractFileName().empty();
671 } 716 }
672 717
673 return false; 718 return false;
674 } 719 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698