Title: [131704] trunk/Source
Revision
131704
Author
[email protected]
Date
2012-10-17 22:09:09 -0700 (Wed, 17 Oct 2012)

Log Message

Move mixed content logic out of FrameLoader
https://bugs.webkit.org/show_bug.cgi?id=45638

Reviewed by Eric Seidel.

Source/WebCore:

This change moves checks for mixed content out of FrameLoader, and into
a new MixedContentChecker object. It's a pretty straightforward
refactoring with no change to the overall logic, and only minor changes
to the code to reduce repetition.

The only substantive change is renaming the methods from 'checkIf*' to
'can*' to reflect the value of the boolean they return.

The visible functionality shouldn't change; this change should be
covered by existing tests in http/tests/security/mixedContent.

This patch is mostly a revitalization of Eric Sidel's original
patch: https://bugs.webkit.org/attachment.cgi?id=67432&action=""

* CMakeLists.txt:
* GNUmakefile.list.am:
* Target.pri:
* WebCore.gypi:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
    Hey, look! A new file!
* loader/FrameLoader.cpp:
(WebCore::FrameLoader::FrameLoader):
* loader/FrameLoader.h:
(WebCore::FrameLoader::mixedContentChecker):
(FrameLoader):
* loader/MixedContentChecker.cpp: Added.
(WebCore):
(WebCore::MixedContentChecker::MixedContentChecker):
(WebCore::MixedContentChecker::client):
(WebCore::asUTF8):
(WebCore::MixedContentChecker::isMixedContent):
(WebCore::MixedContentChecker::canDisplayInsecureContent):
(WebCore::MixedContentChecker::canRunInsecureContent):
(WebCore::MixedContentChecker::logWarning):
* loader/MixedContentChecker.h: Added.
(WebCore):
(MixedContentChecker):
    Migrate functionality from FrameLoader::checkIf* to
    MixedContentChecker::can*.
* loader/MainResourceLoader.cpp:
(WebCore::MainResourceLoader::willSendRequest):
* loader/SubframeLoader.cpp:
(WebCore::SubframeLoader::pluginIsLoadable):
(WebCore::SubframeLoader::loadMediaPlayerProxyPlugin):
* loader/cache/CachedResourceLoader.cpp:
(WebCore::CachedResourceLoader::checkInsecureContent):
    Use the new method locations.

Source/WebKit/chromium:

* src/WebFrameImpl.cpp:
(WebKit::WebFrameImpl::checkIfRunInsecureContent):
    Use the new method location.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/CMakeLists.txt (131703 => 131704)


--- trunk/Source/WebCore/CMakeLists.txt	2012-10-18 05:01:00 UTC (rev 131703)
+++ trunk/Source/WebCore/CMakeLists.txt	2012-10-18 05:09:09 UTC (rev 131704)
@@ -1634,6 +1634,7 @@
     loader/ImageLoader.cpp
     loader/LinkLoader.cpp
     loader/MainResourceLoader.cpp
+    loader/MixedContentChecker.cpp
     loader/NavigationAction.cpp
     loader/NetscapePlugInStreamLoader.cpp
     loader/PingLoader.cpp

Modified: trunk/Source/WebCore/ChangeLog (131703 => 131704)


