⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 243219 in webkit


Ignore:
Timestamp:
Mar 20, 2019, 11:53:47 AM (7 years ago)
Author:
Devin Rousso
Message:

Web Inspector: Database: lazily create the agent
https://bugs.webkit.org/show_bug.cgi?id=195587
<rdar://problem/48791735>

Reviewed by Timothy Hatcher.

Source/WebCore:

No change in functionality.

  • inspector/agents/InspectorDatabaseAgent.h:
  • inspector/agents/InspectorDatabaseAgent.cpp:

(WebCore::InspectorDatabaseAgent::didCommitLoad): Added.
(WebCore::InspectorDatabaseAgent::didOpenDatabase):
(WebCore::InspectorDatabaseAgent::InspectorDatabaseAgent):
(WebCore::InspectorDatabaseAgent::enable):
(WebCore::InspectorDatabaseAgent::disable):
(WebCore::InspectorDatabaseAgent::getDatabaseTableNames):
(WebCore::InspectorDatabaseAgent::executeSQL):
(WebCore::InspectorDatabaseAgent::databaseId):
(WebCore::InspectorDatabaseAgent::findByFileName):
(WebCore::InspectorDatabaseAgent::databaseForId):
(WebCore::InspectorDatabaseAgent::clearResources): Deleted.
(WebCore::InspectorDatabaseAgent::~InspectorDatabaseAgent): Deleted.

  • inspector/InspectorDatabaseResource.h:

(WebCore::InspectorDatabaseResource::database const):
(WebCore::InspectorDatabaseResource::setDatabase):
(WebCore::InspectorDatabaseResource::database): Deleted.

  • inspector/InspectorDatabaseResource.cpp:

(WebCore::InspectorDatabaseResource::create):
(WebCore::InspectorDatabaseResource::InspectorDatabaseResource):
(WebCore::InspectorDatabaseResource::bind):

  • inspector/InspectorInstrumentation.h:

(WebCore::InspectorInstrumentation::didOpenDatabase):

  • inspector/InspectorInstrumentation.cpp:

(WebCore::InspectorInstrumentation::didCommitLoadImpl):
(WebCore::InspectorInstrumentation::didOpenDatabaseImpl):
Pass the Database as a reference instead of a pointer. Retrieve any information directly
from the Database, rather than using the arguments that were used to create it.

  • Modules/webdatabase/Database.h:

(WebCore::Database::expectedVersion const): Deleted.

  • Modules/webdatabase/Database.cpp:

(WebCore::Database::expectedVersion const): Added.

  • Modules/webdatabase/DatabaseManager.cpp:

(WebCore::DatabaseManager::openDatabase):

  • Modules/webdatabase/DatabaseTracker.h:
  • Modules/webdatabase/DatabaseTracker.cpp:

(WebCore::DatabaseTracker::closeAllDatabases):
(WebCore::DatabaseTracker::openDatabases): Added.
Expose various values used by InspectorDatabaseAgent and InspectorDatabaseResource.

  • inspector/InspectorController.cpp:

(WebCore::InspectorController::InspectorController):
(WebCore::InspectorController::createLazyAgents):

  • inspector/WorkerInspectorController.cpp:

(WebCore::WorkerInspectorController::WorkerInspectorController):

  • inspector/CommandLineAPIHost.h:

(WebCore::CommandLineAPIHost::init):

  • inspector/CommandLineAPIHost.cpp:

(WebCore::CommandLineAPIHost::disconnect):
(WebCore::CommandLineAPIHost::inspect):
(WebCore::CommandLineAPIHost::clearConsoleMessages):
(WebCore::CommandLineAPIHost::databaseId):
(WebCore::CommandLineAPIHost::storageId):
Rather than pass each agent individually, pass the entire InstrumentingAgents so that the
current agent can be used instead of whatever was initially created.

LayoutTests:

  • inspector/protocol/backend-dispatcher-argument-errors.html:
  • inspector/runtime/CommandLineAPI-inspect.html:
