Internals: Remove injectPagePopupController()
authortkent@chromium.org <tkent@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Jul 2012 08:22:17 +0000 (08:22 +0000)
committertkent@chromium.org <tkent@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Jul 2012 08:22:17 +0000 (08:22 +0000)
https://bugs.webkit.org/show_bug.cgi?id=91471

Reviewed by Hajime Morita.

r122558 introduced injectPagePopupController(), however we'd like to
avoid adding such JavaScript binding code. We can avoid it by exposing a
PagePopupController for a mock and injecting the following code to the
popup document:

<script>window.pagePopupController = window.internals.pagePopupController</script>

No new tests. This is a kind of refactoring.

* testing/InternalSettings.cpp:
(WebCore::InternalSettings::pagePopupController):
Added. Accessor for PagePopupControler owned by the MockPagePopupDriver.
* testing/InternalSettings.h:
(InternalSettings): Declare pagePopupController() for Internals::pagePopupController().
* testing/Internals.cpp:
(WebCore::Internals::pagePopupController):
Added. This uses InternalSettings::pagePopupController().
* testing/Internals.h:
(Internals): Declare pagePopupController() for Internals.idl.
* testing/Internals.idl: Declare pagePopupController.

* testing/MockPagePopupDriver.cpp:
Moved m_pagePopupController from MockPagePopup to MockPagePopupDriver.
(WebCore::MockPagePopup::MockPagePopup):
Added a script element to prepare window.pagePopupController.
Removed a callsite of injectPagePopupController().
(WebCore::MockPagePopupDriver::openPagePopup):
(WebCore::MockPagePopupDriver::closePagePopup):
* testing/MockPagePopupDriver.h:
(WebCore::MockPagePopupDriver::pagePopupController):
Accessor for a PagePopupController object.
(MockPagePopupDriver): Add RefPtr<PagePopupController> data member.

* testing/v8/WebCoreTestSupport.cpp: Remove injectPagePopupController().
* testing/v8/WebCoreTestSupport.h: ditto.

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

Source/WebCore/ChangeLog
Source/WebCore/testing/InternalSettings.cpp
Source/WebCore/testing/InternalSettings.h
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h
Source/WebCore/testing/Internals.idl
Source/WebCore/testing/MockPagePopupDriver.cpp
Source/WebCore/testing/MockPagePopupDriver.h
Source/WebCore/testing/v8/WebCoreTestSupport.cpp
Source/WebCore/testing/v8/WebCoreTestSupport.h

index bcb0524..e26b5da 100644 (file)
@@ -1,3 +1,46 @@
+2012-07-17  Kent Tamura  <tkent@chromium.org>
+
+        Internals: Remove injectPagePopupController()
+        https://bugs.webkit.org/show_bug.cgi?id=91471
+
+        Reviewed by Hajime Morita.
+
+        r122558 introduced injectPagePopupController(), however we'd like to
+        avoid adding such JavaScript binding code. We can avoid it by exposing a
+        PagePopupController for a mock and injecting the following code to the
+        popup document:
+
+        <script>window.pagePopupController = window.internals.pagePopupController</script>
+
+        No new tests. This is a kind of refactoring.
+
+        * testing/InternalSettings.cpp:
+        (WebCore::InternalSettings::pagePopupController):
+        Added. Accessor for PagePopupControler owned by the MockPagePopupDriver.
+        * testing/InternalSettings.h:
+        (InternalSettings): Declare pagePopupController() for Internals::pagePopupController().
+        * testing/Internals.cpp:
+        (WebCore::Internals::pagePopupController):
+        Added. This uses InternalSettings::pagePopupController().
+        * testing/Internals.h:
+        (Internals): Declare pagePopupController() for Internals.idl.
+        * testing/Internals.idl: Declare pagePopupController.
+
+        * testing/MockPagePopupDriver.cpp:
+        Moved m_pagePopupController from MockPagePopup to MockPagePopupDriver.
+        (WebCore::MockPagePopup::MockPagePopup):
+        Added a script element to prepare window.pagePopupController.
+        Removed a callsite of injectPagePopupController().
+        (WebCore::MockPagePopupDriver::openPagePopup):
+        (WebCore::MockPagePopupDriver::closePagePopup):
+        * testing/MockPagePopupDriver.h:
+        (WebCore::MockPagePopupDriver::pagePopupController):
+        Accessor for a PagePopupController object.
+        (MockPagePopupDriver): Add RefPtr<PagePopupController> data member.
+
+        * testing/v8/WebCoreTestSupport.cpp: Remove injectPagePopupController().
+        * testing/v8/WebCoreTestSupport.h: ditto.
+
 2012-07-17  Ryuan Choi  <ryuan.choi@samsung.com>
 
         [EFL] Move codes related to theme setting from Widget to RenderTheme
