WebCore:
authorggaren <ggaren@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 3 Nov 2006 20:56:29 +0000 (20:56 +0000)
committerggaren <ggaren@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 3 Nov 2006 20:56:29 +0000 (20:56 +0000)
        Reviewed by Darin, Beth.

        First cut at factoring Page's UIDelegate-related functions into Chrome
        and ChromeClient.

        Layout tests pass.

        * bridge/mac/PageMac.mm: Removed platform-specific constructor, added
        setBridge method to replace it.
        (WebCore::Page::setBridge):

        * bridge/mac/WebCorePageBridge.h: Simplified some things based on the fact
        that WebCorePageBridge.h doesn't need to be included by ObjC-only files,
        and, now that it uses PassRefPtr, can't be.

        * page/Chrome.cpp: Added. Code copied and converted to c++ from WebCorePageBridge.mm.

        * page/Page.h:
        (WebCore::Page::dragCaretController): Made this function non-const so that
        m_dragCaretController doesn't have to be mutable.

WebKit:

        Reviewed by Darin, Beth.

        First cut at factoring Page's UIDelegate-related functions into Chrome
        and ChromeClient.

        Layout tests pass.

        * WebCoreSupport/WebEditorClient.h:
        * WebCoreSupport/WebPageBridge.mm:
        * WebKit.xcodeproj/project.pbxproj:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@17577 268f45cc-cd09-0410-ab3c-d52691b4dbfc

18 files changed:
WebCore/ChangeLog
WebCore/WebCore.exp
WebCore/WebCore.xcodeproj/project.pbxproj
WebCore/bindings/js/kjs_window.cpp
WebCore/bridge/mac/PageMac.mm
WebCore/bridge/mac/WebCorePageBridge.h
WebCore/bridge/mac/WebCorePageBridge.mm
WebCore/loader/ResourceLoader.h
WebCore/loader/mac/ResourceLoaderMac.mm
WebCore/page/Chrome.cpp [new file with mode: 0644]
WebCore/page/Chrome.h [new file with mode: 0644]
WebCore/page/ChromeClient.h [new file with mode: 0644]
WebCore/page/Page.cpp
WebCore/page/Page.h
WebKit/ChangeLog
WebKit/WebCoreSupport/WebPageBridge.mm
WebKit/WebKit.xcodeproj/project.pbxproj
WebKit/WebView/WebView.mm

index 8040236..d003e15 100644 (file)
@@ -1,3 +1,26 @@
+2006-11-02  Geoffrey Garen  <ggaren@apple.com>
+
+        Reviewed by Darin, Beth.
+        
+        First cut at factoring Page's UIDelegate-related functions into Chrome
+        and ChromeClient.
+
+        Layout tests pass.
+        
+        * bridge/mac/PageMac.mm: Removed platform-specific constructor, added
+        setBridge method to replace it.
+        (WebCore::Page::setBridge):
+
+        * bridge/mac/WebCorePageBridge.h: Simplified some things based on the fact
+        that WebCorePageBridge.h doesn't need to be included by ObjC-only files,
+        and, now that it uses PassRefPtr, can't be.
+        
+        * page/Chrome.cpp: Added. Code copied and converted to c++ from WebCorePageBridge.mm.
+
+        * page/Page.h:
+        (WebCore::Page::dragCaretController): Made this function non-const so that
+        m_dragCaretController doesn't have to be mutable.
+
 2006-11-03  Alexey Proskuryakov  <ap@nypop.com>
 
         Reviewed by Adele.
index 31b1aeb..98cdfc9 100644 (file)
@@ -173,7 +173,6 @@ __ZN7WebCore14DocumentLoaderC2EP12NSURLRequest
 __ZN7WebCore14DocumentLoaderD2Ev
 __ZN7WebCore14RenderListItem17markerStringValueEv
 __ZN7WebCore14ResourceLoader14cancelledErrorEv
