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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "components/content_settings/content/common/content_settings_messages.h
" | 9 #include "components/content_settings/content/common/content_settings_messages.h
" |
10 #include "content/public/common/url_constants.h" | 10 #include "content/public/common/url_constants.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 static const char kGoogleIntlPathPrefix[] = "/intl/"; | 100 static const char kGoogleIntlPathPrefix[] = "/intl/"; |
101 static const char kDotJS[] = ".js"; | 101 static const char kDotJS[] = ".js"; |
102 static const char kDotCSS[] = ".css"; | 102 static const char kDotCSS[] = ".css"; |
103 static const char kDotSWF[] = ".swf"; | 103 static const char kDotSWF[] = ".swf"; |
104 static const char kDotHTML[] = ".html"; | 104 static const char kDotHTML[] = ".html"; |
105 | 105 |
106 // Constants for mixed-content blocking. | 106 // Constants for mixed-content blocking. |
107 static const char kGoogleDotCom[] = "google.com"; | 107 static const char kGoogleDotCom[] = "google.com"; |
108 | 108 |
109 static bool IsHostInDomain(const std::string& host, const std::string& domain) { | 109 static bool IsHostInDomain(const std::string& host, const std::string& domain) { |
110 return (EndsWith(host, domain, false) && | 110 return (base::EndsWith(host, domain, false) && |
111 (host.length() == domain.length() || | 111 (host.length() == domain.length() || |
112 (host.length() > domain.length() && | 112 (host.length() > domain.length() && |
113 host[host.length() - domain.length() - 1] == '.'))); | 113 host[host.length() - domain.length() - 1] == '.'))); |
114 } | 114 } |
115 | 115 |
116 GURL GetOriginOrURL(const WebFrame* frame) { | 116 GURL GetOriginOrURL(const WebFrame* frame) { |
117 WebString top_origin = frame->top()->securityOrigin().toString(); | 117 WebString top_origin = frame->top()->securityOrigin().toString(); |
118 // The |top_origin| is unique ("null") e.g., for file:// URLs. Use the | 118 // The |top_origin| is unique ("null") e.g., for file:// URLs. Use the |
119 // document URL as the primary URL in those cases. | 119 // document URL as the primary URL in those cases. |
120 // TODO(alexmos): This is broken for --site-per-process, since top() can be a | 120 // TODO(alexmos): This is broken for --site-per-process, since top() can be a |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HOST_CODE_GOOGLE); | 502 SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HOST_CODE_GOOGLE); |
503 } else if (origin_host == kGroupsDotGoogleDotCom) { | 503 } else if (origin_host == kGroupsDotGoogleDotCom) { |
504 SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HOST_GROUPS_GOOGLE); | 504 SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HOST_GROUPS_GOOGLE); |
505 } else if (origin_host == kMapsDotGoogleDotCom) { | 505 } else if (origin_host == kMapsDotGoogleDotCom) { |
506 SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HOST_MAPS_GOOGLE); | 506 SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HOST_MAPS_GOOGLE); |
507 } else if (origin_host == kWWWDotYoutubeDotCom) { | 507 } else if (origin_host == kWWWDotYoutubeDotCom) { |
508 SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HOST_YOUTUBE); | 508 SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HOST_YOUTUBE); |
509 } | 509 } |
510 | 510 |
511 GURL resource_gurl(resource_url); | 511 GURL resource_gurl(resource_url); |
512 if (EndsWith(resource_gurl.path(), kDotHTML, false)) | 512 if (base::EndsWith(resource_gurl.path(), kDotHTML, false)) |
513 SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HTML); | 513 SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HTML); |
514 | 514 |
515 if (allowed_per_settings || allow_displaying_insecure_content_) | 515 if (allowed_per_settings || allow_displaying_insecure_content_) |
516 return true; | 516 return true; |
517 | 517 |
518 Send(new ChromeViewHostMsg_DidBlockDisplayingInsecureContent(routing_id())); | 518 Send(new ChromeViewHostMsg_DidBlockDisplayingInsecureContent(routing_id())); |
519 | 519 |
520 return false; | 520 return false; |
521 } | 521 } |
522 | 522 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 } else if (origin_host == kPicasawebDotGoogleDotCom) { | 557 } else if (origin_host == kPicasawebDotGoogleDotCom) { |
558 SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_PICASAWEB_GOOGLE); | 558 SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_PICASAWEB_GOOGLE); |
559 } else if (origin_host == kCodeDotGoogleDotCom) { | 559 } else if (origin_host == kCodeDotGoogleDotCom) { |
560 SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_CODE_GOOGLE); | 560 SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_CODE_GOOGLE); |
561 } else if (origin_host == kGroupsDotGoogleDotCom) { | 561 } else if (origin_host == kGroupsDotGoogleDotCom) { |
562 SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_GROUPS_GOOGLE); | 562 SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_GROUPS_GOOGLE); |
563 } else if (origin_host == kMapsDotGoogleDotCom) { | 563 } else if (origin_host == kMapsDotGoogleDotCom) { |
564 SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_MAPS_GOOGLE); | 564 SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_MAPS_GOOGLE); |
565 } else if (origin_host == kWWWDotYoutubeDotCom) { | 565 } else if (origin_host == kWWWDotYoutubeDotCom) { |
566 SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_YOUTUBE); | 566 SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_YOUTUBE); |
567 } else if (EndsWith(origin_host, kDotGoogleUserContentDotCom, false)) { | 567 } else if (base::EndsWith(origin_host, kDotGoogleUserContentDotCom, false)) { |
568 SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_GOOGLEUSERCONTENT); | 568 SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_GOOGLEUSERCONTENT); |
569 } | 569 } |
570 | 570 |
571 GURL resource_gurl(resource_url); | 571 GURL resource_gurl(resource_url); |
572 if (resource_gurl.host() == kWWWDotYoutubeDotCom) | 572 if (resource_gurl.host() == kWWWDotYoutubeDotCom) |
573 SendInsecureContentSignal(INSECURE_CONTENT_RUN_TARGET_YOUTUBE); | 573 SendInsecureContentSignal(INSECURE_CONTENT_RUN_TARGET_YOUTUBE); |
574 | 574 |
575 if (EndsWith(resource_gurl.path(), kDotJS, false)) | 575 if (base::EndsWith(resource_gurl.path(), kDotJS, false)) |
576 SendInsecureContentSignal(INSECURE_CONTENT_RUN_JS); | 576 SendInsecureContentSignal(INSECURE_CONTENT_RUN_JS); |
577 else if (EndsWith(resource_gurl.path(), kDotCSS, false)) | 577 else if (base::EndsWith(resource_gurl.path(), kDotCSS, false)) |
578 SendInsecureContentSignal(INSECURE_CONTENT_RUN_CSS); | 578 SendInsecureContentSignal(INSECURE_CONTENT_RUN_CSS); |
579 else if (EndsWith(resource_gurl.path(), kDotSWF, false)) | 579 else if (base::EndsWith(resource_gurl.path(), kDotSWF, false)) |
580 SendInsecureContentSignal(INSECURE_CONTENT_RUN_SWF); | 580 SendInsecureContentSignal(INSECURE_CONTENT_RUN_SWF); |
581 | 581 |
582 if (!allow_running_insecure_content_ && !allowed_per_settings) { | 582 if (!allow_running_insecure_content_ && !allowed_per_settings) { |
583 DidBlockContentType(CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, origin.host()); | 583 DidBlockContentType(CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, origin.host()); |
584 return false; | 584 return false; |
585 } | 585 } |
586 | 586 |
587 return true; | 587 return true; |
588 } | 588 } |
589 | 589 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
717 | 717 |
718 // If the scheme is file:, an empty file name indicates a directory listing, | 718 // If the scheme is file:, an empty file name indicates a directory listing, |
719 // which requires JavaScript to function properly. | 719 // which requires JavaScript to function properly. |
720 if (base::EqualsASCII(origin.protocol(), url::kFileScheme)) { | 720 if (base::EqualsASCII(origin.protocol(), url::kFileScheme)) { |
721 return document_url.SchemeIs(url::kFileScheme) && | 721 return document_url.SchemeIs(url::kFileScheme) && |
722 document_url.ExtractFileName().empty(); | 722 document_url.ExtractFileName().empty(); |
723 } | 723 } |
724 | 724 |
725 return false; | 725 return false; |
726 } | 726 } |
OLD | NEW |