-
-
Notifications
You must be signed in to change notification settings - Fork 34.4k
inspector: initial support storage inspection #61139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
islandryu
wants to merge
12
commits into
nodejs:main
Choose a base branch
from
islandryu:feat/storageInspection
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
611b71e
inspector: initial support storage inspection
islandryu 4d0900b
fix test
islandryu 0f8e739
Update src/node_options.cc
islandryu 19be6a8
fix storage key
islandryu 9197bde
fix test
islandryu 2df3321
fix test
islandryu 931b766
use localStorage file as storageKey
islandryu e9f2484
fix test
islandryu fd6c29a
fix file path
islandryu a115284
fix file path
islandryu 89354d2
organize code
islandryu 7f25f1e
fix test
islandryu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,238 @@ | ||
| #include "dom_storage_agent.h" | ||
| #include "env-inl.h" | ||
| #include "inspector/inspector_object_utils.h" | ||
| #include "v8-isolate.h" | ||
|
|
||
| namespace node { | ||
| namespace inspector { | ||
|
|
||
| using v8::Array; | ||
| using v8::Context; | ||
| using v8::HandleScope; | ||
| using v8::Isolate; | ||
| using v8::Local; | ||
| using v8::Object; | ||
| using v8::Value; | ||
|
|
||
| std::unique_ptr<protocol::DOMStorage::StorageId> createStorageIdFromObject( | ||
| Local<Context> context, Local<Object> storage_id_obj) { | ||
| protocol::String security_origin; | ||
| if (!ObjectGetProtocolString(context, storage_id_obj, "securityOrigin") | ||
| .To(&security_origin)) { | ||
| return {}; | ||
| } | ||
| bool is_local_storage = | ||
| ObjectGetBool(context, storage_id_obj, "isLocalStorage").FromMaybe(false); | ||
| protocol::String storageKey; | ||
| if (!ObjectGetProtocolString(context, storage_id_obj, "storageKey") | ||
| .To(&storageKey)) { | ||
| return {}; | ||
| } | ||
|
|
||
| return protocol::DOMStorage::StorageId::create() | ||
| .setSecurityOrigin(security_origin) | ||
| .setIsLocalStorage(is_local_storage) | ||
| .setStorageKey(storageKey) | ||
| .build(); | ||
| } | ||
|
|
||
| DOMStorageAgent::DOMStorageAgent(Environment* env) : env_(env) {} | ||
|
|
||
| DOMStorageAgent::~DOMStorageAgent() {} | ||
|
|
||
| void DOMStorageAgent::Wire(protocol::UberDispatcher* dispatcher) { | ||
| frontend_ = | ||
| std::make_unique<protocol::DOMStorage::Frontend>(dispatcher->channel()); | ||
| protocol::DOMStorage::Dispatcher::wire(dispatcher, this); | ||
| addEventNotifier("domStorageItemAdded", | ||
| (EventNotifier)(&DOMStorageAgent::domStorageItemAdded)); | ||
| addEventNotifier("domStorageItemRemoved", | ||
| (EventNotifier)(&DOMStorageAgent::domStorageItemRemoved)); | ||
| addEventNotifier("domStorageItemUpdated", | ||
| (EventNotifier)(&DOMStorageAgent::domStorageItemUpdated)); | ||
| addEventNotifier("domStorageItemsCleared", | ||
| (EventNotifier)(&DOMStorageAgent::domStorageItemsCleared)); | ||
| addEventNotifier("registerStorage", | ||
| (EventNotifier)(&DOMStorageAgent::registerStorage)); | ||
| } | ||
|
|
||
| protocol::DispatchResponse DOMStorageAgent::enable() { | ||
| this->enabled_ = true; | ||
| return protocol::DispatchResponse::Success(); | ||
| } | ||
|
|
||
| protocol::DispatchResponse DOMStorageAgent::disable() { | ||
| this->enabled_ = false; | ||
| return protocol::DispatchResponse::Success(); | ||
| } | ||
|
|
||
| protocol::DispatchResponse DOMStorageAgent::getDOMStorageItems( | ||
| std::unique_ptr<protocol::DOMStorage::StorageId> storageId, | ||
| std::unique_ptr<protocol::Array<protocol::Array<protocol::String>>>* | ||
| items) { | ||
| if (!enabled_) { | ||
| return protocol::DispatchResponse::ServerError( | ||
| "DOMStorage domain is not enabled"); | ||
| } | ||
| bool is_local_storage = storageId->getIsLocalStorage(); | ||
| const std::unordered_map<std::string, std::string>& storage_map = | ||
| is_local_storage ? local_storage_map_ : session_storage_map_; | ||
| auto result = | ||
| std::make_unique<protocol::Array<protocol::Array<protocol::String>>>(); | ||
| for (const auto& pair : storage_map) { | ||
| auto item = std::make_unique<protocol::Array<protocol::String>>(); | ||
| item->push_back(pair.first); | ||
| item->push_back(pair.second); | ||
| result->push_back(std::move(item)); | ||
| } | ||
| *items = std::move(result); | ||
| return protocol::DispatchResponse::Success(); | ||
| } | ||
|
|
||
| protocol::DispatchResponse DOMStorageAgent::setDOMStorageItem( | ||
| std::unique_ptr<protocol::DOMStorage::StorageId> storageId, | ||
| const std::string& key, | ||
| const std::string& value) { | ||
| return protocol::DispatchResponse::ServerError("Not implemented"); | ||
| } | ||
|
|
||
| protocol::DispatchResponse DOMStorageAgent::removeDOMStorageItem( | ||
| std::unique_ptr<protocol::DOMStorage::StorageId> storageId, | ||
| const std::string& key) { | ||
| return protocol::DispatchResponse::ServerError("Not implemented"); | ||
| } | ||
|
|
||
| protocol::DispatchResponse DOMStorageAgent::clear( | ||
| std::unique_ptr<protocol::DOMStorage::StorageId> storageId) { | ||
| return protocol::DispatchResponse::ServerError("Not implemented"); | ||
| } | ||
|
|
||
| void DOMStorageAgent::domStorageItemAdded(Local<Context> context, | ||
| Local<Object> params) { | ||
| Local<Object> storage_id_obj; | ||
| if (!ObjectGetObject(context, params, "storageId").ToLocal(&storage_id_obj)) { | ||
| return; | ||
| } | ||
|
|
||
| std::unique_ptr<protocol::DOMStorage::StorageId> storage_id = | ||
| createStorageIdFromObject(context, storage_id_obj); | ||
| if (!storage_id) { | ||
| return; | ||
| } | ||
|
|
||
| protocol::String key; | ||
| if (!ObjectGetProtocolString(context, params, "key").To(&key)) { | ||
| return; | ||
| } | ||
| protocol::String new_value; | ||
| if (!ObjectGetProtocolString(context, params, "newValue").To(&new_value)) { | ||
| return; | ||
| } | ||
| frontend_->domStorageItemAdded(std::move(storage_id), key, new_value); | ||
| } | ||
|
|
||
| void DOMStorageAgent::domStorageItemRemoved(Local<Context> context, | ||
| Local<Object> params) { | ||
| Local<Object> storage_id_obj; | ||
| if (!ObjectGetObject(context, params, "storageId").ToLocal(&storage_id_obj)) { | ||
| return; | ||
| } | ||
| std::unique_ptr<protocol::DOMStorage::StorageId> storage_id = | ||
| createStorageIdFromObject(context, storage_id_obj); | ||
|
|
||
| if (!storage_id) { | ||
| return; | ||
| } | ||
|
|
||
| protocol::String key; | ||
| if (!ObjectGetProtocolString(context, params, "key").To(&key)) { | ||
| return; | ||
| } | ||
| frontend_->domStorageItemRemoved(std::move(storage_id), key); | ||
| } | ||
|
|
||
| void DOMStorageAgent::domStorageItemUpdated(Local<Context> context, | ||
| Local<Object> params) { | ||
| Local<Object> storage_id_obj; | ||
| if (!ObjectGetObject(context, params, "storageId").ToLocal(&storage_id_obj)) { | ||
| return; | ||
| } | ||
|
|
||
| std::unique_ptr<protocol::DOMStorage::StorageId> storage_id = | ||
| createStorageIdFromObject(context, storage_id_obj); | ||
|
|
||
| if (!storage_id) { | ||
| return; | ||
| } | ||
|
|
||
| protocol::String key; | ||
| if (!ObjectGetProtocolString(context, params, "key").To(&key)) { | ||
| return; | ||
| } | ||
| protocol::String old_value; | ||
| if (!ObjectGetProtocolString(context, params, "oldValue").To(&old_value)) { | ||
| return; | ||
| } | ||
| protocol::String new_value; | ||
| if (!ObjectGetProtocolString(context, params, "newValue").To(&new_value)) { | ||
| return; | ||
| } | ||
| frontend_->domStorageItemUpdated( | ||
| std::move(storage_id), key, old_value, new_value); | ||
| } | ||
|
|
||
| void DOMStorageAgent::domStorageItemsCleared(Local<Context> context, | ||
| Local<Object> params) { | ||
| Local<Object> storage_id_obj; | ||
| if (!ObjectGetObject(context, params, "storageId").ToLocal(&storage_id_obj)) { | ||
| return; | ||
| } | ||
| std::unique_ptr<protocol::DOMStorage::StorageId> storage_id = | ||
| createStorageIdFromObject(context, storage_id_obj); | ||
|
|
||
| if (!storage_id) { | ||
| return; | ||
| } | ||
| frontend_->domStorageItemsCleared(std::move(storage_id)); | ||
| } | ||
|
|
||
| void DOMStorageAgent::registerStorage(Local<Context> context, | ||
| Local<Object> params) { | ||
| Isolate* isolate = env_->isolate(); | ||
| HandleScope handle_scope(isolate); | ||
| bool is_local_storage; | ||
| if (!ObjectGetBool(context, params, "isLocalStorage").To(&is_local_storage)) { | ||
| return; | ||
| } | ||
| Local<Object> storage_map_obj; | ||
| if (!ObjectGetObject(context, params, "storageMap") | ||
| .ToLocal(&storage_map_obj)) { | ||
| return; | ||
| } | ||
| std::unordered_map<std::string, std::string>& storage_map = | ||
| is_local_storage ? local_storage_map_ : session_storage_map_; | ||
| Local<Array> property_names; | ||
| if (!storage_map_obj->GetOwnPropertyNames(context).ToLocal(&property_names)) { | ||
| return; | ||
| } | ||
| uint32_t length = property_names->Length(); | ||
| for (uint32_t i = 0; i < length; ++i) { | ||
| Local<Value> key_value; | ||
| if (!property_names->Get(context, i).ToLocal(&key_value)) { | ||
| return; | ||
| } | ||
| Local<Value> value_value; | ||
| if (!storage_map_obj->Get(context, key_value).ToLocal(&value_value)) { | ||
| return; | ||
| } | ||
| node::Utf8Value key_utf8(isolate, key_value); | ||
| node::Utf8Value value_utf8(isolate, value_value); | ||
| storage_map[*key_utf8] = *value_utf8; | ||
| } | ||
| } | ||
|
|
||
| bool DOMStorageAgent::canEmit(const std::string& domain) { | ||
| return domain == "DOMStorage"; | ||
| } | ||
| } // namespace inspector | ||
| } // namespace node |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this correct?