chore: enable check raw ptr fields (#38167)

This commit is contained in:
John Kleinschmidt 2023-05-11 16:07:39 -04:00 committed by GitHub
parent 141175c723
commit 3dbc0a365f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
120 changed files with 298 additions and 185 deletions

View file

@ -76,9 +76,8 @@ gin::WrapperInfo BrowserView::kWrapperInfo = {gin::kEmbedderNativeGin};
BrowserView::BrowserView(gin::Arguments* args,
const gin_helper::Dictionary& options)
: id_(GetNextId()) {
v8::Isolate* isolate = args->isolate();
gin_helper::Dictionary web_preferences =
gin::Dictionary::CreateEmpty(isolate);
gin::Dictionary::CreateEmpty(args->isolate());
options.Get(options::kWebPreferences, &web_preferences);
web_preferences.Set("type", "browserView");
@ -92,7 +91,7 @@ BrowserView::BrowserView(gin::Arguments* args,
auto web_contents =
WebContents::CreateFromWebPreferences(args->isolate(), web_preferences);
web_contents_.Reset(isolate, web_contents.ToV8());
web_contents_.Reset(args->isolate(), web_contents.ToV8());
api_web_contents_ = web_contents.get();
api_web_contents_->AddObserver(this);
Observe(web_contents->web_contents());

View file

@ -9,6 +9,7 @@
#include <string>
#include <vector>
#include "base/memory/raw_ptr.h"
#include "content/public/browser/web_contents_observer.h"
#include "gin/handle.h"
#include "gin/wrappable.h"
@ -79,7 +80,7 @@ class BrowserView : public gin::Wrappable<BrowserView>,
v8::Local<v8::Value> GetWebContents(v8::Isolate*);
v8::Global<v8::Value> web_contents_;
class WebContents* api_web_contents_ = nullptr;
class raw_ptr<WebContents> api_web_contents_ = nullptr;
std::unique_ptr<NativeBrowserView> view_;
base::WeakPtr<BaseWindow> owner_window_;

View file

@ -8,6 +8,7 @@
#include <string>
#include "base/callback_list.h"
#include "base/memory/raw_ptr.h"
#include "base/values.h"
#include "gin/handle.h"
#include "net/cookies/canonical_cookie.h"
@ -61,7 +62,7 @@ class Cookies : public gin::Wrappable<Cookies>,
base::CallbackListSubscription cookie_change_subscription_;
// Weak reference; ElectronBrowserContext is guaranteed to outlive us.
ElectronBrowserContext* browser_context_;
raw_ptr<ElectronBrowserContext> browser_context_;
};
} // namespace api

View file

@ -7,6 +7,7 @@
#include <utility>
#include <vector>
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/no_destructor.h"
#include "base/strings/string_number_conversions.h"
@ -129,7 +130,7 @@ class DataPipeReader {
std::vector<char> buffer_;
// The head of buffer.
char* head_ = nullptr;
raw_ptr<char> head_ = nullptr;
// Remaining data to read.
uint64_t remaining_size_ = 0;

View file

@ -8,6 +8,7 @@
#include <map>
#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "base/values.h"
#include "content/public/browser/devtools_agent_host_client.h"
#include "content/public/browser/web_contents_observer.h"
@ -65,7 +66,7 @@ class Debugger : public gin::Wrappable<Debugger>,
v8::Local<v8::Promise> SendCommand(gin::Arguments* args);
void ClearPendingRequests();
content::WebContents* web_contents_; // Weak Reference.
raw_ptr<content::WebContents> web_contents_; // Weak Reference.
scoped_refptr<content::DevToolsAgentHost> agent_host_;
PendingRequestMap pending_requests_;

View file

@ -8,6 +8,7 @@
#include <string>
#include "base/files/file_path.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "components/download/public/common/download_item.h"
#include "gin/handle.h"
@ -78,9 +79,9 @@ class DownloadItem : public gin::Wrappable<DownloadItem>,
base::FilePath save_path_;
file_dialog::DialogSettings dialog_options_;
download::DownloadItem* download_item_;
raw_ptr<download::DownloadItem> download_item_;
v8::Isolate* isolate_;
raw_ptr<v8::Isolate> isolate_;
base::WeakPtrFactory<DownloadItem> weak_factory_{this};
};

View file

@ -9,6 +9,7 @@
#include <string>
#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "gin/arguments.h"
#include "shell/browser/api/electron_api_base_window.h"
#include "shell/browser/event_emitter_mixin.h"
@ -82,7 +83,7 @@ class Menu : public gin::Wrappable<Menu>,
virtual std::u16string GetAcceleratorTextAtForTesting(int index) const;
std::unique_ptr<ElectronMenuModel> model_;
Menu* parent_ = nullptr;
raw_ptr<Menu> parent_ = nullptr;
// Observable:
void OnMenuWillClose() override;

View file

@ -5,6 +5,7 @@
#ifndef ELECTRON_SHELL_BROWSER_API_ELECTRON_API_NATIVE_THEME_H_
#define ELECTRON_SHELL_BROWSER_API_ELECTRON_API_NATIVE_THEME_H_
#include "base/memory/raw_ptr.h"
#include "gin/handle.h"
#include "gin/wrappable.h"
#include "shell/browser/event_emitter_mixin.h"
@ -51,8 +52,8 @@ class NativeTheme : public gin::Wrappable<NativeTheme>,
void OnNativeThemeUpdatedOnUI();
private:
ui::NativeTheme* ui_theme_;
ui::NativeTheme* web_theme_;
raw_ptr<ui::NativeTheme> ui_theme_;
raw_ptr<ui::NativeTheme> web_theme_;
};
} // namespace electron::api