-__ZN7WebCore14ResourceLoader20inConnectionCallbackEv
 __ZN7WebCore16DeprecatedString6appendENS_14DeprecatedCharE
 __ZN7WebCore16DeprecatedString6appendERKS0_
 __ZN7WebCore16DeprecatedString6appendEc
@@ -328,7 +327,6 @@ __ZNK7WebCore26NetscapePlugInStreamLoader6isDoneEv
 __ZNK7WebCore4Font11primaryFontEv
 __ZNK7WebCore4KURL8getNSURLEv
 __ZNK7WebCore4Page14frameNamespaceEv
-__ZNK7WebCore4Page19dragCaretControllerEv
 __ZNK7WebCore5Frame10isFrameSetEv
 __ZNK7WebCore5Frame13selectionRectEv
 __ZNK7WebCore5Frame15containsPluginsEv
index 3ee9b20..7020e51 100644 (file)
@@ -48,6 +48,9 @@
                14CF7B3309F6ECD700EB3665 /* JSCSSRule.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14CF7B3109F6ECD700EB3665 /* JSCSSRule.cpp */; };
                14CF7B3409F6ECD700EB3665 /* JSCSSRule.h in Headers */ = {isa = PBXBuildFile; fileRef = 14CF7B3209F6ECD700EB3665 /* JSCSSRule.h */; };
                14D0C82509FF0EF5006B36D9 /* kjs_domnode.h in Headers */ = {isa = PBXBuildFile; fileRef = 14D0C82409FF0EF5006B36D9 /* kjs_domnode.h */; };
+               14D823520AF92A790004F057 /* Chrome.h in Headers */ = {isa = PBXBuildFile; fileRef = 14D823500AF92A790004F057 /* Chrome.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               14D8238B0AF92DF60004F057 /* Chrome.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14D8238A0AF92DF60004F057 /* Chrome.cpp */; };
+               14D824080AF93AEB0004F057 /* ChromeClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 14D824060AF93AEB0004F057 /* ChromeClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
                14DC0D3709FED073007B0235 /* JSNode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14DC0D3509FED073007B0235 /* JSNode.cpp */; };
                14DC0D3809FED073007B0235 /* JSNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 14DC0D3609FED073007B0235 /* JSNode.h */; };
                14E8378409F85D1C00B85AE4 /* JSEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14E8378309F85D1C00B85AE4 /* JSEvent.cpp */; };
                14CF7B3209F6ECD700EB3665 /* JSCSSRule.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = JSCSSRule.h; sourceTree = "<group>"; };
                14CF7C2009F7110600EB3665 /* KeyboardEvent.idl */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = KeyboardEvent.idl; sourceTree = "<group>"; };
                14D0C82409FF0EF5006B36D9 /* kjs_domnode.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = kjs_domnode.h; sourceTree = "<group>"; };
+               14D823500AF92A790004F057 /* Chrome.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Chrome.h; sourceTree = "<group>"; };
+               14D8238A0AF92DF60004F057 /* Chrome.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = Chrome.cpp; sourceTree = "<group>"; };
+               14D824060AF93AEB0004F057 /* ChromeClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ChromeClient.h; sourceTree = "<group>"; };
                14DC0D0B09FECFA4007B0235 /* Node.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Node.idl; sourceTree = "<group>"; };
                14DC0D3509FED073007B0235 /* JSNode.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = JSNode.cpp; sourceTree = "<group>"; };
                14DC0D3609FED073007B0235 /* JSNode.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = JSNode.h; sourceTree = "<group>"; };
                                93E22A6E0AF5E94100D48324 /* PageState.cpp */,
                                65D1C1C909932B22000CB324 /* Plugin.h */,
                                F587863A02DE3A1401EA4122 /* Settings.h */,
