@@ -383,10 +383,10 @@ index 1eb7abb2fa21d7a8ec0833160f53e5c523ec4317..7709bcc2ec69aab0589ca1b954db1fb2
383
383
FrontendChannel::ConnectionType connectionType() const;
384
384
diff --git a/Source/JavaScriptCore/inspector/protocol/Browser.json b/Source/JavaScriptCore/inspector/protocol/Browser.json
385
385
new file mode 100644
386
- index 0000000000000000000000000000000000000000..0f9b1c8950b8f5631ddfd8180a851d1ecea4c475
386
+ index 0000000000000000000000000000000000000000..d4f5cbc813facbd8036c0be46304e4a607cbcb79
387
387
--- /dev/null
388
388
+++ b/Source/JavaScriptCore/inspector/protocol/Browser.json
389
- @@ -0,0 +1,210 @@
389
+ @@ -0,0 +1,211 @@
390
390
+{
391
391
+ "domain": "Browser",
392
392
+ "availability": ["web"],
@@ -476,6 +476,7 @@ index 0000000000000000000000000000000000000000..0f9b1c8950b8f5631ddfd8180a851d1e
476
476
+ },
477
477
+ {
478
478
+ "name": "deleteContext",
479
+ + "async": true,
479
480
+ "description": "Deletes browser context previously created with createContect. The command will automatically close all pages that use the context.",
480
481
+ "parameters": [
481
482
+ { "name": "browserContextId", "$ref": "ContextID", "description": "Identifier of the context to delete." }
@@ -7694,10 +7695,10 @@ index 78caedf0c0ce83675569502d150fcc44e5f9868c..42070f8b1969caa0d00863279fcefe01
7694
7695
} // namespace WebKit
7695
7696
diff --git a/Source/WebKit/UIProcess/InspectorBrowserAgent.cpp b/Source/WebKit/UIProcess/InspectorBrowserAgent.cpp
7696
7697
new file mode 100644
7697
- index 0000000000000000000000000000000000000000..f119a3bcf90af6d3183a4079a4a3b06a6b75cabc
7698
+ index 0000000000000000000000000000000000000000..28221673d566aff5e6e839d36ef9c83d244291ba
7698
7699
--- /dev/null
7699
7700
+++ b/Source/WebKit/UIProcess/InspectorBrowserAgent.cpp
7700
- @@ -0,0 +1,526 @@
7701
+ @@ -0,0 +1,587 @@
7701
7702
+/*
7702
7703
+ * Copyright (C) 2019 Microsoft Corporation.
7703
7704
+ *
@@ -7799,6 +7800,55 @@ index 0000000000000000000000000000000000000000..f119a3bcf90af6d3183a4079a4a3b06a
7799
7800
+
7800
7801
+} // namespace
7801
7802
+
7803
+ +Vector<WebPageProxy*> BrowserContext::pages() const {
7804
+ + Vector<WebPageProxy*> pages;
7805
+ + for (auto& process : processPool->processes()) {
7806
+ + for (auto* page : process->pages())
7807
+ + pages.append(page);
7808
+ + }
7809
+ + return pages;
7810
+ +}
7811
+ +
7812
+ +class InspectorBrowserAgent::BrowserContextDeletion {
7813
+ + WTF_MAKE_NONCOPYABLE(BrowserContextDeletion);
7814
+ + WTF_MAKE_FAST_ALLOCATED;
7815
+ +public:
7816
+ + BrowserContextDeletion(const BrowserContext& context, size_t numberOfPages, Ref<DeleteContextCallback>&& callback)
7817
+ + : m_browserContext(context)
7818
+ + , m_numberOfPages(numberOfPages)
7819
+ + , m_callback(WTFMove(callback)) { }
7820
+ +
7821
+ + void willDestroyPage(const WebPageProxy& page)
7822
+ + {
7823
+ + ASSERT(m_browserContext.dataStore->sessionID() == page.sessionID());
7824
+ + // Check if new pages have been created during the context destruction and
7825
+ + // close all of them if necessary.
7826
+ + if (m_numberOfPages == 1) {
7827
+ + Vector<WebPageProxy*> pages = m_browserContext.pages();
7828
+ + size_t numberOfPages = pages.size();
7829
+ + if (numberOfPages > 1) {
7830
+ + m_numberOfPages = numberOfPages;
7831
+ + for (auto* existingPage : pages) {
7832
+ + if (existingPage != &page)
7833
+ + existingPage->closePage();
7834
+ + }
7835
+ + }
7836
+ + }
7837
+ + --m_numberOfPages;
7838
+ + if (m_numberOfPages)
7839
+ + return;
7840
+ + m_callback->sendSuccess();
7841
+ + }
7842
+ +
7843
+ + bool isFinished() const { return !m_numberOfPages; }
7844
+ +
7845
+ +private:
7846
+ + BrowserContext m_browserContext;
7847
+ + size_t m_numberOfPages;
7848
+ + Ref<DeleteContextCallback> m_callback;
7849
+ +};
7850
+ +
7851
+ +
7802
7852
+InspectorBrowserAgent::InspectorBrowserAgent(Inspector::FrontendRouter& frontendRouter, Inspector::BackendDispatcher& backendDispatcher, InspectorBrowserAgentClient* client, PageProxyIDMap& pageProxyIDMap)
7803
7853
+ : InspectorAgentBase("Browser"_s)
7804
7854
+ , m_frontendDispatcher(makeUnique<BrowserFrontendDispatcher>(frontendRouter))
@@ -7818,8 +7868,18 @@ index 0000000000000000000000000000000000000000..f119a3bcf90af6d3183a4079a4a3b06a
7818
7868
+
7819
7869
+void InspectorBrowserAgent::willDestroyWebPageProxy(const WebPageProxy& page)
7820
7870
+{
7821
- + if (m_isConnected)
7822
- + m_frontendDispatcher->pageProxyDestroyed(toPageProxyIDProtocolString(page));
7871
+ + if (!m_isConnected)
7872
+ + return;
7873
+ +
7874
+ + m_frontendDispatcher->pageProxyDestroyed(toPageProxyIDProtocolString(page));
7875
+ +
7876
+ + auto it = m_browserContextDeletions.find(page.sessionID());
7877
+ + if (it == m_browserContextDeletions.end())
7878
+ + return;
7879
+ +
7880
+ + it->value->willDestroyPage(page);
7881
+ + if (it->value->isFinished())
7882
+ + m_browserContextDeletions.remove(it);
7823
7883
+}
7824
7884
+
7825
7885
+void InspectorBrowserAgent::didCreateFrontendAndBackend(FrontendRouter*, BackendDispatcher*)
@@ -7838,6 +7898,7 @@ index 0000000000000000000000000000000000000000..f119a3bcf90af6d3183a4079a4a3b06a
7838
7898
+void InspectorBrowserAgent::willDestroyFrontendAndBackend(DisconnectReason)
7839
7899
+{
7840
7900
+ m_isConnected = false;
7901
+ + m_browserContextDeletions.clear();
7841
7902
+}
7842
7903
+
7843
7904
+void InspectorBrowserAgent::close(Ref<CloseCallback>&& callback)
@@ -7885,24 +7946,25 @@ index 0000000000000000000000000000000000000000..f119a3bcf90af6d3183a4079a4a3b06a
7885
7946
+ m_browserContexts.set(*browserContextID, browserContext);
7886
7947
+}
7887
7948
+
7888
- +void InspectorBrowserAgent::deleteContext(ErrorString& errorString, const String& browserContextID)
7949
+ +void InspectorBrowserAgent::deleteContext(const String& browserContextID, Ref<DeleteContextCallback>&& callback )
7889
7950
+{
7951
+ + String errorString;
7890
7952
+ BrowserContext browserContext = lookupBrowserContext(errorString, &browserContextID);
7891
- + if (!errorString.isEmpty())
7953
+ + if (!errorString.isEmpty()) {
7954
+ + callback->sendFailure(errorString);
7892
7955
+ return;
7893
- +
7894
- + Vector<WebPageProxy*> pages;
7895
- + for (auto& process : browserContext.processPool->processes()) {
7896
- + for (auto* page : process->pages())
7897
- + pages.append(page);
7898
7956
+ }
7899
7957
+
7958
+ + Vector<WebPageProxy*> pages = browserContext.pages();
7959
+ + PAL::SessionID sessionID = browserContext.dataStore->sessionID();
7960
+ +
7961
+ + m_browserContexts.remove(browserContextID);
7962
+ + m_browserContextDeletions.set(sessionID, makeUnique<BrowserContextDeletion>(browserContext, pages.size(), WTFMove(callback)));
7963
+ +
7900
7964
+ for (auto* page : pages)
7901
7965
+ page->closePage();
7902
7966
+
7903
- + PAL::SessionID sessionID = browserContext.dataStore->sessionID();
7904
7967
+ m_client->deleteBrowserContext(errorString, sessionID);
7905
- + m_browserContexts.remove(browserContextID);
7906
7968
+}
7907
7969
+
7908
7970
+void InspectorBrowserAgent::createPage(ErrorString& errorString, const String* browserContextID, String* pageProxyID)
@@ -8226,10 +8288,10 @@ index 0000000000000000000000000000000000000000..f119a3bcf90af6d3183a4079a4a3b06a
8226
8288
+#endif // ENABLE(REMOTE_INSPECTOR)
8227
8289
diff --git a/Source/WebKit/UIProcess/InspectorBrowserAgent.h b/Source/WebKit/UIProcess/InspectorBrowserAgent.h
8228
8290
new file mode 100644
8229
- index 0000000000000000000000000000000000000000..ad8f3d99f45fa6284738c62fe813330b2c208c92
8291
+ index 0000000000000000000000000000000000000000..56ecacafe2d97971880f77913c40ec32393e1997
8230
8292
--- /dev/null
8231
8293
+++ b/Source/WebKit/UIProcess/InspectorBrowserAgent.h
8232
- @@ -0,0 +1,114 @@
8294
+ @@ -0,0 +1,116 @@
8233
8295
+/*
8234
8296
+ * Copyright (C) 2019 Microsoft Corporation.
8235
8297
+ *
@@ -8310,7 +8372,7 @@ index 0000000000000000000000000000000000000000..ad8f3d99f45fa6284738c62fe813330b
8310
8372
+ // BrowserBackendDispatcherHandler
8311
8373
+ void close(Ref<CloseCallback>&&) override;
8312
8374
+ void createContext(Inspector::ErrorString&, String* browserContextID) override;
8313
- + void deleteContext(Inspector::ErrorString&, const String& browserContextID) override;
8375
+ + void deleteContext(const String& browserContextID, Ref<DeleteContextCallback>&& callback ) override;
8314
8376
+ void createPage(Inspector::ErrorString&, const String* browserContextID, String* pageProxyID) override;
8315
8377
+ void navigate(const String& url, const String& pageProxyID, const String* frameId, const String* referrer, Ref<NavigateCallback>&&) override;
8316
8378
+ void setIgnoreCertificateErrors(Inspector::ErrorString&, const String* browserContextID, bool ignore) override;
@@ -8328,6 +8390,7 @@ index 0000000000000000000000000000000000000000..ad8f3d99f45fa6284738c62fe813330b
8328
8390
+ static String toPageProxyIDProtocolString(const WebPageProxy&);
8329
8391
+
8330
8392
+private:
8393
+ + class BrowserContextDeletion;
8331
8394
+ BrowserContext lookupBrowserContext(Inspector::ErrorString&, const String* browserContextID);
8332
8395
+ WebFrameProxy* frameForID(const String& frameID, String& error);
8333
8396
+
@@ -8338,6 +8401,7 @@ index 0000000000000000000000000000000000000000..ad8f3d99f45fa6284738c62fe813330b
8338
8401
+ using Permissions = HashMap<String, HashSet<String>>;
8339
8402
+ HashMap<String, Permissions> m_permissions;
8340
8403
+ HashMap<String, BrowserContext> m_browserContexts;
8404
+ + HashMap<PAL::SessionID, std::unique_ptr<BrowserContextDeletion>> m_browserContextDeletions;
8341
8405
+ bool m_isConnected { false };
8342
8406
+};
8343
8407
+
@@ -8346,10 +8410,10 @@ index 0000000000000000000000000000000000000000..ad8f3d99f45fa6284738c62fe813330b
8346
8410
+#endif // ENABLE(REMOTE_INSPECTOR)
8347
8411
diff --git a/Source/WebKit/UIProcess/InspectorBrowserAgentClient.h b/Source/WebKit/UIProcess/InspectorBrowserAgentClient.h
8348
8412
new file mode 100644
8349
- index 0000000000000000000000000000000000000000..21f8cc9bffd8f2d4a88764a4eafa13f367aa1e7c
8413
+ index 0000000000000000000000000000000000000000..199295c91249d0c400589249feaa2ed24ee35f19
8350
8414
--- /dev/null
8351
8415
+++ b/Source/WebKit/UIProcess/InspectorBrowserAgentClient.h
8352
- @@ -0,0 +1,55 @@
8416
+ @@ -0,0 +1,56 @@
8353
8417
+/*
8354
8418
+ * Copyright (C) 2019 Microsoft Corporation.
8355
8419
+ *
@@ -8389,6 +8453,7 @@ index 0000000000000000000000000000000000000000..21f8cc9bffd8f2d4a88764a4eafa13f3
8389
8453
+class WebProcessPool;
8390
8454
+
8391
8455
+struct BrowserContext {
8456
+ + Vector<WebPageProxy*> pages() const;
8392
8457
+ RefPtr<WebsiteDataStore> dataStore;
8393
8458
+ RefPtr<WebProcessPool> processPool;
8394
8459
+};
0 commit comments