View file

@ -7,6 +7,7 @@
#include "base/files/file_path.h"
#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/values.h"
#include "gin/handle.h"
@ -62,7 +63,7 @@ class NetLog : public gin::Wrappable<NetLog> {
void NetLogStarted(int32_t error);
private:
ElectronBrowserContext* browser_context_;
raw_ptr<ElectronBrowserContext> browser_context_;
mojo::Remote<network::mojom::NetLogExporter> net_log_exporter_;

View file

@ -8,6 +8,7 @@
#include <string>
#include <vector>
#include "base/memory/raw_ptr.h"
#include "base/strings/utf_string_conversions.h"
#include "gin/wrappable.h"
#include "shell/browser/event_emitter_mixin.h"
@ -108,7 +109,7 @@ class Notification : public gin::Wrappable<Notification>,
std::u16string close_button_text_;
std::u16string toast_xml_;
electron::NotificationPresenter* presenter_;
raw_ptr<electron::NotificationPresenter> presenter_;
base::WeakPtr<electron::Notification> notification_;
};

View file

@ -8,6 +8,7 @@
#include <string>
#include <vector>
#include "base/memory/raw_ptr.h"
#include "content/public/browser/content_browser_client.h"
#include "gin/handle.h"
#include "gin/wrappable.h"
@ -101,7 +102,7 @@ class Protocol : public gin::Wrappable<Protocol>,
// Weak pointer; the lifetime of the ProtocolRegistry is guaranteed to be
// longer than the lifetime of this JS interface.
ProtocolRegistry* protocol_registry_;
raw_ptr<ProtocolRegistry> protocol_registry_;
};
} // namespace api

View file

@ -7,6 +7,7 @@
#include <vector>
#include "base/memory/raw_ptr.h"
#include "gin/wrappable.h"
#include "shell/browser/event_emitter_mixin.h"
#include "shell/common/gin_helper/error_thrower.h"
@ -53,7 +54,7 @@ class Screen : public gin::Wrappable<Screen>,
uint32_t changed_metrics) override;
private:
display::Screen* screen_;
raw_ptr<display::Screen> screen_;
};
} // namespace electron::api

View file

@ -5,6 +5,7 @@
#ifndef ELECTRON_SHELL_BROWSER_API_ELECTRON_API_SERVICE_WORKER_CONTEXT_H_
#define ELECTRON_SHELL_BROWSER_API_ELECTRON_API_SERVICE_WORKER_CONTEXT_H_
#include "base/memory/raw_ptr.h"
#include "content/public/browser/service_worker_context.h"
#include "content/public/browser/service_worker_context_observer.h"
#include "gin/handle.h"
@ -53,7 +54,7 @@ class ServiceWorkerContext
~ServiceWorkerContext() override;
private:
content::ServiceWorkerContext* service_worker_context_;
raw_ptr<content::ServiceWorkerContext> service_worker_context_;
base::WeakPtrFactory<ServiceWorkerContext> weak_ptr_factory_{this};
};

View file