--- trunk/Source/WebCore/ChangeLog	2012-10-18 05:01:00 UTC (rev 131703)
+++ trunk/Source/WebCore/ChangeLog	2012-10-18 05:09:09 UTC (rev 131704)
@@ -1,3 +1,59 @@
+2012-10-17  Mike West  <[email protected]>
+
+        Move mixed content logic out of FrameLoader
+        https://bugs.webkit.org/show_bug.cgi?id=45638
+
+        Reviewed by Eric Seidel.
+
+        This change moves checks for mixed content out of FrameLoader, and into
+        a new MixedContentChecker object. It's a pretty straightforward
+        refactoring with no change to the overall logic, and only minor changes
+        to the code to reduce repetition.
+
+        The only substantive change is renaming the methods from 'checkIf*' to
+        'can*' to reflect the value of the boolean they return.
+
+        The visible functionality shouldn't change; this change should be
+        covered by existing tests in http/tests/security/mixedContent.
+
+        This patch is mostly a revitalization of Eric Sidel's original
+        patch: https://bugs.webkit.org/attachment.cgi?id=67432&action=""
+
+        * CMakeLists.txt:
+        * GNUmakefile.list.am:
+        * Target.pri:
+        * WebCore.gypi:
+        * WebCore.vcproj/WebCore.vcproj:
+        * WebCore.xcodeproj/project.pbxproj:
+            Hey, look! A new file!
+        * loader/FrameLoader.cpp:
+        (WebCore::FrameLoader::FrameLoader):
+        * loader/FrameLoader.h:
+        (WebCore::FrameLoader::mixedContentChecker):
+        (FrameLoader):
+        * loader/MixedContentChecker.cpp: Added.
+        (WebCore):
+        (WebCore::MixedContentChecker::MixedContentChecker):
+        (WebCore::MixedContentChecker::client):
+        (WebCore::asUTF8):
+        (WebCore::MixedContentChecker::isMixedContent):
+        (WebCore::MixedContentChecker::canDisplayInsecureContent):
+        (WebCore::MixedContentChecker::canRunInsecureContent):
+        (WebCore::MixedContentChecker::logWarning):
+        * loader/MixedContentChecker.h: Added.
+        (WebCore):
+        (MixedContentChecker):
+            Migrate functionality from FrameLoader::checkIf* to
+            MixedContentChecker::can*.
+        * loader/MainResourceLoader.cpp:
+        (WebCore::MainResourceLoader::willSendRequest):
+        * loader/SubframeLoader.cpp:
+        (WebCore::SubframeLoader::pluginIsLoadable):
+        (WebCore::SubframeLoader::loadMediaPlayerProxyPlugin):
+        * loader/cache/CachedResourceLoader.cpp:
+        (WebCore::CachedResourceLoader::checkInsecureContent):
+            Use the new method locations.
+
 2012-10-17  Dan Bernstein  <[email protected]>
 
         REGRESSION (r95391): ComplexTextController is unnecessarily slow with characters with combining marks when the base character is not covered by any font

Modified: trunk/Source/WebCore/GNUmakefile.list.am (131703 => 131704)


--- trunk/Source/WebCore/GNUmakefile.list.am	2012-10-18 05:01:00 UTC (rev 131703)
+++ trunk/Source/WebCore/GNUmakefile.list.am	2012-10-18 05:09:09 UTC (rev 131704)
@@ -3906,6 +3906,8 @@
 	Source/WebCore/loader/LinkLoaderClient.h \
 	Source/WebCore/loader/MainResourceLoader.cpp \
 	Source/WebCore/loader/MainResourceLoader.h \
+    Source/WebCore/loader/MixedContentChecker.cpp \
+    Source/WebCore/loader/MixedContentChecker.h \
 	Source/WebCore/loader/NavigationAction.cpp \
 	Source/WebCore/loader/NavigationAction.h \
 	Source/WebCore/loader/NetscapePlugInStreamLoader.cpp \

Modified: trunk/Source/WebCore/Target.pri (131703 => 131704)


--- trunk/Source/WebCore/Target.pri	2012-10-18 05:01:00 UTC (rev 131703)
+++ trunk/Source/WebCore/Target.pri	2012-10-18 05:09:09 UTC (rev 131704)
@@ -833,6 +833,7 @@
     loader/ImageLoader.cpp \
     loader/LinkLoader.cpp \
     loader/MainResourceLoader.cpp \
+    loader/MixedContentChecker.cpp \
     loader/NavigationAction.cpp \
     loader/NetscapePlugInStreamLoader.cpp \
     loader/PingLoader.cpp \
@@ -1959,6 +1960,7 @@
     loader/LinkLoader.h \
     loader/LinkLoaderClient.h \
     loader/MainResourceLoader.h \
+    loader/MixedContentChecker.h \
     loader/NavigationAction.h \
     loader/NetscapePlugInStreamLoader.h \
     loader/PlaceholderDocument.h \

Modified: trunk/Source/WebCore/WebCore.gypi (131703 => 131704)


--- trunk/Source/WebCore/WebCore.gypi	2012-10-18 05:01:00 UTC (rev 131703)
+++ trunk/Source/WebCore/WebCore.gypi	2012-10-18 05:09:09 UTC (rev 131704)
@@ -2995,6 +2995,8 @@
             'loader/LinkLoaderClient.h',
             'loader/MainResourceLoader.cpp',
             'loader/MainResourceLoader.h',
+            'loader/MixedContentChecker.cpp',
+            'loader/MixedContentChecker.h',
             'loader/NavigationAction.cpp',
             'loader/NavigationScheduler.cpp',
             'loader/NetscapePlugInStreamLoader.cpp',

