Changeset 155417 in webkit


Ignore:
Timestamp:
Sep 9, 2013 10:43:51 PM (11 years ago)
Author:
akling@apple.com
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.

Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r155416 r155417  
     12013-09-09  Andreas Kling  <akling@apple.com>
     2
     3        ScriptController should have a Frame& internally.
     4        <https://webkit.org/b/121071>
     5
     6        Reviewed by Anders Carlsson.
     7
     8        Change ScriptController::m_frame to a reference since it's tied to
     9        the lifetime of the owning Frame.
     10
    1112013-09-09  Andreas Kling  <akling@apple.com>
    212
  • trunk/Source/WebCore/bindings/ScriptControllerBase.cpp

    r154449 r155417  
    4040bool ScriptController::canExecuteScripts(ReasonForCallingCanExecuteScripts reason)
    4141{
    42     if (m_frame->document() && m_frame->document()->isSandboxed(SandboxScripts)) {
     42    if (m_frame.document() && m_frame.document()->isSandboxed(SandboxScripts)) {
    4343        // FIXME: This message should be moved off the console once a solution to https://bugs.webkit.org/show_bug.cgi?id=103274 exists.
    4444        if (reason == AboutToExecuteScript)
    45             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.");
     45            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.");
    4646        return false;
    4747    }
    4848
    49     if (m_frame->document() && m_frame->document()->isViewSource()) {
    50         ASSERT(m_frame->document()->securityOrigin()->isUnique());
     49    if (m_frame.document() && m_frame.document()->isViewSource()) {
     50        ASSERT(m_frame.document()->securityOrigin()->isUnique());
    5151        return true;
    5252    }
    5353
    54     const bool allowed = m_frame->loader().client().allowScript(m_frame->settings().isScriptEnabled());
     54    const bool allowed = m_frame.loader().client().allowScript(m_frame.settings().isScriptEnabled());
    5555    if (!allowed && reason == AboutToExecuteScript)
    56         m_frame->loader().client().didNotAllowScript();
     56        m_frame.loader().client().didNotAllowScript();
    5757    return allowed;
    5858}
     
    6161{
    6262    UserGestureIndicator gestureIndicator(forceUserGesture ? DefinitelyProcessingUserGesture : PossiblyProcessingUserGesture);
    63     return executeScript(ScriptSourceCode(script, m_frame->document()->url()));
     63    return executeScript(ScriptSourceCode(script, m_frame.document()->url()));
    6464}
    6565
     
    6969        return ScriptValue();
    7070
    71     RefPtr<Frame> protect(m_frame); // Script execution can destroy the frame, and thus the ScriptController.
     71    Ref<Frame> protect(m_frame); // Script execution can destroy the frame, and thus the ScriptController.
    7272
    7373    return evaluate(sourceCode);
     
    7979        return false;
    8080
    81     if (!m_frame->page()
    82         || !m_frame->document()->contentSecurityPolicy()->allowJavaScriptURLs(m_frame->document()->url(), eventHandlerPosition().m_line))
     81    if (!m_frame.page()
     82        || !m_frame.document()->contentSecurityPolicy()->allowJavaScriptURLs(m_frame.document()->url(), eventHandlerPosition().m_line))
    8383        return true;
    8484
    8585    // We need to hold onto the Frame here because executing script can
    8686    // destroy the frame.
    87     RefPtr<Frame> protector(m_frame);
    88     RefPtr<Document> ownerDocument(m_frame->document());
     87    Ref<Frame> protector(m_frame);
     88    RefPtr<Document> ownerDocument(m_frame.document());
    8989
    9090    const int javascriptSchemeLength = sizeof("javascript:") - 1;
     
    9595    // If executing script caused this frame to be removed from the page, we
    9696    // don't want to try to replace its document!
    97     if (!m_frame->page())
     97    if (!m_frame.page())
    9898        return true;
    9999
     
    109109    if (shouldReplaceDocumentIfJavaScriptURL == ReplaceDocumentIfJavaScriptURL) {
    110110        // We're still in a frame, so there should be a DocumentLoader.
    111         ASSERT(m_frame->document()->loader());
     111        ASSERT(m_frame.document()->loader());
    112112       
    113113        // DocumentWriter::replaceDocument can cause the DocumentLoader to get deref'ed and possible destroyed,
    114114        // so protect it with a RefPtr.
    115         if (RefPtr<DocumentLoader> loader = m_frame->document()->loader())
     115        if (RefPtr<DocumentLoader> loader = m_frame.document()->loader())
    116116            loader->writer()->replaceDocument(scriptResult, ownerDocument.get());
    117117    }
  • trunk/Source/WebCore/bindings/js/ScriptController.cpp

    r154142 r155417  
    6666}
    6767
    68 ScriptController::ScriptController(Frame* frame)
     68ScriptController::ScriptController(Frame& frame)
    6969    : m_frame(frame)
    7070    , m_sourceURL(0)
     
    108108    ASSERT(!m_windowShells.contains(world));
    109109    Structure* structure = JSDOMWindowShell::createStructure(*world->vm(), jsNull());
    110     Strong<JSDOMWindowShell> windowShell(*world->vm(), JSDOMWindowShell::create(m_frame->document()->domWindow(), structure, world));
     110    Strong<JSDOMWindowShell> windowShell(*world->vm(), JSDOMWindowShell::create(m_frame.document()->domWindow(), structure, world));
    111111    Strong<JSDOMWindowShell> windowShell2(windowShell);
    112112    m_windowShells.add(world, windowShell);
     
    134134    JSLockHolder lock(exec);
    135135
    136     RefPtr<Frame> protect = m_frame;
    137 
    138     InspectorInstrumentationCookie cookie = InspectorInstrumentation::willEvaluateScript(m_frame, sourceURL, sourceCode.startLine());
     136    Ref<Frame> protect(m_frame);
     137
     138    InspectorInstrumentationCookie cookie = InspectorInstrumentation::willEvaluateScript(&m_frame, sourceURL, sourceCode.startLine());
    139139
    140140    JSValue evaluationException;
     
    193193            m_cacheableBindingRootObject->updateGlobalObject(windowShell->window());
    194194
    195         if (Page* page = m_frame->page()) {
     195        if (Page* page = m_frame.page()) {
    196196            attachDebugger(windowShell, page->debugger());
    197197            windowShell->window()->setProfileGroup(page->group().identifier());
     
    215215    windowShell->window()->updateDocument();
    216216
    217     if (m_frame->document())
    218         windowShell->window()->setEvalEnabled(m_frame->document()->contentSecurityPolicy()->allowEval(0, ContentSecurityPolicy::SuppressReport), m_frame->document()->contentSecurityPolicy()->evalDisabledErrorMessage());   
    219 
    220     if (Page* page = m_frame->page()) {
     217    if (m_frame.document())
     218        windowShell->window()->setEvalEnabled(m_frame.document()->contentSecurityPolicy()->allowEval(0, ContentSecurityPolicy::SuppressReport), m_frame.document()->contentSecurityPolicy()->evalDisabledErrorMessage());
     219
     220    if (Page* page = m_frame.page()) {
    221221        attachDebugger(windowShell, page->debugger());
    222222        windowShell->window()->setProfileGroup(page->group().identifier());
    223223    }
    224224
    225     m_frame->loader().dispatchDidClearWindowObjectInWorld(world);
     225    m_frame.loader().dispatchDidClearWindowObjectInWorld(world);
    226226
    227227    return windowShell;
     
    230230TextPosition ScriptController::eventHandlerPosition() const
    231231{
    232     ScriptableDocumentParser* parser = m_frame->document()->scriptableDocumentParser();
     232    ScriptableDocumentParser* parser = m_frame.document()->scriptableDocumentParser();
    233233    if (parser)
    234234        return parser->textPosition();
     
    459459{
    460460    UserGestureIndicator gestureIndicator(forceUserGesture ? DefinitelyProcessingUserGesture : PossiblyProcessingUserGesture);
    461     ScriptSourceCode sourceCode(script, m_frame->document()->url());
     461    ScriptSourceCode sourceCode(script, m_frame.document()->url());
    462462
    463463    if (!canExecuteScripts(AboutToExecuteScript) || isPaused())
  • trunk/Source/WebCore/bindings/js/ScriptController.h

    r149871 r155417  
    6666
    6767public:
    68     ScriptController(Frame*);
     68    explicit ScriptController(Frame&);
    6969    ~ScriptController();
    7070
     
    166166
    167167    ShellMap m_windowShells;
    168     Frame* m_frame;
     168    Frame& m_frame;
    169169    const String* m_sourceURL;
    170170
  • trunk/Source/WebCore/page/Frame.cpp

    r155374 r155417  
    158158    , m_navigationScheduler(this)
    159159    , m_ownerElement(ownerElement)
    160     , m_script(adoptPtr(new ScriptController(this)))
     160    , m_script(createOwned<ScriptController>(*this))
    161161    , m_editor(Editor::create(*this))
    162162    , m_selection(adoptPtr(new FrameSelection(this)))
Note: See TracChangeset for help on using the changeset viewer.