@ -16,6 +16,7 @@
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/guid.h"
#include "base/memory/raw_ptr.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
@ -327,7 +328,7 @@ class DictionaryObserver final : public SpellcheckCustomDictionary::Observer {
struct UserDataLink : base::SupportsUserData::Data {
explicit UserDataLink(Session* ses) : session(ses) {}
Session* session;
raw_ptr<Session> session;
};
const void* kElectronApiSessionKey = &kElectronApiSessionKey;

View file

@ -8,6 +8,7 @@
#include <string>
#include <vector>
#include "base/memory/raw_ptr.h"
#include "base/values.h"
#include "content/public/browser/download_manager.h"
#include "electron/buildflags/buildflags.h"
@ -203,12 +204,12 @@ class Session : public gin::Wrappable<Session>,
v8::Global<v8::Value> service_worker_context_;
v8::Global<v8::Value> web_request_;
v8::Isolate* isolate_;
raw_ptr<v8::Isolate> isolate_;
// The client id to enable the network throttler.
base::UnguessableToken network_emulation_token_;
ElectronBrowserContext* browser_context_;
raw_ptr<ElectronBrowserContext> browser_context_;
};
} // namespace api

View file

@ -10,6 +10,7 @@
#include <utility>
#include <vector>
#include "base/memory/raw_ptr.h"
#include "base/no_destructor.h"
#include "gin/handle.h"
#include "gin/object_template_builder.h"
@ -312,7 +313,7 @@ class JSChunkedDataPipeGetter : public gin::Wrappable<JSChunkedDataPipeGetter>,
bool is_writing_ = false;
uint64_t bytes_written_ = 0;
v8::Isolate* isolate_;
raw_ptr<v8::Isolate> isolate_;
v8::Global<v8::Function> body_func_;
};

View file

@ -9,6 +9,7 @@
#include <string>
#include <vector>
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "gin/wrappable.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
@ -122,7 +123,7 @@ class SimpleURLLoaderWrapper
void Pin();
void PinBodyGetter(v8::Local<v8::Value>);
ElectronBrowserContext* browser_context_;
raw_ptr<ElectronBrowserContext> browser_context_;
int request_options_;
std::unique_ptr<network::ResourceRequest> request_;
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_;

View file

@ -7,6 +7,7 @@
#include <vector>
#include "base/memory/raw_ptr.h"
#include "electron/buildflags/buildflags.h"
#include "gin/handle.h"
#include "shell/common/gin_helper/wrappable.h"
@ -44,7 +45,7 @@ class View : public gin_helper::Wrappable<View> {
std::vector<v8::Global<v8::Object>> child_views_;
bool delete_view_ = true;
views::View* view_ = nullptr;
raw_ptr<views::View> view_ = nullptr;
};
} // namespace electron::api

View file

@ -11,6 +11,8 @@
#include <utility>
#include <vector>
#include "base/memory/raw_ptr.h"
#include "base/memory/raw_ptr_exclusion.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "base/observer_list_types.h"
@ -766,13 +768,13 @@ class WebContents : public ExclusiveAccessContext,
#endif
// The host webcontents that may contain this webcontents.
WebContents* embedder_ = nullptr;
RAW_PTR_EXCLUSION WebContents* embedder_ = nullptr;
// Whether the guest view has been attached.
bool attached_ = false;
// The zoom controller for this webContents.
WebContentsZoomController* zoom_controller_ = nullptr;
raw_ptr<WebContentsZoomController> zoom_controller_ = nullptr;
// The type of current WebContents.
Type type_ = Type::kBrowserWindow;
@ -810,7 +812,7 @@ class WebContents : public ExclusiveAccessContext,
std::unique_ptr<DevToolsEyeDropper> eye_dropper_;
ElectronBrowserContext* browser_context_;
raw_ptr<ElectronBrowserContext> browser_context_;
// The stored InspectableWebContents object.
// Notice that inspectable_web_contents_ must be placed after
@ -835,7 +837,7 @@ class WebContents : public ExclusiveAccessContext,
#endif
// Stores the frame thats currently in fullscreen, nullptr if there is none.
content::RenderFrameHost* fullscreen_frame_ = nullptr;
raw_ptr<content::RenderFrameHost> fullscreen_frame_ = nullptr;
std::unique_ptr<SkRegion> draggable_region_;

View file

@ -49,7 +49,7 @@ WebContentsView::~WebContentsView() {
}
gin::Handle<WebContents> WebContentsView::GetWebContents(v8::Isolate* isolate) {
return gin::CreateHandle(isolate, api_web_contents_);
return gin::CreateHandle(isolate, api_web_contents_.get());
}
int WebContentsView::NonClientHitTest(const gfx::Point& point) {

View file

@ -5,6 +5,7 @@
#ifndef ELECTRON_SHELL_BROWSER_API_ELECTRON_API_WEB_CONTENTS_VIEW_H_
#define ELECTRON_SHELL_BROWSER_API_ELECTRON_API_WEB_CONTENTS_VIEW_H_
#include "base/memory/raw_ptr.h"
#include "content/public/browser/web_contents_observer.h"
#include "shell/browser/api/electron_api_view.h"
#include "shell/browser/draggable_region_provider.h"
@ -53,7 +54,7 @@ class WebContentsView : public View,
// Keep a reference to v8 wrapper.
v8::Global<v8::Value> web_contents_;
api::WebContents* api_web_contents_;
raw_ptr<api::WebContents> api_web_contents_;
};
} // namespace electron::api