Modified: trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj (131703 => 131704)


--- trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj	2012-10-18 05:01:00 UTC (rev 131703)
+++ trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj	2012-10-18 05:09:09 UTC (rev 131704)
@@ -27615,6 +27615,14 @@
 				>
 			</File>
 			<File
+				RelativePath="..\loader\MixedContentChecker.cpp"
+				>
+			</File>
+			<File
+				RelativePath="..\loader\MixedContentChecker.h"
+				>
+			</File>
+			<File
 				RelativePath="..\loader\NavigationAction.cpp"
 				>
 			</File>

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (131703 => 131704)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2012-10-18 05:01:00 UTC (rev 131703)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2012-10-18 05:09:09 UTC (rev 131704)
@@ -1756,6 +1756,7 @@
 		656D373E0ADBA5DE00A4554D /* FrameLoaderClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 656D37260ADBA5DE00A4554D /* FrameLoaderClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		656D373F0ADBA5DE00A4554D /* ResourceLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 656D37270ADBA5DE00A4554D /* ResourceLoader.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		656D37410ADBA5DE00A4554D /* MainResourceLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 656D37290ADBA5DE00A4554D /* MainResourceLoader.h */; };
+		52F10866162B6DA8009AC81E /* MixedContentChecker.h in Headers */ = {isa = PBXBuildFile; fileRef = 52F10863162B6D82009AC81E /* MixedContentChecker.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		656D37430ADBA5DE00A4554D /* NetscapePlugInStreamLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 656D372B0ADBA5DE00A4554D /* NetscapePlugInStreamLoader.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		656D37480ADBA5DE00A4554D /* SubresourceLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 656D37300ADBA5DE00A4554D /* SubresourceLoader.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		6571DCC81385E6A400702DD0 /* MemoryPressureHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 657EDA071385CB97004E0645 /* MemoryPressureHandler.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -3337,6 +3338,7 @@
 		93D9D53C0DA27E180077216C /* RangeBoundaryPoint.h in Headers */ = {isa = PBXBuildFile; fileRef = 93D9D53B0DA27E180077216C /* RangeBoundaryPoint.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		93E227E00AF589AD00D48324 /* DocumentLoader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93E227DB0AF589AD00D48324 /* DocumentLoader.cpp */; };
 		93E227E10AF589AD00D48324 /* MainResourceLoader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93E227DC0AF589AD00D48324 /* MainResourceLoader.cpp */; };
+		52F10865162B6DA4009AC81E /* MixedContentChecker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 52F10862162B6D82009AC81E /* MixedContentChecker.cpp */; };
 		93E227E30AF589AD00D48324 /* ResourceLoader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93E227DE0AF589AD00D48324 /* ResourceLoader.cpp */; };
 		93E227E40AF589AD00D48324 /* SubresourceLoader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93E227DF0AF589AD00D48324 /* SubresourceLoader.cpp */; };
 		93E241FF0B2B4E4000C732A1 /* HTMLFrameOwnerElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 93E241FE0B2B4E4000C732A1 /* HTMLFrameOwnerElement.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -8966,6 +8968,7 @@
 		656D37260ADBA5DE00A4554D /* FrameLoaderClient.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = FrameLoaderClient.h; sourceTree = "<group>"; };
 		656D37270ADBA5DE00A4554D /* ResourceLoader.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = ResourceLoader.h; sourceTree = "<group>"; };
 		656D37290ADBA5DE00A4554D /* MainResourceLoader.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = MainResourceLoader.h; sourceTree = "<group>"; };
+		52F10863162B6D82009AC81E /* MixedContentChecker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MixedContentChecker.h; sourceTree = "<group>"; };
 		656D372B0ADBA5DE00A4554D /* NetscapePlugInStreamLoader.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = NetscapePlugInStreamLoader.h; sourceTree = "<group>"; };
 		656D37300ADBA5DE00A4554D /* SubresourceLoader.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = SubresourceLoader.h; sourceTree = "<group>"; };
 		657EDA061385CB97004E0645 /* MemoryPressureHandler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MemoryPressureHandler.cpp; sourceTree = "<group>"; };
@@ -10551,6 +10554,7 @@
 		93D9D53B0DA27E180077216C /* RangeBoundaryPoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RangeBoundaryPoint.h; sourceTree = "<group>"; };
 		93E227DB0AF589AD00D48324 /* DocumentLoader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DocumentLoader.cpp; sourceTree = "<group>"; };
 		93E227DC0AF589AD00D48324 /* MainResourceLoader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MainResourceLoader.cpp; sourceTree = "<group>"; };
+		52F10862162B6D82009AC81E /* MixedContentChecker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MixedContentChecker.cpp; sourceTree = "<group>"; };
 		93E227DD0AF589AD00D48324 /* NetscapePlugInStreamLoader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetscapePlugInStreamLoader.cpp; sourceTree = "<group>"; };
 		93E227DE0AF589AD00D48324 /* ResourceLoader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ResourceLoader.cpp; sourceTree = "<group>"; };
 		93E227DF0AF589AD00D48324 /* SubresourceLoader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SubresourceLoader.cpp; sourceTree = "<group>"; };
@@ -20679,6 +20683,8 @@
 				984264EF12D5280A000D88A4 /* LinkLoaderClient.h */,
 				93E227DC0AF589AD00D48324 /* MainResourceLoader.cpp */,
 				656D37290ADBA5DE00A4554D /* MainResourceLoader.h */,