Location:
trunk
Files:
20 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r243211 r243219  
     12019-03-20  Devin Rousso  <drousso@apple.com>
     2
     3        Web Inspector: Database: lazily create the agent
     4        https://bugs.webkit.org/show_bug.cgi?id=195587
     5        <rdar://problem/48791735>
     6
     7        Reviewed by Timothy Hatcher.
     8
     9        * inspector/protocol/backend-dispatcher-argument-errors.html:
     10        * inspector/runtime/CommandLineAPI-inspect.html:
     11
    1122019-03-20  Simon Fraser  <simon.fraser@apple.com>
    213
  • trunk/LayoutTests/inspector/protocol/backend-dispatcher-argument-errors-expected.txt

    r200467 r243219  
    3636
    3737-- Running test case: TestErrorCodeForSyncServerError
    38 Sending message: {"id":123,"method":"Database.getDatabaseTableNames","params":{"databaseId":"thisisNotADatabase"}}
    39 PASS: the backend should send a protocol error when receiving an invalid message.
    40 PASS: the reported error should be "ServerError" (-32000)
    41 Actual error code: -32000
    42 Actual error message: Database agent is not enabled
    43 Actual error data: [{"code":-32000,"message":"Database agent is not enabled"}]
    44 
    45 -- Running test case: TestErrorCodeForAsyncServerError
    46 Sending message: {"id":123,"method":"Database.executeSQL","params":{"databaseId":"thisisNotADatabase","query":"asdf"}}
    47 PASS: the backend should send a protocol error when receiving an invalid message.
    48 PASS: the reported error should be "ServerError" (-32000)
    49 Actual error code: -32000
    50 Actual error message: Database agent is not enabled
    51 Actual error data: [{"code":-32000,"message":"Database agent is not enabled"}]
    52 
    53 -- Running test case: CommandWithBadArgumentValue
    5438Sending message: {"id":123,"method":"Runtime.getProperties","params":{"objectId":"thisisNotAnId"}}
    5539PASS: the backend should send a protocol error when receiving an invalid message.
     
    5943Actual error data: [{"code":-32000,"message":"Could not find InjectedScript for objectId"}]
    6044
     45-- Running test case: TestErrorCodeForAsyncServerError
     46Sending message: {"id":123,"method":"Runtime.awaitPromise","params":{"promiseObjectId":"thisisNotAnId"}}
     47PASS: the backend should send a protocol error when receiving an invalid message.
     48PASS: the reported error should be "ServerError" (-32000)
     49Actual error code: -32000
     50Actual error message: Could not find InjectedScript for promiseObjectId
     51Actual error data: [{"code":-32000,"message":"Could not find InjectedScript for promiseObjectId"}]
     52
  • trunk/LayoutTests/inspector/protocol/backend-dispatcher-argument-errors.html

    r210062 r243219  
    7777        name: "TestErrorCodeForSyncServerError",
    7878        description: "The backend should return a server error with the correct error code.",
    79         message: {id: 123, method: "Database.getDatabaseTableNames", params: {databaseId: "thisisNotADatabase"}},
     79        message: {id: 123, method: "Runtime.getProperties", params: {objectId: "thisisNotAnId"}},
    8080        expectedError: "ServerError"
    8181    });
     
    8484        name: "TestErrorCodeForAsyncServerError",
    8585        description: "The backend should return a server error with the correct error code.",
    86         message: {id: 123, method: "Database.executeSQL", params: {databaseId: "thisisNotADatabase", query: "asdf"}},
    87         expectedError: "ServerError"
    88     });
    89 
    90     addErrorResponseTestCase({
    91         name: "CommandWithBadArgumentValue",
    92         description: "The backend should return an error if something went wrong when invoking the agent's method.",
    93         message: {id: 123, method: "Runtime.getProperties", params: {objectId: "thisisNotAnId"}},
     86        message: {id: 123, method: "Runtime.awaitPromise", params: {promiseObjectId: "thisisNotAnId"}},
    9487        expectedError: "ServerError"
    9588    });
  • trunk/LayoutTests/inspector/runtime/CommandLineAPI-inspect.html

    r220159 r243219  
    2626
    2727    InspectorProtocol.awaitCommand({method: "Inspector.enable", params: {}})
     28    InspectorProtocol.awaitCommand({method: "Database.enable", params: {}})
    2829
    2930    function addTestCase({name, description, expression}) {
  • trunk/Source/WebCore/ChangeLog

    r243218 r243219  
     12019-03-20  Devin Rousso  <drousso@apple.com>
     2
     3        Web Inspector: Database: lazily create the agent
     4        https://bugs.webkit.org/show_bug.cgi?id=195587
     5        <rdar://problem/48791735>
     6
     7        Reviewed by Timothy Hatcher.
     8
     9        No change in functionality.
     10
     11        * inspector/agents/InspectorDatabaseAgent.h:
     12        * inspector/agents/InspectorDatabaseAgent.cpp:
     13        (WebCore::InspectorDatabaseAgent::didCommitLoad): Added.
     14        (WebCore::InspectorDatabaseAgent::didOpenDatabase):
     15        (WebCore::InspectorDatabaseAgent::InspectorDatabaseAgent):
     16        (WebCore::InspectorDatabaseAgent::enable):
     17        (WebCore::InspectorDatabaseAgent::disable):
     18        (WebCore::InspectorDatabaseAgent::getDatabaseTableNames):
     19        (WebCore::InspectorDatabaseAgent::executeSQL):
     20        (WebCore::InspectorDatabaseAgent::databaseId):
     21        (WebCore::InspectorDatabaseAgent::findByFileName):
     22        (WebCore::InspectorDatabaseAgent::databaseForId):
     23        (WebCore::InspectorDatabaseAgent::clearResources): Deleted.
     24        (WebCore::InspectorDatabaseAgent::~InspectorDatabaseAgent): Deleted.
     25        * inspector/InspectorDatabaseResource.h:
     26        (WebCore::InspectorDatabaseResource::database const):
     27        (WebCore::InspectorDatabaseResource::setDatabase):
     28        (WebCore::InspectorDatabaseResource::database): Deleted.
     29        * inspector/InspectorDatabaseResource.cpp:
     30        (WebCore::InspectorDatabaseResource::create):
     31        (WebCore::InspectorDatabaseResource::InspectorDatabaseResource):
     32        (WebCore::InspectorDatabaseResource::bind):
     33        * inspector/InspectorInstrumentation.h:
     34        (WebCore::InspectorInstrumentation::didOpenDatabase):
     35        * inspector/InspectorInstrumentation.cpp:
     36        (WebCore::InspectorInstrumentation::didCommitLoadImpl):
     37        (WebCore::InspectorInstrumentation::didOpenDatabaseImpl):
     38        Pass the `Database` as a reference instead of a pointer. Retrieve any information directly
     39        from the `Database`, rather than using the arguments that were used to create it.
     40
     41        * Modules/webdatabase/Database.h:
     42        (WebCore::Database::expectedVersion const): Deleted.
     43        * Modules/webdatabase/Database.cpp:
     44        (WebCore::Database::expectedVersion const): Added.
     45        * Modules/webdatabase/DatabaseManager.cpp:
     46        (WebCore::DatabaseManager::openDatabase):
     47        * Modules/webdatabase/DatabaseTracker.h:
     48        * Modules/webdatabase/DatabaseTracker.cpp:
     49        (WebCore::DatabaseTracker::closeAllDatabases):
     50        (WebCore::DatabaseTracker::openDatabases): Added.
     51        Expose various values used by `InspectorDatabaseAgent` and `InspectorDatabaseResource`.
     52
     53        * inspector/InspectorController.cpp:
     54        (WebCore::InspectorController::InspectorController):
     55        (WebCore::InspectorController::createLazyAgents):
     56        * inspector/WorkerInspectorController.cpp:
     57        (WebCore::WorkerInspectorController::WorkerInspectorController):
     58
     59        * inspector/CommandLineAPIHost.h:
     60        (WebCore::CommandLineAPIHost::init):
     61        * inspector/CommandLineAPIHost.cpp:
     62        (WebCore::CommandLineAPIHost::disconnect):
     63        (WebCore::CommandLineAPIHost::inspect):
     64        (WebCore::CommandLineAPIHost::clearConsoleMessages):
     65        (WebCore::CommandLineAPIHost::databaseId):
     66        (WebCore::CommandLineAPIHost::storageId):
     67        Rather than pass each agent individually, pass the entire `InstrumentingAgents` so that the
     68        current agent can be used instead of whatever was initially created.
     69
    1702019-03-20  Oriol Brufau  <obrufau@igalia.com>
    271
  • trunk/Source/WebCore/Modules/webdatabase/Database.cpp

    r242251 r243219  
    619619}
    620620
     621String Database::expectedVersion() const
     622{
     623    // Return a deep copy for ref counting thread safety
     624    return m_expectedVersion.isolatedCopy();
     625}
     626
    621627unsigned long long Database::estimatedSize() const
    622628{
  • trunk/Source/WebCore/Modules/webdatabase/Database.h

    r236348 r243219  
    8989    String stringIdentifier() const;
    9090    String displayName() const;
     91    String expectedVersion() const;
    9192    unsigned long long estimatedSize() const;
    9293    String fileName() const;
     
    134135    bool setVersionInDatabase(const String& version, bool shouldCacheVersion = true);
    135136    void setExpectedVersion(const String&);
    136     const String& expectedVersion() const { return m_expectedVersion; }
    137137    String getCachedVersion() const;
    138138    void setCachedVersion(const String&);
  • trunk/Source/WebCore/Modules/webdatabase/DatabaseManager.cpp

    r243163 r243219  
    212212    auto databaseContext = this->databaseContext(context);
    213213    databaseContext->setHasOpenDatabases();
    214     InspectorInstrumentation::didOpenDatabase(&context, database.copyRef(), context.securityOrigin()->host(), name, expectedVersion);
     214    InspectorInstrumentation::didOpenDatabase(*database);
    215215
    216216    if (database->isNew() && creationCallback.get()) {
  • trunk/Source/WebCore/Modules/webdatabase/DatabaseTracker.cpp

    r243163 r243219  
    290290void DatabaseTracker::closeAllDatabases(CurrentQueryBehavior currentQueryBehavior)
    291291{
    292     Vector<Ref<Database>> openDatabases;
    293     {
    294         LockHolder openDatabaseMapLock(m_openDatabaseMapGuard);
    295         if (!m_openDatabaseMap)
    296             return;
    297         for (auto& nameMap : m_openDatabaseMap->values()) {
    298             for (auto& set : nameMap->values()) {
    299                 for (auto& database : *set)
    300                     openDatabases.append(*database);
    301             }
    302         }
    303     }
    304     for (auto& database : openDatabases) {
     292    for (auto& database : openDatabases()) {
    305293        if (currentQueryBehavior == CurrentQueryBehavior::Interrupt)
    306294            database->interrupt();
     
    532520    LockHolder lockDatabase(m_databaseGuard);
    533521    doneCreatingDatabase(database.securityOrigin(), database.stringIdentifier());
     522}
     523
     524Vector<Ref<Database>> DatabaseTracker::openDatabases()
     525{
     526    Vector<Ref<Database>> openDatabases;
     527    {
     528        LockHolder openDatabaseMapLock(m_openDatabaseMapGuard);
     529
     530        if (m_openDatabaseMap) {
     531            for (auto& nameMap : m_openDatabaseMap->values()) {
     532                for (auto& set : nameMap->values()) {
     533                    for (auto& database : *set)
     534                        openDatabases.append(*database);
     535                }
     536            }
     537        }
     538    }
     539    return openDatabases;
    534540}
    535541
  • trunk/Source/WebCore/Modules/webdatabase/DatabaseTracker.h

    r237266 r243219  
    7373    WEBCORE_EXPORT String fullPathForDatabase(const SecurityOriginData&, const String& name, bool createIfDoesNotExist);
    7474
     75    Vector<Ref<Database>> openDatabases();
    7576    void addOpenDatabase(Database&);
    7677    void removeOpenDatabase(Database&);
  • trunk/Source/WebCore/inspector/CommandLineAPIHost.cpp

    r243158 r243219  
    4242#include "Pasteboard.h"
    4343#include "Storage.h"
     44#include "WebConsoleAgent.h"
    4445#include <JavaScriptCore/InspectorAgent.h>
    45 #include <JavaScriptCore/InspectorConsoleAgent.h>
    4646#include <JavaScriptCore/JSCInlines.h>
    4747#include <JavaScriptCore/JSLock.h>
     
    7070void CommandLineAPIHost::disconnect()
    7171{
    72     m_inspectorAgent = nullptr;
    73     m_consoleAgent = nullptr;
    74     m_databaseAgent = nullptr;
     72
     73    m_instrumentingAgents = nullptr;
    7574}
    7675
    7776void CommandLineAPIHost::inspect(JSC::ExecState& state, JSC::JSValue valueToInspect, JSC::JSValue hintsValue)
    7877{
    79     if (!m_inspectorAgent)
     78    if (!m_instrumentingAgents)
     79        return;
     80
     81    auto* inspectorAgent = m_instrumentingAgents->inspectorAgent();
     82    if (!inspectorAgent)
    8083        return;
    8184
     
    8588
    8689    auto remoteObject = BindingTraits<Inspector::Protocol::Runtime::RemoteObject>::runtimeCast(Inspector::toInspectorValue(state, valueToInspect));
    87     m_inspectorAgent->inspect(WTFMove(remoteObject), WTFMove(hintsObject));
     90    inspectorAgent->inspect(WTFMove(remoteObject), WTFMove(hintsObject));
    8891}
    8992
     
    127130void CommandLineAPIHost::clearConsoleMessages()
    128131{
    129     if (m_consoleAgent) {
    130         ErrorString unused;
    131         m_consoleAgent->clearMessages(unused);
    132     }
     132    if (!m_instrumentingAgents)
     133        return;
     134
     135    auto* consoleAgent = m_instrumentingAgents->webConsoleAgent();
     136    if (!consoleAgent)
     137        return;
     138
     139    ErrorString unused;
     140    consoleAgent->clearMessages(unused);
    133141}
    134142
     
    160168String CommandLineAPIHost::databaseId(Database& database)
    161169{
    162     if (m_databaseAgent)
    163         return m_databaseAgent->databaseId(database);
     170    if (m_instrumentingAgents) {
     171        if (auto* databaseAgent = m_instrumentingAgents->inspectorDatabaseAgent())
     172            return databaseAgent->databaseId(database);
     173    }
    164174    return { };
    165175}
  • trunk/Source/WebCore/inspector/CommandLineAPIHost.h

    r243158 r243219  
    3030#pragma once
    3131
     32#include "InstrumentingAgents.h"
    3233#include <JavaScriptCore/PerGlobalObjectWrapperWorld.h>
    3334#include <wtf/RefCounted.h>
     
    3940}
    4041
    41 namespace Inspector {
    42 class InspectorAgent;
    43 class InspectorConsoleAgent;
    44 }
    45 
    4642namespace WebCore {
    4743
    4844class Database;
    4945class EventTarget;
    50 class InspectorDatabaseAgent;
    5146class JSDOMGlobalObject;
    5247class Storage;
     
    5954    ~CommandLineAPIHost();
    6055
    61     void init(Inspector::InspectorAgent* inspectorAgent
    62         , Inspector::InspectorConsoleAgent* consoleAgent
    63         , InspectorDatabaseAgent* databaseAgent
    64         )
     56    void init(RefPtr<InstrumentingAgents> instrumentingAgents)
    6557    {
    66         m_inspectorAgent = inspectorAgent;
    67         m_consoleAgent = consoleAgent;
    68         m_databaseAgent = databaseAgent;
     58        m_instrumentingAgents = instrumentingAgents;
    6959    }
    7060
     
    10393    CommandLineAPIHost();
    10494
    105     Inspector::InspectorAgent* m_inspectorAgent { nullptr };
    106     Inspector::InspectorConsoleAgent* m_consoleAgent { nullptr };
    107     InspectorDatabaseAgent* m_databaseAgent { nullptr };
    108 
     95    RefPtr<InstrumentingAgents> m_instrumentingAgents;
    10996    std::unique_ptr<InspectableObject> m_inspectedObject; // $0
    11097    Inspector::PerGlobalObjectWrapperWorld m_wrappers;
  • trunk/Source/WebCore/inspector/InspectorController.cpp

    r243160 r243219  
    124124    m_agents.append(WTFMove(domAgentPtr));
    125125
    126     auto databaseAgentPtr = std::make_unique<InspectorDatabaseAgent>(pageContext);
    127     InspectorDatabaseAgent* databaseAgent = databaseAgentPtr.get();
    128     m_agents.append(WTFMove(databaseAgentPtr));
    129 
    130     auto consoleAgentPtr = std::make_unique<PageConsoleAgent>(pageContext, m_domAgent);
    131     WebConsoleAgent* consoleAgent = consoleAgentPtr.get();
    132     m_instrumentingAgents->setWebConsoleAgent(consoleAgentPtr.get());
    133     m_agents.append(WTFMove(consoleAgentPtr));
     126    auto consoleAgent = std::make_unique<PageConsoleAgent>(pageContext, m_domAgent);
     127    m_instrumentingAgents->setWebConsoleAgent(consoleAgent.get());
     128    m_agents.append(WTFMove(consoleAgent));
    134129
    135130    ASSERT(m_injectedScriptManager->commandLineAPIHost());
    136     if (CommandLineAPIHost* commandLineAPIHost = m_injectedScriptManager->commandLineAPIHost())
    137         commandLineAPIHost->init(m_inspectorAgent, consoleAgent, databaseAgent);
     131    if (auto* commandLineAPIHost = m_injectedScriptManager->commandLineAPIHost())
     132        commandLineAPIHost->init(m_instrumentingAgents.copyRef());
    138133}
    139134
     
    186181    m_agents.append(std::make_unique<InspectorWorkerAgent>(pageContext));
    187182    m_agents.append(std::make_unique<InspectorDOMStorageAgent>(pageContext));
     183    m_agents.append(std::make_unique<InspectorDatabaseAgent>(pageContext));
    188184#if ENABLE(INDEXED_DATABASE)
    189185    m_agents.append(std::make_unique<InspectorIndexedDBAgent>(pageContext, m_pageAgent));
  • trunk/Source/WebCore/inspector/InspectorDatabaseResource.cpp

    r225263 r243219  
    4141static int nextUnusedId = 1;
    4242
    43 Ref<InspectorDatabaseResource> InspectorDatabaseResource::create(RefPtr<Database>&& database, const String& domain, const String& name, const String& version)
     43Ref<InspectorDatabaseResource> InspectorDatabaseResource::create(Database& database, const String& domain, const String& name, const String& version)
    4444{
    45     return adoptRef(*new InspectorDatabaseResource(WTFMove(database), domain, name, version));
     45    return adoptRef(*new InspectorDatabaseResource(database, domain, name, version));
    4646}
    4747
    48 InspectorDatabaseResource::InspectorDatabaseResource(RefPtr<Database>&& database, const String& domain, const String& name, const String& version)
     48InspectorDatabaseResource::InspectorDatabaseResource(Database& database, const String& domain, const String& name, const String& version)
    4949    : m_database(database)
    5050    , m_id(String::number(nextUnusedId++))
     
    5555}
    5656
    57 void InspectorDatabaseResource::bind(Inspector::DatabaseFrontendDispatcher* databaseFrontendDispatcher)
     57void InspectorDatabaseResource::bind(Inspector::DatabaseFrontendDispatcher& databaseFrontendDispatcher)
    5858{
    5959    auto jsonObject = Inspector::Protocol::Database::Database::create()
     
    6363        .setVersion(m_version)
    6464        .release();
    65     databaseFrontendDispatcher->addDatabase(WTFMove(jsonObject));
     65    databaseFrontendDispatcher.addDatabase(WTFMove(jsonObject));
    6666}
    6767
  • trunk/Source/WebCore/inspector/InspectorDatabaseResource.h

    r228218 r243219  
    4242class InspectorDatabaseResource : public RefCounted<InspectorDatabaseResource> {
    4343public:
    44     static Ref<InspectorDatabaseResource> create(RefPtr<Database>&&, const String& domain, const String& name, const String& version);
     44    static Ref<InspectorDatabaseResource> create(Database&, const String& domain, const String& name, const String& version);
    4545
    46     void bind(Inspector::DatabaseFrontendDispatcher*);
    47     Database* database() { return m_database.get(); }
    48     void setDatabase(RefPtr<Database>&& database) { m_database = WTFMove(database); }
     46    void bind(Inspector::DatabaseFrontendDispatcher&);
     47
     48    Database& database() const { return m_database.get(); }
     49    void setDatabase(Database& database) { m_database = database; }
     50
    4951    String id() const { return m_id; }
    5052
    5153private:
    52     InspectorDatabaseResource(RefPtr<Database>&&, const String& domain, const String& name, const String& version);
     54    InspectorDatabaseResource(Database&, const String& domain, const String& name, const String& version);
    5355
    54     RefPtr<Database> m_database;
     56    Ref<Database> m_database;
    5557    String m_id;
    5658    String m_domain;
  • trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp

    r243161 r243219  
    3636#include "DOMWindow.h"
    3737#include "DOMWrapperWorld.h"
    38 #include "Database.h"
    3938#include "DocumentLoader.h"
    4039#include "Event.h"
     
    716715            cssAgent->reset();
    717716
    718         if (InspectorDatabaseAgent* databaseAgent = instrumentingAgents.inspectorDatabaseAgent())
    719             databaseAgent->clearResources();
     717        if (auto* databaseAgent = instrumentingAgents.inspectorDatabaseAgent())
     718            databaseAgent->didCommitLoad();
    720719
    721720        if (InspectorDOMAgent* domAgent = instrumentingAgents.inspectorDOMAgent())
     
    903902}
    904903
    905 void InspectorInstrumentation::didOpenDatabaseImpl(InstrumentingAgents& instrumentingAgents, RefPtr<Database>&& database, const String& domain, const String& name, const String& version)
    906 {
    907     if (!instrumentingAgents.inspectorEnvironment().developerExtrasEnabled())
    908         return;
    909     if (InspectorDatabaseAgent* dbAgent = instrumentingAgents.inspectorDatabaseAgent())
    910         dbAgent->didOpenDatabase(WTFMove(database), domain, name, version);
     904void InspectorInstrumentation::didOpenDatabaseImpl(InstrumentingAgents& instrumentingAgents, Database& database)
     905{
     906    if (auto* databaseAgent = instrumentingAgents.inspectorDatabaseAgent())
     907        databaseAgent->didOpenDatabase(database);
    911908}
    912909
  • trunk/Source/WebCore/inspector/InspectorInstrumentation.h

    r243161 r243219  
    3636#include "CanvasBase.h"
    3737#include "CanvasRenderingContext.h"
     38#include "Database.h"
    3839#include "DocumentThreadableLoader.h"
    3940#include "Element.h"
     
    6970class DOMWindow;
    7071class DOMWrapperWorld;
    71 class Database;
    7272class Document;
    7373class DocumentLoader;
     
    241241    static void didFireObserverCallback(const InspectorInstrumentationCookie&);
    242242
    243     static void didOpenDatabase(ScriptExecutionContext*, RefPtr<Database>&&, const String& domain, const String& name, const String& version);
     243    static void didOpenDatabase(Database&);
    244244
    245245    static void didDispatchDOMStorageEvent(Page&, const String& key, const String& oldValue, const String& newValue, StorageType, SecurityOrigin*);
     
    418418    static void didFireObserverCallbackImpl(const InspectorInstrumentationCookie&);
    419419
    420     static void didOpenDatabaseImpl(InstrumentingAgents&, RefPtr<Database>&&, const String& domain, const String& name, const String& version);
     420    static void didOpenDatabaseImpl(InstrumentingAgents&, Database&);
    421421
    422422    static void didDispatchDOMStorageEventImpl(InstrumentingAgents&, const String& key, const String& oldValue, const String& newValue, StorageType, SecurityOrigin*);
     
    11731173}
    11741174
    1175 inline void InspectorInstrumentation::didOpenDatabase(ScriptExecutionContext* context, RefPtr<Database>&& database, const String& domain, const String& name, const String& version)
    1176 {
    1177     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(context))
    1178         didOpenDatabaseImpl(*instrumentingAgents, WTFMove(database), domain, name, version);
     1175inline void InspectorInstrumentation::didOpenDatabase(Database& database)
     1176{
     1177    FAST_RETURN_IF_NO_FRONTENDS(void());
     1178    if (auto* instrumentingAgents = instrumentingAgentsForContext(database.scriptExecutionContext()))
     1179        didOpenDatabaseImpl(*instrumentingAgents, database);
    11791180}
    11801181
  • trunk/Source/WebCore/inspector/WorkerInspectorController.cpp

    r243192 r243219  
    7676    m_agents.append(WTFMove(consoleAgent));
    7777
    78     if (CommandLineAPIHost* commandLineAPIHost = m_injectedScriptManager->commandLineAPIHost())
    79         commandLineAPIHost->init(nullptr, m_instrumentingAgents->webConsoleAgent(), nullptr);
     78    if (auto* commandLineAPIHost = m_injectedScriptManager->commandLineAPIHost())
     79        commandLineAPIHost->init(m_instrumentingAgents.copyRef());
    8080}
    8181
  • trunk/Source/WebCore/inspector/agents/InspectorDatabaseAgent.cpp

    r233122 r243219  
    3232
    3333#include "Database.h"
     34#include "DatabaseTracker.h"
    3435#include "InspectorDatabaseResource.h"
    3536#include "InstrumentingAgents.h"
     
    198199} // namespace
    199200
    200 void InspectorDatabaseAgent::didOpenDatabase(RefPtr<Database>&& database, const String& domain, const String& name, const String& version)
    201 {
    202     if (auto* resource = findByFileName(database->fileName())) {
    203         resource->setDatabase(WTFMove(database));
    204         return;
    205     }
    206 
    207     auto resource = InspectorDatabaseResource::create(WTFMove(database), domain, name, version);
     201void InspectorDatabaseAgent::didCommitLoad()
     202{
     203    m_resources.clear();
     204}
     205
     206void InspectorDatabaseAgent::didOpenDatabase(Database& database)
     207{
     208    if (auto resource = findByFileName(database.fileName())) {
     209        resource->setDatabase(database);
     210        return;
     211    }
     212
     213    auto resource = InspectorDatabaseResource::create(database, database.securityOrigin().host, database.stringIdentifier(), database.expectedVersion());
    208214    m_resources.add(resource->id(), resource.ptr());
    209     // Resources are only bound while visible.
    210     if (m_enabled)
    211         resource->bind(m_frontendDispatcher.get());
    212 }
    213 
    214 void InspectorDatabaseAgent::clearResources()
    215 {
    216     m_resources.clear();
     215    resource->bind(*m_frontendDispatcher);
    217216}
    218217
     
    222221    , m_backendDispatcher(Inspector::DatabaseBackendDispatcher::create(context.backendDispatcher, this))
    223222{
    224     m_instrumentingAgents.setInspectorDatabaseAgent(this);
    225 }
    226 
    227 InspectorDatabaseAgent::~InspectorDatabaseAgent()
    228 {
    229     m_instrumentingAgents.setInspectorDatabaseAgent(nullptr);
    230223}
    231224
     
    242235void InspectorDatabaseAgent::enable(ErrorString&)
    243236{
    244     if (m_enabled)
    245         return;
    246     m_enabled = true;
    247 
    248     for (auto& resource : m_resources.values())
    249         resource->bind(m_frontendDispatcher.get());
     237    if (m_instrumentingAgents.inspectorDatabaseAgent() == this)
     238        return;
     239
     240    m_instrumentingAgents.setInspectorDatabaseAgent(this);
     241
     242    for (auto& database : DatabaseTracker::singleton().openDatabases())
     243        didOpenDatabase(database.get());
    250244}
    251245
    252246void InspectorDatabaseAgent::disable(ErrorString&)
    253247{
    254     if (!m_enabled)
    255         return;
    256     m_enabled = false;
    257 }
    258 
    259 void InspectorDatabaseAgent::getDatabaseTableNames(ErrorString& error, const String& databaseId, RefPtr<JSON::ArrayOf<String>>& names)
    260 {
    261     if (!m_enabled) {
    262         error = "Database agent is not enabled"_s;
     248    m_instrumentingAgents.setInspectorDatabaseAgent(nullptr);
     249
     250    m_resources.clear();
     251}
     252
     253void InspectorDatabaseAgent::getDatabaseTableNames(ErrorString& errorString, const String& databaseId, RefPtr<JSON::ArrayOf<String>>& names)
     254{
     255    if (m_instrumentingAgents.inspectorDatabaseAgent() != this) {
     256        errorString = "Database agent is not enabled"_s;
    263257        return;
    264258    }
     
    274268void InspectorDatabaseAgent::executeSQL(const String& databaseId, const String& query, Ref<ExecuteSQLCallback>&& requestCallback)
    275269{
    276     if (!m_enabled) {
    277         requestCallback->sendFailure("Database agent is not enabled");
     270    if (m_instrumentingAgents.inspectorDatabaseAgent() != this) {
     271        requestCallback->sendFailure("Database agent is not enabled"_s);
    278272        return;
    279273    }
     
    293287{
    294288    for (auto& resource : m_resources) {
    295         if (resource.value->database() == &database)
     289        if (&resource.value->database() == &database)
    296290            return resource.key;
    297291    }
     
    302296{
    303297    for (auto& resource : m_resources.values()) {
    304         if (resource->database()->fileName() == fileName)
     298        if (resource->database().fileName() == fileName)
    305299            return resource.get();
    306300    }
     
    310304Database* InspectorDatabaseAgent::databaseForId(const String& databaseId)
    311305{
    312     auto* resource = m_resources.get(databaseId);
    313     if (!resource)
    314         return nullptr;
    315     return resource->database();
     306    if (auto resource = m_resources.get(databaseId))
     307        return &resource->database();
     308    return nullptr;
    316309}
    317310
  • trunk/Source/WebCore/inspector/agents/InspectorDatabaseAgent.h

    r229493 r243219  
    3434#include <JavaScriptCore/InspectorFrontendDispatchers.h>
    3535#include <wtf/HashMap.h>
     36#include <wtf/Optional.h>
    3637#include <wtf/text/WTFString.h>
    3738
     
    4849public:
    4950    explicit InspectorDatabaseAgent(WebAgentContext&);
    50     virtual ~InspectorDatabaseAgent();
     51    virtual ~InspectorDatabaseAgent() = default;
    5152
    5253    void didCreateFrontendAndBackend(Inspector::FrontendRouter*, Inspector::BackendDispatcher*) override;
    5354    void willDestroyFrontendAndBackend(Inspector::DisconnectReason) override;
    5455
    55     void clearResources();
    5656
    5757    // Called from the front-end.
     
    6464    String databaseId(Database&);
    6565
    66     void didOpenDatabase(RefPtr<Database>&&, const String& domain, const String& name, const String& version);
     66    // InspectorInstrumentation
     67    void didCommitLoad();
     68    void didOpenDatabase(Database&);
     69
    6770private:
    6871    Database* databaseForId(const String& databaseId);
     
    7275    RefPtr<Inspector::DatabaseBackendDispatcher> m_backendDispatcher;
    7376
    74     typedef HashMap<String, RefPtr<InspectorDatabaseResource>> DatabaseResourcesMap;
    75     DatabaseResourcesMap m_resources;
    76     bool m_enabled { false };
     77    HashMap<String, RefPtr<InspectorDatabaseResource>> m_resources;
    7778};
    7879
Note: See TracChangeset for help on using the changeset viewer.