index 4ca05ed..531b04f 100644 (file)
@@ -144,6 +144,13 @@ InternalSettings::InternalSettings(Page* page)
 {
 }
 
+#if ENABLE(PAGE_POPUP)
+PagePopupController* InternalSettings::pagePopupController()
+{
+    return m_pagePopupDriver ? m_pagePopupDriver->pagePopupController() : 0;
+}
+#endif
+
 void InternalSettings::reset()
 {
     TextRun::setAllowsRoundingHacks(false);
index c4f833e..f04b1fa 100644 (file)
@@ -44,6 +44,7 @@ class Frame;
 class Document;
 class MockPagePopupDriver;
 class Page;
+class PagePopupController;
 class Settings;
 
 class InternalSettings : public RefCountedSupplement<Page, InternalSettings> {
@@ -81,7 +82,9 @@ public:
     static InternalSettings* from(Page*);
 
     virtual ~InternalSettings();
-
+#if ENABLE(PAGE_POPUP)
+    PagePopupController* pagePopupController();
+#endif
     void reset();
 
     void setInspectorResourcesDataSizeLimits(int maximumResourcesContentSize, int maximumSingleResourceContentSize, ExceptionCode&);
index 869d3d1..e321423 100644 (file)
 #include "NetworkInfoController.h"
 #endif
 
+#if ENABLE(PAGE_POPUP)
+#include "PagePopupController.h"
+#endif
+
 #if ENABLE(TOUCH_ADJUSTMENT)
 #include "EventHandler.h"
 #include "WebKitPoint.h"
@@ -481,6 +485,16 @@ void Internals::setFormControlStateOfPreviousHistoryItem(PassRefPtr<DOMStringLis
         ec = INVALID_ACCESS_ERR;
 }
 
+#if ENABLE(PAGE_POPUP)
+PassRefPtr<PagePopupController> Internals::pagePopupController()
+{
+    InternalSettings* settings = this->settings();
+    if (!settings)
+        return 0;
+    return settings->pagePopupController();
+}
+#endif
+
 PassRefPtr<ClientRect> Internals::absoluteCaretBounds(Document* document, ExceptionCode& ec)
 {
     if (!document || !document->frame() || !document->frame()->selection()) {
index 15b44fc..0400523 100644 (file)
@@ -44,6 +44,7 @@ class Element;
 class Frame;
 class InternalSettings;
 class Node;
+class PagePopupController;
 class Range;
 class ScriptExecutionContext;
 class ShadowRoot;
@@ -101,6 +102,9 @@ public:
 #endif
     PassRefPtr<DOMStringList> formControlStateOfPreviousHistoryItem(ExceptionCode&);
     void setFormControlStateOfPreviousHistoryItem(PassRefPtr<DOMStringList>, ExceptionCode&);
+#if ENABLE(PAGE_POPUP)
+    PassRefPtr<PagePopupController> pagePopupController();
+#endif
 
     PassRefPtr<ClientRect> absoluteCaretBounds(Document*, ExceptionCode&);
 
index f35485f..fde4577 100644 (file)
@@ -71,6 +71,9 @@ module window {
 #endif
         DOMString[] formControlStateOfPreviousHistoryItem() raises(DOMException);
         void setFormControlStateOfPreviousHistoryItem(in DOMString[] values) raises(DOMException);
+#if defined(ENABLE_PAGE_POPUP) && ENABLE_PAGE_POPUP
+        readonly attribute PagePopupController pagePopupController;
+#endif
 
         ClientRect absoluteCaretBounds(in Document document) raises(DOMException);
 
index 2b196a4..1eb7c4a 100644 (file)
@@ -50,12 +50,10 @@ private:
 
     PagePopupClient* m_popupClient;
     RefPtr<HTMLIFrameElement> m_iframe;
-    RefPtr<PagePopupController> m_controller;
 };
 
 inline MockPagePopup::MockPagePopup(PagePopupClient* client, const IntRect& originBoundsInRootView, Frame* mainFrame)
     : m_popupClient(client)
-    , m_controller(PagePopupController::create(client))
 {
     Document* document = mainFrame->document();
     m_iframe = HTMLIFrameElement::create(HTMLNames::iframeTag, document);
@@ -71,10 +69,10 @@ inline MockPagePopup::MockPagePopup(PagePopupClient* client, const IntRect& orig
     writer->setMIMEType("text/html");
     writer->setEncoding("UTF-8", false);
     writer->begin();
+    const char scriptToSetUpPagePopupController[] = "<script>window.pagePopupController = parent.internals.pagePopupController;</script>";
+    writer->addData(scriptToSetUpPagePopupController, sizeof(scriptToSetUpPagePopupController));
     m_popupClient->writeDocument(*writer);
     writer->end();
-
-    WebCoreTestSupport::injectPagePopupController(contentFrame, m_controller.get());
 }
 
 PassOwnPtr<MockPagePopup> MockPagePopup::create(PagePopupClient* client, const IntRect& originBoundsInRootView, Frame* mainFrame)
@@ -110,6 +108,7 @@ PagePopup* MockPagePopupDriver::openPagePopup(PagePopupClient* client, const Int
         closePagePopup(m_mockPagePopup.get());
     if (!client || !m_mainFrame)
         return 0;
+    m_pagePopupController = PagePopupController::create(client);
     m_mockPagePopup = MockPagePopup::create(client, originBoundsInRootView, m_mainFrame);
     return m_mockPagePopup.get();
 }
@@ -119,6 +118,7 @@ void MockPagePopupDriver::closePagePopup(PagePopup* popup)
     if (!popup || popup != m_mockPagePopup.get())
         return;
     m_mockPagePopup.clear();
+    m_pagePopupController.clear();
 }
 
 }
index fdbb47f..e69234b 100644 (file)
@@ -37,11 +37,13 @@ class Frame;
 class IntRect;
 class MockPagePopup;
 class PagePopup;
+class PagePopupController;
 
 class MockPagePopupDriver : public PagePopupDriver {
 public:
     static PassOwnPtr<MockPagePopupDriver> create(Frame* mainFrame);
     virtual ~MockPagePopupDriver();
+    PagePopupController* pagePopupController() { return m_pagePopupController.get(); }
 
 private:
     MockPagePopupDriver(Frame* mainFrame);
@@ -52,6 +54,7 @@ private:
 
     OwnPtr<MockPagePopup> m_mockPagePopup;
     Frame* m_mainFrame;
+    RefPtr<PagePopupController> m_pagePopupController;
 };
 
 }
index 2bdb7a9..218c51c 100644 (file)
@@ -63,14 +63,4 @@ void resetInternalsObject(v8::Local<v8::Context> context)
     InternalSettings::from(static_cast<Document*>(scriptContext)->frame()->page())->reset();
 }
 
-#if ENABLE(PAGE_POPUP)
-void injectPagePopupController(Frame* frame, PagePopupController* controller)
-{
-    ASSERT(frame);
-    ASSERT(controller);
-    v8::HandleScope scope;
-    V8Proxy::mainWorldContext(frame)->Global()->Set(v8::String::New("pagePopupController"), toV8(controller));
-}
-#endif
-
 }
index 258eea3..1ff2d76 100644 (file)
@@ -41,10 +41,6 @@ namespace WebCoreTestSupport {
 void injectInternalsObject(v8::Local<v8::Context>);
 void resetInternalsObject(v8::Local<v8::Context>);
 
-#if ENABLE(PAGE_POPUP)
-void injectPagePopupController(WebCore::Frame*, WebCore::PagePopupController*);
-#endif
-
 } // namespace WebCore
 
 #endif