+				52F10862162B6D82009AC81E /* MixedContentChecker.cpp */,
+				52F10863162B6D82009AC81E /* MixedContentChecker.h */,
 				93CCF05F0AF6CA7600018E89 /* NavigationAction.cpp */,
 				93CCF0260AF6C52900018E89 /* NavigationAction.h */,
 				979F43D11075E44A0000F83B /* NavigationScheduler.cpp */,
@@ -24457,6 +24463,7 @@
 				BCE1C41B0D982980003B02F2 /* Location.h in Headers */,
 				A8239E0109B3CF8A00B60641 /* Logging.h in Headers */,
 				656D37410ADBA5DE00A4554D /* MainResourceLoader.h in Headers */,
+				52F10866162B6DA8009AC81E /* MixedContentChecker.h in Headers */,
 				1A8F6BC60DB55CDC001DB794 /* ManifestParser.h in Headers */,
 				93309DF8099E64920056E581 /* markup.h in Headers */,
 				9728C3141268E4390041E89B /* MarkupAccumulator.h in Headers */,
@@ -27780,6 +27787,7 @@
 				A8239E0009B3CF8A00B60641 /* Logging.cpp in Sources */,
 				1402645E0AFDC19B005919E2 /* LoggingMac.mm in Sources */,
 				93E227E10AF589AD00D48324 /* MainResourceLoader.cpp in Sources */,
+				52F10865162B6DA4009AC81E /* MixedContentChecker.cpp in Sources */,
 				1A8F6BC50DB55CDC001DB794 /* ManifestParser.cpp in Sources */,
 				93309DF7099E64920056E581 /* markup.cpp in Sources */,
 				9728C3131268E4390041E89B /* MarkupAccumulator.cpp in Sources */,

Modified: trunk/Source/WebCore/loader/FrameLoader.cpp (131703 => 131704)


--- trunk/Source/WebCore/loader/FrameLoader.cpp	2012-10-18 05:01:00 UTC (rev 131703)
+++ trunk/Source/WebCore/loader/FrameLoader.cpp	2012-10-18 05:09:09 UTC (rev 131704)
@@ -212,6 +212,7 @@
     , m_notifer(frame)
     , m_subframeLoader(frame)
     , m_icon(frame)
+    , m_mixedContentChecker(frame)
     , m_state(FrameStateCommittedPage)
     , m_loadType(FrameLoadTypeStandard)
     , m_delegateIsHandlingProvisionalLoadError(false)
@@ -914,51 +915,6 @@
     return m_frame->document()->securityOrigin()->toString();
 }
 