View file

@ -8,6 +8,7 @@
#include <string>
#include <vector>
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/process/process.h"
#include "gin/handle.h"
@ -122,7 +123,7 @@ class WebFrameMain : public gin::Wrappable<WebFrameMain>,
int frame_tree_node_id_;
content::RenderFrameHost* render_frame_ = nullptr;
raw_ptr<content::RenderFrameHost> render_frame_ = nullptr;
// Whether the RenderFrameHost has been removed and that it should no longer
// be accessed.

View file

@ -8,6 +8,7 @@
#include <string>
#include <utility>
#include "base/memory/raw_ptr.h"
#include "base/stl_util.h"
#include "base/task/sequenced_task_runner.h"
#include "base/values.h"
@ -91,7 +92,7 @@ const char kUserDataKey[] = "WebRequest";
// BrowserContext <=> WebRequest relationship.
struct UserData : public base::SupportsUserData::Data {
explicit UserData(WebRequest* data) : data(data) {}
WebRequest* data;
raw_ptr<WebRequest> data;
};
extensions::WebRequestResourceType ParseResourceType(const std::string& value) {
@ -612,7 +613,7 @@ gin::Handle<WebRequest> WebRequest::From(
static_cast<UserData*>(browser_context->GetUserData(kUserDataKey));
if (!user_data)
return gin::Handle<WebRequest>();
return gin::CreateHandle(isolate, user_data->data);
return gin::CreateHandle(isolate, user_data->data.get());
}
} // namespace electron::api

View file

@ -8,6 +8,7 @@
#include <map>
#include <set>
#include "base/memory/raw_ptr.h"
#include "base/values.h"
#include "extensions/common/url_pattern.h"
#include "gin/arguments.h"
@ -167,7 +168,7 @@ class WebRequest : public gin::Wrappable<WebRequest>, public WebRequestAPI {
std::map<uint64_t, net::CompletionOnceCallback> callbacks_;
// Weak-ref, it manages us.
content::BrowserContext* browser_context_;
raw_ptr<content::BrowserContext> browser_context_;
};
} // namespace electron::api

View file

@ -9,6 +9,7 @@
#include <string>
#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "components/viz/host/client_frame_sink_video_capturer.h"
#include "content/public/browser/web_contents.h"
@ -69,7 +70,7 @@ class FrameSubscriber : public content::WebContentsObserver,
FrameCaptureCallback callback_;
bool only_dirty_;
content::RenderWidgetHost* host_;
raw_ptr<content::RenderWidgetHost> host_;
std::unique_ptr<viz::ClientFrameSinkVideoCapturer> video_capturer_;
base::WeakPtrFactory<FrameSubscriber> weak_ptr_factory_{this};

View file

@ -8,6 +8,7 @@
#include <memory>
#include <vector>
#include "base/memory/raw_ptr.h"
#include "content/browser/gpu/gpu_data_manager_impl.h" // nogncheck
#include "content/public/browser/gpu_data_manager.h"
#include "content/public/browser/gpu_data_manager_observer.h"
@ -42,7 +43,7 @@ class GPUInfoManager : public content::GpuDataManagerObserver {
// This set maintains all the promises that should be fulfilled
// once we have the complete information data
std::vector<gin_helper::Promise<base::Value>> complete_info_promise_set_;
content::GpuDataManagerImpl* gpu_data_manager_;
raw_ptr<content::GpuDataManagerImpl> gpu_data_manager_;
};
} // namespace electron

View file

@ -5,6 +5,7 @@
#ifndef ELECTRON_SHELL_BROWSER_API_SAVE_PAGE_HANDLER_H_
#define ELECTRON_SHELL_BROWSER_API_SAVE_PAGE_HANDLER_H_
#include "base/memory/raw_ptr.h"
#include "components/download/public/common/download_item.h"
#include "content/public/browser/download_manager.h"
#include "content/public/browser/save_page_type.h"
@ -42,7 +43,7 @@ class SavePageHandler : public content::DownloadManager::Observer,
// download::DownloadItem::Observer:
void OnDownloadUpdated(download::DownloadItem* item) override;
content::WebContents* web_contents_; // weak
raw_ptr<content::WebContents> web_contents_; // weak
gin_helper::Promise<void> promise_;
};