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

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

Issue 8775005: Content settings: whitelist kExtensionScheme and kChromeInternalScheme on the renderer side. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Code review. Created 9 years 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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"
(...skipping 11 matching lines...) Expand all
22 using WebKit::WebFrameClient; 22 using WebKit::WebFrameClient;
23 using WebKit::WebSecurityOrigin; 23 using WebKit::WebSecurityOrigin;
24 using WebKit::WebString; 24 using WebKit::WebString;
25 using WebKit::WebURL; 25 using WebKit::WebURL;
26 using WebKit::WebView; 26 using WebKit::WebView;
27 using content::DocumentState; 27 using content::DocumentState;
28 using content::NavigationState; 28 using content::NavigationState;
29 29
30 namespace { 30 namespace {
31 31
32 // True if |frame| contains content that is white-listed for content settings.
33 static bool IsWhitelistedForContentSettings(WebFrame* frame) {
34 WebSecurityOrigin origin = frame->document().securityOrigin();
35 if (origin.isUnique())
36 return false; // Uninitialized document?
37
38 if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme))
39 return true; // Browser UI elements should still work.
40
41 if (EqualsASCII(origin.protocol(), chrome::kChromeDevToolsScheme))
42 return true; // DevTools UI elements should still work.
43
44 // If the scheme is ftp: or file:, an empty file name indicates a directory
45 // listing, which requires JavaScript to function properly.
46 GURL document_url = frame->document().url();
47 const char* kDirProtocols[] = { chrome::kFtpScheme, chrome::kFileScheme };
48 for (size_t i = 0; i < arraysize(kDirProtocols); ++i) {
49 if (EqualsASCII(origin.protocol(), kDirProtocols[i])) {
50 return document_url.SchemeIs(kDirProtocols[i]) &&
51 document_url.ExtractFileName().empty();
52 }
53 }
54
55 return false;
56 }
57
58 GURL GetOriginOrURL(const WebFrame* frame) { 32 GURL GetOriginOrURL(const WebFrame* frame) {
59 WebString top_origin = frame->top()->document().securityOrigin().toString(); 33 WebString top_origin = frame->top()->document().securityOrigin().toString();
60 // The the |top_origin| is unique ("null") e.g., for file:// URLs. Use the 34 // The the |top_origin| is unique ("null") e.g., for file:// URLs. Use the
61 // document URL as the primary URL in those cases. 35 // document URL as the primary URL in those cases.
62 if (top_origin == "null") 36 if (top_origin == "null")
63 return frame->top()->document().url(); 37 return frame->top()->document().url();
64 return GURL(top_origin); 38 return GURL(top_origin);
65 } 39 }
66 40
67 ContentSetting GetContentSettingFromRules( 41 ContentSetting GetContentSettingFromRules(
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 void ContentSettingsObserver::OnLoadBlockedPlugins() { 275 void ContentSettingsObserver::OnLoadBlockedPlugins() {
302 plugins_temporarily_allowed_ = true; 276 plugins_temporarily_allowed_ = true;
303 } 277 }
304 278
305 void ContentSettingsObserver::ClearBlockedContentSettings() { 279 void ContentSettingsObserver::ClearBlockedContentSettings() {
306 for (size_t i = 0; i < arraysize(content_blocked_); ++i) 280 for (size_t i = 0; i < arraysize(content_blocked_); ++i)
307 content_blocked_[i] = false; 281 content_blocked_[i] = false;
308 cached_storage_permissions_.clear(); 282 cached_storage_permissions_.clear();
309 cached_script_permissions_.clear(); 283 cached_script_permissions_.clear();
310 } 284 }
285
286 bool ContentSettingsObserver::IsWhitelistedForContentSettings(WebFrame* frame) {
287 return IsWhitelistedForContentSettings(frame->document().securityOrigin(),
288 frame->document().url());
289 }
290
291 bool ContentSettingsObserver::IsWhitelistedForContentSettings(
292 const WebSecurityOrigin& origin,
293 const GURL& document_url) {
294 if (origin.isUnique())
295 return false; // Uninitialized document?
296
297 if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme))
298 return true; // Browser UI elements should still work.
299
300 if (EqualsASCII(origin.protocol(), chrome::kChromeDevToolsScheme))
301 return true; // DevTools UI elements should still work.
302
303 if (EqualsASCII(origin.protocol(), chrome::kExtensionScheme))
304 return true;
305
306 if (EqualsASCII(origin.protocol(), chrome::kChromeInternalScheme))
307 return true;
308
309 // If the scheme is ftp: or file:, an empty file name indicates a directory
310 // listing, which requires JavaScript to function properly.
311 const char* kDirProtocols[] = { chrome::kFtpScheme, chrome::kFileScheme };
312 for (size_t i = 0; i < arraysize(kDirProtocols); ++i) {
313 if (EqualsASCII(origin.protocol(), kDirProtocols[i])) {
314 return document_url.SchemeIs(kDirProtocols[i]) &&
315 document_url.ExtractFileName().empty();
316 }
317 }
318
319 return false;
320 }
OLDNEW
« no previous file with comments | « chrome/renderer/content_settings_observer.h ('k') | chrome/renderer/content_settings_observer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698