-bool FrameLoader::isMixedContent(SecurityOrigin* context, const KURL& url)
-{
-    if (context->protocol() != "https")
-        return false;  // We only care about HTTPS security origins.
-
-    // We're in a secure context, so |url| is mixed content if it's insecure.
-    return !SecurityOrigin::isSecure(url);
-}
-
-bool FrameLoader::checkIfDisplayInsecureContent(SecurityOrigin* context, const KURL& url)
-{
-    if (!isMixedContent(context, url))
-        return true;
-
-    Settings* settings = m_frame->settings();
-    bool allowed = m_client->allowDisplayingInsecureContent(settings && settings->allowDisplayOfInsecureContent(), context, url);
-    String message = (allowed ? emptyString() : "[blocked] ") + "The page at " +
-        m_frame->document()->url().string() + " displayed insecure content from " + url.string() + ".\n";
-        
-    m_frame->document()->domWindow()->console()->addMessage(HTMLMessageSource, LogMessageType, WarningMessageLevel, message);
-
-    if (allowed)
-        m_client->didDisplayInsecureContent();
-
-    return allowed;
-}
-
-bool FrameLoader::checkIfRunInsecureContent(SecurityOrigin* context, const KURL& url)
-{
-    if (!isMixedContent(context, url))
-        return true;
-
-    Settings* settings = m_frame->settings();
-    bool allowed = m_client->allowRunningInsecureContent(settings && settings->allowRunningOfInsecureContent(), context, url);
-    String message = (allowed ? emptyString() : "[blocked] ") + "The page at " +
-        m_frame->document()->url().string() + " ran insecure content from " + url.string() + ".\n";
-       
-    m_frame->document()->domWindow()->console()->addMessage(HTMLMessageSource, LogMessageType, WarningMessageLevel, message);
-
-    if (allowed)
-        m_client->didRunInsecureContent(context, url);
-
-    return allowed;
-}
-
 bool FrameLoader::checkIfFormActionAllowedByCSP(const KURL& url) const
 {
     if (m_submittedFormURL.isEmpty())

Modified: trunk/Source/WebCore/loader/FrameLoader.h (131703 => 131704)


--- trunk/Source/WebCore/loader/FrameLoader.h	2012-10-18 05:01:00 UTC (rev 131703)
+++ trunk/Source/WebCore/loader/FrameLoader.h	2012-10-18 05:09:09 UTC (rev 131704)
@@ -39,6 +39,7 @@
 #include "IconController.h"
 #include "IconURL.h"
 #include "LayoutMilestones.h"
+#include "MixedContentChecker.h"
 #include "PolicyChecker.h"
 #include "ResourceHandle.h"
 #include "ResourceLoadNotifier.h"
@@ -93,6 +94,7 @@
     ResourceLoadNotifier* notifier() const { return &m_notifer; }
     SubframeLoader* subframeLoader() const { return &m_subframeLoader; }
     IconController* icon() const { return &m_icon; }
+    MixedContentChecker* mixedContentChecker() const { return &m_mixedContentChecker; }
 
     void prepareForHistoryNavigation();
     void setupForReplace();
@@ -213,11 +215,6 @@
     void forceSandboxFlags(SandboxFlags flags) { m_forcedSandboxFlags |= flags; }
     SandboxFlags effectiveSandboxFlags() const;
 
-    // Mixed content related functions.
-    static bool isMixedContent(SecurityOrigin* context, const KURL&);
-    bool checkIfDisplayInsecureContent(SecurityOrigin* context, const KURL&);
-    bool checkIfRunInsecureContent(SecurityOrigin* context, const KURL&);
-
     bool checkIfFormActionAllowedByCSP(const KURL&) const;
 
     Frame* opener();
@@ -374,12 +371,16 @@
     Frame* m_frame;
     FrameLoaderClient* m_client;
 
+    // FIXME: These should be OwnPtr<T> to reduce build times and simplify
+    // header dependencies unless performance testing proves otherwise.
+    // Some of these could be lazily created for memory savings on devices.
     mutable PolicyChecker m_policyChecker;
     mutable HistoryController m_history;
     mutable ResourceLoadNotifier m_notifer;
     mutable SubframeLoader m_subframeLoader;
     mutable FrameLoaderStateMachine m_stateMachine;
     mutable IconController m_icon;
+    mutable MixedContentChecker m_mixedContentChecker;
 
     class FrameProgressTracker;
     OwnPtr<FrameProgressTracker> m_progressTracker;

Modified: trunk/Source/WebCore/loader/MainResourceLoader.cpp (131703 => 131704)


--- trunk/Source/WebCore/loader/MainResourceLoader.cpp	2012-10-18 05:01:00 UTC (rev 131703)
+++ trunk/Source/WebCore/loader/MainResourceLoader.cpp	2012-10-18 05:09:09 UTC (rev 131704)
@@ -236,7 +236,7 @@
 
     Frame* top = m_frame->tree()->top();
     if (top != m_frame) {
-        if (!frameLoader()->checkIfDisplayInsecureContent(top->document()->securityOrigin(), newRequest.url())) {
+        if (!frameLoader()->mixedContentChecker()->canDisplayInsecureContent(top->document()->securityOrigin(), newRequest.url())) {
             cancel();
             return;
         }

Added: trunk/Source/WebCore/loader/MixedContentChecker.cpp (0 => 131704)


--- trunk/Source/WebCore/loader/MixedContentChecker.cpp	                        (rev 0)
+++ trunk/Source/WebCore/loader/MixedContentChecker.cpp	2012-10-18 05:09:09 UTC (rev 131704)
@@ -0,0 +1,108 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer. 
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution. 
+ * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission. 
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "MixedContentChecker.h"
+
+#include "Console.h"
+#include "DOMWindow.h"
+#include "Document.h"
+#include "Frame.h"
+#include "FrameLoaderClient.h"
+#include "SchemeRegistry.h"
+#include "SecurityOrigin.h"
+#include "Settings.h"
+#include <wtf/text/CString.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+MixedContentChecker::MixedContentChecker(Frame* frame)
+    : m_frame(frame)
+{
+}
+
+FrameLoaderClient* MixedContentChecker::client() const
+{
+    return m_frame->loader()->client();
+}
+
+static inline CString asUTF8(const KURL& url)
+{
+    return url.string().utf8();
+}
+
+bool MixedContentChecker::isMixedContent(SecurityOrigin* securityOrigin, const KURL& url)
+{
+    if (securityOrigin->protocol() != "https")
+        return false; // We only care about HTTPS security origins.
+
+    // We're in a secure context, so |url| is mixed content if it's insecure.
+    return !SecurityOrigin::isSecure(url);
+}
+
+bool MixedContentChecker::canDisplayInsecureContent(SecurityOrigin* securityOrigin, const KURL& url) const
+{
+    if (!isMixedContent(securityOrigin, url))
+        return true;
+
+    Settings* settings = m_frame->settings();
+    bool allowed = client()->allowDisplayingInsecureContent(settings && settings->allowDisplayOfInsecureContent(), securityOrigin, url);
+    logWarning(allowed, "displayed", url);
+
+    if (allowed)
+        client()->didDisplayInsecureContent();
+
+    return allowed;
+}
+
+bool MixedContentChecker::canRunInsecureContent(SecurityOrigin* securityOrigin, const KURL& url) const
+{
+    if (!isMixedContent(securityOrigin, url))
+        return true;
+
+    Settings* settings = m_frame->settings();
+    bool allowed = client()->allowRunningInsecureContent(settings && settings->allowRunningOfInsecureContent(), securityOrigin, url);
+    logWarning(allowed, "ran", url);
+
+    if (allowed)
+        client()->didRunInsecureContent(securityOrigin, url);
+
+    return allowed;
+}
+
+void MixedContentChecker::logWarning(bool allowed, const String& action, const KURL& target) const
+{
+    Console* console = m_frame->document()->domWindow()->console();
+    // FIXME: Why does this message not have a source URL or a line number? webkit.org/b/97979
+    String message = String::format("%sThe page at %s %s insecure content from %s.\n",
+        (allowed ? "" : "[blocked] "), asUTF8(m_frame->document()->url()).data(), action.utf8().data(), asUTF8(target).data());
+    console->addMessage(HTMLMessageSource, LogMessageType, WarningMessageLevel, message);
+}
+
+} // namespace WebCore

Added: trunk/Source/WebCore/loader/MixedContentChecker.h (0 => 131704)


--- trunk/Source/WebCore/loader/MixedContentChecker.h	                        (rev 0)
+++ trunk/Source/WebCore/loader/MixedContentChecker.h	2012-10-18 05:09:09 UTC (rev 131704)
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef MixedContentChecker_h
+#define MixedContentChecker_h
+
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+class Frame;
+class FrameLoaderClient;
+class KURL;
+class SecurityOrigin;
+
+class MixedContentChecker {
+    WTF_MAKE_NONCOPYABLE(MixedContentChecker);
+public:
+    MixedContentChecker(Frame*);
+
+    bool canDisplayInsecureContent(SecurityOrigin*, const KURL&) const;
+    bool canRunInsecureContent(SecurityOrigin*, const KURL&) const;
+
+private:
+    // FIXME: This should probably have a separate client from FrameLoader.
+    FrameLoaderClient* client() const;
+
+    static bool isMixedContent(SecurityOrigin*, const KURL&);
+    void logWarning(bool allowed, const String& action, const KURL&) const;
+
+    Frame* m_frame;
+};
+
+} // namespace WebCore
+
+#endif // MixedContentChecker_h
+

Modified: trunk/Source/WebCore/loader/SubframeLoader.cpp (131703 => 131704)


--- trunk/Source/WebCore/loader/SubframeLoader.cpp	2012-10-18 05:01:00 UTC (rev 131703)
+++ trunk/Source/WebCore/loader/SubframeLoader.cpp	2012-10-18 05:09:09 UTC (rev 131704)
@@ -136,7 +136,7 @@
             return false;
         }
 
