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

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

Issue 10440014: Correctly whitelist ftp directory listings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updates Created 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/renderer/content_settings_observer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "chrome/common/render_messages.h" 7 #include "chrome/common/render_messages.h"
8 #include "chrome/common/url_constants.h" 8 #include "chrome/common/url_constants.h"
9 #include "content/public/renderer/document_state.h" 9 #include "content/public/renderer/document_state.h"
10 #include "content/public/renderer/navigation_state.h" 10 #include "content/public/renderer/navigation_state.h"
11 #include "content/public/renderer/render_view.h" 11 #include "content/public/renderer/render_view.h"
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h"
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrameClient.h" 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrameClient.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" 17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
19 #include "webkit/glue/weburlresponse_extradata_impl.h"
19 20
20 using WebKit::WebDataSource; 21 using WebKit::WebDataSource;
21 using WebKit::WebFrame; 22 using WebKit::WebFrame;
22 using WebKit::WebFrameClient; 23 using WebKit::WebFrameClient;
23 using WebKit::WebSecurityOrigin; 24 using WebKit::WebSecurityOrigin;
24 using WebKit::WebString; 25 using WebKit::WebString;
25 using WebKit::WebURL; 26 using WebKit::WebURL;
26 using WebKit::WebView; 27 using WebKit::WebView;
27 using content::DocumentState; 28 using content::DocumentState;
28 using content::NavigationState; 29 using content::NavigationState;
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 } 306 }
306 307
307 void ContentSettingsObserver::ClearBlockedContentSettings() { 308 void ContentSettingsObserver::ClearBlockedContentSettings() {
308 for (size_t i = 0; i < arraysize(content_blocked_); ++i) 309 for (size_t i = 0; i < arraysize(content_blocked_); ++i)
309 content_blocked_[i] = false; 310 content_blocked_[i] = false;
310 cached_storage_permissions_.clear(); 311 cached_storage_permissions_.clear();
311 cached_script_permissions_.clear(); 312 cached_script_permissions_.clear();
312 } 313 }
313 314
314 bool ContentSettingsObserver::IsWhitelistedForContentSettings(WebFrame* frame) { 315 bool ContentSettingsObserver::IsWhitelistedForContentSettings(WebFrame* frame) {
316 // Whitelist ftp directory listings, as they require JavaScript to function
317 // properly.
318 webkit_glue::WebURLResponseExtraDataImpl* extra_data =
319 static_cast<webkit_glue::WebURLResponseExtraDataImpl*>(
320 frame->dataSource()->response().extraData());
321 if (extra_data && extra_data->is_ftp_directory_listing())
322 return true;
315 return IsWhitelistedForContentSettings(frame->document().securityOrigin(), 323 return IsWhitelistedForContentSettings(frame->document().securityOrigin(),
316 frame->document().url()); 324 frame->document().url());
317 } 325 }
318 326
319 bool ContentSettingsObserver::IsWhitelistedForContentSettings( 327 bool ContentSettingsObserver::IsWhitelistedForContentSettings(
320 const WebSecurityOrigin& origin, 328 const WebSecurityOrigin& origin,
321 const GURL& document_url) { 329 const GURL& document_url) {
322 if (origin.isUnique()) 330 if (origin.isUnique())
323 return false; // Uninitialized document? 331 return false; // Uninitialized document?
324 332
325 if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme)) 333 if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme))
326 return true; // Browser UI elements should still work. 334 return true; // Browser UI elements should still work.
327 335
328 if (EqualsASCII(origin.protocol(), chrome::kChromeDevToolsScheme)) 336 if (EqualsASCII(origin.protocol(), chrome::kChromeDevToolsScheme))
329 return true; // DevTools UI elements should still work. 337 return true; // DevTools UI elements should still work.
330 338
331 if (EqualsASCII(origin.protocol(), chrome::kExtensionScheme)) 339 if (EqualsASCII(origin.protocol(), chrome::kExtensionScheme))
332 return true; 340 return true;
333 341
334 if (EqualsASCII(origin.protocol(), chrome::kChromeInternalScheme)) 342 if (EqualsASCII(origin.protocol(), chrome::kChromeInternalScheme))
335 return true; 343 return true;
336 344
337 // If the scheme is ftp: or file:, an empty file name indicates a directory 345 // If the scheme is file:, an empty file name indicates a directory listing,
338 // listing, which requires JavaScript to function properly. 346 // which requires JavaScript to function properly.
339 const char* kDirProtocols[] = { chrome::kFtpScheme, chrome::kFileScheme }; 347 if (EqualsASCII(origin.protocol(), chrome::kFileScheme)) {
340 for (size_t i = 0; i < arraysize(kDirProtocols); ++i) { 348 return document_url.SchemeIs(chrome::kFileScheme) &&
341 if (EqualsASCII(origin.protocol(), kDirProtocols[i])) { 349 document_url.ExtractFileName().empty();
342 return document_url.SchemeIs(kDirProtocols[i]) &&
343 document_url.ExtractFileName().empty();
344 }
345 } 350 }
346 351
347 return false; 352 return false;
348 } 353 }
OLDNEW
« no previous file with comments | « no previous file | chrome/renderer/content_settings_observer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698