Title: [155417] trunk/Source/WebCore
Revision
155417
Author
[email protected]
Date
2013-09-09 22:43:51 -0700 (Mon, 09 Sep 2013)

Log Message

ScriptController should have a Frame& internally.
<https://webkit.org/b/121071>

Reviewed by Anders Carlsson.

Change ScriptController::m_frame to a reference since it's tied to
the lifetime of the owning Frame.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (155416 => 155417)


--- trunk/Source/WebCore/ChangeLog	2013-09-10 05:42:15 UTC (rev 155416)
+++ trunk/Source/WebCore/ChangeLog	2013-09-10 05:43:51 UTC (rev 155417)
@@ -1,5 +1,15 @@
 2013-09-09  Andreas Kling  <[email protected]>
 
+        ScriptController should have a Frame& internally.
+        <https://webkit.org/b/121071>
+
+        Reviewed by Anders Carlsson.
+
+        Change ScriptController::m_frame to a reference since it's tied to
+        the lifetime of the owning Frame.
+
+2013-09-09  Andreas Kling  <[email protected]>
+
         ScriptRunner should have a Document& internally.
         <https://webkit.org/b/121072>
 

Modified: trunk/Source/WebCore/bindings/ScriptControllerBase.cpp (155416 => 155417)


--- trunk/Source/WebCore/bindings/ScriptControllerBase.cpp	2013-09-10 05:42:15 UTC (rev 155416)
+++ trunk/Source/WebCore/bindings/ScriptControllerBase.cpp	2013-09-10 05:43:51 UTC (rev 155417)
@@ -39,28 +39,28 @@
 
 bool ScriptController::canExecuteScripts(ReasonForCallingCanExecuteScripts reason)
 {
-    if (m_frame->document() && m_frame->document()->isSandboxed(SandboxScripts)) {
+    if (m_frame.document() && m_frame.document()->isSandboxed(SandboxScripts)) {
         // FIXME: This message should be moved off the console once a solution to https://bugs.webkit.org/show_bug.cgi?id=103274 exists.
         if (reason == AboutToExecuteScript)
-            m_frame->document()->addConsoleMessage(SecurityMessageSource, ErrorMessageLevel, "Blocked script execution in '" + m_frame->document()->url().stringCenterEllipsizedToLength() + "' because the document's frame is sandboxed and the 'allow-scripts' permission is not set.");
+            m_frame.document()->addConsoleMessage(SecurityMessageSource, ErrorMessageLevel, "Blocked script execution in '" + m_frame.document()->url().stringCenterEllipsizedToLength() + "' because the document's frame is sandboxed and the 'allow-scripts' permission is not set.");
         return false;
     }
 
-    if (m_frame->document() && m_frame->document()->isViewSource()) {
-        ASSERT(m_frame->document()->securityOrigin()->isUnique());
+    if (m_frame.document() && m_frame.document()->isViewSource()) {
+        ASSERT(m_frame.document()->securityOrigin()->isUnique());
         return true;
     }
 
-    const bool allowed = m_frame->loader().client().allowScript(m_frame->settings().isScriptEnabled());
+    const bool allowed = m_frame.loader().client().allowScript(m_frame.settings().isScriptEnabled());
     if (!allowed && reason == AboutToExecuteScript)
-        m_frame->loader().client().didNotAllowScript();
+        m_frame.loader().client().didNotAllowScript();
     return allowed;
 }
 
 ScriptValue ScriptController::executeScript(const String& script, bool forceUserGesture)
 {
     UserGestureIndicator gestureIndicator(forceUserGesture ? DefinitelyProcessingUserGesture : PossiblyProcessingUserGesture);
-    return executeScript(ScriptSourceCode(script, m_frame->document()->url()));
+    return executeScript(ScriptSourceCode(script, m_frame.document()->url()));
 }
 
 ScriptValue ScriptController::executeScript(const ScriptSourceCode& sourceCode)
@@ -68,7 +68,7 @@
     if (!canExecuteScripts(AboutToExecuteScript) || isPaused())
         return ScriptValue();
 
-    RefPtr<Frame> protect(m_frame); // Script execution can destroy the frame, and thus the ScriptController.
+    Ref<Frame> protect(m_frame); // Script execution can destroy the frame, and thus the ScriptController.
 
     return evaluate(sourceCode);
 }
@@ -78,14 +78,14 @@
     if (!protocolIsJavaScript(url))
         return false;
 
-    if (!m_frame->page()
-        || !m_frame->document()->contentSecurityPolicy()->allowJavaScriptURLs(m_frame->document()->url(), eventHandlerPosition().m_line))
+    if (!m_frame.page()
+        || !m_frame.document()->contentSecurityPolicy()->allowJavaScriptURLs(m_frame.document()->url(), eventHandlerPosition().m_line))
         return true;
 
     // We need to hold onto the Frame here because executing script can
     // destroy the frame.
-    RefPtr<Frame> protector(m_frame);
-    RefPtr<Document> ownerDocument(m_frame->document());
+    Ref<Frame> protector(m_frame);
+    RefPtr<Document> ownerDocument(m_frame.document());
 
     const int _javascript_SchemeLength = sizeof("_javascript_:") - 1;
 
@@ -94,7 +94,7 @@
 
     // If executing script caused this frame to be removed from the page, we
     // don't want to try to replace its document!
-    if (!m_frame->page())
+    if (!m_frame.page())
         return true;
 
     String scriptResult;
@@ -108,11 +108,11 @@
     //        http://bugs.webkit.org/show_bug.cgi?id=16782
     if (shouldReplaceDocumentIfJavaScriptURL == ReplaceDocumentIfJavaScriptURL) {
         // We're still in a frame, so there should be a DocumentLoader.
-        ASSERT(m_frame->document()->loader());
+        ASSERT(m_frame.document()->loader());
         
         // DocumentWriter::replaceDocument can cause the DocumentLoader to get deref'ed and possible destroyed,
         // so protect it with a RefPtr.
-        if (RefPtr<DocumentLoader> loader = m_frame->document()->loader())
+        if (RefPtr<DocumentLoader> loader = m_frame.document()->loader())
             loader->writer()->replaceDocument(scriptResult, ownerDocument.get());
     }
     return true;

Modified: trunk/Source/WebCore/bindings/js/ScriptController.cpp (155416 => 155417)


--- trunk/Source/WebCore/bindings/js/ScriptController.cpp	2013-09-10 05:42:15 UTC (rev 155416)
+++ trunk/Source/WebCore/bindings/js/ScriptController.cpp	2013-09-10 05:43:51 UTC (rev 155417)
@@ -65,7 +65,7 @@
     WTF::initializeMainThread();
 }
 