-        if (m_frame->loader() && !m_frame->loader()->checkIfRunInsecureContent(document()->securityOrigin(), url))
+        if (m_frame->loader() && !m_frame->loader()->mixedContentChecker()->canRunInsecureContent(document()->securityOrigin(), url))
             return false;
     }
 
@@ -265,7 +265,7 @@
     else if (mediaElement->isVideo())
         size = RenderVideo::defaultSize();
 
-    if (!m_frame->loader()->checkIfRunInsecureContent(m_frame->document()->securityOrigin(), completedURL))
+    if (!m_frame->loader()->mixedContentChecker()->canRunInsecureContent(m_frame->document()->securityOrigin(), completedURL))
         return 0;
 
     RefPtr<Widget> widget = m_frame->loader()->client()->createMediaPlayerProxyPlugin(size, mediaElement, completedURL,

Modified: trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp (131703 => 131704)


--- trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp	2012-10-18 05:01:00 UTC (rev 131703)
+++ trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp	2012-10-18 05:09:09 UTC (rev 131704)
@@ -261,7 +261,7 @@
         // These resource can inject script into the current document (Script,
         // XSL) or exfiltrate the content of the current document (CSS).
         if (Frame* f = frame())
-            if (!f->loader()->checkIfRunInsecureContent(m_document->securityOrigin(), url))
+            if (!f->loader()->mixedContentChecker()->canRunInsecureContent(m_document->securityOrigin(), url))
                 return false;
         break;
 #if ENABLE(VIDEO_TRACK)
@@ -276,7 +276,7 @@
         // These resources can corrupt only the frame's pixels.
         if (Frame* f = frame()) {
             Frame* top = f->tree()->top();
-            if (!top->loader()->checkIfDisplayInsecureContent(top->document()->securityOrigin(), url))
+            if (!top->loader()->mixedContentChecker()->canDisplayInsecureContent(top->document()->securityOrigin(), url))
                 return false;
         }
         break;

Modified: trunk/Source/WebKit/chromium/ChangeLog (131703 => 131704)


--- trunk/Source/WebKit/chromium/ChangeLog	2012-10-18 05:01:00 UTC (rev 131703)
+++ trunk/Source/WebKit/chromium/ChangeLog	2012-10-18 05:09:09 UTC (rev 131704)
@@ -1,3 +1,14 @@
+2012-10-17  Mike West  <[email protected]>
+
+        Move mixed content logic out of FrameLoader
+        https://bugs.webkit.org/show_bug.cgi?id=45638
+
+        Reviewed by Eric Seidel.
+
+        * src/WebFrameImpl.cpp:
+        (WebKit::WebFrameImpl::checkIfRunInsecureContent):
+            Use the new method location.
+
 2012-10-17  Shashi Shekhar  <[email protected]>
 
         Remove redundant sdk_build parameter.

Modified: trunk/Source/WebKit/chromium/src/WebFrameImpl.cpp (131703 => 131704)


--- trunk/Source/WebKit/chromium/src/WebFrameImpl.cpp	2012-10-18 05:01:00 UTC (rev 131703)
+++ trunk/Source/WebKit/chromium/src/WebFrameImpl.cpp	2012-10-18 05:09:09 UTC (rev 131704)
@@ -866,7 +866,7 @@
 bool WebFrameImpl::checkIfRunInsecureContent(const WebURL& url) const
 {
     ASSERT(frame());
-    return frame()->loader()->checkIfRunInsecureContent(frame()->document()->securityOrigin(), url);
+    return frame()->loader()->mixedContentChecker()->canRunInsecureContent(frame()->document()->securityOrigin(), url);
 }
 
 v8::Handle<v8::Value> WebFrameImpl::executeScriptAndReturnValue(const WebScriptSource& source)
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to