+                               14D823500AF92A790004F057 /* Chrome.h */,
+                               14D8238A0AF92DF60004F057 /* Chrome.cpp */,
+                               14D824060AF93AEB0004F057 /* ChromeClient.h */,
                        );
                        path = page;
                        sourceTree = "<group>";
                                B2A015BA0AF6CD53006BCE0E /* SVGResourceMasker.h in Headers */,
                                B2EBDC9D0AF77E3400AE4A68 /* SVGRenderTreeAsText.h in Headers */,
                                930908910AF7EDE40081DF01 /* HitTestRequest.h in Headers */,
+                               14D823520AF92A790004F057 /* Chrome.h in Headers */,
+                               14D824080AF93AEB0004F057 /* ChromeClient.h in Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                0867D690FE84028FC02AAC07 /* Project object */ = {
                        isa = PBXProject;
                        buildConfigurationList = 149C284308902B11008A9EFC /* Build configuration list for PBXProject "WebCore" */;
-                       compatibilityVersion = "Xcode 2.4";
                        hasScannedForEncodings = 1;
                        knownRegions = (
                                English,
                        productRefGroup = 034768DFFF38A50411DB9C8B /* Products */;
                        projectDirPath = "";
                        projectRoot = "";
-                       shouldCheckCompatibility = 1;
                        targets = (
                                93F198A508245E59001E9ABC /* WebCore */,
                                DD041FBE09D9DDBE0010AF2A /* Derived Sources */,
                                B2A015B70AF6CD53006BCE0E /* SVGResourceMarker.cpp in Sources */,
                                B2A015B90AF6CD53006BCE0E /* SVGResourceMasker.cpp in Sources */,
                                B2EBDC9C0AF77E3400AE4A68 /* SVGRenderTreeAsText.cpp in Sources */,
+                               14D8238B0AF92DF60004F057 /* Chrome.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index a3a733b..267d0a1 100644 (file)
@@ -23,6 +23,7 @@
 #include "config.h"
 #include "kjs_window.h"
 
+#include "Chrome.h"
 #include "CString.h"
 #include "DOMWindow.h"
 #include "Element.h"
@@ -594,14 +595,14 @@ static Frame* createNewWindow(ExecState* exec, Window* openerWindow, const Depre
 static bool canShowModalDialog(const Window *window)
 {
     if (Frame* frame = window->frame())
-        return frame->page()->canRunModal();
+        return frame->page()->chrome()->canRunModal();
     return false;
 }
 
 static bool canShowModalDialogNow(const Window *window)
 {
     if (Frame* frame = window->frame())
-        return frame->page()->canRunModalNow();
+        return frame->page()->chrome()->canRunModalNow();
     return false;
 }
 
@@ -668,7 +669,7 @@ static JSValue* showModalDialog(ExecState* exec, Window* openerWindow, const Lis
     // properties (in Window::clear), or when on return from runModal.
     JSValue* returnValue = 0;
     dialogWindow->setReturnValueSlot(&returnValue);
-    dialogFrame->page()->runModal();
+    dialogFrame->page()->chrome()->runModal();
     dialogWindow->setReturnValueSlot(0);
 
     // If we don't have a return value, get it now.
index 37106f5..7f8c7d3 100644 (file)
 
 namespace WebCore {
 
-Page::Page(WebCorePageBridge* bridge)
-    : m_frameCount(0)
-    , m_dragCaretController(0, true)
-    , m_defersLoading(false)
-    , m_bridge(bridge)
+void Page::setBridge(WebCorePageBridge* bridge)
 {
-    init();
+    m_bridge = bridge;
 }
 
 // These methods scale between window and WebView coordinates because JavaScript/DOM operations 
@@ -51,27 +47,4 @@ void Page::setWindowRect(const FloatRect& r)
     [bridge() setWindowFrame:flipScreenRect(scalePageRectToScreenCoordinates(r, this))];
 }
 
-bool Page::canRunModal()
-{
-    BEGIN_BLOCK_OBJC_EXCEPTIONS;
-    return [bridge() canRunModal];
-    END_BLOCK_OBJC_EXCEPTIONS;
-    return false;
-}
-
-bool Page::canRunModalNow()
-{
-    BEGIN_BLOCK_OBJC_EXCEPTIONS;
-    return [bridge() canRunModalNow];
-    END_BLOCK_OBJC_EXCEPTIONS;
-    return false;
-}
-
-void Page::runModal()
-{
-    BEGIN_BLOCK_OBJC_EXCEPTIONS;
-    [bridge() runModal];
-    END_BLOCK_OBJC_EXCEPTIONS;
-}
-
 } // namespace WebCore
index 2356502..c8a7700 100644 (file)
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
 
+#include <wtf/PassRefPtr.h>
+
 // WebCorePageBridge is used to bridge between Page in WebCore and
 // WebView in WebKit. It is a two-way bridge, with subclasses expected
 // to implement a protocol of bridging methods.
 
-#ifdef __cplusplus
-namespace WebCore { class Page; }
-typedef WebCore::Page WebCorePage;
-#else
-@class WebCorePage;
-#endif
+namespace WebCore { 
+    class ChromeClient;
+    class Page;
+}
 
 #ifdef __OBJC__
 @class WebCoreFrameBridge;
@@ -45,9 +45,10 @@ class WebCoreFrameBridge;
 
 @interface WebCorePageBridge : NSObject
 {
-    WebCorePage *_page;
+    WebCore::Page* _page;
     BOOL _closed;
 }
+- (id)initWithChromeClient:(PassRefPtr<WebCore::ChromeClient>)chromeClient;
 - (void)close;
 
 - (void)setMainFrame:(WebCoreFrameBridge *)mainFrame;
@@ -70,9 +71,6 @@ class WebCoreFrameBridge;
 
 - (WebCorePageBridge *)createModalDialogWithURL:(NSURL *)URL referrer:(NSString *)referrer;
 
-- (BOOL)canRunModal;
-- (BOOL)canRunModalNow;
-- (void)runModal;
 @end
 
 // This interface definition allows those who hold a WebCorePageBridge * to call all the methods
@@ -86,5 +84,5 @@ class WebCoreFrameBridge;
 // Could move this to another header, but would be a pity to create an entire header just for that.
 
 @interface WebCorePageBridge (WebCoreInternalUse)
-- (WebCorePage *)impl;
+- (WebCore::Page*)impl;
 @end
index 44d9176..8f9aa76 100644 (file)
@@ -26,6 +26,7 @@
 #import "config.h"
 #import "WebCorePageBridge.h"
 
+#import "ChromeClient.h"
 #import "FrameMac.h"
 #import "Page.h"
 #import "WebCoreFrameBridge.h"
@@ -67,12 +68,14 @@ static void initializeLoggingChannelsIfNecessary()
     initializeLogChannel(LogSpellingAndGrammar);
 }
 
-- (id)init
+- (id)initWithChromeClient:(PassRefPtr<ChromeClient>)chromeClient
 {
     initializeLoggingChannelsIfNecessary();
     self = [super init];
-    if (self)
-        _page = new Page(self);
+    if (self) {
+        _page = new Page(chromeClient);
+        _page->setBridge(self);
+    }
     return self;
 }
 
index 8f3434a..4a9a0b5 100644 (file)
@@ -108,10 +108,11 @@ namespace WebCore {
         void receivedRequestToContinueWithoutCredential(NSURLAuthenticationChallenge *);
         void receivedCancellation(NSURLAuthenticationChallenge *);
 
-        // Used to work around the fact that you don't get any more NSURLConnection callbacks until you return from the first one.
-        static bool inConnectionCallback();
 #endif
 
+        // Used to work around the fact that you don't get any more NSURLConnection callbacks until you return from the one you're in.
+        static bool loadsBlocked();
+
     protected:
         ResourceLoader(Frame*);
 
index 47ddd02..1b25d85 100644 (file)
@@ -424,7 +424,8 @@ NSURLResponse *ResourceLoader::response() const
     return m_response.get();
 }
 
-bool ResourceLoader::inConnectionCallback()
+// FIXME: We should move this to ResourceHandle, once it implements all the connection callbacks
+bool ResourceLoader::loadsBlocked()
 {
     return inNSURLConnectionCallback != 0;
 }
diff --git a/WebCore/page/Chrome.cpp b/WebCore/page/Chrome.cpp
new file mode 100644 (file)
index 0000000..2d96d50
--- /dev/null
@@ -0,0 +1,78 @@
+// -*- mode: c++; c-basic-offset: 4 -*-
+/*
+ * Copyright (C) 2006 Apple Computer, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "config.h"
+#include "Chrome.h"
+
+#include "Page.h"
+#include "ResourceLoader.h"
+#include "ChromeClient.h"
+#include <wtf/Vector.h>
+
+namespace WebCore {
+
+bool Chrome::canRunModal()
+{
+    if (!m_client)
+        return false;
+    return m_client->canRunModal();
+}
+
+bool Chrome::canRunModalNow()
+{
+    // If loads are blocked, we can't run modal because the contents
+    // of the modal dialog will never show up!
+    return canRunModal() && !ResourceLoader::loadsBlocked();
+}
+
+void Chrome::runModal()
+{
+    if (!canRunModal())
+        return;
+
+    if (m_page->defersLoading()) {
+        LOG_ERROR("Tried to run modal in a page when it was deferring loading -- should never happen.");
+        return;
+    }
+
+    // Defer callbacks in all the other pages in this group, so we don't try to run JavaScript
+    // in a way that could interact with this view.
+    Vector<Page*> pagesToDefer;
+    if (const HashSet<Page*>* group = m_page->frameNamespace()) {
+        HashSet<Page*>::const_iterator end = group->end();
+        for (HashSet<Page*>::const_iterator it = group->begin(); it != end; ++it) {
+            Page* otherPage = *it;
+            if (otherPage != m_page && !otherPage->defersLoading())
+                pagesToDefer.append(otherPage);
+        }
+    }
+    size_t count = pagesToDefer.size();
+    for (size_t i = 0; i < count; ++i)
+        pagesToDefer[i]->setDefersLoading(true);
+
+    // Go run the modal event loop.
+    m_client->runModal();
+    
+    // Restore loading for any views that we shut down.
+    for (size_t i = 0; i < count; ++i)
+        pagesToDefer[i]->setDefersLoading(false);
+}
+
+} // namespace WebCore
diff --git a/WebCore/page/Chrome.h b/WebCore/page/Chrome.h
new file mode 100644 (file)
index 0000000..144038e
--- /dev/null
@@ -0,0 +1,50 @@
+// -*- mode: c++; c-basic-offset: 4 -*-
+/*
+ * Copyright (C) 2006 Apple Computer, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef Chrome_h
+#define Chrome_h
+
+#include "ChromeClient.h"
+#include <wtf/RefPtr.h>
+#include <wtf/PassRefPtr.h>
+
+namespace WebCore {
+
+    class Page;
+    
+    class Chrome {
+    public:
+        Chrome(Page* page, PassRefPtr<ChromeClient> client)
+            : m_page(page)
+            , m_client(client)
+        {
+        }
+        
+        bool canRunModal();
+        bool canRunModalNow();
+        void runModal();
+
+    private:
+        Page* m_page;
+        RefPtr<ChromeClient> m_client;
+    };
+}
+
+#endif // Chrome_h
diff --git a/WebCore/page/ChromeClient.h b/WebCore/page/ChromeClient.h
new file mode 100644 (file)
index 0000000..9ddf482
--- /dev/null
@@ -0,0 +1,38 @@
+// -*- mode: c++; c-basic-offset: 4 -*-
+/*
+ * Copyright (C) 2006 Apple Computer, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef ChromeClient_h
+#define ChromeClient_h
+
+#include "Shared.h"
+
+namespace WebCore {
+
+    class ChromeClient : public Shared<ChromeClient> {
+    public:
+        virtual ~ChromeClient() { }
+        
+        virtual bool canRunModal() = 0;
+        virtual void runModal() = 0;
+    };
+
+}
+
+#endif // ChromeClient_h
index 0bad24e..24ae35a 100644 (file)
 #include "config.h"
 #include "Page.h"
 
+#include "Chrome.h"
 #include "Frame.h"
 #include "FrameLoader.h"
 #include "FrameTree.h"
+#include "SelectionController.h"
 #include "StringHash.h"
 #include "Widget.h"
 #include <kjs/collector.h>
@@ -37,12 +39,17 @@ namespace WebCore {
 static HashSet<Page*>* allPages;
 static HashMap<String, HashSet<Page*>*>* frameNamespaces;
 
-void Page::init()
+Page::Page(PassRefPtr<ChromeClient> chromeClient)
+    : m_dragCaretController(new SelectionController(0, true))
+    , m_chrome(new Chrome(this, chromeClient))
+    , m_frameCount(0)
+    , m_defersLoading(false)
 {
     if (!allPages) {
         allPages = new HashSet<Page*>;
         setFocusRingColorChangeFunction(setNeedsReapplyStyles);
     }
+
     ASSERT(!allPages->contains(this));
     allPages->add(this);
 }
@@ -64,11 +71,14 @@ Page::~Page()
         Collector::collect();
 #endif
     }
+    
+    delete m_dragCaretController;
+    delete m_chrome;
 }
 
 void Page::setMainFrame(PassRefPtr<Frame> mainFrame)
 {
-    ASSERT(!m_mainFrame);
+    ASSERT(!m_mainFrame); // Should only be called during initialization
     m_mainFrame = mainFrame;
 }
 
@@ -128,11 +138,6 @@ void Page::setNeedsReapplyStylesForSettingsChange(Settings* settings)
                 frame->setNeedsReapplyStyles();
 }
 
-SelectionController* Page::dragCaretController() const
-{
-    return &m_dragCaretController;
-}
-
 void Page::setDefersLoading(bool defers)
 {
     if (defers == m_defersLoading)
index 171bf45..2ad3896 100644 (file)
@@ -22,7 +22,6 @@
 #define Page_h
 
 #include "PlatformString.h"
-#include "SelectionController.h"
 #include <wtf/HashSet.h>
 
 #if PLATFORM(MAC)
@@ -40,14 +39,18 @@ typedef struct HINSTANCE__* HINSTANCE;
 
 namespace WebCore {
 
+    class Chrome;
+    class ChromeClient;
     class Frame;
     class FrameNamespace;
     class FloatRect;
     class Settings;
+    class SelectionController;
     class Widget;
 
     class Page : Noncopyable {
     public:
+        Page(PassRefPtr<ChromeClient>);
         ~Page();
 
         void setMainFrame(PassRefPtr<Frame>);
@@ -69,22 +72,18 @@ namespace WebCore {
         static void setNeedsReapplyStyles();
         static void setNeedsReapplyStylesForSettingsChange(Settings*);
 
-        SelectionController* dragCaretController() const;
-
-        bool canRunModal();
-        bool canRunModalNow();
-        void runModal();
+        SelectionController* dragCaretController() { return m_dragCaretController; }
+        Chrome* chrome() { return m_chrome; }
 
         void setDefersLoading(bool);
         bool defersLoading() const { return m_defersLoading; }
 
 #if PLATFORM(MAC)
-        Page(WebCorePageBridge*);
+        void setBridge(WebCorePageBridge* bridge);
         WebCorePageBridge* bridge() const { return m_bridge; }
 #endif
 
 #if PLATFORM(WIN)
-        Page();
         // The global DLL or application instance used for all windows.
         static void setInstanceHandle(HINSTANCE instanceHandle) { s_instanceHandle = instanceHandle; }
         static HINSTANCE instanceHandle() { return s_instanceHandle; }
@@ -93,12 +92,15 @@ namespace WebCore {
     private:
         void init();
 
+        SelectionController* m_dragCaretController;
+        Chrome* m_chrome;
+
         RefPtr<Frame> m_mainFrame;
         int m_frameCount;
         String m_groupName;
-        mutable SelectionController m_dragCaretController;
 
         bool m_defersLoading;
+
 #if PLATFORM(MAC)
         WebCorePageBridge* m_bridge;
 #endif
index 1cc3ec4..fa901e4 100644 (file)
@@ -1,3 +1,16 @@
+2006-11-02  Geoffrey Garen  <ggaren@apple.com>
+
+        Reviewed by Darin, Beth.
+
+        First cut at factoring Page's UIDelegate-related functions into Chrome
+        and ChromeClient.
+
+        Layout tests pass.
+        
+        * WebCoreSupport/WebEditorClient.h:
+        * WebCoreSupport/WebPageBridge.mm:
+        * WebKit.xcodeproj/project.pbxproj:
+
 2006-11-02  Timothy Hatcher  <timothy@apple.com>
 
         Reviewed by Brady.
index 63600db..192a07f 100644 (file)
@@ -28,6 +28,7 @@
 
 #import "WebPageBridge.h"
 
+#import "WebChromeClient.h"
 #import "WebDefaultUIDelegate.h"
 #import "WebFrameBridge.h"
 #import "WebFrameView.h"
@@ -38,8 +39,9 @@
 #import "WebViewInternal.h"
 #import <JavaScriptCore/Assertions.h>
 #import <WebCore/Page.h>
-#import <WebCore/WebCoreFrameNamespaces.h>
 #import <WebCore/ResourceLoader.h>
+#import <WebCore/WebCoreFrameNamespaces.h>
+#import <wtf/Forward.h>
 
 using namespace WebCore;
 
@@ -47,7 +49,7 @@ using namespace WebCore;
 
 - (id)initWithMainFrameName:(NSString *)frameName webView:(WebView *)webView frameView:(WebFrameView *)frameView
 {
-    self = [super init];
+    self = [super initWithChromeClient:WebChromeClient::create(webView)];
     if (self) {
         _webView = webView;
         WebFrameBridge *mainFrame = [[WebFrameBridge alloc] initMainFrameWithPage:self frameName:frameName view:frameView];
@@ -103,47 +105,4 @@ using namespace WebCore;
     return [newWebView _pageBridge];
 }
 
-- (BOOL)canRunModal
-{
-    return [[_webView UIDelegate] respondsToSelector:@selector(webViewRunModal:)];
-}
-
-- (BOOL)canRunModalNow
-{
-    return [self canRunModal] && !ResourceLoader::inConnectionCallback();
-}
-
-- (void)runModal
-{
-    if (![self canRunModal])
-        return;
-
-    if (_page->defersLoading()) {
-        LOG_ERROR("tried to run modal in a view when it was deferring loading -- should never happen");
-        return;
-    }
-
-    // Defer callbacks in all the other pages in this group, so we don't try to run JavaScript
-    // in a way that could interact with this view.
-    Vector<Page*> pagesToDefer;
-    if (const HashSet<Page*>* group = _page->frameNamespace()) {
-        HashSet<Page*>::const_iterator end = group->end();
-        for (HashSet<Page*>::const_iterator it = group->begin(); it != end; ++it) {
-            Page* otherPage = *it;
-            if (otherPage != _page && !otherPage->defersLoading())
-                pagesToDefer.append(otherPage);
-        }
-    }
-    size_t count = pagesToDefer.size();
-    for (size_t i = 0; i < count; ++i)
-        pagesToDefer[i]->setDefersLoading(true);
-
-    // Go run the modal event loop.
-    [[_webView UIDelegate] webViewRunModal:_webView];
-
-    // Restore loading for any views that we shut down.
-    for (size_t i = 0; i < count; ++i)
-        pagesToDefer[i]->setDefersLoading(false);
-}
-
 @end
index b0022b6..13d0c11 100644 (file)
@@ -7,6 +7,8 @@
        objects = {
 
 /* Begin PBXBuildFile section */
+               14D8252F0AF955090004F057 /* WebChromeClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 14D8252D0AF955090004F057 /* WebChromeClient.h */; };
+               14D825300AF955090004F057 /* WebChromeClient.mm in Sources */ = {isa = PBXBuildFile; fileRef = 14D8252E0AF955090004F057 /* WebChromeClient.mm */; };
                1C0706630A431E01001078F6 /* WebScriptDebugServer.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C0706620A431E01001078F6 /* WebScriptDebugServer.h */; settings = {ATTRIBUTES = (Private, ); }; };
                1C07073D0A433BD8001078F6 /* WebScriptDebugServer.m in Sources */ = {isa = PBXBuildFile; fileRef = 1C07073C0A433BD8001078F6 /* WebScriptDebugServer.m */; };
                1C07079A0A433E22001078F6 /* WebScriptDebugServerPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C0707990A433E22001078F6 /* WebScriptDebugServerPrivate.h */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXFileReference section */
+               14D8252D0AF955090004F057 /* WebChromeClient.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = WebChromeClient.h; sourceTree = "<group>"; };
+               14D8252E0AF955090004F057 /* WebChromeClient.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = WebChromeClient.mm; sourceTree = "<group>"; };
                1C0706620A431E01001078F6 /* WebScriptDebugServer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebScriptDebugServer.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
                1C07073C0A433BD8001078F6 /* WebScriptDebugServer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WebScriptDebugServer.m; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
                1C0707990A433E22001078F6 /* WebScriptDebugServerPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebScriptDebugServerPrivate.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
                F5B36B400281DE87018635CB /* WebCoreSupport */ = {
                        isa = PBXGroup;
                        children = (
+                               14D8252D0AF955090004F057 /* WebChromeClient.h */,
+                               14D8252E0AF955090004F057 /* WebChromeClient.mm */,
                                9305892A070868B300E79D96 /* WebDashboardRegion.h */,
                                4BF99F8E0AE050BC00815C2B /* WebEditorClient.h */,
                                4BF99F8F0AE050BC00815C2B /* WebEditorClient.mm */,
                                1CA57D620AED6A470009BDD0 /* WebGraphicsExtras.h in Headers */,
                                656D333E0AF21AE900212169 /* WebResourceLoadDelegatePrivate.h in Headers */,
                                931633EB0AEDFF930062B92D /* WebFrameLoaderClient.h in Headers */,
+                               14D8252F0AF955090004F057 /* WebChromeClient.h in Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                                4BF99F910AE050BC00815C2B /* WebEditorClient.mm in Sources */,
                                1CA57D630AED6A470009BDD0 /* WebGraphicsExtras.c in Sources */,
                                931633EF0AEDFFAE0062B92D /* WebFrameLoaderClient.mm in Sources */,
+                               14D825300AF955090004F057 /* WebChromeClient.mm in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index b700dd7..64305b4 100644 (file)
@@ -93,6 +93,7 @@
 #import <WebCore/FrameMac.h>
 #import <WebCore/FrameTree.h>
 #import <WebCore/Page.h>
+#import <WebCore/SelectionController.h>
 #import <WebCore/WebCoreEncodings.h>
 #import <WebCore/WebCoreFrameBridge.h>
 #import <WebCore/WebCoreSettings.h>