-ScriptController::ScriptController(Frame* frame)
+ScriptController::ScriptController(Frame& frame)
     : m_frame(frame)
     , m_sourceURL(0)
     , m_paused(false)
@@ -107,7 +107,7 @@
 {
     ASSERT(!m_windowShells.contains(world));
     Structure* structure = JSDOMWindowShell::createStructure(*world->vm(), jsNull());
-    Strong<JSDOMWindowShell> windowShell(*world->vm(), JSDOMWindowShell::create(m_frame->document()->domWindow(), structure, world));
+    Strong<JSDOMWindowShell> windowShell(*world->vm(), JSDOMWindowShell::create(m_frame.document()->domWindow(), structure, world));
     Strong<JSDOMWindowShell> windowShell2(windowShell);
     m_windowShells.add(world, windowShell);
     world->didCreateWindowShell(this);
@@ -133,9 +133,9 @@
 
     JSLockHolder lock(exec);
 
-    RefPtr<Frame> protect = m_frame;
+    Ref<Frame> protect(m_frame);
 
-    InspectorInstrumentationCookie cookie = InspectorInstrumentation::willEvaluateScript(m_frame, sourceURL, sourceCode.startLine());
+    InspectorInstrumentationCookie cookie = InspectorInstrumentation::willEvaluateScript(&m_frame, sourceURL, sourceCode.startLine());
 
     JSValue evaluationException;
 
@@ -192,7 +192,7 @@
         if (m_cacheableBindingRootObject)
             m_cacheableBindingRootObject->updateGlobalObject(windowShell->window());
 
-        if (Page* page = m_frame->page()) {
+        if (Page* page = m_frame.page()) {
             attachDebugger(windowShell, page->debugger());
             windowShell->window()->setProfileGroup(page->group().identifier());
         }
@@ -214,22 +214,22 @@
 
     windowShell->window()->updateDocument();
 
-    if (m_frame->document())
-        windowShell->window()->setEvalEnabled(m_frame->document()->contentSecurityPolicy()->allowEval(0, ContentSecurityPolicy::SuppressReport), m_frame->document()->contentSecurityPolicy()->evalDisabledErrorMessage());   
+    if (m_frame.document())
+        windowShell->window()->setEvalEnabled(m_frame.document()->contentSecurityPolicy()->allowEval(0, ContentSecurityPolicy::SuppressReport), m_frame.document()->contentSecurityPolicy()->evalDisabledErrorMessage());
 
-    if (Page* page = m_frame->page()) {
+    if (Page* page = m_frame.page()) {
         attachDebugger(windowShell, page->debugger());
         windowShell->window()->setProfileGroup(page->group().identifier());
     }
 
-    m_frame->loader().dispatchDidClearWindowObjectInWorld(world);
+    m_frame.loader().dispatchDidClearWindowObjectInWorld(world);
 
     return windowShell;
 }
 
 TextPosition ScriptController::eventHandlerPosition() const
 {
-    ScriptableDocumentParser* parser = m_frame->document()->scriptableDocumentParser();
+    ScriptableDocumentParser* parser = m_frame.document()->scriptableDocumentParser();
     if (parser)
         return parser->textPosition();
     return TextPosition::minimumPosition();
@@ -458,7 +458,7 @@
 ScriptValue ScriptController::executeScriptInWorld(DOMWrapperWorld* world, const String& script, bool forceUserGesture)
 {
     UserGestureIndicator gestureIndicator(forceUserGesture ? DefinitelyProcessingUserGesture : PossiblyProcessingUserGesture);
-    ScriptSourceCode sourceCode(script, m_frame->document()->url());
+    ScriptSourceCode sourceCode(script, m_frame.document()->url());
 
     if (!canExecuteScripts(AboutToExecuteScript) || isPaused())
         return ScriptValue();

Modified: trunk/Source/WebCore/bindings/js/ScriptController.h (155416 => 155417)


--- trunk/Source/WebCore/bindings/js/ScriptController.h	2013-09-10 05:42:15 UTC (rev 155416)
+++ trunk/Source/WebCore/bindings/js/ScriptController.h	2013-09-10 05:43:51 UTC (rev 155417)
@@ -65,7 +65,7 @@
     typedef WTF::HashMap< RefPtr<DOMWrapperWorld>, JSC::Strong<JSDOMWindowShell> > ShellMap;
 
 public:
-    ScriptController(Frame*);
+    explicit ScriptController(Frame&);
     ~ScriptController();
 
     static PassRefPtr<DOMWrapperWorld> createWorld();
@@ -165,7 +165,7 @@
     void disconnectPlatformScriptObjects();
 
     ShellMap m_windowShells;
-    Frame* m_frame;
+    Frame& m_frame;
     const String* m_sourceURL;
 
     bool m_paused;

Modified: trunk/Source/WebCore/page/Frame.cpp (155416 => 155417)


--- trunk/Source/WebCore/page/Frame.cpp	2013-09-10 05:42:15 UTC (rev 155416)
+++ trunk/Source/WebCore/page/Frame.cpp	2013-09-10 05:43:51 UTC (rev 155417)
@@ -157,7 +157,7 @@
     , m_loader(*this, *frameLoaderClient)
     , m_navigationScheduler(this)
     , m_ownerElement(ownerElement)
-    , m_script(adoptPtr(new ScriptController(this)))
+    , m_script(createOwned<ScriptController>(*this))
     , m_editor(Editor::create(*this))
     , m_selection(adoptPtr(new FrameSelection(this)))
     , m_eventHandler(adoptPtr(new EventHandler(*this)))
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to