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

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

Issue 2928033002: Move GetDocument method from WebFrame to WebLocalFrame. (Closed)
Patch Set: Split a DCHECK in two as suggested by boliu@. Created 3 years, 6 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 "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"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 namespace { 47 namespace {
48 48
49 GURL GetOriginOrURL(const WebFrame* frame) { 49 GURL GetOriginOrURL(const WebFrame* frame) {
50 url::Origin top_origin = url::Origin(frame->Top()->GetSecurityOrigin()); 50 url::Origin top_origin = url::Origin(frame->Top()->GetSecurityOrigin());
51 // The |top_origin| is unique ("null") e.g., for file:// URLs. Use the 51 // The |top_origin| is unique ("null") e.g., for file:// URLs. Use the
52 // document URL as the primary URL in those cases. 52 // document URL as the primary URL in those cases.
53 // TODO(alexmos): This is broken for --site-per-process, since top() can be a 53 // TODO(alexmos): This is broken for --site-per-process, since top() can be a
54 // WebRemoteFrame which does not have a document(), and the WebRemoteFrame's 54 // WebRemoteFrame which does not have a document(), and the WebRemoteFrame's
55 // URL is not replicated. See https://crbug.com/628759. 55 // URL is not replicated. See https://crbug.com/628759.
56 if (top_origin.unique() && frame->Top()->IsWebLocalFrame()) 56 if (top_origin.unique() && frame->Top()->IsWebLocalFrame())
57 return frame->Top()->GetDocument().Url(); 57 return frame->Top()->ToWebLocalFrame()->GetDocument().Url();
58 return top_origin.GetURL(); 58 return top_origin.GetURL();
59 } 59 }
60 60
61 // Allow passing both WebURL and GURL here, so that we can early return without 61 // Allow passing both WebURL and GURL here, so that we can early return without
62 // allocating a new backing string if only the default rule matches. 62 // allocating a new backing string if only the default rule matches.
63 template <typename URL> 63 template <typename URL>
64 ContentSetting GetContentSettingFromRules( 64 ContentSetting GetContentSettingFromRules(
65 const ContentSettingsForOneType& rules, 65 const ContentSettingsForOneType& rules,
66 const WebFrame* frame, 66 const WebFrame* frame,
67 const URL& secondary_url) { 67 const URL& secondary_url) {
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 IPC_BEGIN_MESSAGE_MAP(ContentSettingsObserver, message) 175 IPC_BEGIN_MESSAGE_MAP(ContentSettingsObserver, message)
176 IPC_MESSAGE_HANDLER(ChromeViewMsg_LoadBlockedPlugins, OnLoadBlockedPlugins) 176 IPC_MESSAGE_HANDLER(ChromeViewMsg_LoadBlockedPlugins, OnLoadBlockedPlugins)
177 IPC_END_MESSAGE_MAP() 177 IPC_END_MESSAGE_MAP()
178 178
179 return false; 179 return false;
180 } 180 }
181 181
182 void ContentSettingsObserver::DidCommitProvisionalLoad( 182 void ContentSettingsObserver::DidCommitProvisionalLoad(
183 bool is_new_navigation, 183 bool is_new_navigation,
184 bool is_same_document_navigation) { 184 bool is_same_document_navigation) {
185 WebFrame* frame = render_frame()->GetWebFrame(); 185 blink::WebLocalFrame* frame = render_frame()->GetWebFrame();
186 if (frame->Parent()) 186 if (frame->Parent())
187 return; // Not a top-level navigation. 187 return; // Not a top-level navigation.
188 188
189 if (!is_same_document_navigation) { 189 if (!is_same_document_navigation) {
190 // Clear "block" flags for the new page. This needs to happen before any of 190 // Clear "block" flags for the new page. This needs to happen before any of
191 // |allowScript()|, |allowScriptFromSource()|, |allowImage()|, or 191 // |allowScript()|, |allowScriptFromSource()|, |allowImage()|, or
192 // |allowPlugins()| is called for the new page so that these functions can 192 // |allowPlugins()| is called for the new page so that these functions can
193 // correctly detect that a piece of content flipped from "not blocked" to 193 // correctly detect that a piece of content flipped from "not blocked" to
194 // "blocked". 194 // "blocked".
195 ClearBlockedContentSettings(); 195 ClearBlockedContentSettings();
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 bool ContentSettingsObserver::AllowPlugins(bool enabled_per_settings) { 300 bool ContentSettingsObserver::AllowPlugins(bool enabled_per_settings) {
301 return enabled_per_settings; 301 return enabled_per_settings;
302 } 302 }
303 303
304 bool ContentSettingsObserver::AllowScript(bool enabled_per_settings) { 304 bool ContentSettingsObserver::AllowScript(bool enabled_per_settings) {
305 if (!enabled_per_settings) 305 if (!enabled_per_settings)
306 return false; 306 return false;
307 if (is_interstitial_page_) 307 if (is_interstitial_page_)
308 return true; 308 return true;
309 309
310 WebFrame* frame = render_frame()->GetWebFrame(); 310 blink::WebLocalFrame* frame = render_frame()->GetWebFrame();
311 const auto it = cached_script_permissions_.find(frame); 311 const auto it = cached_script_permissions_.find(frame);
312 if (it != cached_script_permissions_.end()) 312 if (it != cached_script_permissions_.end())
313 return it->second; 313 return it->second;
314 314
315 // Evaluate the content setting rules before 315 // Evaluate the content setting rules before
316 // |IsWhitelistedForContentSettings|; if there is only the default rule 316 // |IsWhitelistedForContentSettings|; if there is only the default rule
317 // allowing all scripts, it's quicker this way. 317 // allowing all scripts, it's quicker this way.
318 bool allow = true; 318 bool allow = true;
319 if (content_setting_rules_) { 319 if (content_setting_rules_) {
320 ContentSetting setting = GetContentSettingFromRules( 320 ContentSetting setting = GetContentSettingFromRules(
(...skipping 19 matching lines...) Expand all
340 if (content_setting_rules_) { 340 if (content_setting_rules_) {
341 ContentSetting setting = 341 ContentSetting setting =
342 GetContentSettingFromRules(content_setting_rules_->script_rules, 342 GetContentSettingFromRules(content_setting_rules_->script_rules,
343 render_frame()->GetWebFrame(), script_url); 343 render_frame()->GetWebFrame(), script_url);
344 allow = setting != CONTENT_SETTING_BLOCK; 344 allow = setting != CONTENT_SETTING_BLOCK;
345 } 345 }
346 return allow || IsWhitelistedForContentSettings(); 346 return allow || IsWhitelistedForContentSettings();
347 } 347 }
348 348
349 bool ContentSettingsObserver::AllowStorage(bool local) { 349 bool ContentSettingsObserver::AllowStorage(bool local) {
350 WebFrame* frame = render_frame()->GetWebFrame(); 350 blink::WebLocalFrame* frame = render_frame()->GetWebFrame();
351 if (frame->GetSecurityOrigin().IsUnique() || 351 if (frame->GetSecurityOrigin().IsUnique() ||
352 frame->Top()->GetSecurityOrigin().IsUnique()) 352 frame->Top()->GetSecurityOrigin().IsUnique())
353 return false; 353 return false;
354 354
355 StoragePermissionsKey key( 355 StoragePermissionsKey key(
356 url::Origin(frame->GetDocument().GetSecurityOrigin()).GetURL(), local); 356 url::Origin(frame->GetDocument().GetSecurityOrigin()).GetURL(), local);
357 const auto permissions = cached_storage_permissions_.find(key); 357 const auto permissions = cached_storage_permissions_.find(key);
358 if (permissions != cached_storage_permissions_.end()) 358 if (permissions != cached_storage_permissions_.end())
359 return permissions->second; 359 return permissions->second;
360 360
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 return false; 416 return false;
417 } 417 }
418 418
419 return true; 419 return true;
420 } 420 }
421 421
422 bool ContentSettingsObserver::AllowAutoplay(bool default_value) { 422 bool ContentSettingsObserver::AllowAutoplay(bool default_value) {
423 if (!content_setting_rules_) 423 if (!content_setting_rules_)
424 return default_value; 424 return default_value;
425 425
426 WebFrame* frame = render_frame()->GetWebFrame(); 426 blink::WebLocalFrame* frame = render_frame()->GetWebFrame();
427 return GetContentSettingFromRules( 427 return GetContentSettingFromRules(
428 content_setting_rules_->autoplay_rules, frame, 428 content_setting_rules_->autoplay_rules, frame,
429 url::Origin(frame->GetDocument().GetSecurityOrigin()).GetURL()) == 429 url::Origin(frame->GetDocument().GetSecurityOrigin()).GetURL()) ==
430 CONTENT_SETTING_ALLOW; 430 CONTENT_SETTING_ALLOW;
431 } 431 }
432 432
433 void ContentSettingsObserver::PassiveInsecureContentFound( 433 void ContentSettingsObserver::PassiveInsecureContentFound(
434 const blink::WebURL& resource_url) { 434 const blink::WebURL& resource_url) {
435 // Note: this implementation is a mirror of 435 // Note: this implementation is a mirror of
436 // Browser::PassiveInsecureContentFound. 436 // Browser::PassiveInsecureContentFound.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 } 473 }
474 474
475 void ContentSettingsObserver::ClearBlockedContentSettings() { 475 void ContentSettingsObserver::ClearBlockedContentSettings() {
476 content_blocked_.clear(); 476 content_blocked_.clear();
477 cached_storage_permissions_.clear(); 477 cached_storage_permissions_.clear();
478 cached_script_permissions_.clear(); 478 cached_script_permissions_.clear();
479 } 479 }
480 480
481 bool ContentSettingsObserver::IsPlatformApp() { 481 bool ContentSettingsObserver::IsPlatformApp() {
482 #if BUILDFLAG(ENABLE_EXTENSIONS) 482 #if BUILDFLAG(ENABLE_EXTENSIONS)
483 WebFrame* frame = render_frame()->GetWebFrame(); 483 blink::WebLocalFrame* frame = render_frame()->GetWebFrame();
484 WebSecurityOrigin origin = frame->GetDocument().GetSecurityOrigin(); 484 WebSecurityOrigin origin = frame->GetDocument().GetSecurityOrigin();
485 const extensions::Extension* extension = GetExtension(origin); 485 const extensions::Extension* extension = GetExtension(origin);
486 return extension && extension->is_platform_app(); 486 return extension && extension->is_platform_app();
487 #else 487 #else
488 return false; 488 return false;
489 #endif 489 #endif
490 } 490 }
491 491
492 #if BUILDFLAG(ENABLE_EXTENSIONS) 492 #if BUILDFLAG(ENABLE_EXTENSIONS)
493 const extensions::Extension* ContentSettingsObserver::GetExtension( 493 const extensions::Extension* ContentSettingsObserver::GetExtension(
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 #endif 540 #endif
541 541
542 // If the scheme is file:, an empty file name indicates a directory listing, 542 // If the scheme is file:, an empty file name indicates a directory listing,
543 // which requires JavaScript to function properly. 543 // which requires JavaScript to function properly.
544 if (protocol == url::kFileScheme && 544 if (protocol == url::kFileScheme &&
545 document_url.ProtocolIs(url::kFileScheme)) { 545 document_url.ProtocolIs(url::kFileScheme)) {
546 return GURL(document_url).ExtractFileName().empty(); 546 return GURL(document_url).ExtractFileName().empty();
547 } 547 }
548 return false; 548 return false;
549 } 549 }
OLDNEW
« no previous file with comments | « chrome/renderer/chrome_content_renderer_client.cc ('k') | chrome/renderer/safe_browsing/phishing_dom_feature_extractor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698