Update source files for bracket style

This commit is contained in:
Marshall Greenblatt 2023-01-02 17:59:03 -05:00
parent d84b07a5cb
commit 3af3eab3e4
366 changed files with 7275 additions and 3834 deletions

View File

@ -80,22 +80,25 @@ class CefVisitedLinkListener : public visitedlink::VisitedLinkWriter::Listener {
void NewTable(base::ReadOnlySharedMemoryRegion* table_region) override {
CEF_REQUIRE_UIT();
ListenerMap::iterator it = listener_map_.begin();
for (; it != listener_map_.end(); ++it)
for (; it != listener_map_.end(); ++it) {
it->second->NewTable(table_region);
}
}
void Add(visitedlink::VisitedLinkCommon::Fingerprint fingerprint) override {
CEF_REQUIRE_UIT();
ListenerMap::iterator it = listener_map_.begin();
for (; it != listener_map_.end(); ++it)
for (; it != listener_map_.end(); ++it) {
it->second->Add(fingerprint);
}
}
void Reset(bool invalidate_hashes) override {
CEF_REQUIRE_UIT();
ListenerMap::iterator it = listener_map_.begin();
for (; it != listener_map_.end(); ++it)
for (; it != listener_map_.end(); ++it) {
it->second->Reset(invalidate_hashes);
}
}
private:
@ -161,8 +164,9 @@ void AlloyBrowserContext::Initialize() {
// Initialize visited links management.
base::FilePath visited_link_path;
if (!cache_path_.empty())
if (!cache_path_.empty()) {
visited_link_path = cache_path_.Append(FILE_PATH_LITERAL("Visited Links"));
}
visitedlink_listener_ = new CefVisitedLinkListener;
visitedlink_master_.reset(new visitedlink::VisitedLinkWriter(
visitedlink_listener_, this, !visited_link_path.empty(), false,
@ -181,8 +185,9 @@ void AlloyBrowserContext::Initialize() {
user_prefs::UserPrefs::Set(this, pref_service);
key_->SetPrefs(pref_service);
if (extensions_enabled)
if (extensions_enabled) {
extension_system_->Init();
}
ChromePluginServiceFilter::GetInstance()->RegisterProfile(this);
@ -227,8 +232,9 @@ void AlloyBrowserContext::Shutdown() {
// Delete the download manager delegate here because otherwise we'll crash
// when it's accessed from the content::BrowserContext destructor.
if (download_manager_delegate_)
if (download_manager_delegate_) {
download_manager_delegate_.reset(nullptr);
}
}
void AlloyBrowserContext::RemoveCefRequestContext(
@ -249,8 +255,9 @@ void AlloyBrowserContext::LoadExtension(
CefRefPtr<CefExtensionHandler> handler,
CefRefPtr<CefRequestContext> loader_context) {
if (!extensions::ExtensionsEnabled()) {
if (handler)
if (handler) {
handler->OnExtensionLoadFailed(ERR_ABORTED);
}
return;
}
@ -267,23 +274,26 @@ void AlloyBrowserContext::LoadExtension(
}
bool AlloyBrowserContext::GetExtensions(std::vector<CefString>& extension_ids) {
if (!extensions::ExtensionsEnabled())
if (!extensions::ExtensionsEnabled()) {
return false;
}
extensions::CefExtensionSystem::ExtensionMap extension_map =
extension_system()->GetExtensions();
extensions::CefExtensionSystem::ExtensionMap::const_iterator it =
extension_map.begin();
for (; it != extension_map.end(); ++it)
for (; it != extension_map.end(); ++it) {
extension_ids.push_back(it->second->GetIdentifier());
}
return true;
}
CefRefPtr<CefExtension> AlloyBrowserContext::GetExtension(
const CefString& extension_id) {
if (!extensions::ExtensionsEnabled())
if (!extensions::ExtensionsEnabled()) {
return nullptr;
}
return extension_system()->GetExtension(extension_id);
}
@ -295,8 +305,9 @@ bool AlloyBrowserContext::UnloadExtension(const CefString& extension_id) {
bool AlloyBrowserContext::IsPrintPreviewSupported() const {
CEF_REQUIRE_UIT();
if (!extensions::PrintPreviewEnabled())
if (!extensions::PrintPreviewEnabled()) {
return false;
}
return !GetPrefs()->GetBoolean(prefs::kPrintPreviewDisabled);
}
@ -334,8 +345,9 @@ base::FilePath AlloyBrowserContext::GetPath() const {
std::unique_ptr<content::ZoomLevelDelegate>
AlloyBrowserContext::CreateZoomLevelDelegate(
const base::FilePath& partition_path) {
if (cache_path_.empty())
if (cache_path_.empty()) {
return std::unique_ptr<content::ZoomLevelDelegate>();
}
return base::WrapUnique(new ChromeZoomLevelPrefs(
GetPrefs(), cache_path_, partition_path,
@ -352,8 +364,9 @@ AlloyBrowserContext::GetDownloadManagerDelegate() {
}
content::BrowserPluginGuestManager* AlloyBrowserContext::GetGuestManager() {
if (!extensions::ExtensionsEnabled())
if (!extensions::ExtensionsEnabled()) {
return nullptr;
}
return guest_view::GuestViewManager::FromBrowserContext(this);
}
@ -376,8 +389,9 @@ AlloyBrowserContext::GetStorageNotificationService() {
}
content::SSLHostStateDelegate* AlloyBrowserContext::GetSSLHostStateDelegate() {
if (!ssl_host_state_delegate_)
if (!ssl_host_state_delegate_) {
ssl_host_state_delegate_.reset(new CefSSLHostStateDelegate());
}
return ssl_host_state_delegate_.get();
}

View File

@ -130,8 +130,9 @@ CefRefPtr<AlloyBrowserHostImpl> AlloyBrowserHostImpl::Create(
static_cast<AlloyBrowserHostImpl*>(create_params.devtools_opener.get()),
is_devtools_popup, request_context_impl, std::move(platform_delegate),
cef_extension);
if (!browser)
if (!browser) {
return nullptr;
}
GURL url = url_util::MakeGURL(create_params.url, /*fixup=*/true);
@ -173,8 +174,9 @@ CefRefPtr<AlloyBrowserHostImpl> AlloyBrowserHostImpl::CreateInternal(
if (opener) {
if (!opener->platform_delegate_) {
// The opener window is being destroyed. Cancel the popup.
if (own_web_contents)
if (own_web_contents) {
delete web_contents;
}
return nullptr;
}
@ -193,8 +195,9 @@ CefRefPtr<AlloyBrowserHostImpl> AlloyBrowserHostImpl::CreateInternal(
std::move(platform_delegate), extension);
browser->InitializeBrowser();
if (!browser->CreateHostWindow())
if (!browser->CreateHostWindow()) {
return nullptr;
}
// Notify that the browser has been created. These must be delivered in the
// expected order.
@ -316,8 +319,9 @@ CefWindowHandle AlloyBrowserHostImpl::GetWindowHandle() {
if (is_views_hosted_ && CEF_CURRENTLY_ON_UIT()) {
// Always return the most up-to-date window handle for a views-hosted
// browser since it may change if the view is re-parented.
if (platform_delegate_)
if (platform_delegate_) {
return platform_delegate_->GetHostWindowHandle();
}
}
return host_window_handle_;
}
@ -333,16 +337,18 @@ double AlloyBrowserHostImpl::GetZoomLevel() {
return 0;
}
if (web_contents())
if (web_contents()) {
return content::HostZoomMap::GetZoomLevel(web_contents());
}
return 0;
}
void AlloyBrowserHostImpl::SetZoomLevel(double zoomLevel) {
if (CEF_CURRENTLY_ON_UIT()) {
if (web_contents())
if (web_contents()) {
content::HostZoomMap::SetZoomLevel(web_contents(), zoomLevel);
}
} else {
CEF_POST_TASK(CEF_UIT, base::BindOnce(&AlloyBrowserHostImpl::SetZoomLevel,
this, zoomLevel));
@ -372,8 +378,9 @@ void AlloyBrowserHostImpl::StopFinding(bool clearSelection) {
return;
}
if (platform_delegate_)
if (platform_delegate_) {
platform_delegate_->StopFinding(clearSelection);
}
}
void AlloyBrowserHostImpl::ShowDevTools(const CefWindowInfo& windowInfo,
@ -387,8 +394,9 @@ void AlloyBrowserHostImpl::ShowDevTools(const CefWindowInfo& windowInfo,
return;
}
if (!EnsureDevToolsManager())
if (!EnsureDevToolsManager()) {
return;
}
devtools_manager_->ShowDevTools(windowInfo, client, settings,
inspect_element_at);
}
@ -400,8 +408,9 @@ void AlloyBrowserHostImpl::CloseDevTools() {
return;
}
if (!devtools_manager_)
if (!devtools_manager_) {
return;
}
devtools_manager_->CloseDevTools();
}
@ -411,8 +420,9 @@ bool AlloyBrowserHostImpl::HasDevTools() {
return false;
}
if (!devtools_manager_)
if (!devtools_manager_) {
return false;
}
return devtools_manager_->HasDevTools();
}
@ -464,8 +474,9 @@ void AlloyBrowserHostImpl::WasResized() {
return;
}
if (platform_delegate_)
if (platform_delegate_) {
platform_delegate_->WasResized();
}
}
void AlloyBrowserHostImpl::WasHidden(bool hidden) {
@ -480,8 +491,9 @@ void AlloyBrowserHostImpl::WasHidden(bool hidden) {
return;
}
if (platform_delegate_)
if (platform_delegate_) {
platform_delegate_->WasHidden(hidden);
}
}
void AlloyBrowserHostImpl::NotifyScreenInfoChanged() {
@ -497,8 +509,9 @@ void AlloyBrowserHostImpl::NotifyScreenInfoChanged() {
return;
}
if (platform_delegate_)
if (platform_delegate_) {
platform_delegate_->NotifyScreenInfoChanged();
}
}
void AlloyBrowserHostImpl::Invalidate(PaintElementType type) {
@ -513,8 +526,9 @@ void AlloyBrowserHostImpl::Invalidate(PaintElementType type) {
return;
}
if (platform_delegate_)
if (platform_delegate_) {
platform_delegate_->Invalidate(type);
}
}
void AlloyBrowserHostImpl::SendExternalBeginFrame() {
@ -530,8 +544,9 @@ void AlloyBrowserHostImpl::SendExternalBeginFrame() {
return;
}
if (platform_delegate_)
if (platform_delegate_) {
platform_delegate_->SendExternalBeginFrame();
}
}
void AlloyBrowserHostImpl::SendTouchEvent(const CefTouchEvent& event) {
@ -546,8 +561,9 @@ void AlloyBrowserHostImpl::SendTouchEvent(const CefTouchEvent& event) {
return;
}
if (platform_delegate_)
if (platform_delegate_) {
platform_delegate_->SendTouchEvent(event);
}
}
void AlloyBrowserHostImpl::SendCaptureLostEvent() {
@ -558,8 +574,9 @@ void AlloyBrowserHostImpl::SendCaptureLostEvent() {
return;
}
if (platform_delegate_)
if (platform_delegate_) {
platform_delegate_->SendCaptureLostEvent();
}
}
int AlloyBrowserHostImpl::GetWindowlessFrameRate() {
@ -582,8 +599,9 @@ void AlloyBrowserHostImpl::SetWindowlessFrameRate(int frame_rate) {
settings_.windowless_frame_rate = frame_rate;
if (platform_delegate_)
if (platform_delegate_) {
platform_delegate_->SetWindowlessFrameRate(frame_rate);
}
}
// AlloyBrowserHostImpl public methods.
@ -635,10 +653,12 @@ void AlloyBrowserHostImpl::DestroyBrowser() {
OnBeforeClose();
// Destroy any platform constructs first.
if (javascript_dialog_manager_.get())
if (javascript_dialog_manager_.get()) {
javascript_dialog_manager_->Destroy();
if (menu_manager_.get())
}
if (menu_manager_.get()) {
menu_manager_->Destroy();
}
// Notify any observers that may have state associated with this browser.
OnBrowserDestroyed();
@ -670,8 +690,9 @@ void AlloyBrowserHostImpl::DestroyBrowser() {
void AlloyBrowserHostImpl::CancelContextMenu() {
CEF_REQUIRE_UIT();
if (menu_manager_)
if (menu_manager_) {
menu_manager_->CancelContextMenu();
}
}
bool AlloyBrowserHostImpl::MaybeAllowNavigation(
@ -710,11 +731,13 @@ void AlloyBrowserHostImpl::OnSetFocus(cef_focus_source_t source) {
return;
}
if (contents_delegate_->OnSetFocus(source))
if (contents_delegate_->OnSetFocus(source)) {
return;
}
if (platform_delegate_)
if (platform_delegate_) {
platform_delegate_->SetFocus(true);
}
}
void AlloyBrowserHostImpl::EnterFullscreenModeForTab(
@ -842,8 +865,9 @@ void AlloyBrowserHostImpl::ImeCancelComposition() {
return;
}
if (platform_delegate_)
if (platform_delegate_) {
platform_delegate_->ImeCancelComposition();
}
}
void AlloyBrowserHostImpl::DragTargetDragEnter(
@ -905,8 +929,9 @@ void AlloyBrowserHostImpl::DragTargetDragLeave() {
return;
}
if (platform_delegate_)
if (platform_delegate_) {
platform_delegate_->DragTargetDragLeave();
}
}
void AlloyBrowserHostImpl::DragTargetDrop(const CefMouseEvent& event) {
@ -921,8 +946,9 @@ void AlloyBrowserHostImpl::DragTargetDrop(const CefMouseEvent& event) {
return;
}
if (platform_delegate_)
if (platform_delegate_) {
platform_delegate_->DragTargetDrop(event);
}
}
void AlloyBrowserHostImpl::DragSourceSystemDragEnded() {
@ -938,8 +964,9 @@ void AlloyBrowserHostImpl::DragSourceSystemDragEnded() {
return;
}
if (platform_delegate_)
if (platform_delegate_) {
platform_delegate_->DragSourceSystemDragEnded();
}
}
void AlloyBrowserHostImpl::DragSourceEndedAt(
@ -958,8 +985,9 @@ void AlloyBrowserHostImpl::DragSourceEndedAt(
return;
}
if (platform_delegate_)
if (platform_delegate_) {
platform_delegate_->DragSourceEndedAt(x, y, op);
}
}
void AlloyBrowserHostImpl::SetAudioMuted(bool mute) {
@ -968,8 +996,9 @@ void AlloyBrowserHostImpl::SetAudioMuted(bool mute) {
this, mute));
return;
}
if (!web_contents())
if (!web_contents()) {
return;
}
web_contents()->SetAudioMuted(mute);
}
@ -978,8 +1007,9 @@ bool AlloyBrowserHostImpl::IsAudioMuted() {
NOTREACHED() << "called on invalid thread";
return false;
}
if (!web_contents())
if (!web_contents()) {
return false;
}
return web_contents()->IsAudioMuted();
}
@ -1028,8 +1058,9 @@ void AlloyBrowserHostImpl::LoadingStateChanged(content::WebContents* source,
void AlloyBrowserHostImpl::CloseContents(content::WebContents* source) {
CEF_REQUIRE_UIT();
if (destruction_state_ == DESTRUCTION_STATE_COMPLETED)
if (destruction_state_ == DESTRUCTION_STATE_COMPLETED) {
return;
}
bool close_browser = true;
@ -1043,8 +1074,9 @@ void AlloyBrowserHostImpl::CloseContents(content::WebContents* source) {
}
if (close_browser) {
if (destruction_state_ != DESTRUCTION_STATE_ACCEPTED)
if (destruction_state_ != DESTRUCTION_STATE_ACCEPTED) {
destruction_state_ = DESTRUCTION_STATE_ACCEPTED;
}
if (!IsWindowless() && !window_destroyed_) {
// A window exists so try to close it using the platform method. Will
@ -1101,8 +1133,9 @@ bool AlloyBrowserHostImpl::TakeFocus(content::WebContents* source,
bool reverse) {
if (client_.get()) {
CefRefPtr<CefFocusHandler> handler = client_->GetFocusHandler();
if (handler.get())
if (handler.get()) {
handler->OnTakeFocus(this, !reverse);
}
}
return false;
@ -1125,14 +1158,17 @@ bool AlloyBrowserHostImpl::HandleKeyboardEvent(
content::WebContents* source,
const content::NativeWebKeyboardEvent& event) {
// Check to see if event should be ignored.
if (event.skip_in_browser)
if (event.skip_in_browser) {
return false;
}
if (contents_delegate_->HandleKeyboardEvent(source, event))
if (contents_delegate_->HandleKeyboardEvent(source, event)) {
return true;
}
if (platform_delegate_)
if (platform_delegate_) {
return platform_delegate_->HandleKeyboardEvent(event);
}
return false;
}
@ -1146,8 +1182,9 @@ bool AlloyBrowserHostImpl::CanDragEnter(content::WebContents* source,
const content::DropData& data,
blink::DragOperationsMask mask) {
CefRefPtr<CefDragHandler> handler;
if (client_)
if (client_) {
handler = client_->GetDragHandler();
}
if (handler) {
CefRefPtr<CefDragDataImpl> drag_data(new CefDragDataImpl(data));
drag_data->SetReadOnly(true);
@ -1200,8 +1237,9 @@ void AlloyBrowserHostImpl::WebContentsCreated(
CefRefPtr<AlloyBrowserHostImpl> opener =
GetBrowserForContents(source_contents);
if (!opener)
if (!opener) {
return;
}
// Popups must share the same RequestContext as the parent.
CefRefPtr<CefRequestContextImpl> request_context = opener->request_context();
@ -1251,8 +1289,9 @@ void AlloyBrowserHostImpl::UpdatePreferredSize(content::WebContents* source,
const gfx::Size& pref_size) {
#if BUILDFLAG(IS_WIN) || (BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC))
CEF_REQUIRE_UIT();
if (platform_delegate_)
if (platform_delegate_) {
platform_delegate_->SizeTo(pref_size.width(), pref_size.height());
}
#endif
}
@ -1336,13 +1375,15 @@ void AlloyBrowserHostImpl::DidFinishNavigation(
void AlloyBrowserHostImpl::OnAudioStateChanged(bool audible) {
if (audible) {
if (recently_audible_timer_)
if (recently_audible_timer_) {
recently_audible_timer_->Stop();
}
StartAudioCapturer();
} else if (audio_capturer_) {
if (!recently_audible_timer_)
if (!recently_audible_timer_) {
recently_audible_timer_ = std::make_unique<base::OneShotTimer>();
}
// If you have a media playing that has a short quiet moment, web_contents
// will immediately switch to non-audible state. We don't want to stop
@ -1363,8 +1404,9 @@ void AlloyBrowserHostImpl::AccessibilityEventReceived(
const content::AXEventNotificationDetails& content_event_bundle) {
// Only needed in windowless mode.
if (IsWindowless()) {
if (!web_contents() || !platform_delegate_)
if (!web_contents() || !platform_delegate_) {
return;
}
platform_delegate_->AccessibilityEventReceived(content_event_bundle);
}
@ -1374,8 +1416,9 @@ void AlloyBrowserHostImpl::AccessibilityLocationChangesReceived(
const std::vector<content::AXLocationChangeNotificationDetails>& locData) {
// Only needed in windowless mode.
if (IsWindowless()) {
if (!web_contents() || !platform_delegate_)
if (!web_contents() || !platform_delegate_) {
return;
}
platform_delegate_->AccessibilityLocationChangesReceived(locData);
}
@ -1384,25 +1427,29 @@ void AlloyBrowserHostImpl::AccessibilityLocationChangesReceived(
void AlloyBrowserHostImpl::WebContentsDestroyed() {
auto wc = web_contents();
content::WebContentsObserver::Observe(nullptr);
if (platform_delegate_)
if (platform_delegate_) {
platform_delegate_->WebContentsDestroyed(wc);
}
}
void AlloyBrowserHostImpl::StartAudioCapturer() {
if (!client_.get() || audio_capturer_)
if (!client_.get() || audio_capturer_) {
return;
}
CefRefPtr<CefAudioHandler> audio_handler = client_->GetAudioHandler();
if (!audio_handler.get())
if (!audio_handler.get()) {
return;
}
CefAudioParameters params;
params.channel_layout = CEF_CHANNEL_LAYOUT_STEREO;
params.sample_rate = media::AudioParameters::kAudioCDSampleRate;
params.frames_per_buffer = 1024;
if (!audio_handler->GetAudioParameters(this, params))
if (!audio_handler->GetAudioParameters(this, params)) {
return;
}
audio_capturer_.reset(new CefAudioCapturer(params, this, audio_handler));
}
@ -1447,18 +1494,21 @@ bool AlloyBrowserHostImpl::CreateHostWindow() {
// |host_window_handle_| will not change after initial host creation for
// non-views-hosted browsers.
bool success = true;
if (!IsWindowless())
if (!IsWindowless()) {
success = platform_delegate_->CreateHostWindow();
if (success && !is_views_hosted_)
}
if (success && !is_views_hosted_) {
host_window_handle_ = platform_delegate_->GetHostWindowHandle();
}
return success;
}
gfx::Point AlloyBrowserHostImpl::GetScreenPoint(const gfx::Point& view,
bool want_dip_coords) const {
CEF_REQUIRE_UIT();
if (platform_delegate_)
if (platform_delegate_) {
return platform_delegate_->GetScreenPoint(view, want_dip_coords);
}
return gfx::Point();
}
@ -1477,6 +1527,7 @@ void AlloyBrowserHostImpl::StartDragging(
void AlloyBrowserHostImpl::UpdateDragCursor(
ui::mojom::DragOperation operation) {
if (platform_delegate_)
if (platform_delegate_) {
platform_delegate_->UpdateDragCursor(operation);
}
}

View File

@ -122,13 +122,15 @@ class LinuxUiGetterImpl : public ui::LinuxUiGetter {
ui::LinuxUi* GetLinuxUI() {
// We can't use GtkUi in combination with multi-threaded-message-loop because
// Chromium's GTK implementation doesn't use GDK threads.
if (!!CefContext::Get()->settings().multi_threaded_message_loop)
if (!!CefContext::Get()->settings().multi_threaded_message_loop) {
return nullptr;
}
// If the ozone backend hasn't provided a LinuxUiDelegate, don't try to create
// a LinuxUi instance as this may result in a crash in toolkit initialization.
if (!ui::LinuxUiDelegate::GetInstance())
if (!ui::LinuxUiDelegate::GetInstance()) {
return nullptr;
}
return ui::GetDefaultLinuxUi();
}
@ -176,10 +178,11 @@ void AlloyBrowserMainParts::ToolkitInitialized() {
#endif // BUILDFLAG(IS_LINUX)
#if BUILDFLAG(IS_MAC)
if (base::FeatureList::IsEnabled(features::kViewsJSAppModalDialog))
if (base::FeatureList::IsEnabled(features::kViewsJSAppModalDialog)) {
InstallChromeJavaScriptAppModalDialogViewFactory();
else
} else {
InstallChromeJavaScriptAppModalDialogViewCocoaFactory();
}
#else
InstallChromeJavaScriptAppModalDialogViewFactory();
#endif

View File

@ -185,13 +185,15 @@ class CefSelectClientCertificateCallbackImpl
~CefSelectClientCertificateCallbackImpl() {
// If Select has not been called, call it with NULL to continue without any
// client certificate.
if (delegate_)
if (delegate_) {
DoSelect(nullptr);
}
}
void Select(CefRefPtr<CefX509Certificate> cert) override {
if (delegate_)
if (delegate_) {
DoSelect(cert);
}
}
private:
@ -246,8 +248,9 @@ class CefSelectClientCertificateCallbackImpl
#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC)
int GetCrashSignalFD() {
if (!crash_reporting::Enabled())
if (!crash_reporting::Enabled()) {
return -1;
}
int fd;
pid_t pid;
@ -262,8 +265,9 @@ void BindPluginInfoHost(
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
content::RenderProcessHost* host =
content::RenderProcessHost::FromID(render_process_id);
if (!host)
if (!host) {
return;
}
Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
mojo::MakeSelfOwnedAssociatedReceiver(
@ -300,12 +304,14 @@ base::FilePath GetRootCachePath() {
const extensions::Extension* GetEnabledExtensionFromSiteURL(
content::BrowserContext* context,
const GURL& site_url) {
if (!site_url.SchemeIs(extensions::kExtensionScheme))
if (!site_url.SchemeIs(extensions::kExtensionScheme)) {
return nullptr;
}
auto registry = extensions::ExtensionRegistry::Get(context);
if (!registry)
if (!registry) {
return nullptr;
}
return registry->enabled_extensions().GetByID(site_url.host());
}
@ -394,11 +400,13 @@ bool AlloyContentBrowserClient::ShouldTreatURLSchemeAsFirstPartyWhenTopLevel(
// with SameSite cookies on accounts.google.com, which are used for logging
// into Cloud Print from chrome://print, for displaying a list of available
// accounts on the NTP (chrome://new-tab-page), etc.
if (is_embedded_origin_secure && scheme == content::kChromeUIScheme)
if (is_embedded_origin_secure && scheme == content::kChromeUIScheme) {
return true;
}
if (extensions::ExtensionsEnabled())
if (extensions::ExtensionsEnabled()) {
return scheme == extensions::kExtensionScheme;
}
return false;
}
@ -456,21 +464,24 @@ bool AlloyContentBrowserClient::IsWebUIAllowedToMakeNetworkRequests(
}
bool AlloyContentBrowserClient::IsHandledURL(const GURL& url) {
if (!url.is_valid())
if (!url.is_valid()) {
return false;
}
const std::string& scheme = url.scheme();
DCHECK_EQ(scheme, base::ToLowerASCII(scheme));
if (scheme::IsInternalHandledScheme(scheme))
if (scheme::IsInternalHandledScheme(scheme)) {
return true;
}
return CefAppManager::Get()->HasCustomScheme(scheme);
}
void AlloyContentBrowserClient::SiteInstanceGotProcess(
content::SiteInstance* site_instance) {
if (!extensions::ExtensionsEnabled())
if (!extensions::ExtensionsEnabled()) {
return;
}
CHECK(site_instance->HasProcess());
@ -484,8 +495,9 @@ void AlloyContentBrowserClient::SiteInstanceGotProcess(
// since it isn't treated as a hosted app.
const auto extension =
GetEnabledExtensionFromSiteURL(context, site_instance->GetSiteURL());
if (!extension)
if (!extension) {
return;
}
extensions::ProcessMap::Get(context)->Insert(
extension->id(), site_instance->GetProcess()->GetID(),
@ -494,21 +506,25 @@ void AlloyContentBrowserClient::SiteInstanceGotProcess(
void AlloyContentBrowserClient::SiteInstanceDeleting(
content::SiteInstance* site_instance) {
if (!extensions::ExtensionsEnabled())
if (!extensions::ExtensionsEnabled()) {
return;
}
if (!site_instance->HasProcess())
if (!site_instance->HasProcess()) {
return;
}
auto context = site_instance->GetBrowserContext();
auto registry = extensions::ExtensionRegistry::Get(context);
if (!registry)
if (!registry) {
return;
}
auto extension = registry->enabled_extensions().GetExtensionOrAppByURL(
site_instance->GetSiteURL());
if (!extension)
if (!extension) {
return;
}
extensions::ProcessMap::Get(context)->Remove(
extension->id(), site_instance->GetProcess()->GetID(),
@ -619,8 +635,9 @@ void AlloyContentBrowserClient::AppendExtraCommandLineSwitches(
// Force use of the sub-process executable path for the zygote process.
const base::FilePath& subprocess_path =
browser_cmd->GetSwitchValuePath(switches::kBrowserSubprocessPath);
if (!subprocess_path.empty())
if (!subprocess_path.empty()) {
command_line->SetProgram(subprocess_path);
}
}
// Propagate the following switches to the zygote command line (along with
@ -666,8 +683,9 @@ AlloyContentBrowserClient::GetSystemSharedURLLoaderFactory() {
content::BrowserThread::CurrentlyOn(content::BrowserThread::UI) ||
!content::BrowserThread::IsThreadInitialized(content::BrowserThread::UI));
if (!SystemNetworkContextManager::GetInstance())
if (!SystemNetworkContextManager::GetInstance()) {
return nullptr;
}
return SystemNetworkContextManager::GetInstance()
->GetSharedURLLoaderFactory();
@ -688,8 +706,9 @@ content::SpeechRecognitionManagerDelegate*
AlloyContentBrowserClient::CreateSpeechRecognitionManagerDelegate() {
const base::CommandLine* command_line =
base::CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(switches::kEnableSpeechInput))
if (command_line->HasSwitch(switches::kEnableSpeechInput)) {
return new CefSpeechRecognitionManagerDelegate();
}
return nullptr;
}
@ -732,8 +751,9 @@ base::OnceClosure AlloyContentBrowserClient::SelectClientCertificate(
AlloyBrowserHostImpl::GetBrowserForContents(web_contents);
if (browser.get()) {
CefRefPtr<CefClient> client = browser->GetClient();
if (client.get())
if (client.get()) {
handler = client->GetRequestHandler();
}
}
if (!handler.get()) {
@ -865,13 +885,15 @@ AlloyContentBrowserClient::CreateThrottlesForNavigation(
if (extensions::ExtensionsEnabled()) {
auto pdf_iframe_throttle =
PDFIFrameNavigationThrottle::MaybeCreateThrottleFor(navigation_handle);
if (pdf_iframe_throttle)
if (pdf_iframe_throttle) {
throttles.push_back(std::move(pdf_iframe_throttle));
}
auto pdf_throttle = pdf::PdfNavigationThrottle::MaybeCreateThrottleFor(
navigation_handle, std::make_unique<ChromePdfStreamDelegate>());
if (pdf_throttle)
if (pdf_throttle) {
throttles.push_back(std::move(pdf_throttle));
}
}
throttle::CreateThrottlesForNavigation(navigation_handle, throttles);
@ -915,8 +937,9 @@ AlloyContentBrowserClient::WillCreateURLLoaderRequestInterceptors(
auto pdf_interceptor =
pdf::PdfURLLoaderRequestInterceptor::MaybeCreateInterceptor(
frame_tree_node_id, std::make_unique<ChromePdfStreamDelegate>());
if (pdf_interceptor)
if (pdf_interceptor) {
interceptors.push_back(std::move(pdf_interceptor));
}
}
return interceptors;
@ -995,8 +1018,9 @@ void AlloyContentBrowserClient::RegisterNonNetworkNavigationURLLoaderFactories(
int frame_tree_node_id,
ukm::SourceIdObj ukm_source_id,
NonNetworkURLLoaderFactoryMap* factories) {
if (!extensions::ExtensionsEnabled())
if (!extensions::ExtensionsEnabled()) {
return;
}
content::WebContents* web_contents =
content::WebContents::FromFrameTreeNodeId(frame_tree_node_id);
@ -1012,20 +1036,23 @@ void AlloyContentBrowserClient::RegisterNonNetworkSubresourceURLLoaderFactories(
int render_frame_id,
const absl::optional<url::Origin>& request_initiator_origin,
NonNetworkURLLoaderFactoryMap* factories) {
if (!extensions::ExtensionsEnabled())
if (!extensions::ExtensionsEnabled()) {
return;
}
auto factory = extensions::CreateExtensionURLLoaderFactory(render_process_id,
render_frame_id);
if (factory)
if (factory) {
factories->emplace(extensions::kExtensionScheme, std::move(factory));
}
content::RenderFrameHost* frame_host =
content::RenderFrameHost::FromID(render_process_id, render_frame_id);
content::WebContents* web_contents =
content::WebContents::FromRenderFrameHost(frame_host);
if (!web_contents)
if (!web_contents) {
return;
}
extensions::CefExtensionWebContentsObserver* web_observer =
extensions::CefExtensionWebContentsObserver::FromWebContents(
@ -1033,13 +1060,15 @@ void AlloyContentBrowserClient::RegisterNonNetworkSubresourceURLLoaderFactories(
// There is nothing to do if no CefExtensionWebContentsObserver is attached
// to the |web_contents|.
if (!web_observer)
if (!web_observer) {
return;
}
const extensions::Extension* extension =
web_observer->GetExtensionFromFrame(frame_host, false);
if (!extension)
if (!extension) {
return;
}
std::vector<std::string> allowed_webui_hosts;
// Support for chrome:// scheme if appropriate.
@ -1222,25 +1251,29 @@ void AlloyContentBrowserClient::RegisterBrowserInterfaceBindersForFrame(
map->Add<network_hints::mojom::NetworkHintsHandler>(
base::BindRepeating(&BindNetworkHintsHandler));
if (!extensions::ExtensionsEnabled())
if (!extensions::ExtensionsEnabled()) {
return;
}
content::WebContents* web_contents =
content::WebContents::FromRenderFrameHost(render_frame_host);
if (!web_contents)
if (!web_contents) {
return;
}
const GURL& site = render_frame_host->GetSiteInstance()->GetSiteURL();
if (!site.SchemeIs(extensions::kExtensionScheme))
if (!site.SchemeIs(extensions::kExtensionScheme)) {
return;
}
content::BrowserContext* browser_context =
render_frame_host->GetProcess()->GetBrowserContext();
auto* extension = extensions::ExtensionRegistry::Get(browser_context)
->enabled_extensions()
.GetByID(site.host());
if (!extension)
if (!extension) {
return;
}
extensions::ExtensionsBrowserClient::Get()
->RegisterBrowserInterfaceBindersForFrame(map, render_frame_host,
extension);
@ -1306,8 +1339,9 @@ AlloyContentBrowserClient::GetPluginMimeTypesWithExternalHandlers(
content::BrowserContext* browser_context) {
base::flat_set<std::string> mime_types;
auto map = PluginUtils::GetMimeTypeToExtensionIdMap(browser_context);
for (const auto& pair : map)
for (const auto& pair : map) {
mime_types.insert(pair.first);
}
mime_types.insert(pdf::kInternalPluginMimeType);
return mime_types;
}
@ -1372,8 +1406,9 @@ const extensions::Extension* AlloyContentBrowserClient::GetExtension(
content::SiteInstance* site_instance) {
extensions::ExtensionRegistry* registry =
extensions::ExtensionRegistry::Get(site_instance->GetBrowserContext());
if (!registry)
if (!registry) {
return nullptr;
}
return registry->enabled_extensions().GetExtensionOrAppByURL(
site_instance->GetSiteURL());
}

View File

@ -161,8 +161,9 @@ void CefBrowserPlatformDelegateAlloy::BrowserCreated(
CefBrowserPlatformDelegate::BrowserCreated(browser);
// Only register WebContents delegate/observers if we're the primary delegate.
if (!primary_)
if (!primary_) {
return;
}
DCHECK(!web_contents_->GetDelegate());
web_contents_->SetDelegate(static_cast<AlloyBrowserHostImpl*>(browser));
@ -243,22 +244,26 @@ CefBrowserPlatformDelegateAlloy::GetWebContentsModalDialogHost() const {
}
void CefBrowserPlatformDelegateAlloy::SendCaptureLostEvent() {
if (!web_contents_)
if (!web_contents_) {
return;
}
content::RenderViewHost* host = web_contents_->GetRenderViewHost();
if (!host)
if (!host) {
return;
}
content::RenderWidgetHostImpl* widget =
content::RenderWidgetHostImpl::From(host->GetWidget());
if (widget)
if (widget) {
widget->LostCapture();
}
}
#if BUILDFLAG(IS_WIN) || (BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC))
void CefBrowserPlatformDelegateAlloy::NotifyMoveOrResizeStarted() {
if (!web_contents_)
if (!web_contents_) {
return;
}
// Dismiss any existing popups.
web_contents_->ClearFocusedElement();
@ -268,15 +273,17 @@ void CefBrowserPlatformDelegateAlloy::NotifyMoveOrResizeStarted() {
bool CefBrowserPlatformDelegateAlloy::PreHandleGestureEvent(
content::WebContents* source,
const blink::WebGestureEvent& event) {
if (extension_host_)
if (extension_host_) {
return extension_host_->PreHandleGestureEvent(source, event);
}
return false;
}
bool CefBrowserPlatformDelegateAlloy::IsNeverComposited(
content::WebContents* web_contents) {
if (extension_host_)
if (extension_host_) {
return extension_host_->IsNeverComposited(web_contents);
}
return false;
}
@ -284,8 +291,9 @@ void CefBrowserPlatformDelegateAlloy::SetAutoResizeEnabled(
bool enabled,
const CefSize& min_size,
const CefSize& max_size) {
if (enabled == auto_resize_enabled_)
if (enabled == auto_resize_enabled_) {
return;
}
auto_resize_enabled_ = enabled;
if (enabled) {
@ -315,14 +323,16 @@ void CefBrowserPlatformDelegateAlloy::SetAccessibilityState(
// Do nothing if state is set to default. It'll be disabled by default and
// controlled by the commmand-line flags "force-renderer-accessibility" and
// "disable-renderer-accessibility".
if (accessibility_state == STATE_DEFAULT)
if (accessibility_state == STATE_DEFAULT) {
return;
}
content::WebContentsImpl* web_contents_impl =
static_cast<content::WebContentsImpl*>(web_contents_);
if (!web_contents_impl)
if (!web_contents_impl) {
return;
}
ui::AXMode accMode;
// In windowless mode set accessibility to TreeOnly mode. Else native
@ -337,8 +347,9 @@ bool CefBrowserPlatformDelegateAlloy::IsPrintPreviewSupported() const {
REQUIRE_ALLOY_RUNTIME();
// Print preview is not currently supported with OSR.
if (IsWindowless())
if (IsWindowless()) {
return false;
}
auto cef_browser_context =
CefBrowserContext::FromBrowserContext(web_contents_->GetBrowserContext());
@ -349,8 +360,9 @@ void CefBrowserPlatformDelegateAlloy::Find(const CefString& searchText,
bool forward,
bool matchCase,
bool findNext) {
if (!web_contents_)
if (!web_contents_) {
return;
}
find_in_page::FindTabHelper::FromWebContents(web_contents_)
->StartFinding(searchText.ToString16(), forward, matchCase, findNext,
@ -358,8 +370,9 @@ void CefBrowserPlatformDelegateAlloy::Find(const CefString& searchText,
}
void CefBrowserPlatformDelegateAlloy::StopFinding(bool clearSelection) {
if (!web_contents_)
if (!web_contents_) {
return;
}
last_search_result_ = find_in_page::FindNotificationDetails();
find_in_page::FindTabHelper::FromWebContents(web_contents_)
@ -373,8 +386,9 @@ bool CefBrowserPlatformDelegateAlloy::HandleFindReply(
const gfx::Rect& selection_rect,
int active_match_ordinal,
bool final_update) {
if (!web_contents_)
if (!web_contents_) {
return false;
}
auto find_in_page =
find_in_page::FindTabHelper::FromWebContents(web_contents_);
@ -407,8 +421,9 @@ void CefBrowserPlatformDelegateAlloy::SetOwnedWebContents(
}
void CefBrowserPlatformDelegateAlloy::DestroyExtensionHost() {
if (!extension_host_)
if (!extension_host_) {
return;
}
if (extension_host_->extension_host_type() ==
extensions::mojom::ViewType::kExtensionBackgroundPage) {
DCHECK(is_background_host_);

View File

@ -114,8 +114,9 @@ void ChromeBrowserProcessAlloy::CleanupOnUIThread() {
// Release any references to |local_state_|.
auto profile = browser_context->AsProfile();
PrefWatcher* pref_watcher = PrefWatcher::Get(profile);
if (pref_watcher)
if (pref_watcher) {
pref_watcher->Shutdown();
}
// Unregister observers for |background_printing_manager_|.
if (background_printing_manager_) {
@ -345,8 +346,9 @@ void ChromeBrowserProcessAlloy::StartAutoupdateTimer() {}
component_updater::ComponentUpdateService*
ChromeBrowserProcessAlloy::component_updater() {
if (component_updater_)
if (component_updater_) {
return component_updater_.get();
}
if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) {
return nullptr;

View File

@ -61,8 +61,9 @@ const Profile::OTRProfileID& ChromeProfileAlloy::GetOTRProfileID() const {
}
variations::VariationsClient* ChromeProfileAlloy::GetVariationsClient() {
if (!variations_client_)
if (!variations_client_) {
variations_client_ = std::make_unique<CefVariationsClient>(this);
}
return variations_client_.get();
}

View File

@ -51,8 +51,9 @@ Profile* ChromeProfileManagerAlloy::GetProfile(
}
bool ChromeProfileManagerAlloy::IsValidProfile(const void* profile) {
if (!profile)
if (!profile) {
return false;
}
return !!CefBrowserContext::FromBrowserContext(
static_cast<const content::BrowserContext*>(profile));
}

View File

@ -81,8 +81,9 @@ gfx::Size AlloyWebContentsDialogHelper::GetMaximumDialogSize() {
void AlloyWebContentsDialogHelper::AddObserver(
web_modal::ModalDialogHostObserver* observer) {
if (observer && !observer_list_.HasObserver(observer))
if (observer && !observer_list_.HasObserver(observer)) {
observer_list_.AddObserver(observer);
}
}
void AlloyWebContentsDialogHelper::RemoveObserver(
@ -91,6 +92,7 @@ void AlloyWebContentsDialogHelper::RemoveObserver(
}
void AlloyWebContentsDialogHelper::OnBoundsChanged() {
for (auto& observer : observer_list_)
for (auto& observer : observer_list_) {
observer.OnPositionRequiresUpdate();
}
}

View File

@ -120,10 +120,12 @@ void CefAudioCapturer::OnCaptureError(
}
void CefAudioCapturer::StopStream() {
if (audio_input_device_)
if (audio_input_device_) {
audio_input_device_->Stop();
if (capturing_)
}
if (capturing_) {
audio_handler_->OnAudioStreamStopped(browser_);
}
audio_input_device_ = nullptr;
capturing_ = false;

View File

@ -130,8 +130,9 @@ content::WebContents* CefBrowserContentsDelegate::OpenURLFromTab(
if (auto handler = c->GetRequestHandler()) {
// May return nullptr for omnibox navigations.
auto frame = browser()->GetFrame(params.frame_tree_node_id);
if (!frame)
if (!frame) {
frame = browser()->GetMainFrame();
}
cancel = handler->OnOpenURLFromTab(
browser(), frame, params.url.spec(),
static_cast<cef_window_open_disposition_t>(params.disposition),
@ -283,8 +284,9 @@ bool CefBrowserContentsDelegate::HandleKeyboardEvent(
content::WebContents* source,
const content::NativeWebKeyboardEvent& event) {
// Check to see if event should be ignored.
if (event.skip_in_browser)
if (event.skip_in_browser) {
return false;
}
if (auto delegate = platform_delegate()) {
if (auto c = client()) {
@ -368,14 +370,15 @@ void CefBrowserContentsDelegate::RenderViewReady() {
void CefBrowserContentsDelegate::PrimaryMainFrameRenderProcessGone(
base::TerminationStatus status) {
cef_termination_status_t ts = TS_ABNORMAL_TERMINATION;
if (status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED)
if (status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED) {
ts = TS_PROCESS_WAS_KILLED;
else if (status == base::TERMINATION_STATUS_PROCESS_CRASHED)
} else if (status == base::TERMINATION_STATUS_PROCESS_CRASHED) {
ts = TS_PROCESS_CRASHED;
else if (status == base::TERMINATION_STATUS_OOM)
} else if (status == base::TERMINATION_STATUS_OOM) {
ts = TS_PROCESS_OOM;
else if (status != base::TERMINATION_STATUS_ABNORMAL_TERMINATION)
} else if (status != base::TERMINATION_STATUS_ABNORMAL_TERMINATION) {
return;
}
if (auto c = client()) {
if (auto handler = c->GetRequestHandler()) {
@ -389,14 +392,16 @@ void CefBrowserContentsDelegate::OnFrameFocused(
content::RenderFrameHost* render_frame_host) {
CefRefPtr<CefFrameHostImpl> frame = static_cast<CefFrameHostImpl*>(
browser_info_->GetFrameForHost(render_frame_host).get());
if (!frame || frame->IsFocused())
if (!frame || frame->IsFocused()) {
return;
}
CefRefPtr<CefFrameHostImpl> previous_frame = focused_frame_;
if (frame->IsMain())
if (frame->IsMain()) {
focused_frame_ = nullptr;
else
} else {
focused_frame_ = frame;
}
if (!previous_frame) {
// The main frame is focused by default.
@ -449,8 +454,9 @@ void CefBrowserContentsDelegate::DidFinishNavigation(
// Skip calls where the navigation has not yet committed and there is no
// error code. For example, when creating a browser without loading a URL.
if (!navigation_handle->HasCommitted() && error_code == net::OK)
if (!navigation_handle->HasCommitted() && error_code == net::OK) {
return;
}
const bool is_main_frame = navigation_handle->IsInMainFrame();
const auto global_id = frame_util::GetGlobalId(navigation_handle);
@ -532,10 +538,11 @@ void CefBrowserContentsDelegate::DidFinishLoad(
void CefBrowserContentsDelegate::TitleWasSet(content::NavigationEntry* entry) {
// |entry| may be NULL if a popup is created via window.open and never
// navigated.
if (entry)
if (entry) {
OnTitleChange(entry->GetTitle());
else if (web_contents())
} else if (web_contents()) {
OnTitleChange(web_contents()->GetTitle());
}
}
void CefBrowserContentsDelegate::DidUpdateFaviconURL(
@ -594,8 +601,9 @@ void CefBrowserContentsDelegate::Observe(
bool CefBrowserContentsDelegate::OnSetFocus(cef_focus_source_t source) {
// SetFocus() might be called while inside the OnSetFocus() callback. If
// so, don't re-enter the callback.
if (is_in_onsetfocus_)
if (is_in_onsetfocus_) {
return true;
}
if (auto c = client()) {
if (auto handler = c->GetFocusHandler()) {
@ -624,8 +632,9 @@ CefRefPtr<CefBrowser> CefBrowserContentsDelegate::browser() const {
CefBrowserPlatformDelegate* CefBrowserContentsDelegate::platform_delegate()
const {
auto browser = browser_info_->browser();
if (browser)
if (browser) {
return browser->platform_delegate();
}
return nullptr;
}
@ -686,8 +695,9 @@ void CefBrowserContentsDelegate::OnTitleChange(const std::u16string& title) {
}
void CefBrowserContentsDelegate::OnFullscreenModeChange(bool fullscreen) {
if (fullscreen == is_fullscreen_)
if (fullscreen == is_fullscreen_) {
return;
}
is_fullscreen_ = fullscreen;
OnStateChanged(State::kFullscreen);

View File

@ -64,8 +64,9 @@ class ImplManager {
if (!path.empty()) {
PathMap::iterator it = map_.find(path);
DCHECK(it != map_.end());
if (it != map_.end())
if (it != map_.end()) {
map_.erase(it);
}
}
}
@ -89,12 +90,14 @@ class ImplManager {
CefBrowserContext* GetImplFromBrowserContext(
const content::BrowserContext* context) {
CEF_REQUIRE_UIT();
if (!context)
if (!context) {
return nullptr;
}
for (const auto& bc : all_) {
if (bc->AsBrowserContext() == context)
if (bc->AsBrowserContext() == context) {
return bc;
}
}
return nullptr;
}
@ -111,8 +114,9 @@ class ImplManager {
CEF_REQUIRE_UIT();
DCHECK(!path.empty());
PathMap::const_iterator it = map_.find(path);
if (it != map_.end())
if (it != map_.end()) {
return it->second;
}
return nullptr;
}
@ -122,8 +126,9 @@ class ImplManager {
Vector::iterator GetImplPos(const CefBrowserContext* impl) {
Vector::iterator it = all_.begin();
for (; it != all_.end(); ++it) {
if (*it == impl)
if (*it == impl) {
return it;
}
}
return all_.end();
}
@ -187,8 +192,9 @@ CefBrowserContext::~CefBrowserContext() {
void CefBrowserContext::Initialize() {
cache_path_ = base::FilePath(CefString(&settings_.cache_path));
if (!cache_path_.empty())
if (!cache_path_.empty()) {
g_manager.Get().SetImplPath(this, cache_path_);
}
iothread_state_ = base::MakeRefCounted<CefIOThreadState>();
@ -262,8 +268,9 @@ CefBrowserContext* CefBrowserContext::FromBrowserContext(
// static
CefBrowserContext* CefBrowserContext::FromProfile(const Profile* profile) {
auto* cef_context = FromBrowserContext(profile);
if (cef_context)
if (cef_context) {
return cef_context;
}
if (cef::IsChromeRuntimeEnabled()) {
auto* original_profile = profile->GetOriginalProfile();
@ -311,8 +318,9 @@ void CefBrowserContext::OnRenderFrameDeleted(
DCHECK(frame_util::IsValidGlobalId(global_id));
auto it1 = render_id_set_.find(global_id);
if (it1 != render_id_set_.end())
if (it1 != render_id_set_.end()) {
render_id_set_.erase(it1);
}
CefRefPtr<CefRequestContextHandler> handler = request_context->GetHandler();
if (handler) {
@ -337,15 +345,17 @@ bool CefBrowserContext::IsAssociatedContext(
if (frame_util::IsValidGlobalId(global_id)) {
const auto it1 = render_id_set_.find(global_id);
if (it1 != render_id_set_.end())
if (it1 != render_id_set_.end()) {
return true;
}
}
if (frame_util::IsValidChildId(global_id.child_id) && !require_frame_match) {
// Choose an arbitrary handler for the same process.
for (const auto& render_ids : render_id_set_) {
if (render_ids.child_id == global_id.child_id)
if (render_ids.child_id == global_id.child_id) {
return true;
}
}
}
@ -374,8 +384,9 @@ void CefBrowserContext::LoadExtension(
CefRefPtr<CefExtensionHandler> handler,
CefRefPtr<CefRequestContext> loader_context) {
NOTIMPLEMENTED();
if (handler)
if (handler) {
handler->OnExtensionLoadFailed(ERR_ABORTED);
}
}
bool CefBrowserContext::GetExtensions(std::vector<CefString>& extension_ids) {
@ -415,8 +426,9 @@ CefMediaRouterManager* CefBrowserContext::GetMediaRouterManager() {
CefBrowserContext::CookieableSchemes CefBrowserContext::GetCookieableSchemes()
const {
CEF_REQUIRE_UIT();
if (cookieable_schemes_)
if (cookieable_schemes_) {
return cookieable_schemes_;
}
return GetGlobalCookieableSchemes();
}

View File

@ -50,8 +50,9 @@ class WebContentsUserDataAdapter : public base::SupportsUserData::Data {
WebContentsUserDataAdapter* adapter =
static_cast<WebContentsUserDataAdapter*>(
web_contents->GetUserData(UserDataKey()));
if (adapter)
if (adapter) {
return adapter->browser_;
}
return nullptr;
}
@ -82,8 +83,9 @@ CefRefPtr<CefBrowserHostBase> CefBrowserHostBase::GetBrowserForHost(
CEF_REQUIRE_UIT();
content::WebContents* web_contents = content::WebContents::FromRenderViewHost(
const_cast<content::RenderViewHost*>(host));
if (web_contents)
if (web_contents) {
return GetBrowserForContents(web_contents);
}
return nullptr;
}
@ -95,8 +97,9 @@ CefRefPtr<CefBrowserHostBase> CefBrowserHostBase::GetBrowserForHost(
content::WebContents* web_contents =
content::WebContents::FromRenderFrameHost(
const_cast<content::RenderFrameHost*>(host));
if (web_contents)
if (web_contents) {
return GetBrowserForContents(web_contents);
}
return nullptr;
}
@ -119,8 +122,9 @@ CefRefPtr<CefBrowserHostBase> CefBrowserHostBase::GetBrowserForGlobalId(
// Use the non-thread-safe but potentially faster approach.
content::RenderFrameHost* render_frame_host =
content::RenderFrameHost::FromID(global_id);
if (!render_frame_host)
if (!render_frame_host) {
return nullptr;
}
return GetBrowserForHost(render_frame_host);
} else {
// Use the thread-safe approach.
@ -150,8 +154,9 @@ CefBrowserHostBase::GetBrowserForTopLevelNativeWindow(
for (const auto& browser_info :
CefBrowserInfoManager::GetInstance()->GetBrowserInfoList()) {
if (auto browser = browser_info->browser()) {
if (browser->GetTopLevelNativeWindow() == owning_window)
if (browser->GetTopLevelNativeWindow() == owning_window) {
return browser;
}
}
}
@ -165,8 +170,9 @@ CefRefPtr<CefBrowserHostBase> CefBrowserHostBase::GetLikelyFocusedBrowser() {
for (const auto& browser_info :
CefBrowserInfoManager::GetInstance()->GetBrowserInfoList()) {
if (auto browser = browser_info->browser()) {
if (browser->IsFocused())
if (browser->IsFocused()) {
return browser;
}
}
}
@ -240,10 +246,11 @@ void CefBrowserHostBase::SetFocus(bool focus) {
return;
}
if (focus)
if (focus) {
OnSetFocus(FOCUS_SOURCE_SYSTEM);
else if (platform_delegate_)
} else if (platform_delegate_) {
platform_delegate_->SetFocus(false);
}
}
void CefBrowserHostBase::RunFileDialog(
@ -262,8 +269,9 @@ void CefBrowserHostBase::RunFileDialog(
if (!callback || !EnsureFileDialogManager()) {
LOG(ERROR) << "File dialog canceled due to invalid state.";
if (callback)
if (callback) {
callback->OnFileDialogDismissed({});
}
return;
}
@ -279,20 +287,24 @@ void CefBrowserHostBase::StartDownload(const CefString& url) {
}
GURL gurl = GURL(url.ToString());
if (gurl.is_empty() || !gurl.is_valid())
if (gurl.is_empty() || !gurl.is_valid()) {
return;
}
auto web_contents = GetWebContents();
if (!web_contents)
if (!web_contents) {
return;
}
auto browser_context = web_contents->GetBrowserContext();
if (!browser_context)
if (!browser_context) {
return;
}
content::DownloadManager* manager = browser_context->GetDownloadManager();
if (!manager)
if (!manager) {
return;
}
std::unique_ptr<download::DownloadUrlParameters> params(
content::DownloadRequestUtils::CreateDownloadForWebContentsMainFrame(
@ -314,16 +326,19 @@ void CefBrowserHostBase::DownloadImage(
return;
}
if (!callback)
if (!callback) {
return;
}
GURL gurl = GURL(image_url.ToString());
if (gurl.is_empty() || !gurl.is_valid())
if (gurl.is_empty() || !gurl.is_valid()) {
return;
}
auto web_contents = GetWebContents();
if (!web_contents)
if (!web_contents) {
return;
}
web_contents->DownloadImage(
gurl, is_favicon, gfx::Size(max_image_size, max_image_size),
@ -356,8 +371,9 @@ void CefBrowserHostBase::Print() {
}
auto web_contents = GetWebContents();
if (!web_contents)
if (!web_contents) {
return;
}
const bool print_preview_disabled =
!platform_delegate_ || !platform_delegate_->IsPrintPreviewSupported();
@ -374,16 +390,18 @@ void CefBrowserHostBase::PrintToPDF(const CefString& path,
}
auto web_contents = GetWebContents();
if (!web_contents)
if (!web_contents) {
return;
}
print_util::PrintToPDF(web_contents, path, settings, callback);
}
bool CefBrowserHostBase::SendDevToolsMessage(const void* message,
size_t message_size) {
if (!message || message_size == 0)
if (!message || message_size == 0) {
return false;
}
if (!CEF_CURRENTLY_ON_UIT()) {
std::string message_str(static_cast<const char*>(message), message_size);
@ -397,8 +415,9 @@ bool CefBrowserHostBase::SendDevToolsMessage(const void* message,
return false;
}
if (!EnsureDevToolsManager())
if (!EnsureDevToolsManager()) {
return false;
}
return devtools_manager_->SendDevToolsMessage(message, message_size);
}
@ -414,15 +433,17 @@ int CefBrowserHostBase::ExecuteDevToolsMethod(
return 0;
}
if (!EnsureDevToolsManager())
if (!EnsureDevToolsManager()) {
return 0;
}
return devtools_manager_->ExecuteDevToolsMethod(message_id, method, params);
}
CefRefPtr<CefRegistration> CefBrowserHostBase::AddDevToolsMessageObserver(
CefRefPtr<CefDevToolsMessageObserver> observer) {
if (!observer)
if (!observer) {
return nullptr;
}
auto registration = CefDevToolsManager::CreateRegistration(observer);
InitializeDevToolsRegistrationOnUIThread(registration);
return registration.get();
@ -432,8 +453,9 @@ void CefBrowserHostBase::GetNavigationEntries(
CefRefPtr<CefNavigationEntryVisitor> visitor,
bool current_only) {
DCHECK(visitor.get());
if (!visitor.get())
if (!visitor.get()) {
return;
}
if (!CEF_CURRENTLY_ON_UIT()) {
CEF_POST_TASK(
@ -443,8 +465,9 @@ void CefBrowserHostBase::GetNavigationEntries(
}
auto web_contents = GetWebContents();
if (!web_contents)
if (!web_contents) {
return;
}
content::NavigationController& controller = web_contents->GetController();
const int total = controller.GetEntryCount();
@ -476,11 +499,13 @@ CefRefPtr<CefNavigationEntry> CefBrowserHostBase::GetVisibleNavigationEntry() {
content::NavigationEntry* entry = nullptr;
auto web_contents = GetWebContents();
if (web_contents)
if (web_contents) {
entry = web_contents->GetController().GetVisibleEntry();
}
if (!entry)
if (!entry) {
return nullptr;
}
return new CefNavigationEntryImpl(entry);
}
@ -494,8 +519,9 @@ void CefBrowserHostBase::NotifyMoveOrResizeStarted() {
return;
}
if (platform_delegate_)
if (platform_delegate_) {
platform_delegate_->NotifyMoveOrResizeStarted();
}
#endif
}
@ -508,8 +534,9 @@ void CefBrowserHostBase::ReplaceMisspelling(const CefString& word) {
}
auto web_contents = GetWebContents();
if (web_contents)
if (web_contents) {
web_contents->ReplaceMisspelling(word);
}
}
void CefBrowserHostBase::AddWordToDictionary(const CefString& word) {
@ -521,15 +548,17 @@ void CefBrowserHostBase::AddWordToDictionary(const CefString& word) {
}
auto web_contents = GetWebContents();
if (!web_contents)
if (!web_contents) {
return;
}
SpellcheckService* spellcheck = nullptr;
content::BrowserContext* browser_context = web_contents->GetBrowserContext();
if (browser_context) {
spellcheck = SpellcheckServiceFactory::GetForContext(browser_context);
if (spellcheck)
if (spellcheck) {
spellcheck->GetCustomDictionary()->AddWord(word);
}
}
#if BUILDFLAG(IS_MAC)
if (spellcheck && spellcheck::UseBrowserSpellChecker()) {
@ -545,8 +574,9 @@ void CefBrowserHostBase::SendKeyEvent(const CefKeyEvent& event) {
return;
}
if (platform_delegate_)
if (platform_delegate_) {
platform_delegate_->SendKeyEvent(event);
}
}
void CefBrowserHostBase::SendMouseClickEvent(const CefMouseEvent& event,
@ -753,8 +783,9 @@ CefRefPtr<CefFrame> CefBrowserHostBase::GetFrame(int64 identifier) {
CefRefPtr<CefFrame> CefBrowserHostBase::GetFrame(const CefString& name) {
for (const auto& frame : browser_info_->GetAllFrames()) {
if (frame->GetName() == name)
if (frame->GetName() == name) {
return frame;
}
}
return nullptr;
}
@ -764,12 +795,14 @@ size_t CefBrowserHostBase::GetFrameCount() {
}
void CefBrowserHostBase::GetFrameIdentifiers(std::vector<int64>& identifiers) {
if (identifiers.size() > 0)
if (identifiers.size() > 0) {
identifiers.clear();
}
const auto frames = browser_info_->GetAllFrames();
if (frames.empty())
if (frames.empty()) {
return;
}
identifiers.reserve(frames.size());
for (const auto& frame : frames) {
@ -778,12 +811,14 @@ void CefBrowserHostBase::GetFrameIdentifiers(std::vector<int64>& identifiers) {
}
void CefBrowserHostBase::GetFrameNames(std::vector<CefString>& names) {
if (names.size() > 0)
if (names.size() > 0) {
names.clear();
}
const auto frames = browser_info_->GetAllFrames();
if (frames.empty())
if (frames.empty()) {
return;
}
names.reserve(frames.size());
for (const auto& frame : frames) {
@ -821,8 +856,9 @@ void CefBrowserHostBase::OnWebContentsDestroyed(
CefRefPtr<CefFrame> CefBrowserHostBase::GetFrameForHost(
const content::RenderFrameHost* host) {
CEF_REQUIRE_UIT();
if (!host)
if (!host) {
return nullptr;
}
return browser_info_->GetFrameForHost(host);
}
@ -870,8 +906,9 @@ bool CefBrowserHostBase::Navigate(const content::OpenURLParams& params) {
auto web_contents = GetWebContents();
if (web_contents) {
GURL gurl = params.url;
if (!url_util::FixupGURL(gurl))
if (!url_util::FixupGURL(gurl)) {
return false;
}
web_contents->GetController().LoadURL(
gurl, params.referrer, params.transition, params.extra_headers);
@ -887,8 +924,9 @@ void CefBrowserHostBase::ViewText(const std::string& text) {
return;
}
if (platform_delegate_)
if (platform_delegate_) {
platform_delegate_->ViewText(text);
}
}
void CefBrowserHostBase::RunFileChooserForBrowser(
@ -965,8 +1003,9 @@ void CefBrowserHostBase::OnBrowserDestroyed() {
file_dialog_manager_.reset();
}
for (auto& observer : observers_)
for (auto& observer : observers_) {
observer.OnBrowserDestroyed(this);
}
}
int CefBrowserHostBase::browser_id() const {
@ -991,8 +1030,9 @@ content::WebContents* CefBrowserHostBase::GetWebContents() const {
content::BrowserContext* CefBrowserHostBase::GetBrowserContext() const {
CEF_REQUIRE_UIT();
auto web_contents = GetWebContents();
if (web_contents)
if (web_contents) {
return web_contents->GetBrowserContext();
}
return nullptr;
}
@ -1006,15 +1046,17 @@ CefMediaStreamRegistrar* CefBrowserHostBase::GetMediaStreamRegistrar() {
views::Widget* CefBrowserHostBase::GetWindowWidget() const {
CEF_REQUIRE_UIT();
if (!platform_delegate_)
if (!platform_delegate_) {
return nullptr;
}
return platform_delegate_->GetWindowWidget();
}
CefRefPtr<CefBrowserView> CefBrowserHostBase::GetBrowserView() const {
CEF_REQUIRE_UIT();
if (is_views_hosted_ && platform_delegate_)
if (is_views_hosted_ && platform_delegate_) {
return platform_delegate_->GetBrowserView();
}
return nullptr;
}
@ -1055,8 +1097,9 @@ bool CefBrowserHostBase::IsVisible() const {
bool CefBrowserHostBase::EnsureDevToolsManager() {
CEF_REQUIRE_UIT();
if (!contents_delegate_->web_contents())
if (!contents_delegate_->web_contents()) {
return false;
}
if (!devtools_manager_) {
devtools_manager_ = std::make_unique<CefDevToolsManager>(this);
@ -1075,15 +1118,17 @@ void CefBrowserHostBase::InitializeDevToolsRegistrationOnUIThread(
return;
}
if (!EnsureDevToolsManager())
if (!EnsureDevToolsManager()) {
return;
}
devtools_manager_->InitializeRegistrationOnUIThread(registration);
}
bool CefBrowserHostBase::EnsureFileDialogManager() {
CEF_REQUIRE_UIT();
if (!contents_delegate_->web_contents())
if (!contents_delegate_->web_contents()) {
return false;
}
if (!file_dialog_manager_) {
file_dialog_manager_ = std::make_unique<CefFileDialogManager>(this);

View File

@ -41,8 +41,9 @@ struct CefBrowserCreateParams {
settings = that.settings;
request_context = that.request_context;
extra_info = that.extra_info;
if (that.window_info)
if (that.window_info) {
MaybeSetWindowInfo(*that.window_info);
}
browser_view = that.browser_view;
return *this;
}

View File

@ -41,8 +41,9 @@ CefBrowserInfo::~CefBrowserInfo() {
CefRefPtr<CefBrowserHostBase> CefBrowserInfo::browser() const {
base::AutoLock lock_scope(lock_);
if (!is_closing_)
if (!is_closing_) {
return browser_;
}
return nullptr;
}
@ -189,8 +190,9 @@ void CefBrowserInfo::FrameHostStateChanged(
bool removed_from_bfcache =
old_state ==
content::RenderFrameHost::LifecycleState::kInBackForwardCache;
if (!added_to_bfcache && !removed_from_bfcache)
if (!added_to_bfcache && !removed_from_bfcache) {
return;
}
base::AutoLock lock_scope(lock_);
@ -238,8 +240,9 @@ void CefBrowserInfo::RemoveFrame(content::RenderFrameHost* host) {
CefRefPtr<CefFrameHostImpl> CefBrowserInfo::GetMainFrame() {
base::AutoLock lock_scope(lock_);
// Early exit if called post-destruction.
if (!browser_ || is_closing_)
if (!browser_ || is_closing_) {
return nullptr;
}
CHECK(main_frame_);
return main_frame_;
@ -248,8 +251,9 @@ CefRefPtr<CefFrameHostImpl> CefBrowserInfo::GetMainFrame() {
CefRefPtr<CefFrameHostImpl> CefBrowserInfo::CreateTempSubFrame(
const content::GlobalRenderFrameHostId& parent_global_id) {
CefRefPtr<CefFrameHostImpl> parent = GetFrameForGlobalId(parent_global_id);
if (!parent)
if (!parent) {
parent = GetMainFrame();
}
// Intentionally not notifying for temporary frames.
return new CefFrameHostImpl(this, parent->GetIdentifier());
}
@ -258,11 +262,13 @@ CefRefPtr<CefFrameHostImpl> CefBrowserInfo::GetFrameForHost(
const content::RenderFrameHost* host,
bool* is_guest_view,
bool prefer_speculative) const {
if (is_guest_view)
if (is_guest_view) {
*is_guest_view = false;
}
if (!host)
if (!host) {
return nullptr;
}
return GetFrameForGlobalId(
const_cast<content::RenderFrameHost*>(host)->GetGlobalId(), is_guest_view,
@ -273,11 +279,13 @@ CefRefPtr<CefFrameHostImpl> CefBrowserInfo::GetFrameForGlobalId(
const content::GlobalRenderFrameHostId& global_id,
bool* is_guest_view,
bool prefer_speculative) const {
if (is_guest_view)
if (is_guest_view) {
*is_guest_view = false;
}
if (!frame_util::IsValidGlobalId(global_id))
if (!frame_util::IsValidGlobalId(global_id)) {
return nullptr;
}
base::AutoLock lock_scope(lock_);
@ -286,8 +294,9 @@ CefRefPtr<CefFrameHostImpl> CefBrowserInfo::GetFrameForGlobalId(
const auto info = it->second;
if (info->is_guest_view_) {
if (is_guest_view)
if (is_guest_view) {
*is_guest_view = true;
}
return nullptr;
}
@ -381,8 +390,9 @@ void CefBrowserInfo::MaybeNotifyDraggableRegionsChanged(
CEF_REQUIRE_UIT();
DCHECK(frame->IsMain());
if (draggable_regions == draggable_regions_)
if (draggable_regions == draggable_regions_) {
return;
}
draggable_regions_ = std::move(draggable_regions);
@ -499,8 +509,9 @@ void CefBrowserInfo::RemoveAllFrames(
}
}
if (main_frame_)
if (main_frame_) {
SetMainFrame(old_browser, nullptr);
}
// And finally delete the frame info.
frame_info_set_.clear();

View File

@ -155,14 +155,18 @@ bool CefBrowserInfoManager::CanCreateWindow(
TranslatePopupFeatures(features, cef_features);
// Default to the size from the popup features.
if (cef_features.xSet)
if (cef_features.xSet) {
window_info.bounds.x = cef_features.x;
if (cef_features.ySet)
}
if (cef_features.ySet) {
window_info.bounds.y = cef_features.y;
if (cef_features.widthSet)
}
if (cef_features.widthSet) {
window_info.bounds.width = cef_features.width;
if (cef_features.heightSet)
}
if (cef_features.heightSet) {
window_info.bounds.height = cef_features.height;
}
allow = !handler->OnBeforePopup(
browser.get(), opener_frame, pending_popup->target_url.spec(),
@ -463,19 +467,22 @@ scoped_refptr<CefBrowserInfo> CefBrowserInfoManager::GetBrowserInfoInternal(
bool* is_guest_view) {
browser_info_lock_.AssertAcquired();
if (is_guest_view)
if (is_guest_view) {
*is_guest_view = false;
}
if (!frame_util::IsValidGlobalId(global_id))
if (!frame_util::IsValidGlobalId(global_id)) {
return nullptr;
}
for (const auto& browser_info : browser_info_list_) {
bool is_guest_view_tmp;
auto frame =
browser_info->GetFrameForGlobalId(global_id, &is_guest_view_tmp);
if (frame || is_guest_view_tmp) {
if (is_guest_view)
if (is_guest_view) {
*is_guest_view = is_guest_view_tmp;
}
return browser_info;
}
}
@ -534,8 +541,9 @@ void CefBrowserInfoManager::TimeoutNewBrowserInfoResponse(
const content::GlobalRenderFrameHostId& global_id,
int timeout_id) {
CEF_REQUIRE_UIT();
if (!g_info_manager)
if (!g_info_manager) {
return;
}
base::AutoLock lock_scope(g_info_manager->browser_info_lock_);
@ -544,8 +552,9 @@ void CefBrowserInfoManager::TimeoutNewBrowserInfoResponse(
if (it != g_info_manager->pending_new_browser_info_map_.end()) {
const auto& pending_info = it->second;
// Don't accidentally timeout a new request for the same frame.
if (pending_info->timeout_id != timeout_id)
if (pending_info->timeout_id != timeout_id) {
return;
}
#if DCHECK_IS_ON()
// This method should never be called for a PDF renderer.

View File

@ -35,8 +35,9 @@ class MessagePumpExternal : public base::MessagePumpForUI {
base::TimeTicks next_run_time; // is_null()
const bool has_more_work = DirectRunWork(delegate, &next_run_time);
if (!has_more_work)
if (!has_more_work) {
break;
}
if (next_run_time.is_null()) {
// We have more work that should run immediately.
@ -44,8 +45,9 @@ class MessagePumpExternal : public base::MessagePumpForUI {
}
const base::TimeDelta& delta = next_run_time - start;
if (delta.InSecondsF() > max_time_slice_)
if (delta.InSecondsF() > max_time_slice_) {
break;
}
}
}
@ -96,8 +98,9 @@ class MessagePumpExternal : public base::MessagePumpForUI {
CefRefPtr<CefBrowserProcessHandler> GetBrowserProcessHandler() {
CefRefPtr<CefApp> app = CefAppManager::Get()->GetApplication();
if (app)
if (app) {
return app->GetBrowserProcessHandler();
}
return nullptr;
}
@ -106,8 +109,9 @@ std::unique_ptr<base::MessagePump> MessagePumpFactoryForUI() {
content::BrowserThread::UI) ||
content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) {
CefRefPtr<CefBrowserProcessHandler> handler = GetBrowserProcessHandler();
if (handler)
if (handler) {
return std::make_unique<MessagePumpExternal>(0.01f, handler);
}
}
#if BUILDFLAG(IS_MAC)

View File

@ -67,8 +67,9 @@ void CefBrowserPlatformDelegate::RenderViewCreated(
content::RenderViewHost* render_view_host) {
// Indicate that the view has an external parent (namely us). This setting is
// required for proper focus handling on Windows and Linux.
if (HasExternalParent() && render_view_host->GetWidget()->GetView())
if (HasExternalParent() && render_view_host->GetWidget()->GetView()) {
render_view_host->GetWidget()->GetView()->SetHasExternalParent(true);
}
}
void CefBrowserPlatformDelegate::RenderViewReady() {}
@ -367,8 +368,9 @@ gfx::Point CefBrowserPlatformDelegate::GetDialogPosition(
}
gfx::Size CefBrowserPlatformDelegate::GetMaximumDialogSize() {
if (!web_contents_)
if (!web_contents_) {
return gfx::Size();
}
// The dialog should try to fit within the overlay for the web contents.
// Note that, for things like print preview, this is just a suggested maximum.
@ -406,33 +408,47 @@ int CefBrowserPlatformDelegate::TranslateWebEventModifiers(
uint32 cef_modifiers) {
int result = 0;
// Set modifiers based on key state.
if (cef_modifiers & EVENTFLAG_CAPS_LOCK_ON)
if (cef_modifiers & EVENTFLAG_CAPS_LOCK_ON) {
result |= blink::WebInputEvent::kCapsLockOn;
if (cef_modifiers & EVENTFLAG_SHIFT_DOWN)
}
if (cef_modifiers & EVENTFLAG_SHIFT_DOWN) {
result |= blink::WebInputEvent::kShiftKey;
if (cef_modifiers & EVENTFLAG_CONTROL_DOWN)
}
if (cef_modifiers & EVENTFLAG_CONTROL_DOWN) {
result |= blink::WebInputEvent::kControlKey;
if (cef_modifiers & EVENTFLAG_ALT_DOWN)
}
if (cef_modifiers & EVENTFLAG_ALT_DOWN) {
result |= blink::WebInputEvent::kAltKey;
if (cef_modifiers & EVENTFLAG_LEFT_MOUSE_BUTTON)
}
if (cef_modifiers & EVENTFLAG_LEFT_MOUSE_BUTTON) {
result |= blink::WebInputEvent::kLeftButtonDown;
if (cef_modifiers & EVENTFLAG_MIDDLE_MOUSE_BUTTON)
}
if (cef_modifiers & EVENTFLAG_MIDDLE_MOUSE_BUTTON) {
result |= blink::WebInputEvent::kMiddleButtonDown;
if (cef_modifiers & EVENTFLAG_RIGHT_MOUSE_BUTTON)
}
if (cef_modifiers & EVENTFLAG_RIGHT_MOUSE_BUTTON) {
result |= blink::WebInputEvent::kRightButtonDown;
if (cef_modifiers & EVENTFLAG_COMMAND_DOWN)
}
if (cef_modifiers & EVENTFLAG_COMMAND_DOWN) {
result |= blink::WebInputEvent::kMetaKey;
if (cef_modifiers & EVENTFLAG_NUM_LOCK_ON)
}
if (cef_modifiers & EVENTFLAG_NUM_LOCK_ON) {
result |= blink::WebInputEvent::kNumLockOn;
if (cef_modifiers & EVENTFLAG_IS_KEY_PAD)
}
if (cef_modifiers & EVENTFLAG_IS_KEY_PAD) {
result |= blink::WebInputEvent::kIsKeyPad;
if (cef_modifiers & EVENTFLAG_IS_LEFT)
}
if (cef_modifiers & EVENTFLAG_IS_LEFT) {
result |= blink::WebInputEvent::kIsLeft;
if (cef_modifiers & EVENTFLAG_IS_RIGHT)
}
if (cef_modifiers & EVENTFLAG_IS_RIGHT) {
result |= blink::WebInputEvent::kIsRight;
if (cef_modifiers & EVENTFLAG_ALTGR_DOWN)
}
if (cef_modifiers & EVENTFLAG_ALTGR_DOWN) {
result |= blink::WebInputEvent::kAltGrKey;
if (cef_modifiers & EVENTFLAG_IS_REPEAT)
}
if (cef_modifiers & EVENTFLAG_IS_REPEAT) {
result |= blink::WebInputEvent::kIsAutoRepeat;
}
return result;
}

View File

@ -28,24 +28,33 @@ bool GetCefKeyEvent(const content::NativeWebKeyboardEvent& event,
}
cef_event.modifiers = 0;
if (event.GetModifiers() & blink::WebKeyboardEvent::kShiftKey)
if (event.GetModifiers() & blink::WebKeyboardEvent::kShiftKey) {
cef_event.modifiers |= EVENTFLAG_SHIFT_DOWN;
if (event.GetModifiers() & blink::WebKeyboardEvent::kControlKey)
}
if (event.GetModifiers() & blink::WebKeyboardEvent::kControlKey) {
cef_event.modifiers |= EVENTFLAG_CONTROL_DOWN;
if (event.GetModifiers() & blink::WebKeyboardEvent::kAltKey)
}
if (event.GetModifiers() & blink::WebKeyboardEvent::kAltKey) {
cef_event.modifiers |= EVENTFLAG_ALT_DOWN;
if (event.GetModifiers() & blink::WebKeyboardEvent::kMetaKey)
}
if (event.GetModifiers() & blink::WebKeyboardEvent::kMetaKey) {
cef_event.modifiers |= EVENTFLAG_COMMAND_DOWN;
if (event.GetModifiers() & blink::WebKeyboardEvent::kIsKeyPad)
}
if (event.GetModifiers() & blink::WebKeyboardEvent::kIsKeyPad) {
cef_event.modifiers |= EVENTFLAG_IS_KEY_PAD;
if (event.GetModifiers() & blink::WebKeyboardEvent::kIsLeft)
}
if (event.GetModifiers() & blink::WebKeyboardEvent::kIsLeft) {
cef_event.modifiers |= EVENTFLAG_IS_LEFT;
if (event.GetModifiers() & blink::WebKeyboardEvent::kIsRight)
}
if (event.GetModifiers() & blink::WebKeyboardEvent::kIsRight) {
cef_event.modifiers |= EVENTFLAG_IS_RIGHT;
if (event.GetModifiers() & blink::WebKeyboardEvent::kAltGrKey)
}
if (event.GetModifiers() & blink::WebKeyboardEvent::kAltGrKey) {
cef_event.modifiers |= EVENTFLAG_ALTGR_DOWN;
if (event.GetModifiers() & blink::WebKeyboardEvent::kIsAutoRepeat)
}
if (event.GetModifiers() & blink::WebKeyboardEvent::kIsAutoRepeat) {
cef_event.modifiers |= EVENTFLAG_IS_REPEAT;
}
cef_event.windows_key_code = event.windows_key_code;
cef_event.native_key_code = event.native_key_code;

View File

@ -140,8 +140,9 @@ void CefBrowserPlatformDelegateChrome::set_chrome_browser(Browser* browser) {
}
gfx::NativeWindow CefBrowserPlatformDelegateChrome::GetNativeWindow() const {
if (chrome_browser_ && chrome_browser_->window())
if (chrome_browser_ && chrome_browser_->window()) {
return chrome_browser_->window()->GetNativeWindow();
}
NOTREACHED();
return gfx::NativeWindow();
}

View File

@ -234,8 +234,9 @@ void ChromeBrowserDelegate::EnterFullscreenModeForTab(
const blink::mojom::FullscreenOptions& options) {
auto web_contents =
content::WebContents::FromRenderFrameHost(requesting_frame);
if (!web_contents)
if (!web_contents) {
return;
}
if (auto delegate = GetDelegateForWebContents(web_contents)) {
delegate->EnterFullscreenModeForTab(requesting_frame, options);
@ -334,8 +335,9 @@ CefBrowserContentsDelegate* ChromeBrowserDelegate::GetDelegateForWebContents(
content::WebContents* web_contents) {
auto browser_host =
ChromeBrowserHostImpl::GetBrowserForContents(web_contents);
if (browser_host)
if (browser_host) {
return browser_host->contents_delegate();
}
return nullptr;
}

View File

@ -134,11 +134,13 @@ void ChromeBrowserHostImpl::OnSetFocus(cef_focus_source_t source) {
return;
}
if (contents_delegate_->OnSetFocus(source))
if (contents_delegate_->OnSetFocus(source)) {
return;
}
if (platform_delegate_)
if (platform_delegate_) {
platform_delegate_->SetFocus(true);
}
if (browser_) {
const int tab_index = GetCurrentTabIndex();
@ -164,8 +166,9 @@ CefWindowHandle ChromeBrowserHostImpl::GetWindowHandle() {
if (CEF_CURRENTLY_ON_UIT()) {
// Always return the most up-to-date window handle for a views-hosted
// browser since it may change if the view is re-parented.
if (platform_delegate_)
if (platform_delegate_) {
return platform_delegate_->GetHostWindowHandle();
}
}
return host_window_handle_;
}
@ -337,8 +340,9 @@ bool ChromeBrowserHostImpl::Navigate(const content::OpenURLParams& params) {
if (browser_) {
GURL gurl = params.url;
if (!url_util::FixupGURL(gurl))
if (!url_util::FixupGURL(gurl)) {
return false;
}
// This is generally equivalent to calling Browser::OpenURL, except:
// 1. It doesn't trigger a call to CefRequestHandler::OnOpenURLFromTab, and
@ -354,8 +358,9 @@ bool ChromeBrowserHostImpl::Navigate(const content::OpenURLParams& params) {
nav_params.source_contents = GetWebContents();
nav_params.tabstrip_add_types = AddTabTypes::ADD_NONE;
if (params.user_gesture)
if (params.user_gesture) {
nav_params.window_action = NavigateParams::SHOW_WINDOW;
}
::Navigate(&nav_params);
return true;
}
@ -498,8 +503,9 @@ void ChromeBrowserHostImpl::SetBrowser(Browser* browser) {
browser_ = browser;
static_cast<CefBrowserPlatformDelegateChrome*>(platform_delegate_.get())
->set_chrome_browser(browser);
if (browser_)
if (browser_) {
host_window_handle_ = platform_delegate_->GetHostWindowHandle();
}
}
void ChromeBrowserHostImpl::WindowDestroyed() {

View File

@ -18,8 +18,9 @@ ChromeBrowserMainExtraPartsCef::~ChromeBrowserMainExtraPartsCef() = default;
void ChromeBrowserMainExtraPartsCef::PostProfileInit(Profile* profile,
bool is_initial_profile) {
if (!is_initial_profile)
if (!is_initial_profile) {
return;
}
CefRequestContextSettings settings;
CefContext::Get()->PopulateGlobalRequestContextSettings(&settings);

View File

@ -58,8 +58,9 @@ void HandleExternalProtocolHelper(
// May return nullptr if frame has been deleted or a cross-document navigation
// has committed in the same RenderFrameHost.
auto initiator_rfh = initiator_document.AsRenderFrameHostIfValid();
if (!initiator_rfh)
if (!initiator_rfh) {
return;
}
// Match the logic of the original call in
// NavigationURLLoaderImpl::PrepareForNonInterceptedRequest.
@ -253,8 +254,9 @@ bool ChromeContentBrowserClientCef::WillCreateURLLoaderFactory(
// For example, the User Manager profile created via
// profiles::CreateSystemProfileForUserManager.
auto profile = Profile::FromBrowserContext(browser_context);
if (!CefBrowserContext::FromProfile(profile))
if (!CefBrowserContext::FromProfile(profile)) {
return false;
}
auto request_handler = net_service::CreateInterceptedRequestHandler(
browser_context, frame, render_process_id,

View File

@ -40,8 +40,9 @@ class CefContextMenuObserver : public RenderViewContextMenuObserver,
bool IsCommandIdSupported(int command_id) override {
// Always claim support for the reserved user ID range.
if (command_id >= MENU_ID_USER_FIRST && command_id <= MENU_ID_USER_LAST)
if (command_id >= MENU_ID_USER_FIRST && command_id <= MENU_ID_USER_LAST) {
return true;
}
// Also claim support in specific cases where an ItemInfo exists.
return GetItemInfo(command_id) != nullptr;
@ -104,25 +105,29 @@ class CefContextMenuObserver : public RenderViewContextMenuObserver,
void SetChecked(int command_id, bool checked) override {
// No-op if already at the default state.
if (!checked && !GetItemInfo(command_id))
if (!checked && !GetItemInfo(command_id)) {
return;
}
auto* info = GetOrCreateItemInfo(command_id);
info->checked = checked;
if (!checked)
if (!checked) {
MaybeDeleteItemInfo(command_id, info);
}
}
void SetAccelerator(int command_id,
absl::optional<ui::Accelerator> accel) override {
// No-op if already at the default state.
if (!accel && !GetItemInfo(command_id))
if (!accel && !GetItemInfo(command_id)) {
return;
}
auto* info = GetOrCreateItemInfo(command_id);
info->accel = accel;
if (!accel)
if (!accel) {
MaybeDeleteItemInfo(command_id, info);
}
}
private:
@ -142,8 +147,9 @@ class CefContextMenuObserver : public RenderViewContextMenuObserver,
}
ItemInfo* GetOrCreateItemInfo(int command_id) {
if (auto info = GetItemInfo(command_id))
if (auto info = GetItemInfo(command_id)) {
return info;
}
auto result = iteminfomap_.insert(std::make_pair(command_id, ItemInfo()));
return &result.first->second;

View File

@ -32,8 +32,9 @@ class PopupWindowDelegate : public CefWindowDelegate {
bool CanClose(CefRefPtr<CefWindow> window) override {
CefRefPtr<CefBrowser> browser = browser_view_->GetBrowser();
if (browser)
if (browser) {
return browser->GetHost()->TryCloseBrowser();
}
return true;
}
@ -49,8 +50,9 @@ CefBrowserPlatformDelegateChromeViews::CefBrowserPlatformDelegateChromeViews(
std::unique_ptr<CefBrowserPlatformDelegateNative> native_delegate,
CefRefPtr<CefBrowserViewImpl> browser_view)
: CefBrowserPlatformDelegateChrome(std::move(native_delegate)) {
if (browser_view)
if (browser_view) {
SetBrowserView(browser_view);
}
}
void CefBrowserPlatformDelegateChromeViews::SetBrowserView(
@ -74,13 +76,15 @@ void CefBrowserPlatformDelegateChromeViews::BrowserCreated(
}
void CefBrowserPlatformDelegateChromeViews::NotifyBrowserCreated() {
if (browser_view_->delegate())
if (browser_view_->delegate()) {
browser_view_->delegate()->OnBrowserCreated(browser_view_, browser_);
}
}
void CefBrowserPlatformDelegateChromeViews::NotifyBrowserDestroyed() {
if (browser_view_->delegate())
if (browser_view_->delegate()) {
browser_view_->delegate()->OnBrowserDestroyed(browser_view_, browser_);
}
}
void CefBrowserPlatformDelegateChromeViews::BrowserDestroyed(
@ -91,8 +95,9 @@ void CefBrowserPlatformDelegateChromeViews::BrowserDestroyed(
void CefBrowserPlatformDelegateChromeViews::CloseHostWindow() {
views::Widget* widget = GetWindowWidget();
if (widget && !widget->IsClosed())
if (widget && !widget->IsClosed()) {
widget->Close();
}
}
CefWindowHandle CefBrowserPlatformDelegateChromeViews::GetHostWindowHandle()
@ -101,8 +106,9 @@ CefWindowHandle CefBrowserPlatformDelegateChromeViews::GetHostWindowHandle()
}
views::Widget* CefBrowserPlatformDelegateChromeViews::GetWindowWidget() const {
if (browser_view_->root_view())
if (browser_view_->root_view()) {
return browser_view_->root_view()->GetWidget();
}
return nullptr;
}

View File

@ -53,8 +53,9 @@ void ChromeBrowserView::ViewHierarchyChanged(
// this View to a CefWindow with FillLayout and then calling
// CefWindow::Show() without first resizing the CefWindow.
size = details.parent->GetPreferredSize();
if (!size.IsEmpty())
if (!size.IsEmpty()) {
SetSize(size);
}
}
}
}

View File

@ -47,8 +47,9 @@ class ChildWindowDelegate : public CefWindowDelegate {
CefRect GetInitialBounds(CefRefPtr<CefWindow> window) override {
CefRect initial_bounds(window_info_.bounds);
if (initial_bounds.IsEmpty())
if (initial_bounds.IsEmpty()) {
return CefRect(0, 0, 800, 600);
}
return initial_bounds;
}
@ -174,15 +175,18 @@ CefRefPtr<CefBrowserHostBase> MaybeCreateChildBrowser(
const CefBrowserCreateParams& create_params) {
// If the BrowserView already exists it means that we're dealing with a popup
// and we'll instead create the Window in OnPopupBrowserViewCreated.
if (create_params.browser_view)
if (create_params.browser_view) {
return nullptr;
}
if (!create_params.window_info)
if (!create_params.window_info) {
return nullptr;
}
const auto parent_handle = GetParentHandle(*create_params.window_info);
if (parent_handle == gfx::kNullAcceleratedWidget)
if (parent_handle == gfx::kNullAcceleratedWidget) {
return nullptr;
}
// Create the BrowserView.
auto browser_view = CefBrowserViewImpl::Create(

View File

@ -47,8 +47,9 @@ class CefShutdownChecker {
// loading chrome://system.
void InitInstallDetails() {
static bool initialized = false;
if (initialized)
if (initialized) {
return;
}
initialized = true;
install_static::InitializeFromPrimaryModule();
}
@ -57,8 +58,9 @@ void InitInstallDetails() {
// DllMain. See https://crbug.com/656800 for details.
void InitCrashReporter() {
static bool initialized = false;
if (initialized)
if (initialized) {
return;
}
initialized = true;
SignalInitializeCrashReporting();
}
@ -67,8 +69,9 @@ void InitCrashReporter() {
bool GetColor(const cef_color_t cef_in, bool is_windowless, SkColor* sk_out) {
// Windowed browser colors must be fully opaque.
if (!is_windowless && CefColorGetA(cef_in) != SK_AlphaOPAQUE)
if (!is_windowless && CefColorGetA(cef_in) != SK_AlphaOPAQUE) {
return false;
}
// Windowless browser colors may be fully transparent.
if (is_windowless && CefColorGetA(cef_in) == SK_AlphaTRANSPARENT) {
@ -86,8 +89,9 @@ bool GetColor(const cef_color_t cef_in, bool is_windowless, SkColor* sk_out) {
base::FilePath NormalizePath(const cef_string_t& path_str,
const char* name,
bool* has_error = nullptr) {
if (has_error)
if (has_error) {
*has_error = false;
}
base::FilePath path = base::FilePath(CefString(&path_str));
if (path.EndsWithSeparator()) {
@ -99,8 +103,9 @@ base::FilePath NormalizePath(const cef_string_t& path_str,
if (!path.empty() && !path.IsAbsolute()) {
LOG(ERROR) << "The " << name << " directory (" << path.value()
<< ") is not an absolute path. Defaulting to empty.";
if (has_error)
if (has_error) {
*has_error = true;
}
path = base::FilePath();
}
@ -125,8 +130,9 @@ base::FilePath NormalizePathAndSet(cef_string_t& path_str, const char* name) {
// Verify that |cache_path| is valid and create it if necessary.
bool ValidateCachePath(const base::FilePath& cache_path,
const base::FilePath& root_cache_path) {
if (cache_path.empty())
if (cache_path.empty()) {
return true;
}
if (!root_cache_path.empty() && root_cache_path != cache_path &&
!root_cache_path.IsParent(cache_path)) {
@ -289,8 +295,9 @@ bool CefInitialize(const CefMainArgs& args,
#endif
// Return true if the global context already exists.
if (g_context)
if (g_context) {
return true;
}
if (settings.size != sizeof(cef_settings_t)) {
NOTREACHED() << "invalid CefSettings structure size";
@ -525,10 +532,12 @@ SkColor CefContext::GetBackgroundColor(
CefTraceSubscriber* CefContext::GetTraceSubscriber() {
CEF_REQUIRE_UIT();
if (shutting_down_)
if (shutting_down_) {
return nullptr;
if (!trace_subscriber_.get())
}
if (!trace_subscriber_.get()) {
trace_subscriber_.reset(new CefTraceSubscriber());
}
return trace_subscriber_.get();
}
@ -587,8 +596,9 @@ void CefContext::OnContextInitialized() {
[](CefRefPtr<CefApp> app) {
CefRefPtr<CefBrowserProcessHandler> handler =
app->GetBrowserProcessHandler();
if (handler)
if (handler) {
handler->OnContextInitialized();
}
},
application_));
}
@ -599,11 +609,13 @@ void CefContext::ShutdownOnUIThread() {
browser_info_manager_->DestroyAllBrowsers();
for (auto& observer : observers_)
for (auto& observer : observers_) {
observer.OnContextDestroyed();
}
if (trace_subscriber_.get())
if (trace_subscriber_.get()) {
trace_subscriber_.reset(nullptr);
}
}
void CefContext::FinalizeShutdown() {

View File

@ -33,18 +33,24 @@ CefContextMenuParamsImpl::TypeFlags CefContextMenuParamsImpl::GetTypeFlags() {
CEF_VALUE_VERIFY_RETURN(false, CM_TYPEFLAG_NONE);
const content::ContextMenuParams& params = const_value();
int type_flags = CM_TYPEFLAG_NONE;
if (!params.page_url.is_empty())
if (!params.page_url.is_empty()) {
type_flags |= CM_TYPEFLAG_PAGE;
if (!params.frame_url.is_empty())
}
if (!params.frame_url.is_empty()) {
type_flags |= CM_TYPEFLAG_FRAME;
if (!params.link_url.is_empty())
}
if (!params.link_url.is_empty()) {
type_flags |= CM_TYPEFLAG_LINK;
if (params.media_type != blink::mojom::ContextMenuDataMediaType::kNone)
}
if (params.media_type != blink::mojom::ContextMenuDataMediaType::kNone) {
type_flags |= CM_TYPEFLAG_MEDIA;
if (!params.selection_text.empty())
}
if (!params.selection_text.empty()) {
type_flags |= CM_TYPEFLAG_SELECTION;
if (params.is_editable)
}
if (params.is_editable) {
type_flags |= CM_TYPEFLAG_EDITABLE;
}
return static_cast<TypeFlags>(type_flags);
}
@ -113,16 +119,19 @@ bool CefContextMenuParamsImpl::GetDictionarySuggestions(
std::vector<CefString>& suggestions) {
CEF_VALUE_VERIFY_RETURN(false, false);
if (!suggestions.empty())
if (!suggestions.empty()) {
suggestions.clear();
}
if (const_value().dictionary_suggestions.empty())
if (const_value().dictionary_suggestions.empty()) {
return false;
}
std::vector<std::u16string>::const_iterator it =
const_value().dictionary_suggestions.begin();
for (; it != const_value().dictionary_suggestions.end(); ++it)
for (; it != const_value().dictionary_suggestions.end(); ++it) {
suggestions.push_back(*it);
}
return true;
}

View File

@ -31,8 +31,9 @@ CefDevToolsController::~CefDevToolsController() {
bool CefDevToolsController::SendDevToolsMessage(
const base::StringPiece& message) {
CEF_REQUIRE_UIT();
if (!EnsureAgentHost())
if (!EnsureAgentHost()) {
return false;
}
agent_host_->DispatchProtocolMessage(
this, base::as_bytes(base::make_span(message)));
@ -44,25 +45,29 @@ int CefDevToolsController::ExecuteDevToolsMethod(
const std::string& method,
const base::DictionaryValue* params) {
CEF_REQUIRE_UIT();
if (!EnsureAgentHost())
if (!EnsureAgentHost()) {
return 0;
}
// Message IDs must always be increasing and unique.
int message_id = suggested_message_id;
if (message_id < next_message_id_)
if (message_id < next_message_id_) {
message_id = next_message_id_++;
else
} else {
next_message_id_ = message_id + 1;
}
base::DictionaryValue message;
message.SetIntKey("id", message_id);
message.SetStringKey("method", method);
if (params)
if (params) {
message.SetKey("params", params->Clone());
}
std::string protocol_message;
if (!base::JSONWriter::Write(message, &protocol_message))
if (!base::JSONWriter::Write(message, &protocol_message)) {
return 0;
}
agent_host_->DispatchProtocolMessage(
this, base::as_bytes(base::make_span(protocol_message)));
@ -91,8 +96,9 @@ void CefDevToolsController::RemoveObserver(Observer* observer) {
void CefDevToolsController::DispatchProtocolMessage(
content::DevToolsAgentHost* agent_host,
base::span<const uint8_t> message) {
if (observers_.empty())
if (observers_.empty()) {
return;
}
base::StringPiece str_message(reinterpret_cast<const char*>(message.data()),
message.size());

View File

@ -82,8 +82,9 @@ void CefDevToolsFileManager::Save(const std::string& url,
if (const base::Value* path_value = file_map.Find(base::MD5String(url))) {
absl::optional<base::FilePath> path = base::ValueToFilePath(*path_value);
if (path)
if (path) {
initial_path = std::move(*path);
}
}
if (initial_path.empty()) {
@ -91,8 +92,9 @@ void CefDevToolsFileManager::Save(const std::string& url,
std::string suggested_file_name =
gurl.is_valid() ? gurl.ExtractFileName() : url;
if (suggested_file_name.length() > 64)
if (suggested_file_name.length() > 64) {
suggested_file_name = suggested_file_name.substr(0, 64);
}
if (!g_last_save_path.Pointer()->empty()) {
initial_path = g_last_save_path.Pointer()->DirName().AppendASCII(
@ -167,8 +169,9 @@ void CefDevToolsFileManager::Append(const std::string& url,
const std::string& content,
AppendCallback callback) {
auto it = saved_files_.find(url);
if (it == saved_files_.end())
if (it == saved_files_.end()) {
return;
}
std::move(callback).Run();
file_task_runner_->PostTask(
FROM_HERE, base::BindOnce(&::AppendToFile, it->second, content));

View File

@ -98,8 +98,9 @@ base::DictionaryValue BuildObjectForResponse(const net::HttpResponseHeaders* rh,
std::string value;
// TODO(caseq): this probably needs to handle duplicate header names
// correctly by folding them.
while (rh && rh->EnumerateHeaderLines(&iterator, &name, &value))
while (rh && rh->EnumerateHeaderLines(&iterator, &name, &value)) {
headers->SetString(name, value);
}
response.Set("headers", std::move(headers));
return response;
@ -135,8 +136,9 @@ void LogProtocolMessage(const base::FilePath& log_file,
std::string to_log) {
// Track if logging has failed, in which case we don't keep trying.
static bool log_error = false;
if (log_error)
if (log_error) {
return;
}
if (storage::NativeFileUtil::EnsureFileExists(log_file, nullptr) !=
base::File::FILE_OK) {
@ -289,10 +291,12 @@ void CefDevToolsFrontend::Focus() {
}
void CefDevToolsFrontend::InspectElementAt(int x, int y) {
if (inspect_element_at_.x != x || inspect_element_at_.y != y)
if (inspect_element_at_.x != x || inspect_element_at_.y != y) {
inspect_element_at_.Set(x, y);
if (agent_host_)
}
if (agent_host_) {
agent_host_->InspectElement(inspected_contents_->GetFocusedFrame(), x, y);
}
}
void CefDevToolsFrontend::Close() {
@ -334,8 +338,9 @@ void CefDevToolsFrontend::ReadyToCommitNavigation(
std::string origin =
navigation_handle->GetURL().DeprecatedGetOriginAsURL().spec();
auto it = extensions_api_.find(origin);
if (it == extensions_api_.end())
if (it == extensions_api_.end()) {
return;
}
std::string script = base::StringPrintf("%s(\"%s\")", it->second.c_str(),
base::GenerateGUID().c_str());
content::DevToolsFrontendHost::SetupExtensionsAPI(frame, script);
@ -348,8 +353,9 @@ void CefDevToolsFrontend::PrimaryMainDocumentElementAvailable() {
scoped_refptr<content::DevToolsAgentHost> agent_host =
content::DevToolsAgentHost::GetOrCreateFor(inspected_contents_);
if (agent_host != agent_host_) {
if (agent_host_)
if (agent_host_) {
agent_host_->DetachClient(this);
}
agent_host_ = agent_host;
agent_host_->AttachClient(this);
if (!inspect_element_at_.IsEmpty()) {
@ -371,8 +377,9 @@ void CefDevToolsFrontend::WebContentsDestroyed() {
void CefDevToolsFrontend::HandleMessageFromDevToolsFrontend(
base::Value::Dict message) {
const std::string* method = message.FindString("method");
if (!method)
if (!method) {
return;
}
int request_id = message.FindInt("id").value_or(0);
base::Value::List* params_value = message.FindList("params");
@ -384,11 +391,13 @@ void CefDevToolsFrontend::HandleMessageFromDevToolsFrontend(
}
if (*method == "dispatchProtocolMessage") {
if (params.size() < 1)
if (params.size() < 1) {
return;
}
const std::string* protocol_message = params[0].GetIfString();
if (!agent_host_ || !protocol_message)
if (!agent_host_ || !protocol_message) {
return;
}
if (ProtocolLoggingEnabled()) {
LogProtocolMessage(ProtocolMessageType::METHOD, *protocol_message);
}
@ -398,8 +407,9 @@ void CefDevToolsFrontend::HandleMessageFromDevToolsFrontend(
web_contents()->GetPrimaryMainFrame()->ExecuteJavaScriptForTests(
u"DevToolsAPI.setUseSoftMenu(true);", base::NullCallback());
} else if (*method == "loadNetworkResource") {
if (params.size() < 3)
if (params.size() < 3) {
return;
}
// TODO(pfeldman): handle some of the embedder messages in content.
const std::string* url = params[0].GetIfString();
@ -486,62 +496,73 @@ void CefDevToolsFrontend::HandleMessageFromDevToolsFrontend(
base::Value(GetPrefs()->GetDict(prefs::kDevToolsPreferences).Clone()));
return;
} else if (*method == "setPreference") {
if (params.size() < 2)
if (params.size() < 2) {
return;
}
const std::string* name = params[0].GetIfString();
// We're just setting params[1] as a value anyways, so just make sure it's
// the type we want, but don't worry about getting it.
if (!name || !params[1].is_string())
if (!name || !params[1].is_string()) {
return;
}
DictionaryPrefUpdate update(GetPrefs(), prefs::kDevToolsPreferences);
update.Get()->SetKey(*name, std::move(params[1]));
} else if (*method == "removePreference") {
const std::string* name = params[0].GetIfString();
if (!name)
if (!name) {
return;
}
DictionaryPrefUpdate update(GetPrefs(), prefs::kDevToolsPreferences);
update.Get()->RemoveKey(*name);
} else if (*method == "requestFileSystems") {
web_contents()->GetPrimaryMainFrame()->ExecuteJavaScriptForTests(
u"DevToolsAPI.fileSystemsLoaded([]);", base::NullCallback());
} else if (*method == "reattach") {
if (!agent_host_)
if (!agent_host_) {
return;
}
agent_host_->DetachClient(this);
agent_host_->AttachClient(this);
} else if (*method == "registerExtensionsAPI") {
if (params.size() < 2)
if (params.size() < 2) {
return;
}
const std::string* origin = params[0].GetIfString();
const std::string* script = params[1].GetIfString();
if (!origin || !script)
if (!origin || !script) {
return;
}
extensions_api_[*origin + "/"] = *script;
} else if (*method == "save") {
if (params.size() < 3)
if (params.size() < 3) {
return;
}
const std::string* url = params[0].GetIfString();
const std::string* content = params[1].GetIfString();
absl::optional<bool> save_as = params[2].GetIfBool();
if (!url || !content || !save_as.has_value())
if (!url || !content || !save_as.has_value()) {
return;
}
file_manager_.SaveToFile(*url, *content, *save_as);
} else if (*method == "append") {
if (params.size() < 2)
if (params.size() < 2) {
return;
}
const std::string* url = params[0].GetIfString();
const std::string* content = params[1].GetIfString();
if (!url || !content)
if (!url || !content) {
return;
}
file_manager_.AppendToFile(*url, *content);
} else {
return;
}
if (request_id)
if (request_id) {
SendMessageAck(request_id, base::Value());
}
}
void CefDevToolsFrontend::DispatchProtocolMessage(

View File

@ -30,8 +30,9 @@ class CefDevToolsRegistrationImpl : public CefRegistration,
CEF_REQUIRE_UIT();
// May be null if OnDevToolsControllerDestroyed was called.
if (!controller_)
if (!controller_) {
return;
}
controller_->RemoveObserver(this);
}
@ -132,8 +133,9 @@ void CefDevToolsManager::ShowDevTools(const CefWindowInfo& windowInfo,
void CefDevToolsManager::CloseDevTools() {
CEF_REQUIRE_UIT();
if (!devtools_frontend_)
if (!devtools_frontend_) {
return;
}
devtools_frontend_->Close();
}
@ -145,11 +147,13 @@ bool CefDevToolsManager::HasDevTools() {
bool CefDevToolsManager::SendDevToolsMessage(const void* message,
size_t message_size) {
CEF_REQUIRE_UIT();
if (!message || message_size == 0)
if (!message || message_size == 0) {
return false;
}
if (!EnsureController())
if (!EnsureController()) {
return false;
}
return devtools_controller_->SendDevToolsMessage(
base::StringPiece(static_cast<const char*>(message), message_size));
@ -160,11 +164,13 @@ int CefDevToolsManager::ExecuteDevToolsMethod(
const CefString& method,
CefRefPtr<CefDictionaryValue> params) {
CEF_REQUIRE_UIT();
if (method.empty())
if (method.empty()) {
return 0;
}
if (!EnsureController())
if (!EnsureController()) {
return 0;
}
if (params && params->IsValid()) {
CefDictionaryValueImpl* impl =
@ -189,8 +195,9 @@ void CefDevToolsManager::InitializeRegistrationOnUIThread(
CefRefPtr<CefRegistration> registration) {
CEF_REQUIRE_UIT();
if (!EnsureController())
if (!EnsureController()) {
return;
}
static_cast<CefDevToolsRegistrationImpl*>(registration.get())
->Initialize(inspected_browser_, devtools_controller_->GetWeakPtr());

View File

@ -51,8 +51,10 @@ class TCPServerSocketFactory : public content::DevToolsSocketFactory {
std::unique_ptr<net::ServerSocket> CreateForHttpServer() override {
std::unique_ptr<net::ServerSocket> socket(
new net::TCPServerSocket(nullptr, net::NetLogSource()));
if (socket->ListenWithAddressAndPort(address_, port_, kBackLog) != net::OK)
if (socket->ListenWithAddressAndPort(address_, port_, kBackLog) !=
net::OK) {
return std::unique_ptr<net::ServerSocket>();
}
return socket;
}
@ -85,8 +87,9 @@ std::unique_ptr<content::DevToolsSocketFactory> CreateSocketFactory() {
DLOG(WARNING) << "Invalid http debugger port number " << temp_port;
}
}
if (port == 0)
if (port == 0) {
return nullptr;
}
return std::unique_ptr<content::DevToolsSocketFactory>(
new TCPServerSocketFactory("127.0.0.1", port));
}
@ -100,8 +103,9 @@ void CefDevToolsManagerDelegate::StartHttpHandler(
content::BrowserContext* browser_context) {
std::unique_ptr<content::DevToolsSocketFactory> socket_factory =
CreateSocketFactory();
if (!socket_factory)
if (!socket_factory) {
return;
}
content::DevToolsAgentHost::StartRemoteDebuggingServer(
std::move(socket_factory), browser_context->GetPath(), base::FilePath());

View File

@ -25,16 +25,19 @@ bool ParseEvent(const base::StringPiece& message,
static const char kMethodEnd[] = "\"";
static const char kParamsStart[] = ",\"params\":";
if (!base::StartsWith(message, kMethodStart))
if (!base::StartsWith(message, kMethodStart)) {
return false;
}
const size_t method_start = sizeof(kMethodStart) - 1;
const size_t method_end = message.find(kMethodEnd, method_start);
if (method_end == base::StringPiece::npos)
if (method_end == base::StringPiece::npos) {
return false;
}
method = message.substr(method_start, method_end - method_start);
if (method.empty())
if (method.empty()) {
return false;
}
size_t remainder_start = method_end + sizeof(kMethodEnd) - 1;
if (remainder_start == message.size() - 1) {
@ -52,8 +55,9 @@ bool ParseEvent(const base::StringPiece& message,
return false;
}
if (!IsValidDictionary(params, /*allow_empty=*/true))
if (!IsValidDictionary(params, /*allow_empty=*/true)) {
return false;
}
}
return true;
@ -72,16 +76,19 @@ bool ParseResult(const base::StringPiece& message,
static const char kResultStart[] = "\"result\":";
static const char kErrorStart[] = "\"error\":";
if (!base::StartsWith(message, kIdStart))
if (!base::StartsWith(message, kIdStart)) {
return false;
}
const size_t id_start = sizeof(kIdStart) - 1;
const size_t id_end = message.find(kIdEnd, id_start);
if (id_end == base::StringPiece::npos)
if (id_end == base::StringPiece::npos) {
return false;
}
const base::StringPiece& id_str = message.substr(id_start, id_end - id_start);
if (id_str.empty() || !base::StringToInt(id_str, &message_id))
if (id_str.empty() || !base::StringToInt(id_str, &message_id)) {
return false;
}
size_t remainder_start = id_end + sizeof(kIdEnd) - 1;
const base::StringPiece& remainder = message.substr(remainder_start);
@ -102,8 +109,9 @@ bool ParseResult(const base::StringPiece& message,
return false;
}
if (!IsValidDictionary(result, /*allow_empty=*/true))
if (!IsValidDictionary(result, /*allow_empty=*/true)) {
return false;
}
return true;
}
@ -116,8 +124,9 @@ bool ProtocolParser::IsValidMessage(const base::StringPiece& message) {
}
bool ProtocolParser::Initialize(const base::StringPiece& message) {
if (status_ != UNINITIALIZED)
if (status_ != UNINITIALIZED) {
return false;
}
if (ParseEvent(message, method_, params_)) {
status_ = EVENT;

View File

@ -35,8 +35,9 @@ namespace {
CefRefPtr<CefDownloadHandler> GetDownloadHandler(
CefRefPtr<AlloyBrowserHostImpl> browser) {
CefRefPtr<CefClient> client = browser->GetClient();
if (client.get())
if (client.get()) {
return client->GetDownloadHandler();
}
return nullptr;
}
@ -58,8 +59,9 @@ class CefBeforeDownloadCallbackImpl : public CefBeforeDownloadCallback {
void Continue(const CefString& download_path, bool show_dialog) override {
if (CEF_CURRENTLY_ON_UIT()) {
if (download_id_ <= 0)
if (download_id_ <= 0) {
return;
}
if (manager_) {
base::FilePath path = base::FilePath(download_path);
@ -119,12 +121,14 @@ class CefBeforeDownloadCallbackImpl : public CefBeforeDownloadCallback {
const base::FilePath& suggested_path,
bool show_dialog,
content::DownloadTargetCallback callback) {
if (!manager)
if (!manager) {
return;
}
DownloadItem* item = manager->GetDownload(download_id);
if (!item || item->GetState() != DownloadItem::IN_PROGRESS)
if (!item || item->GetState() != DownloadItem::IN_PROGRESS) {
return;
}
bool handled = false;
@ -170,8 +174,9 @@ class CefBeforeDownloadCallbackImpl : public CefBeforeDownloadCallback {
DCHECK_LE(file_paths.size(), (size_t)1);
base::FilePath path;
if (file_paths.size() > 0)
if (file_paths.size() > 0) {
path = file_paths.front();
}
// The download will be cancelled if |path| is empty.
std::move(callback).Run(path, DownloadItem::TARGET_DISPOSITION_OVERWRITE,
@ -218,37 +223,43 @@ class CefDownloadItemCallbackImpl : public CefDownloadItemCallback {
private:
void DoCancel() {
if (download_id_ <= 0)
if (download_id_ <= 0) {
return;
}
if (manager_) {
DownloadItem* item = manager_->GetDownload(download_id_);
if (item && item->GetState() == DownloadItem::IN_PROGRESS)
if (item && item->GetState() == DownloadItem::IN_PROGRESS) {
item->Cancel(true);
}
}
download_id_ = 0;
}
void DoPause() {
if (download_id_ <= 0)
if (download_id_ <= 0) {
return;
}
if (manager_) {
DownloadItem* item = manager_->GetDownload(download_id_);
if (item && item->GetState() == DownloadItem::IN_PROGRESS)
if (item && item->GetState() == DownloadItem::IN_PROGRESS) {
item->Pause();
}
}
}
void DoResume() {
if (download_id_ <= 0)
if (download_id_ <= 0) {
return;
}
if (manager_) {
DownloadItem* item = manager_->GetDownload(download_id_);
if (item && item->CanResume())
if (item && item->CanResume()) {
item->Resume(true);
}
}
}
@ -268,8 +279,9 @@ CefDownloadManagerDelegate::CefDownloadManagerDelegate(DownloadManager* manager)
DownloadManager::DownloadVector items;
manager->GetAllDownloads(&items);
DownloadManager::DownloadVector::const_iterator it = items.begin();
for (; it != items.end(); ++it)
for (; it != items.end(); ++it) {
OnDownloadCreated(manager, *it);
}
}
CefDownloadManagerDelegate::~CefDownloadManagerDelegate() {
@ -278,15 +290,17 @@ CefDownloadManagerDelegate::~CefDownloadManagerDelegate() {
manager_->RemoveObserver(this);
}
while (!item_browser_map_.empty())
while (!item_browser_map_.empty()) {
OnDownloadDestroyed(item_browser_map_.begin()->first);
}
}
void CefDownloadManagerDelegate::OnDownloadUpdated(DownloadItem* download) {
CefRefPtr<AlloyBrowserHostImpl> browser = GetBrowser(download);
CefRefPtr<CefDownloadHandler> handler;
if (browser.get())
if (browser.get()) {
handler = GetDownloadHandler(browser);
}
if (handler.get()) {
CefRefPtr<CefDownloadItemImpl> download_item(
@ -324,8 +338,9 @@ void CefDownloadManagerDelegate::OnDownloadDestroyed(DownloadItem* item) {
}
}
if (!has_remaining)
if (!has_remaining) {
browser->RemoveObserver(this);
}
}
}
@ -374,8 +389,9 @@ bool CefDownloadManagerDelegate::DetermineDownloadTarget(
// from either method.
CefRefPtr<AlloyBrowserHostImpl> browser = GetOrAssociateBrowser(item);
CefRefPtr<CefDownloadHandler> handler;
if (browser.get())
if (browser.get()) {
handler = GetDownloadHandler(browser);
}
if (handler.get()) {
base::FilePath suggested_name = net::GenerateFileName(
@ -423,8 +439,9 @@ void CefDownloadManagerDelegate::OnBrowserDestroyed(
AlloyBrowserHostImpl* CefDownloadManagerDelegate::GetOrAssociateBrowser(
download::DownloadItem* item) {
ItemBrowserMap::const_iterator it = item_browser_map_.find(item);
if (it != item_browser_map_.end())
if (it != item_browser_map_.end()) {
return it->second;
}
AlloyBrowserHostImpl* browser = nullptr;
content::WebContents* contents =
@ -433,8 +450,9 @@ AlloyBrowserHostImpl* CefDownloadManagerDelegate::GetOrAssociateBrowser(
browser = AlloyBrowserHostImpl::GetBrowserForContents(contents).get();
DCHECK(browser);
}
if (!browser)
if (!browser) {
return nullptr;
}
item->AddObserver(this);
@ -442,8 +460,9 @@ AlloyBrowserHostImpl* CefDownloadManagerDelegate::GetOrAssociateBrowser(
// Register as an observer so that we can cancel associated DownloadItems when
// the browser is destroyed.
if (!browser->HasObserver(this))
if (!browser->HasObserver(this)) {
browser->AddObserver(this);
}
return browser;
}
@ -451,8 +470,9 @@ AlloyBrowserHostImpl* CefDownloadManagerDelegate::GetOrAssociateBrowser(
AlloyBrowserHostImpl* CefDownloadManagerDelegate::GetBrowser(
DownloadItem* item) {
ItemBrowserMap::const_iterator it = item_browser_map_.find(item);
if (it != item_browser_map_.end())
if (it != item_browser_map_.end()) {
return it->second;
}
// If the download is rejected (e.g. ALT+click on an invalid protocol link)
// then an "interrupted" download will be started via DownloadManagerImpl::

View File

@ -37,12 +37,14 @@ CefRefPtr<CefDictionaryValue> CefExtensionImpl::GetManifest() {
bool CefExtensionImpl::IsSame(CefRefPtr<CefExtension> that) {
CefExtensionImpl* that_impl = static_cast<CefExtensionImpl*>(that.get());
if (!that_impl)
if (!that_impl) {
return false;
}
// Maybe the same object.
if (this == that_impl)
if (this == that_impl) {
return true;
}
return id_ == that_impl->id_ && path_ == that_impl->path_ &&
loader_context_ == that_impl->loader_context_;
@ -77,11 +79,13 @@ void CefExtensionImpl::Unload() {
}
// Will be NULL for internal extensions. They can't be unloaded.
if (!loader_context_)
if (!loader_context_) {
return;
}
if (unloaded_)
if (unloaded_) {
return;
}
// CefExtensionHandler callbacks triggered by UnloadExtension may check this
// flag, so set it here.
@ -96,8 +100,9 @@ void CefExtensionImpl::Unload() {
void CefExtensionImpl::OnExtensionLoaded() {
CEF_REQUIRE_UIT();
if (handler_)
if (handler_) {
handler_->OnExtensionLoaded(this);
}
}
void CefExtensionImpl::OnExtensionUnloaded() {
@ -108,6 +113,7 @@ void CefExtensionImpl::OnExtensionUnloaded() {
unloaded_ = true;
loader_context_ = nullptr;
if (handler_)
if (handler_) {
handler_->OnExtensionUnloaded(this);
}
}

View File

@ -11,8 +11,9 @@ namespace alloy {
int GetTabIdForWebContents(content::WebContents* web_contents) {
auto browser = AlloyBrowserHostImpl::GetBrowserForContents(web_contents);
if (!browser)
if (!browser) {
return -1;
}
return browser->GetIdentifier();
}

View File

@ -68,12 +68,15 @@ void CefFileSystemDelegate::ConfirmSensitiveDirectoryAccess(
// Based on ChromeFileSystemDelegate::GetDescriptionIdForAcceptType.
int CefFileSystemDelegate::GetDescriptionIdForAcceptType(
const std::string& accept_type) {
if (accept_type == "image/*")
if (accept_type == "image/*") {
return IDS_IMAGE_FILES;
if (accept_type == "audio/*")
}
if (accept_type == "audio/*") {
return IDS_AUDIO_FILES;
if (accept_type == "video/*")
}
if (accept_type == "video/*") {
return IDS_VIDEO_FILES;
}
return 0;
}

View File

@ -82,8 +82,9 @@ void SyncValueStoreCache::DeleteStorageSoon(const std::string& extension_id) {
value_store::ValueStore* SyncValueStoreCache::GetStorage(
const Extension* extension) {
auto iter = storage_map_.find(extension->id());
if (iter != storage_map_.end())
if (iter != storage_map_.end()) {
return iter->second.get();
}
value_store_util::ModelType model_type =
extension->is_app() ? value_store_util::ModelType::APP

View File

@ -85,8 +85,9 @@ ExtensionFunction::ResponseAction TabsCreateFunction::Run() {
std::string error;
auto result = cef_details_.OpenTab(options, user_gesture(), &error);
if (!result)
if (!result) {
return RespondNow(Error(error));
}
// Return data about the newly created tab.
return RespondNow(has_callback() ? OneArgument(base::Value(result->ToValue()))
@ -99,8 +100,9 @@ content::WebContents* BaseAPIFunction::GetWebContents(int tab_id) {
// Find a browser that we can access, or set |error_| and return nullptr.
CefRefPtr<AlloyBrowserHostImpl> browser =
cef_details_.GetBrowserForTabIdFirstTime(tab_id, &error_);
if (!browser)
if (!browser) {
return nullptr;
}
return browser->web_contents();
}
@ -112,8 +114,9 @@ ExtensionFunction::ResponseAction TabsUpdateFunction::Run() {
tab_id_ = params->tab_id ? *params->tab_id : -1;
content::WebContents* web_contents = GetWebContents(tab_id_);
if (!web_contents)
if (!web_contents) {
return RespondNow(Error(std::move(error_)));
}
web_contents_ = web_contents;
@ -124,19 +127,22 @@ ExtensionFunction::ResponseAction TabsUpdateFunction::Run() {
// Navigate the tab to a new location if the url is different.
if (params->update_properties.url.has_value()) {
std::string updated_url = *params->update_properties.url;
if (!UpdateURL(updated_url, tab_id_, &error_))
if (!UpdateURL(updated_url, tab_id_, &error_)) {
return RespondNow(Error(std::move(error_)));
}
}
bool active = false;
// TODO(rafaelw): Setting |active| from js doesn't make much sense.
// Move tab selection management up to window.
if (params->update_properties.selected.has_value())
if (params->update_properties.selected.has_value()) {
active = *params->update_properties.selected;
}
// The 'active' property has replaced 'selected'.
if (params->update_properties.active.has_value())
if (params->update_properties.active.has_value()) {
active = *params->update_properties.active;
}
if (active) {
// TODO: Activate the tab at |tab_id_|.
@ -168,8 +174,9 @@ ExtensionFunction::ResponseAction TabsUpdateFunction::Run() {
if (params->update_properties.opener_tab_id.has_value()) {
int opener_id = *params->update_properties.opener_tab_id;
if (opener_id == tab_id_)
if (opener_id == tab_id_) {
return RespondNow(Error("Cannot set a tab's opener to itself."));
}
// TODO: Set the opener for the tab at |tab_id_|.
NOTIMPLEMENTED();
@ -227,8 +234,9 @@ bool TabsUpdateFunction::UpdateURL(const std::string& url_string,
}
ExtensionFunction::ResponseValue TabsUpdateFunction::GetResult() {
if (!has_callback())
if (!has_callback()) {
return NoArguments();
}
return ArgumentList(tabs::Get::Results::Create(cef_details_.CreateTabObject(
AlloyBrowserHostImpl::GetBrowserForContents(web_contents_),
@ -241,11 +249,13 @@ ExecuteCodeInTabFunction::ExecuteCodeInTabFunction()
ExecuteCodeInTabFunction::~ExecuteCodeInTabFunction() {}
ExecuteCodeFunction::InitResult ExecuteCodeInTabFunction::Init() {
if (init_result_)
if (init_result_) {
return init_result_.value();
}
if (args().size() < 2)
if (args().size() < 2) {
return set_init_result(VALIDATION_FAILURE);
}
const auto& tab_id_value = args()[0];
// |tab_id| is optional so it's ok if it's not there.
@ -260,18 +270,21 @@ ExecuteCodeFunction::InitResult ExecuteCodeInTabFunction::Init() {
// |details| are not optional.
const base::Value& details_value = args()[1];
if (!details_value.is_dict())
if (!details_value.is_dict()) {
return set_init_result(VALIDATION_FAILURE);
}
std::unique_ptr<InjectDetails> details(new InjectDetails());
if (!InjectDetails::Populate(details_value, details.get()))
if (!InjectDetails::Populate(details_value, details.get())) {
return set_init_result(VALIDATION_FAILURE);
}
// Find a browser that we can access, or fail with error.
std::string error;
CefRefPtr<AlloyBrowserHostImpl> browser =
cef_details_.GetBrowserForTabIdFirstTime(tab_id, &error);
if (!browser)
if (!browser) {
return set_init_result_error(error);
}
execute_tab_id_ = browser->GetIdentifier();
details_ = std::move(details);
@ -293,8 +306,9 @@ bool ExecuteCodeInTabFunction::CanExecuteScriptOnPage(std::string* error) {
CefRefPtr<AlloyBrowserHostImpl> browser =
cef_details_.GetBrowserForTabIdAgain(execute_tab_id_, error);
if (!browser)
if (!browser) {
return false;
}
int frame_id = details_->frame_id ? *details_->frame_id
: ExtensionApiFrameIdMap::kTopFrameId;
@ -348,8 +362,9 @@ ScriptExecutor* ExecuteCodeInTabFunction::GetScriptExecutor(
CefRefPtr<AlloyBrowserHostImpl> browser =
cef_details_.GetBrowserForTabIdAgain(execute_tab_id_, error);
if (!browser)
if (!browser) {
return nullptr;
}
return CefExtensionWebContentsObserver::FromWebContents(
browser->web_contents())
@ -406,12 +421,14 @@ ExtensionFunction::ResponseAction TabsSetZoomFunction::Run() {
int tab_id = params->tab_id ? *params->tab_id : -1;
content::WebContents* web_contents = GetWebContents(tab_id);
if (!web_contents)
if (!web_contents) {
return RespondNow(Error(std::move(error_)));
}
GURL url(web_contents->GetVisibleURL());
if (extension()->permissions_data()->IsRestrictedUrl(url, &error_))
if (extension()->permissions_data()->IsRestrictedUrl(url, &error_)) {
return RespondNow(Error(std::move(error_)));
}
ZoomController* zoom_controller =
ZoomController::FromWebContents(web_contents);
@ -436,8 +453,9 @@ ExtensionFunction::ResponseAction TabsGetZoomFunction::Run() {
int tab_id = params->tab_id ? *params->tab_id : -1;
content::WebContents* web_contents = GetWebContents(tab_id);
if (!web_contents)
if (!web_contents) {
return RespondNow(Error(std::move(error_)));
}
double zoom_level =
zoom::ZoomController::FromWebContents(web_contents)->GetZoomLevel();
@ -455,13 +473,15 @@ ExtensionFunction::ResponseAction TabsSetZoomSettingsFunction::Run() {
int tab_id = params->tab_id ? *params->tab_id : -1;
content::WebContents* web_contents = GetWebContents(tab_id);
if (!web_contents)
if (!web_contents) {
return RespondNow(Error(std::move(error_)));
}
GURL url(web_contents->GetVisibleURL());
std::string error;
if (extension()->permissions_data()->IsRestrictedUrl(url, &error_))
if (extension()->permissions_data()->IsRestrictedUrl(url, &error_)) {
return RespondNow(Error(std::move(error_)));
}
// "per-origin" scope is only available in "automatic" mode.
if (params->zoom_settings.scope == tabs::ZOOM_SETTINGS_SCOPE_PER_ORIGIN &&
@ -504,8 +524,9 @@ ExtensionFunction::ResponseAction TabsGetZoomSettingsFunction::Run() {
int tab_id = params->tab_id ? *params->tab_id : -1;
content::WebContents* web_contents = GetWebContents(tab_id);
if (!web_contents)
if (!web_contents) {
return RespondNow(Error(std::move(error_)));
}
ZoomController* zoom_controller =
ZoomController::FromWebContents(web_contents);

View File

@ -65,8 +65,9 @@ CefRefPtr<CefBrowserHostBase> GetOwnerBrowserForGlobalId(
// Use the non-thread-safe but potentially faster approach.
content::RenderFrameHost* host =
content::RenderFrameHost::FromID(global_id);
if (host)
if (host) {
return GetOwnerBrowserForHost(host, is_guest_view);
}
return nullptr;
} else {
// Use the thread-safe approach.
@ -89,8 +90,9 @@ CefRefPtr<CefBrowserHostBase> GetOwnerBrowserForGlobalId(
CefRefPtr<CefBrowserHostBase> GetOwnerBrowserForHost(
content::RenderViewHost* host,
bool* is_guest_view) {
if (is_guest_view)
if (is_guest_view) {
*is_guest_view = false;
}
CefRefPtr<CefBrowserHostBase> browser =
CefBrowserHostBase::GetBrowserForHost(host);
@ -100,8 +102,9 @@ CefRefPtr<CefBrowserHostBase> GetOwnerBrowserForHost(
content::WebContents::FromRenderViewHost(host));
if (owner) {
browser = CefBrowserHostBase::GetBrowserForContents(owner);
if (browser.get() && is_guest_view)
if (browser.get() && is_guest_view) {
*is_guest_view = true;
}
}
}
return browser;
@ -110,8 +113,9 @@ CefRefPtr<CefBrowserHostBase> GetOwnerBrowserForHost(
CefRefPtr<CefBrowserHostBase> GetOwnerBrowserForHost(
content::RenderFrameHost* host,
bool* is_guest_view) {
if (is_guest_view)
if (is_guest_view) {
*is_guest_view = false;
}
CefRefPtr<CefBrowserHostBase> browser =
CefBrowserHostBase::GetBrowserForHost(host);
@ -121,8 +125,9 @@ CefRefPtr<CefBrowserHostBase> GetOwnerBrowserForHost(
content::WebContents::FromRenderFrameHost(host));
if (owner) {
browser = CefBrowserHostBase::GetBrowserForContents(owner);
if (browser.get() && is_guest_view)
if (browser.get() && is_guest_view) {
*is_guest_view = true;
}
}
}
return browser;
@ -134,8 +139,9 @@ CefRefPtr<AlloyBrowserHostImpl> GetBrowserForTabId(
REQUIRE_ALLOY_RUNTIME();
CEF_REQUIRE_UIT();
DCHECK(browser_context);
if (tab_id < 0 || !browser_context)
if (tab_id < 0 || !browser_context) {
return nullptr;
}
auto cef_browser_context =
CefBrowserContext::FromBrowserContext(browser_context);
@ -164,8 +170,9 @@ CefRefPtr<AlloyBrowserHostImpl> GetBrowserForTabId(
const Extension* GetExtensionForUrl(content::BrowserContext* browser_context,
const GURL& url) {
ExtensionRegistry* registry = ExtensionRegistry::Get(browser_context);
if (!registry)
if (!registry) {
return nullptr;
}
std::string extension_id = url.host();
return registry->enabled_extensions().GetByID(extension_id);
}

View File

@ -66,8 +66,9 @@ const char* const kSupportedAPIs[] = {
// static
bool ChromeFunctionRegistry::IsSupported(const std::string& name) {
for (size_t i = 0; kSupportedAPIs[i] != nullptr; ++i) {
if (name == kSupportedAPIs[i])
if (name == kSupportedAPIs[i]) {
return true;
}
}
return false;
}

View File

@ -148,8 +148,9 @@ Profile* CefExtensionFunctionDetails::GetProfile() const {
CefRefPtr<AlloyBrowserHostImpl> CefExtensionFunctionDetails::GetSenderBrowser()
const {
content::WebContents* web_contents = function_->GetSenderWebContents();
if (web_contents)
if (web_contents) {
return AlloyBrowserHostImpl::GetBrowserForContents(web_contents);
}
return nullptr;
}
@ -293,20 +294,23 @@ std::unique_ptr<api::tabs::Tab> CefExtensionFunctionDetails::OpenTab(
bool user_gesture,
std::string* error_message) const {
CefRefPtr<AlloyBrowserHostImpl> sender_browser = GetSenderBrowser();
if (!sender_browser)
if (!sender_browser) {
return nullptr;
}
// windowId defaults to "current" window.
int window_id = extension_misc::kCurrentWindowId;
if (params.window_id.has_value())
if (params.window_id.has_value()) {
window_id = *params.window_id;
}
// CEF doesn't have the concept of windows containing tab strips so we'll
// select an "active browser" for BrowserContext sharing instead.
CefRefPtr<AlloyBrowserHostImpl> active_browser =
GetBrowserForTabIdFirstTime(window_id, error_message);
if (!active_browser)
if (!active_browser) {
return nullptr;
}
// If an opener browser was specified then we expect it to exist.
int opener_browser_id = -1;
@ -330,13 +334,15 @@ std::unique_ptr<api::tabs::Tab> CefExtensionFunctionDetails::OpenTab(
// Default to foreground for the new tab. The presence of 'active' property
// will override this default.
bool active = true;
if (params.active.has_value())
if (params.active.has_value()) {
active = *params.active;
}
// CEF doesn't use the index value but we let the client see/modify it.
int index = 0;
if (params.index.has_value())
if (params.index.has_value()) {
index = *params.index;
}
auto cef_browser_context = CefBrowserContext::FromBrowserContext(
active_browser->GetBrowserContext());
@ -345,15 +351,17 @@ std::unique_ptr<api::tabs::Tab> CefExtensionFunctionDetails::OpenTab(
CefRefPtr<CefExtension> cef_extension =
cef_browser_context->GetExtension(function()->extension()->id());
DCHECK(cef_extension);
if (!cef_extension)
if (!cef_extension) {
return nullptr;
}
// Always use the same request context that the extension was registered with.
// GetLoaderContext() will return NULL for internal extensions.
CefRefPtr<CefRequestContext> request_context =
cef_extension->GetLoaderContext();
if (!request_context)
if (!request_context) {
return nullptr;
}
CefBrowserCreateParams create_params;
create_params.url = url.spec();
@ -387,8 +395,9 @@ std::unique_ptr<api::tabs::Tab> CefExtensionFunctionDetails::OpenTab(
// Browser creation may fail under certain rare circumstances.
CefRefPtr<AlloyBrowserHostImpl> new_browser =
AlloyBrowserHostImpl::Create(create_params);
if (!new_browser)
if (!new_browser) {
return nullptr;
}
// Return data about the newly created tab.
auto extension = function()->extension();
@ -436,8 +445,9 @@ api::tabs::Tab CefExtensionFunctionDetails::CreateTabObject(
tab_object.fav_icon_url = entry->GetFavicon().url.spec();
}
if (opener_browser_id >= 0)
if (opener_browser_id >= 0) {
tab_object.opener_tab_id = opener_browser_id;
}
return tab_object;
}

View File

@ -76,8 +76,9 @@ std::unique_ptr<base::DictionaryValue> ParseManifest(
void ExecuteLoadFailure(CefRefPtr<CefExtensionHandler> handler,
cef_errorcode_t result) {
if (!handler)
if (!handler) {
return;
}
if (!CEF_CURRENTLY_ON_UIT()) {
CEF_POST_TASK(CEF_UIT, base::BindOnce(ExecuteLoadFailure, handler, result));
@ -313,8 +314,9 @@ void CefExtensionSystem::LoadExtension(
ComponentExtensionInfo info(manifest.get(), root_directory, internal);
const Extension* extension = LoadExtension(info, loader_context, handler);
if (!extension)
if (!extension) {
ExecuteLoadFailure(handler, ERR_FAILED);
}
}
// Implementation based on ExtensionService::RemoveComponentExtension.
@ -353,8 +355,9 @@ CefRefPtr<CefExtension> CefExtensionSystem::GetExtension(
const std::string& extension_id) const {
CEF_REQUIRE_UIT();
ExtensionMap::const_iterator it = extension_map_.find(extension_id);
if (it != extension_map_.end())
if (it != extension_map_.end()) {
return it->second;
}
return nullptr;
}
@ -374,8 +377,9 @@ void CefExtensionSystem::OnRequestContextDeleted(CefRequestContext* context) {
for (; it != map.end(); ++it) {
CefRefPtr<CefExtensionImpl> cef_extension =
static_cast<CefExtensionImpl*>(it->second.get());
if (cef_extension->loader_context() == context)
if (cef_extension->loader_context() == context) {
UnloadExtension(it->first);
}
}
}
@ -434,8 +438,9 @@ CefExtensionSystem::store_factory() {
}
InfoMap* CefExtensionSystem::info_map() {
if (!info_map_.get())
if (!info_map_.get()) {
info_map_ = new InfoMap;
}
return info_map_.get();
}
@ -686,8 +691,9 @@ void CefExtensionSystem::NotifyExtensionLoaded(const Extension* extension) {
void CefExtensionSystem::OnExtensionRegisteredWithRequestContexts(
scoped_refptr<const extensions::Extension> extension) {
registry_->AddReady(extension);
if (registry_->enabled_extensions().Contains(extension->id()))
if (registry_->enabled_extensions().Contains(extension->id())) {
registry_->TriggerOnReady(extension.get());
}
}
// Implementation based on ExtensionService::NotifyExtensionUnloaded.

View File

@ -72,8 +72,9 @@ bool CefExtensionViewHost::PreHandleGestureEvent(
}
WebContents* CefExtensionViewHost::GetVisibleWebContents() const {
if (extension_host_type() == mojom::ViewType::kExtensionPopup)
if (extension_host_type() == mojom::ViewType::kExtensionPopup) {
return host_contents();
}
return nullptr;
}

View File

@ -37,8 +37,9 @@ void CefExtensionWebContentsObserver::RenderFrameCreated(
ExtensionWebContentsObserver::RenderFrameCreated(render_frame_host);
const Extension* extension = GetExtensionFromFrame(render_frame_host, false);
if (!extension)
if (!extension) {
return;
}
int process_id = render_frame_host->GetProcess()->GetID();
auto policy = content::ChildProcessSecurityPolicy::GetInstance();

View File

@ -75,8 +75,9 @@ void CefExtensionsAPIClient::AddAdditionalValueStoreCaches(
}
FileSystemDelegate* CefExtensionsAPIClient::GetFileSystemDelegate() {
if (!file_system_delegate_)
if (!file_system_delegate_) {
file_system_delegate_ = std::make_unique<cef::CefFileSystemDelegate>();
}
return file_system_delegate_.get();
}

View File

@ -5,7 +5,7 @@
#include "libcef/browser/extensions/extensions_browser_api_provider.h"
#include "libcef/browser/extensions/chrome_api_registration.h"
//#include "cef/libcef/browser/extensions/api/generated_api_registration.h"
// #include "cef/libcef/browser/extensions/api/generated_api_registration.h"
#include "extensions/browser/api/generated_api_registration.h"
namespace extensions {

View File

@ -49,13 +49,15 @@ void BindMimeHandlerService(
mojo::PendingReceiver<extensions::mime_handler::MimeHandlerService>
receiver) {
auto* web_contents = content::WebContents::FromRenderFrameHost(frame_host);
if (!web_contents)
if (!web_contents) {
return;
}
auto* guest_view =
extensions::MimeHandlerViewGuest::FromWebContents(web_contents);
if (!guest_view)
if (!guest_view) {
return;
}
extensions::MimeHandlerServiceImpl::Create(guest_view->GetStreamWeakPtr(),
std::move(receiver));
}
@ -65,13 +67,15 @@ void BindBeforeUnloadControl(
mojo::PendingReceiver<extensions::mime_handler::BeforeUnloadControl>
receiver) {
auto* web_contents = content::WebContents::FromRenderFrameHost(frame_host);
if (!web_contents)
if (!web_contents) {
return;
}
auto* guest_view =
extensions::MimeHandlerViewGuest::FromWebContents(web_contents);
if (!guest_view)
if (!guest_view) {
return;
}
guest_view->FuseBeforeUnloadControl(std::move(receiver));
}
@ -138,8 +142,9 @@ BrowserContext* CefExtensionsBrowserClient::GetOffTheRecordContext(
BrowserContext* CefExtensionsBrowserClient::GetOriginalContext(
BrowserContext* context) {
auto cef_browser_context = CefBrowserContext::FromBrowserContext(context);
if (cef_browser_context)
if (cef_browser_context) {
return cef_browser_context->AsBrowserContext();
}
return nullptr;
}
@ -393,8 +398,9 @@ CefExtensionsBrowserClient::GetExtensionWebContentsObserver(
}
KioskDelegate* CefExtensionsBrowserClient::GetKioskDelegate() {
if (!kiosk_delegate_)
if (!kiosk_delegate_) {
kiosk_delegate_.reset(new CefKioskDelegate());
}
return kiosk_delegate_.get();
}

View File

@ -57,8 +57,9 @@ ValueStore::ReadResult CefValueStore::Get(const std::string& key) {
ValueStore::ReadResult CefValueStore::Get(
const std::vector<std::string>& keys) {
read_count_++;
if (!status_.ok())
if (!status_.ok()) {
return ReadResult(CreateStatusCopy(status_));
}
base::Value::Dict settings;
for (const auto& key : keys) {
@ -72,8 +73,9 @@ ValueStore::ReadResult CefValueStore::Get(
ValueStore::ReadResult CefValueStore::Get() {
read_count_++;
if (!status_.ok())
if (!status_.ok()) {
return ReadResult(CreateStatusCopy(status_));
}
return ReadResult(storage_.Clone(), CreateStatusCopy(status_));
}
@ -88,8 +90,9 @@ ValueStore::WriteResult CefValueStore::Set(WriteOptions options,
ValueStore::WriteResult CefValueStore::Set(WriteOptions options,
const base::Value::Dict& settings) {
write_count_++;
if (!status_.ok())
if (!status_.ok()) {
return WriteResult(CreateStatusCopy(status_));
}
ValueStoreChangeList changes;
for (const auto [key, value] : settings) {
@ -113,8 +116,9 @@ ValueStore::WriteResult CefValueStore::Remove(const std::string& key) {
ValueStore::WriteResult CefValueStore::Remove(
const std::vector<std::string>& keys) {
write_count_++;
if (!status_.ok())
if (!status_.ok()) {
return WriteResult(CreateStatusCopy(status_));
}
ValueStoreChangeList changes;
for (auto const& key : keys) {

View File

@ -63,10 +63,11 @@ void CefValueStoreFactory::Reset() {
std::unique_ptr<ValueStore> CefValueStoreFactory::CreateStore() {
std::unique_ptr<ValueStore> store;
if (db_path_.empty())
if (db_path_.empty()) {
store = std::make_unique<CefValueStore>();
else
} else {
store = std::make_unique<LeveldbValueStore>(kUMAClientName, db_path_);
}
last_created_store_ = store.get();
return store;
}

View File

@ -47,8 +47,9 @@ class CefFileDialogCallbackImpl : public CefFileDialogCallback {
std::vector<base::FilePath> vec;
if (!file_paths.empty()) {
std::vector<CefString>::const_iterator it = file_paths.begin();
for (; it != file_paths.end(); ++it)
for (; it != file_paths.end(); ++it) {
vec.push_back(base::FilePath(*it));
}
}
std::move(callback_).Run(vec);
}
@ -88,8 +89,9 @@ void RunFileDialogDismissed(CefRefPtr<CefRunFileDialogCallback> callback,
const std::vector<base::FilePath>& file_paths) {
std::vector<CefString> paths;
if (file_paths.size() > 0) {
for (size_t i = 0; i < file_paths.size(); ++i)
for (size_t i = 0; i < file_paths.size(); ++i) {
paths.push_back(file_paths[i].value());
}
}
callback->OnFileDialogDismissed(paths);
}
@ -298,8 +300,9 @@ void CefFileDialogManager::RunFileDialog(
const std::vector<CefString>& accept_filters,
CefRefPtr<CefRunFileDialogCallback> callback) {
DCHECK(callback.get());
if (!callback.get())
if (!callback.get()) {
return;
}
blink::mojom::FileChooserParams params;
switch (mode) {
@ -318,13 +321,15 @@ void CefFileDialogManager::RunFileDialog(
}
params.title = title;
if (!default_file_path.empty())
if (!default_file_path.empty()) {
params.default_file_name = base::FilePath(default_file_path);
}
if (!accept_filters.empty()) {
std::vector<CefString>::const_iterator it = accept_filters.begin();
for (; it != accept_filters.end(); ++it)
for (; it != accept_filters.end(); ++it) {
params.accept_types.push_back(*it);
}
}
RunFileChooser(params, base::BindOnce(RunFileDialogDismissed, callback));
@ -493,8 +498,9 @@ CefFileDialogManager::MaybeRunDelegate(
std::vector<CefString> accept_filters;
it = params.accept_types.begin();
for (; it != params.accept_types.end(); ++it)
for (; it != params.accept_types.end(); ++it) {
accept_filters.push_back(*it);
}
CefRefPtr<CefFileDialogCallbackImpl> callbackImpl(
new CefFileDialogCallbackImpl(std::move(callback)));
@ -519,8 +525,9 @@ void CefFileDialogManager::SelectFileDoneByDelegateCallback(
// The listener may already be gone. This can occur if the client holds a
// RunFileChooserCallback past the call to SelectFileListenerDestroyed().
if (active_listeners_.find(listener) == active_listeners_.end())
if (active_listeners_.find(listener) == active_listeners_.end()) {
return;
}
active_listeners_.erase(listener);
@ -545,8 +552,9 @@ void CefFileDialogManager::SelectFileDoneByListenerCallback(
// CefSelectFileDialogListener::Destroy(). Similarly, the below call to
// Cancel() may trigger another execution from
// CefSelectFileDialogListener::Destroy().
if (!dialog_listener_)
if (!dialog_listener_) {
return;
}
DCHECK(dialog_);
DCHECK(dialog_listener_);

View File

@ -130,8 +130,9 @@ class CefSelectFileDialog final : public ui::SelectFileDialog {
}
void ListenerDestroyed() override {
if (browser_)
if (browser_) {
browser_->SelectFileListenerDestroyed(listener_);
}
listener_ = nullptr;
}

View File

@ -177,14 +177,16 @@ CefRefPtr<CefFrame> CefFrameHostImpl::GetParent() {
{
base::AutoLock lock_scope(state_lock_);
if (is_main_frame_ || parent_frame_id_ == kInvalidFrameId)
if (is_main_frame_ || parent_frame_id_ == kInvalidFrameId) {
return nullptr;
}
parent_frame_id = parent_frame_id_;
}
auto browser = GetBrowserHostBase();
if (browser)
if (browser) {
return browser->GetFrame(parent_frame_id);
}
return nullptr;
}
@ -210,8 +212,9 @@ void CefFrameHostImpl::VisitDOM(CefRefPtr<CefDOMVisitor> visitor) {
CefRefPtr<CefURLRequest> CefFrameHostImpl::CreateURLRequest(
CefRefPtr<CefRequest> request,
CefRefPtr<CefURLRequestClient> client) {
if (!request || !client)
if (!request || !client) {
return nullptr;
}
if (!CefTaskRunnerImpl::GetCurrentTaskRunner()) {
NOTREACHED() << "called on invalid thread";
@ -219,15 +222,17 @@ CefRefPtr<CefURLRequest> CefFrameHostImpl::CreateURLRequest(
}
auto browser = GetBrowserHostBase();
if (!browser)
if (!browser) {
return nullptr;
}
auto request_context = browser->request_context();
CefRefPtr<CefBrowserURLRequest> impl =
new CefBrowserURLRequest(this, request, client, request_context);
if (impl->Start())
if (impl->Start()) {
return impl.get();
}
return nullptr;
}
@ -236,8 +241,9 @@ void CefFrameHostImpl::SendProcessMessage(
CefRefPtr<CefProcessMessage> message) {
DCHECK_EQ(PID_RENDERER, target_process);
DCHECK(message && message->IsValid());
if (!message || !message->IsValid())
if (!message || !message->IsValid()) {
return;
}
if (message->GetArgumentList() != nullptr) {
// Invalidate the message object immediately by taking the argument list.
@ -275,8 +281,9 @@ void CefFrameHostImpl::RefreshAttributes() {
CEF_REQUIRE_UIT();
base::AutoLock lock_scope(state_lock_);
if (!render_frame_host_)
if (!render_frame_host_) {
return;
}
url_ = render_frame_host_->GetLastCommittedURL().spec();
// Use the assigned name if it is non-empty. This represents the name property
@ -298,8 +305,9 @@ void CefFrameHostImpl::RefreshAttributes() {
}
void CefFrameHostImpl::LoadRequest(cef::mojom::RequestParamsPtr params) {
if (!url_util::FixupGURL(params->url))
if (!url_util::FixupGURL(params->url)) {
return;
}
SendToRenderFrame(__FUNCTION__,
base::BindOnce(
@ -310,8 +318,9 @@ void CefFrameHostImpl::LoadRequest(cef::mojom::RequestParamsPtr params) {
std::move(params)));
auto browser = GetBrowserHostBase();
if (browser)
if (browser) {
browser->OnSetFocus(FOCUS_SOURCE_NAVIGATION);
}
}
void CefFrameHostImpl::LoadURLWithExtras(const std::string& url,
@ -320,8 +329,9 @@ void CefFrameHostImpl::LoadURLWithExtras(const std::string& url,
const std::string& extra_headers) {
// Only known frame ids or kMainFrameId are supported.
const auto frame_id = GetFrameId();
if (frame_id < CefFrameHostImpl::kMainFrameId)
if (frame_id < CefFrameHostImpl::kMainFrameId) {
return;
}
// Any necessary fixup will occur in LoadRequest.
GURL gurl = url_util::MakeGURL(url, /*fixup=*/false);
@ -378,8 +388,9 @@ void CefFrameHostImpl::SendCommandWithResponse(
void CefFrameHostImpl::SendJavaScript(const std::u16string& jsCode,
const std::string& scriptUrl,
int startLine) {
if (jsCode.empty())
if (jsCode.empty()) {
return;
}
if (startLine <= 0) {
// A value of 0 is v8::Message::kNoLineNumberInfo in V8. There is code in
// V8 that will assert on that value (e.g. V8StackTraceImpl::Frame::Frame
@ -399,8 +410,9 @@ void CefFrameHostImpl::SendJavaScript(const std::u16string& jsCode,
void CefFrameHostImpl::MaybeSendDidStopLoading() {
auto rfh = GetRenderFrameHost();
if (!rfh)
if (!rfh) {
return;
}
// We only want to notify for the highest-level LocalFrame in this frame's
// renderer process subtree. If this frame has a parent in the same process
@ -541,8 +553,9 @@ scoped_refptr<CefBrowserInfo> CefFrameHostImpl::GetBrowserInfo() const {
}
CefRefPtr<CefBrowserHostBase> CefFrameHostImpl::GetBrowserHostBase() const {
if (auto browser_info = GetBrowserInfo())
if (auto browser_info = GetBrowserInfo()) {
return browser_info->browser();
}
return nullptr;
}
@ -650,8 +663,9 @@ void CefFrameHostImpl::FrameAttached(
void CefFrameHostImpl::UpdateDraggableRegions(
absl::optional<std::vector<cef::mojom::DraggableRegionEntryPtr>> regions) {
auto browser = GetBrowserHostBase();
if (!browser)
if (!browser) {
return;
}
std::vector<CefDraggableRegion> draggable_regions;
if (regions) {
@ -679,6 +693,7 @@ std::string CefFrameHostImpl::GetDebugString() const {
void CefExecuteJavaScriptWithUserGestureForTests(CefRefPtr<CefFrame> frame,
const CefString& javascript) {
CefFrameHostImpl* impl = static_cast<CefFrameHostImpl*>(frame.get());
if (impl)
if (impl) {
impl->ExecuteJavaScriptWithUserGestureForTests(javascript);
}
}

View File

@ -85,8 +85,9 @@ class FrameServiceBase : public Interface, public WebContentsObserver {
void DidFinishNavigation(NavigationHandle* navigation_handle) final {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
if (!ShouldCloseOnFinishNavigation())
if (!ShouldCloseOnFinishNavigation()) {
return;
}
if (!navigation_handle->HasCommitted() ||
navigation_handle->IsSameDocument() ||

View File

@ -85,12 +85,14 @@ bool CefImageImpl::IsEmpty() {
bool CefImageImpl::IsSame(CefRefPtr<CefImage> that) {
CefImageImpl* that_impl = static_cast<CefImageImpl*>(that.get());
if (!that_impl)
if (!that_impl) {
return false;
}
// Quick check for the same object.
if (this == that_impl)
if (this == that_impl) {
return true;
}
base::AutoLock lock_scope(lock_);
return image_.AsImageSkia().BackedBySameObjectAs(
@ -108,10 +110,12 @@ bool CefImageImpl::AddBitmap(float scale_factor,
const SkAlphaType at = GetSkAlphaType(alpha_type);
// Make sure the client passed in the expected values.
if (ct != kBGRA_8888_SkColorType && ct != kRGBA_8888_SkColorType)
if (ct != kBGRA_8888_SkColorType && ct != kRGBA_8888_SkColorType) {
return false;
if (pixel_data_size != pixel_width * pixel_height * 4U)
}
if (pixel_data_size != pixel_width * pixel_height * 4U) {
return false;
}
SkBitmap bitmap;
if (!bitmap.tryAllocPixels(
@ -142,8 +146,9 @@ bool CefImageImpl::AddJPEG(float scale_factor,
size_t jpeg_data_size) {
std::unique_ptr<SkBitmap> bitmap(gfx::JPEGCodec::Decode(
static_cast<const unsigned char*>(jpeg_data), jpeg_data_size));
if (!bitmap.get())
if (!bitmap.get()) {
return false;
}
return AddBitmap(scale_factor, *bitmap);
}
@ -179,12 +184,14 @@ bool CefImageImpl::GetRepresentationInfo(float scale_factor,
int& pixel_height) {
base::AutoLock lock_scope(lock_);
gfx::ImageSkia image_skia = image_.AsImageSkia();
if (image_skia.isNull())
if (image_skia.isNull()) {
return false;
}
const gfx::ImageSkiaRep& rep = image_skia.GetRepresentation(scale_factor);
if (rep.is_null())
if (rep.is_null()) {
return false;
}
actual_scale_factor = rep.scale();
pixel_width = rep.GetBitmap().width();
@ -202,8 +209,9 @@ CefRefPtr<CefBinaryValue> CefImageImpl::GetAsBitmap(float scale_factor,
base::AutoLock lock_scope(lock_);
const SkBitmap* bitmap = GetBitmap(scale_factor);
if (!bitmap)
if (!bitmap) {
return nullptr;
}
DCHECK(bitmap->readyToDraw());
@ -216,8 +224,9 @@ CefRefPtr<CefBinaryValue> CefImageImpl::GetAsBitmap(float scale_factor,
bitmap->computeByteSize());
} else {
SkBitmap desired_bitmap;
if (!ConvertBitmap(*bitmap, &desired_bitmap, desired_ct, desired_at))
if (!ConvertBitmap(*bitmap, &desired_bitmap, desired_ct, desired_at)) {
return nullptr;
}
DCHECK(desired_bitmap.readyToDraw());
return CefBinaryValue::Create(desired_bitmap.getPixels(),
desired_bitmap.computeByteSize());
@ -230,12 +239,14 @@ CefRefPtr<CefBinaryValue> CefImageImpl::GetAsPNG(float scale_factor,
int& pixel_height) {
base::AutoLock lock_scope(lock_);
const SkBitmap* bitmap = GetBitmap(scale_factor);
if (!bitmap)
if (!bitmap) {
return nullptr;
}
std::vector<unsigned char> compressed;
if (!WritePNG(*bitmap, &compressed, with_transparency))
if (!WritePNG(*bitmap, &compressed, with_transparency)) {
return nullptr;
}
pixel_width = bitmap->width();
pixel_height = bitmap->height();
@ -249,12 +260,14 @@ CefRefPtr<CefBinaryValue> CefImageImpl::GetAsJPEG(float scale_factor,
int& pixel_height) {
base::AutoLock lock_scope(lock_);
const SkBitmap* bitmap = GetBitmap(scale_factor);
if (!bitmap)
if (!bitmap) {
return nullptr;
}
std::vector<unsigned char> compressed;
if (!WriteJPEG(*bitmap, &compressed, quality))
if (!WriteJPEG(*bitmap, &compressed, quality)) {
return nullptr;
}
pixel_width = bitmap->width();
pixel_height = bitmap->height();
@ -269,8 +282,9 @@ void CefImageImpl::AddBitmaps(int32_t scale_1x_size,
int32_t min_size = std::numeric_limits<int32_t>::max();
for (const SkBitmap& bitmap : bitmaps) {
const int32_t size = std::max(bitmap.width(), bitmap.height());
if (size < min_size)
if (size < min_size) {
min_size = size;
}
}
scale_1x_size = min_size;
}
@ -293,8 +307,9 @@ gfx::ImageSkia CefImageImpl::GetForced1xScaleRepresentation(
const SkBitmap* bitmap = GetBitmap(scale_factor);
gfx::ImageSkia image_skia;
if (bitmap)
if (bitmap) {
image_skia.AddRepresentation(gfx::ImageSkiaRep(*bitmap, 1.0f));
}
return image_skia;
}
@ -315,8 +330,9 @@ bool CefImageImpl::AddBitmap(float scale_factor, const SkBitmap& bitmap) {
// CHECKs in ImageSkiaRep and eventual conversion to N32 at some later point
// in the compositing pipeline.
SkBitmap n32_bitmap;
if (!skia::SkBitmapToN32OpaqueOrPremul(bitmap, &n32_bitmap))
if (!skia::SkBitmapToN32OpaqueOrPremul(bitmap, &n32_bitmap)) {
return false;
}
gfx::ImageSkiaRep skia_rep(n32_bitmap, scale_factor);
base::AutoLock lock_scope(lock_);
@ -331,12 +347,14 @@ bool CefImageImpl::AddBitmap(float scale_factor, const SkBitmap& bitmap) {
const SkBitmap* CefImageImpl::GetBitmap(float scale_factor) const {
lock_.AssertAcquired();
gfx::ImageSkia image_skia = image_.AsImageSkia();
if (image_skia.isNull())
if (image_skia.isNull()) {
return nullptr;
}
const gfx::ImageSkiaRep& rep = image_skia.GetRepresentation(scale_factor);
if (rep.is_null())
if (rep.is_null()) {
return nullptr;
}
return &rep.GetBitmap();
}
@ -353,8 +371,9 @@ bool CefImageImpl::ConvertBitmap(const SkBitmap& src_bitmap,
SkImageInfo target_info = SkImageInfo::Make(
src_bitmap.width(), src_bitmap.height(), target_ct, target_at);
if (!target_bitmap->tryAllocPixels(target_info))
if (!target_bitmap->tryAllocPixels(target_info)) {
return false;
}
if (!src_bitmap.readPixels(target_info, target_bitmap->getPixels(),
target_bitmap->rowBytes(), 0, 0)) {

View File

@ -72,8 +72,9 @@ void CefIOThreadState::RegisterSchemeHandlerFactory(
} else {
// Remove the existing factory, if any.
auto it = scheme_handler_factory_map_.find(key);
if (it != scheme_handler_factory_map_.end())
if (it != scheme_handler_factory_map_.end()) {
scheme_handler_factory_map_.erase(it);
}
}
}
@ -90,8 +91,9 @@ CefRefPtr<CefSchemeHandlerFactory> CefIOThreadState::GetSchemeHandlerFactory(
const GURL& url) {
CEF_REQUIRE_IOT();
if (scheme_handler_factory_map_.empty())
if (scheme_handler_factory_map_.empty()) {
return nullptr;
}
const std::string& scheme_lower = url.scheme();
const std::string& domain_lower =
@ -104,15 +106,17 @@ CefRefPtr<CefSchemeHandlerFactory> CefIOThreadState::GetSchemeHandlerFactory(
// Try for a match with hostname first.
const auto it = scheme_handler_factory_map_.find(
std::make_pair(scheme_lower, domain_lower));
if (it != scheme_handler_factory_map_.end())
if (it != scheme_handler_factory_map_.end()) {
return it->second;
}
}
// Try for a match with no specified hostname.
const auto it = scheme_handler_factory_map_.find(
std::make_pair(scheme_lower, std::string()));
if (it != scheme_handler_factory_map_.end())
if (it != scheme_handler_factory_map_.end()) {
return it->second;
}
return nullptr;
}

View File

@ -238,8 +238,9 @@ bool CefJavaScriptDialogManager::HandleJavaScriptDialog(
return true;
}
if (!CanUseChromeDialogs())
if (!CanUseChromeDialogs()) {
return true;
}
auto manager = GetTabModalDialogManager(web_contents);
return manager->HandleJavaScriptDialog(web_contents, accept, prompt_override);
@ -262,11 +263,13 @@ void CefJavaScriptDialogManager::CancelDialogs(
}
// Null when called from DialogClosed() or Destroy().
if (!web_contents)
if (!web_contents) {
return;
}
if (!CanUseChromeDialogs())
if (!CanUseChromeDialogs()) {
return;
}
auto manager = GetTabModalDialogManager(web_contents);
manager->CancelDialogs(web_contents, reset_state);

View File

@ -134,8 +134,9 @@ class CefUIThread : public base::PlatformThread::Delegate {
}
// Can't join if the |thread_| is either already gone or is non-joinable.
if (thread_.is_null())
if (thread_.is_null()) {
return;
}
base::PlatformThread::Join(thread_);
thread_ = base::PlatformThreadHandle();
@ -283,8 +284,9 @@ void CefMainRunner::RunMessageLoop() {
void CefMainRunner::QuitMessageLoop() {
if (!quit_when_idle_callback_.is_null()) {
if (main_delegate_->HandleMainMessageLoopQuit())
if (main_delegate_->HandleMainMessageLoopQuit()) {
return;
}
std::move(quit_when_idle_callback_).Run();
}
}
@ -301,15 +303,17 @@ int CefMainRunner::RunAsHelperProcess(const CefMainArgs& args,
#endif
// Wait for the debugger as early in process initialization as possible.
if (command_line.HasSwitch(switches::kWaitForDebugger))
if (command_line.HasSwitch(switches::kWaitForDebugger)) {
base::debug::WaitForDebugger(60, true);
}
// If no process type is specified then it represents the browser process and
// we do nothing.
const std::string& process_type =
command_line.GetSwitchValueASCII(switches::kProcessType);
if (process_type.empty())
if (process_type.empty()) {
return -1;
}
auto runtime_type = command_line.HasSwitch(switches::kEnableChromeRuntime)
? RuntimeType::CHROME
@ -436,8 +440,9 @@ int CefMainRunner::RunMainProcess(
// loop.
int exit_code =
browser_runner_->Initialize(std::move(main_function_params));
if (exit_code >= 0)
if (exit_code >= 0) {
return exit_code;
}
} else {
// Running on the separate UI thread.
DCHECK(ui_thread_);
@ -489,8 +494,9 @@ void CefMainRunner::FinishShutdownOnUIThread(
std::move(shutdown_on_ui_thread).Run();
main_delegate_->AfterUIThreadShutdown();
if (uithread_shutdown_event)
if (uithread_shutdown_event) {
uithread_shutdown_event->Signal();
}
}
void CefMainRunner::FinalizeShutdown(base::OnceClosure finalize_shutdown) {

View File

@ -172,10 +172,12 @@ class CefMediaAccessQuery {
*stream_devices_set->stream_devices[0];
// At most one audio device and one video device can be used in a stream.
if (!audio_devices.empty())
if (!audio_devices.empty()) {
devices.audio_device = audio_devices.front();
if (!video_devices.empty())
}
if (!video_devices.empty()) {
devices.video_device = video_devices.front();
}
return stream_devices_set;
}
@ -326,8 +328,9 @@ content::MediaResponseCallback RequestMediaAccessPermission(
auto frame =
browser->GetFrameForGlobalId(content::GlobalRenderFrameHostId(
request.render_process_id, request.render_frame_id));
if (!frame)
if (!frame) {
frame = browser->GetMainFrame();
}
handled = handler->OnRequestMediaAccessPermission(
browser, frame, request.security_origin.spec(), requested_permissions,
callbackImpl.get());

View File

@ -18,8 +18,9 @@ namespace {
const blink::MediaStreamDevice* FindDefaultDeviceWithId(
const blink::MediaStreamDevices& devices,
const std::string& device_id) {
if (devices.empty())
if (devices.empty()) {
return nullptr;
}
blink::MediaStreamDevices::const_iterator iter = devices.begin();
for (; iter != devices.end(); ++iter) {
@ -82,15 +83,17 @@ void CefMediaCaptureDevicesDispatcher::GetRequestedDevice(
const blink::MediaStreamDevices& audio_devices = GetAudioCaptureDevices();
const blink::MediaStreamDevice* const device =
FindDefaultDeviceWithId(audio_devices, requested_device_id);
if (device)
if (device) {
devices->push_back(*device);
}
}
if (video) {
const blink::MediaStreamDevices& video_devices = GetVideoCaptureDevices();
const blink::MediaStreamDevice* const device =
FindDefaultDeviceWithId(video_devices, requested_device_id);
if (device)
if (device) {
devices->push_back(*device);
}
}
}

View File

@ -70,8 +70,9 @@ void CefMediaRouteImpl::Terminate() {
}
auto browser_context = GetBrowserContext(browser_context_getter_);
if (!browser_context)
if (!browser_context) {
return;
}
browser_context->GetMediaRouterManager()->TerminateRoute(
route_.media_route_id());
@ -79,8 +80,9 @@ void CefMediaRouteImpl::Terminate() {
void CefMediaRouteImpl::SendRouteMessageInternal(std::string message) {
auto browser_context = GetBrowserContext(browser_context_getter_);
if (!browser_context)
if (!browser_context) {
return;
}
browser_context->GetMediaRouterManager()->SendRouteMessage(
route_.media_route_id(), message);

View File

@ -38,12 +38,14 @@ class CefRegistrationImpl : public CefRegistration,
CEF_REQUIRE_UIT();
// May be null if OnMediaRouterDestroyed was called.
if (browser_context_getter_.is_null())
if (browser_context_getter_.is_null()) {
return;
}
auto browser_context = GetBrowserContext(browser_context_getter_);
if (!browser_context)
if (!browser_context) {
return;
}
browser_context->GetMediaRouterManager()->RemoveObserver(this);
}
@ -55,8 +57,9 @@ class CefRegistrationImpl : public CefRegistration,
browser_context_getter_ = browser_context_getter;
auto browser_context = GetBrowserContext(browser_context_getter_);
if (!browser_context)
if (!browser_context) {
return;
}
browser_context->GetMediaRouterManager()->AddObserver(this);
}
@ -165,8 +168,9 @@ void CefMediaRouterImpl::Initialize(
CefRefPtr<CefRegistration> CefMediaRouterImpl::AddObserver(
CefRefPtr<CefMediaObserver> observer) {
if (!observer)
if (!observer) {
return nullptr;
}
CefRefPtr<CefRegistrationImpl> registration =
new CefRegistrationImpl(observer);
StoreOrTriggerInitCallback(base::BindOnce(
@ -175,8 +179,9 @@ CefRefPtr<CefRegistration> CefMediaRouterImpl::AddObserver(
}
CefRefPtr<CefMediaSource> CefMediaRouterImpl::GetSource(const CefString& urn) {
if (urn.empty())
if (urn.empty()) {
return nullptr;
}
// Check for a valid URL and supported Cast/DIAL schemes.
GURL presentation_url(urn.ToString());
@ -222,8 +227,9 @@ void CefMediaRouterImpl::NotifyCurrentSinksInternal() {
DCHECK(ValidContext());
auto browser_context = GetBrowserContext(browser_context_getter_);
if (!browser_context)
if (!browser_context) {
return;
}
browser_context->GetMediaRouterManager()->NotifyCurrentSinks();
}
@ -268,8 +274,9 @@ void CefMediaRouterImpl::NotifyCurrentRoutesInternal() {
DCHECK(ValidContext());
auto browser_context = GetBrowserContext(browser_context_getter_);
if (!browser_context)
if (!browser_context) {
return;
}
browser_context->GetMediaRouterManager()->NotifyCurrentRoutes();
}
@ -284,8 +291,9 @@ void CefMediaRouterImpl::CreateRouteCallback(
<< result.result_code() << ")";
}
if (!callback)
if (!callback) {
return;
}
CefRefPtr<CefMediaRoute> route;
if (result.result_code() == media_router::mojom::RouteRequestResultCode::OK &&

View File

@ -283,14 +283,16 @@ void CefMediaRouterManager::CreateRouteState(
CefMediaRouterManager::RouteState* CefMediaRouterManager::GetRouteState(
const media_router::MediaRoute::Id& route_id) {
const auto it = route_state_map_.find(route_id);
if (it != route_state_map_.end())
if (it != route_state_map_.end()) {
return it->second.get();
}
return nullptr;
}
void CefMediaRouterManager::RemoveRouteState(
const media_router::MediaRoute::Id& route_id) {
auto it = route_state_map_.find(route_id);
if (it != route_state_map_.end())
if (it != route_state_map_.end()) {
route_state_map_.erase(it);
}
}

View File

@ -35,8 +35,9 @@ void GetSinkInternalAndContinue(
for (auto service : services) {
sink_internal = service->GetSinkById(sink_id);
if (sink_internal)
if (sink_internal) {
break;
}
}
if (sink_internal) {
@ -131,10 +132,12 @@ bool CefMediaSinkImpl::IsDialSink() {
bool CefMediaSinkImpl::IsCompatibleWith(CefRefPtr<CefMediaSource> source) {
if (source) {
if (IsCastSink())
if (IsCastSink()) {
return source->IsCastSource();
if (IsDialSink())
}
if (IsDialSink()) {
return source->IsDialSource();
}
}
return false;
}

View File

@ -87,10 +87,12 @@ void CefMediaStreamRegistrar::NotifyMediaStreamChange() {
bool audio = false;
for (const auto& media_stream : registered_streams_) {
const auto& info = media_stream.second;
if (!video)
if (!video) {
video = info.video;
if (!audio)
}
if (!audio) {
audio = info.audio;
}
}
if (audio == last_notified_info_.audio &&

View File

@ -109,13 +109,15 @@ CefMenuManager::~CefMenuManager() {
void CefMenuManager::Destroy() {
CancelContextMenu();
if (runner_)
if (runner_) {
runner_.reset(nullptr);
}
}
bool CefMenuManager::IsShowingContextMenu() {
if (!web_contents())
if (!web_contents()) {
return false;
}
return web_contents()->IsShowingContextMenu();
}
@ -128,8 +130,9 @@ bool CefMenuManager::CreateContextMenu(
// the second mouse event arrives. In this case, |HandleContextMenu()| will
// get called multiple times - if so, don't create another context menu.
// TODO(asvitkine): Fix the renderer so that it doesn't do this.
if (IsShowingContextMenu())
if (IsShowingContextMenu()) {
return true;
}
params_ = params;
model_->Clear();
@ -188,8 +191,9 @@ bool CefMenuManager::CreateContextMenu(
}
}
if (custom_menu)
if (custom_menu) {
return true;
}
if (!runner_ || !runner_->RunContextMenu(browser_, model_.get(), params_)) {
LOG(ERROR) << "Default context menu implementation is not available; "
@ -201,10 +205,11 @@ bool CefMenuManager::CreateContextMenu(
void CefMenuManager::CancelContextMenu() {
if (IsShowingContextMenu()) {
if (custom_menu_callback_)
if (custom_menu_callback_) {
custom_menu_callback_->Cancel();
else if (runner_)
} else if (runner_) {
runner_->CancelContextMenu();
}
}
}
@ -227,8 +232,9 @@ void CefMenuManager::ExecuteCommand(CefRefPtr<CefMenuModelImpl> source,
std::ignore = paramsPtr->Detach(nullptr);
DCHECK(paramsPtr->HasOneRef());
if (handled)
if (handled) {
return;
}
}
}
@ -238,15 +244,18 @@ void CefMenuManager::ExecuteCommand(CefRefPtr<CefMenuModelImpl> source,
void CefMenuManager::MenuWillShow(CefRefPtr<CefMenuModelImpl> source) {
// May be called for sub-menus as well.
if (source.get() != model_.get())
if (source.get() != model_.get()) {
return;
}
if (!web_contents())
if (!web_contents()) {
return;
}
// May be called multiple times.
if (IsShowingContextMenu())
if (IsShowingContextMenu()) {
return;
}
// Notify the host before showing the context menu.
web_contents()->SetShowingContextMenu(true);
@ -254,11 +263,13 @@ void CefMenuManager::MenuWillShow(CefRefPtr<CefMenuModelImpl> source) {
void CefMenuManager::MenuClosed(CefRefPtr<CefMenuModelImpl> source) {
// May be called for sub-menus as well.
if (source.get() != model_.get())
if (source.get() != model_.get()) {
return;
}
if (!web_contents())
if (!web_contents()) {
return;
}
DCHECK(IsShowingContextMenu());
@ -278,8 +289,9 @@ void CefMenuManager::MenuClosed(CefRefPtr<CefMenuModelImpl> source) {
bool CefMenuManager::FormatLabel(CefRefPtr<CefMenuModelImpl> source,
std::u16string& label) {
if (!runner_)
if (!runner_) {
return false;
}
return runner_->FormatLabel(label);
}
@ -287,8 +299,9 @@ void CefMenuManager::ExecuteCommandCallback(int command_id,
cef_event_flags_t event_flags) {
DCHECK(IsShowingContextMenu());
DCHECK(custom_menu_callback_);
if (command_id != kInvalidCommandId)
if (command_id != kInvalidCommandId) {
ExecuteCommand(model_, command_id, event_flags);
}
MenuClosed(model_);
custom_menu_callback_ = nullptr;
}
@ -320,20 +333,27 @@ void CefMenuManager::CreateDefaultModel() {
model_->AddItem(MENU_ID_SELECT_ALL,
GetLabel(IDS_CONTENT_CONTEXT_SELECTALL));
if (!(params_.edit_flags & CM_EDITFLAG_CAN_UNDO))
if (!(params_.edit_flags & CM_EDITFLAG_CAN_UNDO)) {
model_->SetEnabled(MENU_ID_UNDO, false);
if (!(params_.edit_flags & CM_EDITFLAG_CAN_REDO))
}
if (!(params_.edit_flags & CM_EDITFLAG_CAN_REDO)) {
model_->SetEnabled(MENU_ID_REDO, false);
if (!(params_.edit_flags & CM_EDITFLAG_CAN_CUT))
}
if (!(params_.edit_flags & CM_EDITFLAG_CAN_CUT)) {
model_->SetEnabled(MENU_ID_CUT, false);
if (!(params_.edit_flags & CM_EDITFLAG_CAN_COPY))
}
if (!(params_.edit_flags & CM_EDITFLAG_CAN_COPY)) {
model_->SetEnabled(MENU_ID_COPY, false);
if (!(params_.edit_flags & CM_EDITFLAG_CAN_PASTE))
}
if (!(params_.edit_flags & CM_EDITFLAG_CAN_PASTE)) {
model_->SetEnabled(MENU_ID_PASTE, false);
if (!(params_.edit_flags & CM_EDITFLAG_CAN_DELETE))
}
if (!(params_.edit_flags & CM_EDITFLAG_CAN_DELETE)) {
model_->SetEnabled(MENU_ID_DELETE, false);
if (!(params_.edit_flags & CM_EDITFLAG_CAN_SELECT_ALL))
}
if (!(params_.edit_flags & CM_EDITFLAG_CAN_SELECT_ALL)) {
model_->SetEnabled(MENU_ID_SELECT_ALL, false);
}
if (!params_.misspelled_word.empty()) {
// Always add a separator before the list of dictionary suggestions or
@ -374,10 +394,12 @@ void CefMenuManager::CreateDefaultModel() {
model_->AddItem(MENU_ID_VIEW_SOURCE,
GetLabel(IDS_CONTENT_CONTEXT_VIEWPAGESOURCE));
if (!browser_->CanGoBack())
if (!browser_->CanGoBack()) {
model_->SetEnabled(MENU_ID_BACK, false);
if (!browser_->CanGoForward())
}
if (!browser_->CanGoForward()) {
model_->SetEnabled(MENU_ID_FORWARD, false);
}
}
}
@ -467,16 +489,18 @@ void CefMenuManager::ExecuteDefaultCommand(int command_id) {
bool CefMenuManager::IsCustomContextMenuCommand(int command_id) {
// Verify that the command ID is in the correct range.
if (command_id < MENU_ID_CUSTOM_FIRST || command_id > MENU_ID_CUSTOM_LAST)
if (command_id < MENU_ID_CUSTOM_FIRST || command_id > MENU_ID_CUSTOM_LAST) {
return false;
}
command_id -= MENU_ID_CUSTOM_FIRST;
// Verify that the specific command ID was passed from the renderer process.
if (!params_.custom_items.empty()) {
for (size_t i = 0; i < params_.custom_items.size(); ++i) {
if (static_cast<int>(params_.custom_items[i]->action) == command_id)
if (static_cast<int>(params_.custom_items[i]->action) == command_id) {
return true;
}
}
}
return false;

View File

@ -86,12 +86,15 @@ class CefSimpleMenuModel : public ui::MenuModel {
if (impl_->GetAcceleratorAt(index, key_code, shift_pressed, ctrl_pressed,
alt_pressed)) {
int modifiers = 0;
if (shift_pressed)
if (shift_pressed) {
modifiers |= ui::EF_SHIFT_DOWN;
if (ctrl_pressed)
}
if (ctrl_pressed) {
modifiers |= ui::EF_CONTROL_DOWN;
if (alt_pressed)
}
if (alt_pressed) {
modifiers |= ui::EF_ALT_DOWN;
}
*accelerator =
ui::Accelerator(static_cast<ui::KeyboardCode>(key_code), modifiers);
@ -132,8 +135,9 @@ class CefSimpleMenuModel : public ui::MenuModel {
MenuModel* GetSubmenuModelAt(size_t index) const override {
CefRefPtr<CefMenuModel> submenu = impl_->GetSubMenuAt(index);
if (submenu.get())
if (submenu.get()) {
return static_cast<CefMenuModelImpl*>(submenu.get())->model();
}
return nullptr;
}
@ -193,8 +197,9 @@ CefRefPtr<CefMenuModel> CefMenuModel::CreateMenuModel(
CefRefPtr<CefMenuModelDelegate> delegate) {
CEF_REQUIRE_UIT_RETURN(nullptr);
DCHECK(delegate);
if (!delegate)
if (!delegate) {
return nullptr;
}
CefRefPtr<CefMenuModelImpl> menu_model =
new CefMenuModelImpl(nullptr, delegate, false);
@ -250,29 +255,33 @@ CefMenuModelImpl::CefMenuModelImpl(
CefMenuModelImpl::~CefMenuModelImpl() {}
bool CefMenuModelImpl::IsSubMenu() {
if (!VerifyContext())
if (!VerifyContext()) {
return false;
}
return is_submenu_;
}
bool CefMenuModelImpl::Clear() {
if (!VerifyContext())
if (!VerifyContext()) {
return false;
}
items_.clear();
return true;
}
size_t CefMenuModelImpl::GetCount() {
if (!VerifyContext())
if (!VerifyContext()) {
return 0;
}
return items_.size();
}
bool CefMenuModelImpl::AddSeparator() {
if (!VerifyContext())
if (!VerifyContext()) {
return false;
}
AppendItem(
Item(MENUITEMTYPE_SEPARATOR, kSeparatorId, CefString(), kInvalidGroupId));
@ -280,16 +289,18 @@ bool CefMenuModelImpl::AddSeparator() {
}
bool CefMenuModelImpl::AddItem(int command_id, const CefString& label) {
if (!VerifyContext())
if (!VerifyContext()) {
return false;
}
AppendItem(Item(MENUITEMTYPE_COMMAND, command_id, label, kInvalidGroupId));
return true;
}
bool CefMenuModelImpl::AddCheckItem(int command_id, const CefString& label) {
if (!VerifyContext())
if (!VerifyContext()) {
return false;
}
AppendItem(Item(MENUITEMTYPE_CHECK, command_id, label, kInvalidGroupId));
return true;
@ -298,8 +309,9 @@ bool CefMenuModelImpl::AddCheckItem(int command_id, const CefString& label) {
bool CefMenuModelImpl::AddRadioItem(int command_id,
const CefString& label,
int group_id) {
if (!VerifyContext())
if (!VerifyContext()) {
return false;
}
AppendItem(Item(MENUITEMTYPE_RADIO, command_id, label, group_id));
return true;
@ -307,8 +319,9 @@ bool CefMenuModelImpl::AddRadioItem(int command_id,
CefRefPtr<CefMenuModel> CefMenuModelImpl::AddSubMenu(int command_id,
const CefString& label) {
if (!VerifyContext())
if (!VerifyContext()) {
return nullptr;
}
Item item(MENUITEMTYPE_SUBMENU, command_id, label, kInvalidGroupId);
item.submenu_ = new CefMenuModelImpl(delegate_, menu_model_delegate_, true);
@ -317,8 +330,9 @@ CefRefPtr<CefMenuModel> CefMenuModelImpl::AddSubMenu(int command_id,
}
bool CefMenuModelImpl::InsertSeparatorAt(size_t index) {
if (!VerifyContext())
if (!VerifyContext()) {
return false;
}
InsertItemAt(
Item(MENUITEMTYPE_SEPARATOR, kSeparatorId, CefString(), kInvalidGroupId),
@ -329,8 +343,9 @@ bool CefMenuModelImpl::InsertSeparatorAt(size_t index) {
bool CefMenuModelImpl::InsertItemAt(size_t index,
int command_id,
const CefString& label) {
if (!VerifyContext())
if (!VerifyContext()) {
return false;
}
InsertItemAt(Item(MENUITEMTYPE_COMMAND, command_id, label, kInvalidGroupId),
index);
@ -340,8 +355,9 @@ bool CefMenuModelImpl::InsertItemAt(size_t index,
bool CefMenuModelImpl::InsertCheckItemAt(size_t index,
int command_id,
const CefString& label) {
if (!VerifyContext())
if (!VerifyContext()) {
return false;
}
InsertItemAt(Item(MENUITEMTYPE_CHECK, command_id, label, kInvalidGroupId),
index);
@ -352,8 +368,9 @@ bool CefMenuModelImpl::InsertRadioItemAt(size_t index,
int command_id,
const CefString& label,
int group_id) {
if (!VerifyContext())
if (!VerifyContext()) {
return false;
}
InsertItemAt(Item(MENUITEMTYPE_RADIO, command_id, label, group_id), index);
return true;
@ -363,8 +380,9 @@ CefRefPtr<CefMenuModel> CefMenuModelImpl::InsertSubMenuAt(
size_t index,
int command_id,
const CefString& label) {
if (!VerifyContext())
if (!VerifyContext()) {
return nullptr;
}
Item item(MENUITEMTYPE_SUBMENU, command_id, label, kInvalidGroupId);
item.submenu_ = new CefMenuModelImpl(delegate_, menu_model_delegate_, true);
@ -377,8 +395,9 @@ bool CefMenuModelImpl::Remove(int command_id) {
}
bool CefMenuModelImpl::RemoveAt(size_t index) {
if (!VerifyContext())
if (!VerifyContext()) {
return false;
}
if (index < items_.size()) {
items_.erase(items_.begin() + index);
@ -388,8 +407,9 @@ bool CefMenuModelImpl::RemoveAt(size_t index) {
}
int CefMenuModelImpl::GetIndexOf(int command_id) {
if (!VerifyContext())
if (!VerifyContext()) {
return kInvalidIndex;
}
for (ItemVector::iterator i = items_.begin(); i != items_.end(); ++i) {
if ((*i).command_id_ == command_id) {
@ -400,17 +420,20 @@ int CefMenuModelImpl::GetIndexOf(int command_id) {
}
int CefMenuModelImpl::GetCommandIdAt(size_t index) {
if (!VerifyContext())
if (!VerifyContext()) {
return kInvalidCommandId;
}
if (index < items_.size())
if (index < items_.size()) {
return items_[index].command_id_;
}
return kInvalidCommandId;
}
bool CefMenuModelImpl::SetCommandIdAt(size_t index, int command_id) {
if (!VerifyContext())
if (!VerifyContext()) {
return false;
}
if (index < items_.size()) {
items_[index].command_id_ = command_id;
@ -424,11 +447,13 @@ CefString CefMenuModelImpl::GetLabel(int command_id) {
}
CefString CefMenuModelImpl::GetLabelAt(size_t index) {
if (!VerifyContext())
if (!VerifyContext()) {
return CefString();
}
if (index < items_.size())
if (index < items_.size()) {
return items_[index].label_;
}
return CefString();
}
@ -437,8 +462,9 @@ bool CefMenuModelImpl::SetLabel(int command_id, const CefString& label) {
}
bool CefMenuModelImpl::SetLabelAt(size_t index, const CefString& label) {
if (!VerifyContext())
if (!VerifyContext()) {
return false;
}
if (index < items_.size()) {
items_[index].label_ = label;
@ -452,11 +478,13 @@ CefMenuModelImpl::MenuItemType CefMenuModelImpl::GetType(int command_id) {
}
CefMenuModelImpl::MenuItemType CefMenuModelImpl::GetTypeAt(size_t index) {
if (!VerifyContext())
if (!VerifyContext()) {
return MENUITEMTYPE_NONE;
}
if (index < items_.size())
if (index < items_.size()) {
return items_[index].type_;
}
return MENUITEMTYPE_NONE;
}
@ -465,11 +493,13 @@ int CefMenuModelImpl::GetGroupId(int command_id) {
}
int CefMenuModelImpl::GetGroupIdAt(size_t index) {
if (!VerifyContext())
if (!VerifyContext()) {
return kInvalidGroupId;
}
if (index < items_.size())
if (index < items_.size()) {
return items_[index].group_id_;
}
return kInvalidGroupId;
}
@ -478,8 +508,9 @@ bool CefMenuModelImpl::SetGroupId(int command_id, int group_id) {
}
bool CefMenuModelImpl::SetGroupIdAt(size_t index, int group_id) {
if (!VerifyContext())
if (!VerifyContext()) {
return false;
}
if (index < items_.size()) {
items_[index].group_id_ = group_id;
@ -493,11 +524,13 @@ CefRefPtr<CefMenuModel> CefMenuModelImpl::GetSubMenu(int command_id) {
}
CefRefPtr<CefMenuModel> CefMenuModelImpl::GetSubMenuAt(size_t index) {
if (!VerifyContext())
if (!VerifyContext()) {
return nullptr;
}
if (index < items_.size())
if (index < items_.size()) {
return items_[index].submenu_.get();
}
return nullptr;
}
@ -506,11 +539,13 @@ bool CefMenuModelImpl::IsVisible(int command_id) {
}
bool CefMenuModelImpl::IsVisibleAt(size_t index) {
if (!VerifyContext())
if (!VerifyContext()) {
return false;
}
if (index < items_.size())
if (index < items_.size()) {
return items_[index].visible_;
}
return false;
}
@ -519,8 +554,9 @@ bool CefMenuModelImpl::SetVisible(int command_id, bool visible) {
}
bool CefMenuModelImpl::SetVisibleAt(size_t index, bool visible) {
if (!VerifyContext())
if (!VerifyContext()) {
return false;
}
if (index < items_.size()) {
items_[index].visible_ = visible;
@ -534,11 +570,13 @@ bool CefMenuModelImpl::IsEnabled(int command_id) {
}
bool CefMenuModelImpl::IsEnabledAt(size_t index) {
if (!VerifyContext())
if (!VerifyContext()) {
return false;
}
if (index < items_.size())
if (index < items_.size()) {
return items_[index].enabled_;
}
return false;
}
@ -547,8 +585,9 @@ bool CefMenuModelImpl::SetEnabled(int command_id, bool enabled) {
}
bool CefMenuModelImpl::SetEnabledAt(size_t index, bool enabled) {
if (!VerifyContext())
if (!VerifyContext()) {
return false;
}
if (index < items_.size()) {
items_[index].enabled_ = enabled;
@ -562,11 +601,13 @@ bool CefMenuModelImpl::IsChecked(int command_id) {
}
bool CefMenuModelImpl::IsCheckedAt(size_t index) {
if (!VerifyContext())
if (!VerifyContext()) {
return false;
}
if (index < items_.size())
if (index < items_.size()) {
return items_[index].checked_;
}
return false;
}
@ -575,8 +616,9 @@ bool CefMenuModelImpl::SetChecked(int command_id, bool checked) {
}
bool CefMenuModelImpl::SetCheckedAt(size_t index, bool checked) {
if (!VerifyContext())
if (!VerifyContext()) {
return false;
}
if (index < items_.size()) {
items_[index].checked_ = checked;
@ -590,11 +632,13 @@ bool CefMenuModelImpl::HasAccelerator(int command_id) {
}
bool CefMenuModelImpl::HasAcceleratorAt(size_t index) {
if (!VerifyContext())
if (!VerifyContext()) {
return false;
}
if (index < items_.size())
if (index < items_.size()) {
return items_[index].has_accelerator_;
}
return false;
}
@ -612,8 +656,9 @@ bool CefMenuModelImpl::SetAcceleratorAt(size_t index,
bool shift_pressed,
bool ctrl_pressed,
bool alt_pressed) {
if (!VerifyContext())
if (!VerifyContext()) {
return false;
}
if (index < items_.size()) {
Item& item = items_[index];
@ -632,8 +677,9 @@ bool CefMenuModelImpl::RemoveAccelerator(int command_id) {
}
bool CefMenuModelImpl::RemoveAcceleratorAt(size_t index) {
if (!VerifyContext())
if (!VerifyContext()) {
return false;
}
if (index < items_.size()) {
Item& item = items_[index];
@ -663,8 +709,9 @@ bool CefMenuModelImpl::GetAcceleratorAt(size_t index,
bool& shift_pressed,
bool& ctrl_pressed,
bool& alt_pressed) {
if (!VerifyContext())
if (!VerifyContext()) {
return false;
}
if (index < items_.size()) {
const Item& item = items_[index];
@ -688,11 +735,13 @@ bool CefMenuModelImpl::SetColor(int command_id,
bool CefMenuModelImpl::SetColorAt(int index,
cef_menu_color_type_t color_type,
cef_color_t color) {
if (!VerifyContext())
if (!VerifyContext()) {
return false;
}
if (color_type < 0 || color_type >= CEF_MENU_COLOR_COUNT)
if (color_type < 0 || color_type >= CEF_MENU_COLOR_COUNT) {
return false;
}
if (index == kDefaultIndex) {
default_colors_[color_type] = color;
@ -717,11 +766,13 @@ bool CefMenuModelImpl::GetColor(int command_id,
bool CefMenuModelImpl::GetColorAt(int index,
cef_menu_color_type_t color_type,
cef_color_t& color) {
if (!VerifyContext())
if (!VerifyContext()) {
return false;
}
if (color_type < 0 || color_type >= CEF_MENU_COLOR_COUNT)
if (color_type < 0 || color_type >= CEF_MENU_COLOR_COUNT) {
return false;
}
if (index == kDefaultIndex) {
color = default_colors_[color_type];
@ -742,8 +793,9 @@ bool CefMenuModelImpl::SetFontList(int command_id, const CefString& font_list) {
}
bool CefMenuModelImpl::SetFontListAt(int index, const CefString& font_list) {
if (!VerifyContext())
if (!VerifyContext()) {
return false;
}
if (index == kDefaultIndex) {
if (font_list.empty()) {
@ -770,19 +822,23 @@ bool CefMenuModelImpl::SetFontListAt(int index, const CefString& font_list) {
void CefMenuModelImpl::ActivatedAt(size_t index,
cef_event_flags_t event_flags) {
if (!VerifyContext())
if (!VerifyContext()) {
return;
}
const int command_id = GetCommandIdAt(index);
if (delegate_)
if (delegate_) {
delegate_->ExecuteCommand(this, command_id, event_flags);
if (menu_model_delegate_)
}
if (menu_model_delegate_) {
menu_model_delegate_->ExecuteCommand(this, command_id, event_flags);
}
}
void CefMenuModelImpl::MouseOutsideMenu(const gfx::Point& screen_point) {
if (!VerifyContext())
if (!VerifyContext()) {
return;
}
// Allow the callstack to unwind before notifying the delegate since it may
// result in the menu being destroyed.
@ -792,8 +848,9 @@ void CefMenuModelImpl::MouseOutsideMenu(const gfx::Point& screen_point) {
}
void CefMenuModelImpl::UnhandledOpenSubmenu(bool is_rtl) {
if (!VerifyContext())
if (!VerifyContext()) {
return;
}
// Allow the callstack to unwind before notifying the delegate since it may
// result in the menu being destroyed.
@ -803,8 +860,9 @@ void CefMenuModelImpl::UnhandledOpenSubmenu(bool is_rtl) {
}
void CefMenuModelImpl::UnhandledCloseSubmenu(bool is_rtl) {
if (!VerifyContext())
if (!VerifyContext()) {
return;
}
// Allow the callstack to unwind before notifying the delegate since it may
// result in the menu being destroyed.
@ -865,21 +923,26 @@ bool CefMenuModelImpl::GetBackgroundColor(size_t index,
}
void CefMenuModelImpl::MenuWillShow() {
if (!VerifyContext())
if (!VerifyContext()) {
return;
}
if (delegate_)
if (delegate_) {
delegate_->MenuWillShow(this);
if (menu_model_delegate_)
}
if (menu_model_delegate_) {
menu_model_delegate_->MenuWillShow(this);
}
}
void CefMenuModelImpl::MenuWillClose() {
if (!VerifyContext())
if (!VerifyContext()) {
return;
}
if (!auto_notify_menu_closed_)
if (!auto_notify_menu_closed_) {
return;
}
// Due to how menus work on the different platforms, ActivatedAt will be
// called after this. It's more convenient for the delegate to be called
@ -890,12 +953,14 @@ void CefMenuModelImpl::MenuWillClose() {
std::u16string CefMenuModelImpl::GetFormattedLabelAt(size_t index) {
std::u16string label = GetLabelAt(index).ToString16();
if (delegate_)
if (delegate_) {
delegate_->FormatLabel(this, label);
}
if (menu_model_delegate_) {
CefString new_label = label;
if (menu_model_delegate_->FormatLabel(this, new_label))
if (menu_model_delegate_->FormatLabel(this, new_label)) {
label = new_label;
}
}
return label;
}
@ -903,26 +968,31 @@ std::u16string CefMenuModelImpl::GetFormattedLabelAt(size_t index) {
const gfx::FontList* CefMenuModelImpl::GetLabelFontListAt(size_t index) const {
if (index < items_.size()) {
const Item& item = items_[index];
if (item.has_font_list_)
if (item.has_font_list_) {
return &item.font_list_;
}
}
if (has_default_font_list_)
if (has_default_font_list_) {
return &default_font_list_;
}
return nullptr;
}
bool CefMenuModelImpl::VerifyRefCount() {
if (!VerifyContext())
if (!VerifyContext()) {
return false;
}
if (!HasOneRef())
if (!HasOneRef()) {
return false;
}
for (ItemVector::iterator i = items_.begin(); i != items_.end(); ++i) {
if ((*i).submenu_.get()) {
if (!(*i).submenu_->VerifyRefCount())
if (!(*i).submenu_->VerifyRefCount()) {
return false;
}
}
}
@ -949,15 +1019,17 @@ void CefMenuModelImpl::AddMenuItem(
case blink::mojom::CustomContextMenuItemType::kSubMenu: {
CefRefPtr<CefMenuModelImpl> sub_menu = static_cast<CefMenuModelImpl*>(
AddSubMenu(command_id, menu_item.label).get());
for (size_t i = 0; i < menu_item.submenu.size(); ++i)
for (size_t i = 0; i < menu_item.submenu.size(); ++i) {
sub_menu->AddMenuItem(*menu_item.submenu[i]);
}
break;
}
}
if (!menu_item.enabled &&
menu_item.type != blink::mojom::CustomContextMenuItemType::kSeparator)
menu_item.type != blink::mojom::CustomContextMenuItemType::kSeparator) {
SetEnabled(command_id, false);
}
if (menu_item.checked &&
(menu_item.type ==
@ -979,8 +1051,9 @@ void CefMenuModelImpl::AppendItem(const Item& item) {
void CefMenuModelImpl::InsertItemAt(const Item& item, size_t index) {
// Sanitize the index.
if (index > items_.size())
if (index > items_.size()) {
index = items_.size();
}
ValidateItem(item);
items_.insert(items_.begin() + index, item);
@ -997,8 +1070,9 @@ void CefMenuModelImpl::ValidateItem(const Item& item) {
}
void CefMenuModelImpl::OnMouseOutsideMenu(const gfx::Point& screen_point) {
if (delegate_)
if (delegate_) {
delegate_->MouseOutsideMenu(this, screen_point);
}
if (menu_model_delegate_) {
menu_model_delegate_->MouseOutsideMenu(
this, CefPoint(screen_point.x(), screen_point.y()));
@ -1006,24 +1080,30 @@ void CefMenuModelImpl::OnMouseOutsideMenu(const gfx::Point& screen_point) {
}
void CefMenuModelImpl::OnUnhandledOpenSubmenu(bool is_rtl) {
if (delegate_)
if (delegate_) {
delegate_->UnhandledOpenSubmenu(this, is_rtl);
if (menu_model_delegate_)
}
if (menu_model_delegate_) {
menu_model_delegate_->UnhandledOpenSubmenu(this, is_rtl);
}
}
void CefMenuModelImpl::OnUnhandledCloseSubmenu(bool is_rtl) {
if (delegate_)
if (delegate_) {
delegate_->UnhandledCloseSubmenu(this, is_rtl);
if (menu_model_delegate_)
}
if (menu_model_delegate_) {
menu_model_delegate_->UnhandledCloseSubmenu(this, is_rtl);
}
}
void CefMenuModelImpl::OnMenuClosed() {
if (delegate_)
if (delegate_) {
delegate_->MenuClosed(this);
if (menu_model_delegate_)
}
if (menu_model_delegate_) {
menu_model_delegate_->MenuClosed(this);
}
}
bool CefMenuModelImpl::VerifyContext() {

View File

@ -23,8 +23,9 @@ CefBrowserPlatformDelegateNativeAura::CefBrowserPlatformDelegateNativeAura(
void CefBrowserPlatformDelegateNativeAura::SendKeyEvent(
const CefKeyEvent& event) {
auto view = GetHostView();
if (!view)
if (!view) {
return;
}
ui::KeyEvent ui_event = TranslateUiKeyEvent(event);
view->OnKeyEvent(&ui_event);
@ -36,8 +37,9 @@ void CefBrowserPlatformDelegateNativeAura::SendMouseClickEvent(
bool mouseUp,
int clickCount) {
auto view = GetHostView();
if (!view)
if (!view) {
return;
}
ui::MouseEvent ui_event =
TranslateUiClickEvent(event, type, mouseUp, clickCount);
@ -48,8 +50,9 @@ void CefBrowserPlatformDelegateNativeAura::SendMouseMoveEvent(
const CefMouseEvent& event,
bool mouseLeave) {
auto view = GetHostView();
if (!view)
if (!view) {
return;
}
ui::MouseEvent ui_event = TranslateUiMoveEvent(event, mouseLeave);
view->OnMouseEvent(&ui_event);
@ -60,8 +63,9 @@ void CefBrowserPlatformDelegateNativeAura::SendMouseWheelEvent(
int deltaX,
int deltaY) {
auto view = GetHostView();
if (!view)
if (!view) {
return;
}
ui::MouseWheelEvent ui_event = TranslateUiWheelEvent(event, deltaX, deltaY);
view->OnMouseEvent(&ui_event);
@ -80,11 +84,13 @@ CefBrowserPlatformDelegateNativeAura::CreateMenuRunner() {
gfx::Point CefBrowserPlatformDelegateNativeAura::GetScreenPoint(
const gfx::Point& view,
bool want_dip_coords) const {
if (windowless_handler_)
if (windowless_handler_) {
return windowless_handler_->GetParentScreenPoint(view, want_dip_coords);
}
if (!window_widget_)
if (!window_widget_) {
return view;
}
gfx::Point screen_pt(view);
if (!view_util::ConvertPointToScreen(
@ -220,30 +226,42 @@ int CefBrowserPlatformDelegateNativeAura::TranslateUiEventModifiers(
uint32 cef_modifiers) {
int result = 0;
// Set modifiers based on key state.
if (cef_modifiers & EVENTFLAG_CAPS_LOCK_ON)
if (cef_modifiers & EVENTFLAG_CAPS_LOCK_ON) {
result |= ui::EF_CAPS_LOCK_ON;
if (cef_modifiers & EVENTFLAG_SHIFT_DOWN)
}
if (cef_modifiers & EVENTFLAG_SHIFT_DOWN) {
result |= ui::EF_SHIFT_DOWN;
if (cef_modifiers & EVENTFLAG_CONTROL_DOWN)
}
if (cef_modifiers & EVENTFLAG_CONTROL_DOWN) {
result |= ui::EF_CONTROL_DOWN;
if (cef_modifiers & EVENTFLAG_ALT_DOWN)
}
if (cef_modifiers & EVENTFLAG_ALT_DOWN) {
result |= ui::EF_ALT_DOWN;
if (cef_modifiers & EVENTFLAG_LEFT_MOUSE_BUTTON)
}
if (cef_modifiers & EVENTFLAG_LEFT_MOUSE_BUTTON) {
result |= ui::EF_LEFT_MOUSE_BUTTON;
if (cef_modifiers & EVENTFLAG_MIDDLE_MOUSE_BUTTON)
}
if (cef_modifiers & EVENTFLAG_MIDDLE_MOUSE_BUTTON) {
result |= ui::EF_MIDDLE_MOUSE_BUTTON;
if (cef_modifiers & EVENTFLAG_RIGHT_MOUSE_BUTTON)
}
if (cef_modifiers & EVENTFLAG_RIGHT_MOUSE_BUTTON) {
result |= ui::EF_RIGHT_MOUSE_BUTTON;
if (cef_modifiers & EVENTFLAG_COMMAND_DOWN)
}
if (cef_modifiers & EVENTFLAG_COMMAND_DOWN) {
result |= ui::EF_COMMAND_DOWN;
if (cef_modifiers & EVENTFLAG_NUM_LOCK_ON)
}
if (cef_modifiers & EVENTFLAG_NUM_LOCK_ON) {
result |= ui::EF_NUM_LOCK_ON;
if (cef_modifiers & EVENTFLAG_IS_KEY_PAD)
}
if (cef_modifiers & EVENTFLAG_IS_KEY_PAD) {
result |= ui::EF_IS_EXTENDED_KEY;
if (cef_modifiers & EVENTFLAG_ALTGR_DOWN)
}
if (cef_modifiers & EVENTFLAG_ALTGR_DOWN) {
result |= ui::EF_ALTGR_DOWN;
if (cef_modifiers & EVENTFLAG_IS_REPEAT)
}
if (cef_modifiers & EVENTFLAG_IS_REPEAT) {
result |= ui::EF_IS_REPEAT;
}
return result;
}
@ -251,19 +269,21 @@ int CefBrowserPlatformDelegateNativeAura::TranslateUiEventModifiers(
int CefBrowserPlatformDelegateNativeAura::TranslateUiChangedButtonFlags(
uint32 cef_modifiers) {
int result = 0;
if (cef_modifiers & EVENTFLAG_LEFT_MOUSE_BUTTON)
if (cef_modifiers & EVENTFLAG_LEFT_MOUSE_BUTTON) {
result |= ui::EF_LEFT_MOUSE_BUTTON;
else if (cef_modifiers & EVENTFLAG_MIDDLE_MOUSE_BUTTON)
} else if (cef_modifiers & EVENTFLAG_MIDDLE_MOUSE_BUTTON) {
result |= ui::EF_MIDDLE_MOUSE_BUTTON;
else if (cef_modifiers & EVENTFLAG_RIGHT_MOUSE_BUTTON)
} else if (cef_modifiers & EVENTFLAG_RIGHT_MOUSE_BUTTON) {
result |= ui::EF_RIGHT_MOUSE_BUTTON;
}
return result;
}
content::RenderWidgetHostViewAura*
CefBrowserPlatformDelegateNativeAura::GetHostView() const {
if (!web_contents_)
if (!web_contents_) {
return nullptr;
}
return static_cast<content::RenderWidgetHostViewAura*>(
web_contents_->GetRenderWidgetHostView());
}

View File

@ -45,10 +45,12 @@ void CefBrowserPlatformDelegateNativeLinux::BrowserDestroyed(
bool CefBrowserPlatformDelegateNativeLinux::CreateHostWindow() {
DCHECK(!window_widget_);
if (window_info_.bounds.width == 0)
if (window_info_.bounds.width == 0) {
window_info_.bounds.width = 800;
if (window_info_.bounds.height == 0)
}
if (window_info_.bounds.height == 0) {
window_info_.bounds.height = 600;
}
gfx::Rect rect(window_info_.bounds.x, window_info_.bounds.y,
window_info_.bounds.width, window_info_.bounds.height);
@ -114,15 +116,17 @@ bool CefBrowserPlatformDelegateNativeLinux::CreateHostWindow() {
void CefBrowserPlatformDelegateNativeLinux::CloseHostWindow() {
#if BUILDFLAG(OZONE_PLATFORM_X11)
if (window_x11_)
if (window_x11_) {
window_x11_->Close();
}
#endif
}
CefWindowHandle CefBrowserPlatformDelegateNativeLinux::GetHostWindowHandle()
const {
if (windowless_handler_)
if (windowless_handler_) {
return windowless_handler_->GetParentWindowHandle();
}
return window_info_.window;
}
@ -131,8 +135,9 @@ views::Widget* CefBrowserPlatformDelegateNativeLinux::GetWindowWidget() const {
}
void CefBrowserPlatformDelegateNativeLinux::SetFocus(bool setFocus) {
if (!setFocus)
if (!setFocus) {
return;
}
if (web_contents_) {
// Give logical focus to the RenderWidgetHostViewAura in the views
@ -154,16 +159,19 @@ void CefBrowserPlatformDelegateNativeLinux::NotifyMoveOrResizeStarted() {
// Call the parent method to dismiss any existing popups.
CefBrowserPlatformDelegateNativeAura::NotifyMoveOrResizeStarted();
if (!web_contents_)
if (!web_contents_) {
return;
}
#if BUILDFLAG(OZONE_PLATFORM_X11)
if (!window_x11_)
if (!window_x11_) {
return;
}
views::DesktopWindowTreeHostLinux* tree_host = window_x11_->GetHost();
if (!tree_host)
if (!tree_host) {
return;
}
// Explicitly set the screen bounds so that WindowTreeHost::*Screen()
// methods return the correct results.
@ -191,12 +199,14 @@ void CefBrowserPlatformDelegateNativeLinux::ViewText(const std::string& text) {
char buff[] = "/tmp/CEFSourceXXXXXX";
int fd = mkstemp(buff);
if (fd == -1)
if (fd == -1) {
return;
}
FILE* srcOutput = fdopen(fd, "w+");
if (!srcOutput)
if (!srcOutput) {
return;
}
if (fputs(text.c_str(), srcOutput) < 0) {
fclose(srcOutput);
@ -207,8 +217,9 @@ void CefBrowserPlatformDelegateNativeLinux::ViewText(const std::string& text) {
std::string newName(buff);
newName.append(".txt");
if (rename(buff, newName.c_str()) != 0)
if (rename(buff, newName.c_str()) != 0) {
return;
}
std::string openCommand("xdg-open ");
openCommand += newName;

View File

@ -111,9 +111,9 @@ namespace {
NSTimeInterval currentEventTimestamp() {
NSEvent* currentEvent = [NSApp currentEvent];
if (currentEvent)
if (currentEvent) {
return [currentEvent timestamp];
else {
} else {
// FIXME(API): In case there is no current event, the timestamp could be
// obtained by getting the time since the application started. This involves
// taking some more static functions from Chromium code.
@ -125,18 +125,24 @@ NSTimeInterval currentEventTimestamp() {
NSUInteger NativeModifiers(int cef_modifiers) {
NSUInteger native_modifiers = 0;
if (cef_modifiers & EVENTFLAG_SHIFT_DOWN)
if (cef_modifiers & EVENTFLAG_SHIFT_DOWN) {
native_modifiers |= NSEventModifierFlagShift;
if (cef_modifiers & EVENTFLAG_CONTROL_DOWN)
}
if (cef_modifiers & EVENTFLAG_CONTROL_DOWN) {
native_modifiers |= NSEventModifierFlagControl;
if (cef_modifiers & EVENTFLAG_ALT_DOWN)
}
if (cef_modifiers & EVENTFLAG_ALT_DOWN) {
native_modifiers |= NSEventModifierFlagOption;
if (cef_modifiers & EVENTFLAG_COMMAND_DOWN)
}
if (cef_modifiers & EVENTFLAG_COMMAND_DOWN) {
native_modifiers |= NSEventModifierFlagCommand;
if (cef_modifiers & EVENTFLAG_CAPS_LOCK_ON)
}
if (cef_modifiers & EVENTFLAG_CAPS_LOCK_ON) {
native_modifiers |= NSEventModifierFlagCapsLock;
if (cef_modifiers & EVENTFLAG_NUM_LOCK_ON)
}
if (cef_modifiers & EVENTFLAG_NUM_LOCK_ON) {
native_modifiers |= NSEventModifierFlagNumericPad;
}
return native_modifiers;
}
@ -342,16 +348,18 @@ void CefBrowserPlatformDelegateNativeMac::CloseHostWindow() {
CefWindowHandle CefBrowserPlatformDelegateNativeMac::GetHostWindowHandle()
const {
if (windowless_handler_)
if (windowless_handler_) {
return windowless_handler_->GetParentWindowHandle();
}
return window_info_.view;
}
void CefBrowserPlatformDelegateNativeMac::SendKeyEvent(
const CefKeyEvent& event) {
auto view = GetHostView();
if (!view)
if (!view) {
return;
}
content::NativeWebKeyboardEvent web_event = TranslateWebKeyEvent(event);
view->ForwardKeyboardEvent(web_event, ui::LatencyInfo());
@ -363,8 +371,9 @@ void CefBrowserPlatformDelegateNativeMac::SendMouseClickEvent(
bool mouseUp,
int clickCount) {
auto view = GetHostView();
if (!view)
if (!view) {
return;
}
blink::WebMouseEvent web_event =
TranslateWebClickEvent(event, type, mouseUp, clickCount);
@ -375,8 +384,9 @@ void CefBrowserPlatformDelegateNativeMac::SendMouseMoveEvent(
const CefMouseEvent& event,
bool mouseLeave) {
auto view = GetHostView();
if (!view)
if (!view) {
return;
}
blink::WebMouseEvent web_event = TranslateWebMoveEvent(event, mouseLeave);
view->RouteOrProcessMouseEvent(web_event);
@ -387,8 +397,9 @@ void CefBrowserPlatformDelegateNativeMac::SendMouseWheelEvent(
int deltaX,
int deltaY) {
auto view = GetHostView();
if (!view)
if (!view) {
return;
}
blink::WebMouseWheelEvent web_event =
TranslateWebWheelEvent(event, deltaX, deltaY);
@ -418,8 +429,9 @@ gfx::Point CefBrowserPlatformDelegateNativeMac::GetScreenPoint(
const gfx::Point& view,
bool want_dip_coords) const {
// Mac always operates in DIP coordinates so |want_dip_coords| is ignored.
if (windowless_handler_)
if (windowless_handler_) {
return windowless_handler_->GetParentScreenPoint(view, want_dip_coords);
}
NSView* nsview = CAST_CEF_WINDOW_HANDLE_TO_NSVIEW(window_info_.parent_view);
if (nsview) {
@ -442,8 +454,9 @@ void CefBrowserPlatformDelegateNativeMac::ViewText(const std::string& text) {
bool CefBrowserPlatformDelegateNativeMac::HandleKeyboardEvent(
const content::NativeWebKeyboardEvent& event) {
// Give the top level menu equivalents a chance to handle the event.
if ([event.os_event type] == NSEventTypeKeyDown)
if ([event.os_event type] == NSEventTypeKeyDown) {
return [[NSApp mainMenu] performKeyEquivalent:event.os_event];
}
return false;
}
@ -517,8 +530,9 @@ CefBrowserPlatformDelegateNativeMac::TranslateWebKeyEvent(
keyCode:key_event.native_key_code];
result = content::NativeWebKeyboardEvent(synthetic_event);
if (key_event.type == KEYEVENT_CHAR)
if (key_event.type == KEYEVENT_CHAR) {
result.SetType(blink::WebInputEvent::Type::kChar);
}
result.is_system_key = key_event.is_system_key;
@ -567,14 +581,15 @@ blink::WebMouseEvent CefBrowserPlatformDelegateNativeMac::TranslateWebMoveEvent(
if (!mouseLeave) {
result.SetType(blink::WebInputEvent::Type::kMouseMove);
if (mouse_event.modifiers & EVENTFLAG_LEFT_MOUSE_BUTTON)
if (mouse_event.modifiers & EVENTFLAG_LEFT_MOUSE_BUTTON) {
result.button = blink::WebMouseEvent::Button::kLeft;
else if (mouse_event.modifiers & EVENTFLAG_MIDDLE_MOUSE_BUTTON)
} else if (mouse_event.modifiers & EVENTFLAG_MIDDLE_MOUSE_BUTTON) {
result.button = blink::WebMouseEvent::Button::kMiddle;
else if (mouse_event.modifiers & EVENTFLAG_RIGHT_MOUSE_BUTTON)
} else if (mouse_event.modifiers & EVENTFLAG_RIGHT_MOUSE_BUTTON) {
result.button = blink::WebMouseEvent::Button::kRight;
else
} else {
result.button = blink::WebMouseEvent::Button::kNoButton;
}
} else {
result.SetType(blink::WebInputEvent::Type::kMouseLeave);
result.button = blink::WebMouseEvent::Button::kNoButton;
@ -602,14 +617,15 @@ CefBrowserPlatformDelegateNativeMac::TranslateWebWheelEvent(
result.wheel_ticks_y = deltaY / scrollbarPixelsPerCocoaTick;
result.delta_units = ui::ScrollGranularity::kScrollByPrecisePixel;
if (mouse_event.modifiers & EVENTFLAG_LEFT_MOUSE_BUTTON)
if (mouse_event.modifiers & EVENTFLAG_LEFT_MOUSE_BUTTON) {
result.button = blink::WebMouseEvent::Button::kLeft;
else if (mouse_event.modifiers & EVENTFLAG_MIDDLE_MOUSE_BUTTON)
} else if (mouse_event.modifiers & EVENTFLAG_MIDDLE_MOUSE_BUTTON) {
result.button = blink::WebMouseEvent::Button::kMiddle;
else if (mouse_event.modifiers & EVENTFLAG_RIGHT_MOUSE_BUTTON)
} else if (mouse_event.modifiers & EVENTFLAG_RIGHT_MOUSE_BUTTON) {
result.button = blink::WebMouseEvent::Button::kRight;
else
} else {
result.button = blink::WebMouseEvent::Button::kNoButton;
}
return result;
}
@ -637,8 +653,9 @@ void CefBrowserPlatformDelegateNativeMac::TranslateWebMouseEvent(
content::RenderWidgetHostViewMac*
CefBrowserPlatformDelegateNativeMac::GetHostView() const {
if (!web_contents_)
if (!web_contents_) {
return nullptr;
}
return static_cast<content::RenderWidgetHostViewMac*>(
web_contents_->GetRenderWidgetHostView());
}

View File

@ -46,8 +46,9 @@ void WriteTempFileAndView(const std::string& data) {
CEF_REQUIRE_BLOCKING();
base::FilePath tmp_file;
if (!base::CreateTemporaryFile(&tmp_file))
if (!base::CreateTemporaryFile(&tmp_file)) {
return;
}
// The shell command will look at the file extension to identify the correct
// program to open.
@ -82,8 +83,9 @@ bool HasExternalHandler(const std::string& scheme) {
void ExecuteExternalProtocol(const GURL& url) {
CEF_REQUIRE_BLOCKING();
if (!HasExternalHandler(url.scheme()))
if (!HasExternalHandler(url.scheme())) {
return;
}
// Quote the input scheme to be sure that the command does not have
// parameters unexpected by the external program. This url should already
@ -99,8 +101,9 @@ void ExecuteExternalProtocol(const GURL& url) {
//
// It may be possible to increase this. https://crbug.com/727909
const size_t kMaxUrlLength = 2048;
if (escaped_url.length() > kMaxUrlLength)
if (escaped_url.length() > kMaxUrlLength) {
return;
}
// Specify %windir%\system32 as the CWD so that any new proc spawned does not
// inherit this proc's CWD. Without this, uninstalls may be broken by a
@ -239,8 +242,9 @@ bool CefBrowserPlatformDelegateNativeWin::CreateHostWindow() {
// It's possible for CreateWindowEx to fail if the parent window was
// destroyed between the call to CreateBrowser and the above one.
DCHECK(window_info_.window);
if (!window_info_.window)
if (!window_info_.window) {
return false;
}
host_window_created_ = true;
@ -257,8 +261,9 @@ bool CefBrowserPlatformDelegateNativeWin::CreateHostWindow() {
return reinterpret_cast<EnableChildWindowDpiMessagePtr>(GetProcAddress(
GetModuleHandle(L"user32.dll"), "EnableChildWindowDpiMessage"));
}();
if (enable_child_window_dpi_message_func)
if (enable_child_window_dpi_message_func) {
enable_child_window_dpi_message_func(window_info_.window, TRUE);
}
}
DCHECK(!window_widget_);
@ -317,8 +322,9 @@ void CefBrowserPlatformDelegateNativeWin::CloseHostWindow() {
CefWindowHandle CefBrowserPlatformDelegateNativeWin::GetHostWindowHandle()
const {
if (windowless_handler_)
if (windowless_handler_) {
return windowless_handler_->GetParentWindowHandle();
}
return window_info_.window;
}
@ -327,8 +333,9 @@ views::Widget* CefBrowserPlatformDelegateNativeWin::GetWindowWidget() const {
}
void CefBrowserPlatformDelegateNativeWin::SetFocus(bool setFocus) {
if (!setFocus)
if (!setFocus) {
return;
}
if (window_widget_) {
// Give native focus to the DesktopWindowTreeHostWin ("Chrome_WidgetWin_0")
@ -397,8 +404,9 @@ void CefBrowserPlatformDelegateNativeWin::NotifyMoveOrResizeStarted() {
// Call the parent method to dismiss any existing popups.
CefBrowserPlatformDelegateNativeAura::NotifyMoveOrResizeStarted();
if (!window_widget_)
if (!window_widget_) {
return;
}
// Notify DesktopWindowTreeHostWin of move events so that screen rectangle
// information is communicated to the renderer process and popups are
@ -444,8 +452,9 @@ bool CefBrowserPlatformDelegateNativeWin::HandleKeyboardEvent(
MSG msg = {};
msg.hwnd = GetHostWindowHandle();
if (!msg.hwnd)
if (!msg.hwnd) {
return false;
}
switch (event.GetType()) {
case blink::WebInputEvent::Type::kRawKeyDown:
@ -467,8 +476,9 @@ bool CefBrowserPlatformDelegateNativeWin::HandleKeyboardEvent(
UINT scan_code = ::MapVirtualKeyW(event.windows_key_code, MAPVK_VK_TO_VSC);
msg.lParam = (scan_code << 16) | // key scan code
1; // key repeat count
if (event.GetModifiers() & content::NativeWebKeyboardEvent::kAltKey)
if (event.GetModifiers() & content::NativeWebKeyboardEvent::kAltKey) {
msg.lParam |= (1 << 29);
}
return !DefWindowProc(msg.hwnd, msg.message, msg.wParam, msg.lParam);
}
@ -481,8 +491,9 @@ void CefBrowserPlatformDelegate::HandleExternalProtocol(const GURL& url) {
CefEventHandle CefBrowserPlatformDelegateNativeWin::GetEventHandle(
const content::NativeWebKeyboardEvent& event) const {
if (!event.os_event)
if (!event.os_event) {
return NULL;
}
return ChromeToWindowsType(
const_cast<CHROME_MSG*>(&event.os_event->native_event()));
}
@ -545,8 +556,9 @@ gfx::Vector2d CefBrowserPlatformDelegateNativeWin::GetUiWheelEventOffset(
// static
void CefBrowserPlatformDelegateNativeWin::RegisterWindowClass() {
static bool registered = false;
if (registered)
if (registered) {
return;
}
// Register the window class
WNDCLASSEX wcex = {
@ -651,16 +663,18 @@ LRESULT CALLBACK CefBrowserPlatformDelegateNativeWin::WndProc(HWND hwnd,
case WM_MOVING:
case WM_MOVE:
if (browser)
if (browser) {
browser->NotifyMoveOrResizeStarted();
}
return 0;
case WM_SETFOCUS:
// Selecting "Close window" from the task bar menu may send a focus
// notification even though the window is currently disabled (e.g. while
// a modal JS dialog is displayed).
if (browser && ::IsWindowEnabled(hwnd))
if (browser && ::IsWindowEnabled(hwnd)) {
browser->SetFocus(true);
}
return 0;
case WM_ERASEBKGND:

View File

@ -50,14 +50,18 @@ display::Display::Rotation OrientationAngleToRotation(
// angle. The former is the physical display rotation while the later is the
// rotation required by the content to be shown properly on the screen, in
// other words, relative to the physical display.
if (orientation_angle == 0)
if (orientation_angle == 0) {
return display::Display::ROTATE_0;
if (orientation_angle == 90)
}
if (orientation_angle == 90) {
return display::Display::ROTATE_270;
if (orientation_angle == 180)
}
if (orientation_angle == 180) {
return display::Display::ROTATE_180;
if (orientation_angle == 270)
}
if (orientation_angle == 270) {
return display::Display::ROTATE_90;
}
NOTREACHED();
return display::Display::ROTATE_0;
}
@ -69,11 +73,13 @@ display::Display::Rotation OrientationAngleToRotation(
bool OnCursorChange(CefRefPtr<CefBrowser> browser,
const ui::Cursor& ui_cursor) {
auto client = browser->GetHost()->GetClient();
if (!client)
if (!client) {
return false;
}
auto handler = client->GetDisplayHandler();
if (!handler)
if (!handler) {
return false;
}
const cef_cursor_type_t cursor_type =
static_cast<cef_cursor_type_t>(ui_cursor.type());

View File

@ -38,8 +38,9 @@
- (id)initHelperWithCallback:
(CefJavaScriptDialogRunner::DialogClosedCallback)callback {
if (self = [super init])
if (self = [super init]) {
callback_ = std::move(callback);
}
return self;
}
@ -62,13 +63,15 @@
- (void)alertDidEnd:(NSAlert*)alert
returnCode:(int)returnCode
contextInfo:(void*)contextInfo {
if (returnCode == NSModalResponseStop)
if (returnCode == NSModalResponseStop) {
return;
}
bool success = returnCode == NSAlertFirstButtonReturn;
std::u16string input;
if (textField_)
if (textField_) {
input = base::SysNSStringToUTF16([textField_ stringValue]);
}
std::move(callback_).Run(success, input);
}
@ -130,8 +133,9 @@ void CefJavaScriptDialogRunnerMac::Run(
const std::u16string& display_url =
url_formatter::FormatUrlForSecurityDisplay(origin_url);
if (!display_url.empty())
if (!display_url.empty()) {
label += u" - " + display_url;
}
[alert setMessageText:base::SysUTF16ToNSString(label)];
@ -156,8 +160,9 @@ void CefJavaScriptDialogRunnerMac::Run(
contextInfo:this];
#pragma clang diagnostic pop
if ([alert accessoryView])
if ([alert accessoryView]) {
[[alert window] makeFirstResponder:[alert accessoryView]];
}
}
void CefJavaScriptDialogRunnerMac::Handle(

View File

@ -45,8 +45,9 @@ bool CefMenuRunnerMac::RunContextMenu(
// Show the menu. Blocks until the menu is dismissed.
if (browser->IsWindowless()) {
// Don't show the menu unless a native window handle exists.
if (!browser->GetWindowHandle())
if (!browser->GetWindowHandle()) {
return false;
}
const gfx::Point& screen_point = browser->GetScreenPoint(
gfx::Point(params.x, params.y), /*want_dip_coords=*/true);
@ -85,6 +86,7 @@ bool CefMenuRunnerMac::RunContextMenu(
}
void CefMenuRunnerMac::CancelContextMenu() {
if (menu_controller_.get())
if (menu_controller_.get()) {
[menu_controller_ cancel];
}
}

View File

@ -41,8 +41,9 @@ bool CefMenuRunnerViewsAura::RunContextMenu(
}
void CefMenuRunnerViewsAura::CancelContextMenu() {
if (menu_)
if (menu_) {
menu_->Cancel();
}
}
bool CefMenuRunnerViewsAura::FormatLabel(std::u16string& label) {

View File

@ -74,12 +74,14 @@ void CefWindowDelegateView::InitContent() {
void CefWindowDelegateView::ViewHierarchyChanged(
const views::ViewHierarchyChangedDetails& details) {
if (details.is_add && details.child == this)
if (details.is_add && details.child == this) {
InitContent();
}
}
void CefWindowDelegateView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
views::WidgetDelegateView::OnBoundsChanged(previous_bounds);
if (!on_bounds_changed_.is_null())
if (!on_bounds_changed_.is_null()) {
on_bounds_changed_.Run();
}
}

View File

@ -46,16 +46,18 @@ bool PropertyExists(x11::Window window, x11::Atom property) {
// Deleted from ui/base/x/x11_util.h in https://crrev.com/62fc260067.
bool IsWindowVisible(x11::Window window) {
auto response = x11::Connection::Get()->GetWindowAttributes({window}).Sync();
if (!response || response->map_state != x11::MapState::Viewable)
if (!response || response->map_state != x11::MapState::Viewable) {
return false;
}
// Minimized windows are not visible.
std::vector<x11::Atom> wm_states;
if (x11::GetArrayProperty(window, x11::GetAtom("_NET_WM_STATE"),
&wm_states)) {
x11::Atom hidden_atom = x11::GetAtom("_NET_WM_STATE_HIDDEN");
if (base::Contains(wm_states, hidden_atom))
if (base::Contains(wm_states, hidden_atom)) {
return false;
}
}
// Do not check _NET_CURRENT_DESKTOP/_NET_WM_DESKTOP since some
@ -79,8 +81,9 @@ x11::Window FindToplevelParent(x11::Window window) {
do {
auto query_tree = x11::Connection::Get()->QueryTree({window}).Sync();
if (!query_tree)
if (!query_tree) {
break;
}
top_level_window = window;
if (!PropertyExists(query_tree->parent, x11::GetAtom(kNetWMPid)) ||
@ -97,8 +100,9 @@ x11::Window FindToplevelParent(x11::Window window) {
} // namespace
CEF_EXPORT XDisplay* cef_get_xdisplay() {
if (!CEF_CURRENTLY_ON(CEF_UIT))
if (!CEF_CURRENTLY_ON(CEF_UIT)) {
return nullptr;
}
return x11::Connection::Get()->GetXlibDisplay();
}
@ -111,8 +115,9 @@ CefWindowX11::CefWindowX11(CefRefPtr<CefBrowserHostBase> browser,
parent_xwindow_(parent_xwindow),
bounds_(bounds),
weak_ptr_factory_(this) {
if (parent_xwindow_ == x11::Window::None)
if (parent_xwindow_ == x11::Window::None) {
parent_xwindow_ = ui::GetX11RootWindow();
}
x11::VisualId visual;
uint8_t depth;
@ -184,8 +189,9 @@ CefWindowX11::~CefWindowX11() {
}
void CefWindowX11::Close() {
if (xwindow_ == x11::Window::None)
if (xwindow_ == x11::Window::None) {
return;
}
ui::SendClientMessage(
xwindow_, xwindow_, x11::GetAtom(kWMProtocols),
@ -194,13 +200,15 @@ void CefWindowX11::Close() {
x11::EventMask::NoEvent);
auto host = GetHost();
if (host)
if (host) {
host->Close();
}
}
void CefWindowX11::Show() {
if (xwindow_ == x11::Window::None)
if (xwindow_ == x11::Window::None) {
return;
}
if (!window_mapped_) {
// Before we map the window, set size hints. Otherwise, some window managers
@ -245,8 +253,9 @@ void CefWindowX11::Show() {
}
void CefWindowX11::Hide() {
if (xwindow_ == x11::Window::None)
if (xwindow_ == x11::Window::None) {
return;
}
if (window_mapped_) {
ui::WithdrawWindow(xwindow_);
@ -255,8 +264,9 @@ void CefWindowX11::Hide() {
}
void CefWindowX11::Focus() {
if (xwindow_ == x11::Window::None || !window_mapped_)
if (xwindow_ == x11::Window::None || !window_mapped_) {
return;
}
x11::Window focus_target = xwindow_;
@ -277,8 +287,9 @@ void CefWindowX11::Focus() {
}
void CefWindowX11::SetBounds(const gfx::Rect& bounds) {
if (xwindow_ == x11::Window::None)
if (xwindow_ == x11::Window::None) {
return;
}
x11::ConfigureWindowRequest req{.window = xwindow_};
@ -338,30 +349,35 @@ uint32_t CefWindowX11::DispatchEvent(const ui::PlatformEvent& event) {
}
void CefWindowX11::OnEvent(const x11::Event& event) {
if (event.window() != xwindow_)
if (event.window() != xwindow_) {
return;
}
ProcessXEvent(event);
}
void CefWindowX11::ContinueFocus() {
if (!focus_pending_)
if (!focus_pending_) {
return;
if (browser_.get())
}
if (browser_.get()) {
browser_->SetFocus(true);
}
focus_pending_ = false;
}
bool CefWindowX11::TopLevelAlwaysOnTop() const {
auto toplevel_window = FindToplevelParent(xwindow_);
if (toplevel_window == x11::Window::None)
if (toplevel_window == x11::Window::None) {
return false;
}
std::vector<x11::Atom> wm_states;
if (x11::GetArrayProperty(toplevel_window, x11::GetAtom(kNetWMState),
&wm_states)) {
x11::Atom keep_above_atom = x11::GetAtom(kNetWMStateKeepAbove);
if (base::Contains(wm_states, keep_above_atom))
if (base::Contains(wm_states, keep_above_atom)) {
return true;
}
}
return false;
}
@ -434,8 +450,9 @@ void CefWindowX11::ProcessXEvent(const x11::Event& event) {
// Cancel the pending focus change if some other window has gained focus
// while waiting for the async task to run. Otherwise we can get stuck in
// a focus change loop.
if (focus_pending_)
if (focus_pending_) {
focus_pending_ = false;
}
}
} else if (auto* property = event.As<x11::PropertyNotifyEvent>()) {
const auto& wm_state_atom = x11::GetAtom(kNetWMState);

View File

@ -157,8 +157,9 @@ void GetAllowedHosts(std::vector<std::string>* hosts) {
bool IsUnlistedHost(const std::string& host) {
for (size_t i = 0; i < sizeof(kUnlistedHosts) / sizeof(kUnlistedHosts[0]);
++i) {
if (host == kUnlistedHosts[i])
if (host == kUnlistedHosts[i]) {
return true;
}
}
return false;
}
@ -166,8 +167,9 @@ bool IsUnlistedHost(const std::string& host) {
// Returns true if a host is WebUI and should be allowed to load.
bool IsAllowedWebUIHost(const std::string& host) {
// Chrome runtime allows all WebUI hosts.
if (cef::IsChromeRuntimeEnabled())
if (cef::IsChromeRuntimeEnabled()) {
return true;
}
// Explicitly whitelisted WebUI hosts.
for (size_t i = 0;
@ -216,8 +218,10 @@ std::string GetCommandLine() {
std::string command_line = "";
using ArgvList = std::vector<std::string>;
const ArgvList& argv = base::CommandLine::ForCurrentProcess()->argv();
for (ArgvList::const_iterator iter = argv.begin(); iter != argv.end(); iter++)
for (ArgvList::const_iterator iter = argv.begin(); iter != argv.end();
iter++) {
command_line += " " + *iter;
}
// TODO(viettrungluu): |command_line| could really have any encoding, whereas
// below we assumes it's UTF-8.
return command_line;
@ -226,8 +230,9 @@ std::string GetCommandLine() {
std::string GetModulePath() {
base::FilePath path;
if (base::PathService::Get(base::FILE_MODULE, &path))
if (base::PathService::Get(base::FILE_MODULE, &path)) {
return CefString(path.value());
}
return std::string();
}
@ -414,8 +419,9 @@ bool OnWebUIHostsUI(std::string* mime_type, std::string* output) {
std::sort(list.begin(), list.end());
for (size_t i = 0U; i < list.size(); ++i) {
if (IsUnlistedHost(list[i]))
if (IsUnlistedHost(list[i])) {
continue;
}
html += "<li><a href=\"chrome://" + list[i] + "\">chrome://" + list[i] +
"</a></li>\n";
@ -533,16 +539,18 @@ class CefWebUIControllerFactory : public content::WebUIControllerFactory {
return false;
}
if (IsAllowedWebUIHost(url.host()))
if (IsAllowedWebUIHost(url.host())) {
return true;
}
return false;
}
// Returns true if WebUI is allowed to make network requests.
static bool IsWebUIAllowedToMakeNetworkRequests(const url::Origin& origin) {
if (!AllowWebUIForURL(origin.GetURL()))
if (!AllowWebUIForURL(origin.GetURL())) {
return false;
}
if (ChromeWebUIControllerFactory::IsWebUIAllowedToMakeNetworkRequests(
origin)) {
@ -556,8 +564,9 @@ class CefWebUIControllerFactory : public content::WebUIControllerFactory {
content::WebUI* web_ui,
const GURL& url) override {
std::unique_ptr<content::WebUIController> controller;
if (!AllowWebUIForURL(url))
if (!AllowWebUIForURL(url)) {
return controller;
}
// Set up the chrome://theme/ source. These URLs are referenced from many
// places (WebUI and chrome://resources which live in //ui). WebUI code
@ -577,8 +586,9 @@ class CefWebUIControllerFactory : public content::WebUIControllerFactory {
controller = content::WebUIConfigMap::GetInstance()
.controller_factory()
->CreateWebUIControllerForURL(web_ui, url);
if (controller)
if (controller) {
return controller;
}
return ChromeWebUIControllerFactory::GetInstance()
->CreateWebUIControllerForURL(web_ui, url);
@ -587,8 +597,9 @@ class CefWebUIControllerFactory : public content::WebUIControllerFactory {
content::WebUI::TypeID GetWebUIType(content::BrowserContext* browser_context,
const GURL& url) override {
content::WebUI::TypeID type = content::WebUI::kNoWebUI;
if (!AllowWebUIForURL(url))
if (!AllowWebUIForURL(url)) {
return type;
}
const auto host_id = GetChromeHostId(url.host());
if (host_id != CHROME_UNKNOWN) {
@ -598,21 +609,24 @@ class CefWebUIControllerFactory : public content::WebUIControllerFactory {
type = content::WebUIConfigMap::GetInstance()
.controller_factory()
->GetWebUIType(browser_context, url);
if (type != content::WebUI::kNoWebUI)
if (type != content::WebUI::kNoWebUI) {
return type;
}
type = ChromeWebUIControllerFactory::GetInstance()->GetWebUIType(
browser_context, url);
if (type != content::WebUI::kNoWebUI)
if (type != content::WebUI::kNoWebUI) {
return type;
}
return content::WebUI::kNoWebUI;
}
bool UseWebUIForURL(content::BrowserContext* browser_context,
const GURL& url) override {
if (!AllowWebUIForURL(url))
if (!AllowWebUIForURL(url)) {
return false;
}
const auto host_id = GetChromeHostId(url.host());
if (host_id != CHROME_UNKNOWN) {
@ -657,8 +671,9 @@ class CefWebUIControllerFactory : public content::WebUIControllerFactory {
// Handles rewriting Web UI URLs.
static bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
if (!GetInstance()->UseWebUIForURL(browser_context, *url))
if (!GetInstance()->UseWebUIForURL(browser_context, *url)) {
return false;
}
return true;
}

View File

@ -29,8 +29,9 @@ class Delegate : public InternalHandlerDelegate {
Action* action) override {
GURL url = GURL(request->GetURL().ToString());
std::string path = url.path();
if (path.length() > 0)
if (path.length() > 0) {
path = path.substr(1);
}
action->bytes =
content::DevToolsFrontendHost::GetFrontendResourceBytes(path);

View File

@ -36,16 +36,19 @@ std::string GetMimeType(const std::string& filename) {
std::string mime_type;
const base::FilePath& file_path = FilePathFromASCII(filename);
if (net::GetMimeTypeFromFile(file_path, &mime_type))
if (net::GetMimeTypeFromFile(file_path, &mime_type)) {
return mime_type;
}
// Check for newer extensions used by internal resources but not yet
// recognized by the mime type detector.
const std::string& extension = CefString(file_path.FinalExtension());
if (extension == ".md")
if (extension == ".md") {
return "text/markdown";
if (extension == ".woff2")
}
if (extension == ".woff2") {
return "application/font-woff2";
}
NOTREACHED() << "No known mime type for file: " << filename.c_str();
return "text/plain";
@ -161,11 +164,13 @@ class InternalHandlerFactory : public CefSchemeHandlerFactory {
InternalHandlerDelegate::Action action;
if (delegate_->OnRequest(browser, request, &action)) {
if (!action.redirect_url.is_empty() && action.redirect_url.is_valid())
if (!action.redirect_url.is_empty() && action.redirect_url.is_valid()) {
return new RedirectHandler(action.redirect_url);
}
if (action.mime_type.empty())
if (action.mime_type.empty()) {
action.mime_type = GetMimeType(url.path());
}
if (!action.bytes && action.resource_id >= 0) {
std::string str =

View File

@ -16,8 +16,9 @@
namespace scheme {
void RegisterInternalHandlers(CefIOThreadState* iothread_state) {
if (!cef::IsAlloyRuntimeEnabled())
if (!cef::IsAlloyRuntimeEnabled()) {
return;
}
scheme::RegisterChromeDevToolsHandler(iothread_state);
}

View File

@ -77,8 +77,9 @@ class RequestManager {
}
void Remove(int32_t request_id) {
if (request_id > kInitialRequestID)
if (request_id > kInitialRequestID) {
return;
}
base::AutoLock lock_scope(lock_);
RequestMap::iterator it = map_.find(request_id);
@ -87,8 +88,9 @@ class RequestManager {
}
absl::optional<CefBrowserURLRequest::RequestInfo> Get(int32_t request_id) {
if (request_id > kInitialRequestID)
if (request_id > kInitialRequestID) {
return absl::nullopt;
}
base::AutoLock lock_scope(lock_);
RequestMap::const_iterator it = map_.find(request_id);
@ -143,8 +145,9 @@ class CefBrowserURLRequest::Context
DCHECK(CalledOnValidThread());
const GURL& url = GURL(request_->GetURL().ToString());
if (!url.is_valid())
if (!url.is_valid()) {
return false;
}
if (!request_context_) {
request_context_ = CefRequestContext::GetGlobalContext();
@ -166,8 +169,9 @@ class CefBrowserURLRequest::Context
DCHECK(CalledOnValidThread());
// The request may already be complete or canceled.
if (!url_request_)
if (!url_request_) {
return;
}
DCHECK_EQ(status_, UR_IO_PENDING);
status_ = UR_CANCELED;
@ -252,8 +256,9 @@ class CefBrowserURLRequest::Context
DCHECK(CalledOnValidThread());
// The request may have been canceled.
if (!url_request_)
if (!url_request_) {
return;
}
if (!loader_factory_getter) {
// Cancel the request immediately.
@ -463,8 +468,9 @@ class CefBrowserURLRequest::Context
DCHECK_EQ(status_, UR_IO_PENDING);
upload_data_size_ = total;
if (position == total)
if (position == total) {
got_upload_progress_complete_ = true;
}
client_->OnUploadProgress(url_request_.get(), position, total);
}
@ -511,8 +517,9 @@ class CefBrowserURLRequest::Context
DCHECK(CalledOnValidThread());
// The request may already be complete or canceled.
if (!url_request_)
if (!url_request_) {
return;
}
// Status will be UR_IO_PENDING if we're called when the request is complete
// (via SimpleURLLoaderStreamConsumer or OnHeadersOnly). We can only call
@ -528,8 +535,9 @@ class CefBrowserURLRequest::Context
response_was_cached_ = loader_->LoadedFromCache();
}
if (success)
if (success) {
NotifyUploadProgressIfNecessary();
}
client_->OnRequestComplete(url_request_.get());
@ -629,50 +637,58 @@ CefBrowserURLRequest::CefBrowserURLRequest(
CefBrowserURLRequest::~CefBrowserURLRequest() {}
bool CefBrowserURLRequest::Start() {
if (!VerifyContext())
if (!VerifyContext()) {
return false;
}
return context_->Start();
}
CefRefPtr<CefRequest> CefBrowserURLRequest::GetRequest() {
if (!VerifyContext())
if (!VerifyContext()) {
return nullptr;
}
return context_->request();
}
CefRefPtr<CefURLRequestClient> CefBrowserURLRequest::GetClient() {
if (!VerifyContext())
if (!VerifyContext()) {
return nullptr;
}
return context_->client();
}
CefURLRequest::Status CefBrowserURLRequest::GetRequestStatus() {
if (!VerifyContext())
if (!VerifyContext()) {
return UR_UNKNOWN;
}
return context_->status();
}
CefURLRequest::ErrorCode CefBrowserURLRequest::GetRequestError() {
if (!VerifyContext())
if (!VerifyContext()) {
return ERR_NONE;
}
return context_->response()->GetError();
}
CefRefPtr<CefResponse> CefBrowserURLRequest::GetResponse() {
if (!VerifyContext())
if (!VerifyContext()) {
return nullptr;
}
return context_->response();
}
bool CefBrowserURLRequest::ResponseWasCached() {
if (!VerifyContext())
if (!VerifyContext()) {
return false;
}
return context_->response_was_cached();
}
void CefBrowserURLRequest::Cancel() {
if (!VerifyContext())
if (!VerifyContext()) {
return;
}
return context_->Cancel();
}

View File

@ -94,8 +94,9 @@ void ContinueWithLoadedCookies(const AllowCookieCallback& allow_cookie_callback,
for (const auto& status : cookies) {
bool allow = false;
allow_cookie_callback.Run(status.cookie, &allow);
if (allow)
if (allow) {
allowed_cookies.push_back(status.cookie);
}
}
std::move(done_callback).Run(cookies.size(), std::move(allowed_cookies));
}
@ -213,16 +214,18 @@ void SaveCookiesOnUIThread(
bool IsCookieableScheme(
const GURL& url,
const absl::optional<std::vector<std::string>>& cookieable_schemes) {
if (!url.has_scheme())
if (!url.has_scheme()) {
return false;
}
if (cookieable_schemes) {
// The client has explicitly registered the full set of schemes that should
// be supported.
const auto url_scheme = url.scheme_piece();
for (auto scheme : *cookieable_schemes) {
if (url_scheme == scheme)
if (url_scheme == scheme) {
return true;
}
}
return false;
}
@ -272,8 +275,9 @@ void SaveCookies(const CefBrowserContext::Getter& browser_context_getter,
// Match the logic in
// URLRequestHttpJob::SaveCookiesAndNotifyHeadersComplete.
base::Time response_date;
if (!headers->GetDateValue(&response_date))
if (!headers->GetDateValue(&response_date)) {
response_date = base::Time();
}
const base::StringPiece name(net_service::kHTTPSetCookieHeaderName);
std::string cookie_string;
@ -295,8 +299,9 @@ void SaveCookies(const CefBrowserContext::Getter& browser_context_getter,
bool allow = false;
allow_cookie_callback.Run(*cookie, &allow);
if (allow)
if (allow) {
allowed_cookies.push_back(*cookie);
}
}
if (!allowed_cookies.empty()) {

View File

@ -37,8 +37,9 @@ CookieManager* GetCookieManager(CefBrowserContext* browser_context) {
// Always execute the callback asynchronously.
void RunAsyncCompletionOnUIThread(CefRefPtr<CefCompletionCallback> callback) {
if (!callback.get())
if (!callback.get()) {
return;
}
CEF_POST_TASK(CEF_UIT, base::BindOnce(&CefCompletionCallback::OnComplete,
callback.get()));
}
@ -46,8 +47,9 @@ void RunAsyncCompletionOnUIThread(CefRefPtr<CefCompletionCallback> callback) {
// Always execute the callback asynchronously.
void SetCookieCallbackImpl(CefRefPtr<CefSetCookieCallback> callback,
net::CookieAccessResult access_result) {
if (!callback.get())
if (!callback.get()) {
return;
}
const bool is_include = access_result.status.IsInclude();
if (!is_include) {
LOG(WARNING) << "SetCookie failed with reason: "
@ -60,8 +62,9 @@ void SetCookieCallbackImpl(CefRefPtr<CefSetCookieCallback> callback,
// Always execute the callback asynchronously.
void DeleteCookiesCallbackImpl(CefRefPtr<CefDeleteCookiesCallback> callback,
uint32_t num_deleted) {
if (!callback.get())
if (!callback.get()) {
return;
}
CEF_POST_TASK(CEF_UIT, base::BindOnce(&CefDeleteCookiesCallback::OnComplete,
callback.get(), num_deleted));
}
@ -72,8 +75,9 @@ void ExecuteVisitor(CefRefPtr<CefCookieVisitor> visitor,
CEF_REQUIRE_UIT();
auto browser_context = GetBrowserContext(browser_context_getter);
if (!browser_context)
if (!browser_context) {
return;
}
auto cookie_manager = GetCookieManager(browser_context);
@ -88,8 +92,9 @@ void ExecuteVisitor(CefRefPtr<CefCookieVisitor> visitor,
cookie_manager->DeleteCanonicalCookie(
cc, CookieManager::DeleteCanonicalCookieCallback());
}
if (!keepLooping)
if (!keepLooping) {
break;
}
count++;
}
}
@ -141,8 +146,9 @@ void CefCookieManagerImpl::Initialize(
bool CefCookieManagerImpl::VisitAllCookies(
CefRefPtr<CefCookieVisitor> visitor) {
if (!visitor.get())
if (!visitor.get()) {
return false;
}
if (!ValidContext()) {
StoreOrTriggerInitCallback(base::BindOnce(
@ -158,12 +164,14 @@ bool CefCookieManagerImpl::VisitUrlCookies(
const CefString& url,
bool includeHttpOnly,
CefRefPtr<CefCookieVisitor> visitor) {
if (!visitor.get())
if (!visitor.get()) {
return false;
}
GURL gurl = GURL(url.ToString());
if (!gurl.is_valid())
if (!gurl.is_valid()) {
return false;
}
if (!ValidContext()) {
StoreOrTriggerInitCallback(base::BindOnce(
@ -179,8 +187,9 @@ bool CefCookieManagerImpl::SetCookie(const CefString& url,
const CefCookie& cookie,
CefRefPtr<CefSetCookieCallback> callback) {
GURL gurl = GURL(url.ToString());
if (!gurl.is_valid())
if (!gurl.is_valid()) {
return false;
}
if (!ValidContext()) {
StoreOrTriggerInitCallback(base::BindOnce(
@ -198,8 +207,9 @@ bool CefCookieManagerImpl::DeleteCookies(
CefRefPtr<CefDeleteCookiesCallback> callback) {
// Empty URLs are allowed but not invalid URLs.
GURL gurl = GURL(url.ToString());
if (!gurl.is_empty() && !gurl.is_valid())
if (!gurl.is_empty() && !gurl.is_valid()) {
return false;
}
if (!ValidContext()) {
StoreOrTriggerInitCallback(base::BindOnce(
@ -229,8 +239,9 @@ bool CefCookieManagerImpl::VisitAllCookiesInternal(
DCHECK(visitor);
auto browser_context = GetBrowserContext(browser_context_getter_);
if (!browser_context)
if (!browser_context) {
return false;
}
GetCookieManager(browser_context)
->GetAllCookies(base::BindOnce(&GetAllCookiesCallbackImpl, visitor,
@ -247,14 +258,16 @@ bool CefCookieManagerImpl::VisitUrlCookiesInternal(
DCHECK(url.is_valid());
net::CookieOptions options;
if (includeHttpOnly)
if (includeHttpOnly) {
options.set_include_httponly();
}
options.set_same_site_cookie_context(
net::CookieOptions::SameSiteCookieContext::MakeInclusive());
auto browser_context = GetBrowserContext(browser_context_getter_);
if (!browser_context)
if (!browser_context) {
return false;
}
GetCookieManager(browser_context)
->GetCookieList(url, options, net::CookiePartitionKeyCollection(),
@ -276,8 +289,9 @@ bool CefCookieManagerImpl::SetCookieInternal(
std::string path = CefString(&cookie.path).ToString();
base::Time expiration_time;
if (cookie.has_expires)
if (cookie.has_expires) {
expiration_time = CefBaseTime(cookie.expires);
}
net::CookieSameSite same_site =
net_service::MakeCookieSameSite(cookie.same_site);
@ -300,14 +314,16 @@ bool CefCookieManagerImpl::SetCookieInternal(
}
net::CookieOptions options;
if (cookie.httponly)
if (cookie.httponly) {
options.set_include_httponly();
}
options.set_same_site_cookie_context(
net::CookieOptions::SameSiteCookieContext::MakeInclusive());
auto browser_context = GetBrowserContext(browser_context_getter_);
if (!browser_context)
if (!browser_context) {
return false;
}
GetCookieManager(browser_context)
->SetCanonicalCookie(*canonical_cookie, url, options,
@ -337,8 +353,9 @@ bool CefCookieManagerImpl::DeleteCookiesInternal(
}
auto browser_context = GetBrowserContext(browser_context_getter_);
if (!browser_context)
if (!browser_context) {
return false;
}
GetCookieManager(browser_context)
->DeleteCookies(std::move(deletion_filter),
@ -351,8 +368,9 @@ bool CefCookieManagerImpl::FlushStoreInternal(
DCHECK(ValidContext());
auto browser_context = GetBrowserContext(browser_context_getter_);
if (!browser_context)
if (!browser_context) {
return false;
}
GetCookieManager(browser_context)
->FlushCookieStore(

View File

@ -428,8 +428,9 @@ InterceptedRequest::InterceptedRequest(
}
InterceptedRequest::~InterceptedRequest() {
if (status_.error_code != net::OK)
if (status_.error_code != net::OK) {
SendErrorCallback(status_.error_code, false);
}
if (on_headers_received_callback_) {
std::move(on_headers_received_callback_)
.Run(net::ERR_ABORTED, absl::nullopt, GURL());
@ -443,8 +444,9 @@ void InterceptedRequest::Restart() {
target_loader_.reset();
}
if (header_client_receiver_.is_bound())
if (header_client_receiver_.is_bound()) {
std::ignore = header_client_receiver_.Unbind();
}
current_request_uses_header_client_ =
factory_->url_loader_header_client_receiver_.is_bound();
@ -500,8 +502,9 @@ void InterceptedRequest::InputStreamFailed(bool restart_needed) {
return;
}
if (!restart_needed)
if (!restart_needed) {
return;
}
input_stream_previously_failed_ = true;
Restart();
@ -521,8 +524,9 @@ void InterceptedRequest::OnBeforeSendHeaders(
std::move(callback).Run(net::OK, absl::nullopt);
// Resume handling of client messages after continuing from an async callback.
if (proxied_client_receiver_.is_bound())
if (proxied_client_receiver_.is_bound()) {
proxied_client_receiver_.Resume();
}
}
void InterceptedRequest::OnHeadersReceived(
@ -685,8 +689,9 @@ void InterceptedRequest::FollowRedirect(
// If |OnURLLoaderClientError| was called then we're just waiting for the
// connection error handler of |proxied_loader_receiver_|. Don't restart the
// job since that'll create another URLLoader.
if (!target_client_)
if (!target_client_) {
return;
}
// Normally we would call FollowRedirect on the target loader and it would
// begin loading the redirected request. However, the client might want to
@ -696,18 +701,21 @@ void InterceptedRequest::FollowRedirect(
void InterceptedRequest::SetPriority(net::RequestPriority priority,
int32_t intra_priority_value) {
if (target_loader_)
if (target_loader_) {
target_loader_->SetPriority(priority, intra_priority_value);
}
}
void InterceptedRequest::PauseReadingBodyFromNet() {
if (target_loader_)
if (target_loader_) {
target_loader_->PauseReadingBodyFromNet();
}
}
void InterceptedRequest::ResumeReadingBodyFromNet() {
if (target_loader_)
if (target_loader_) {
target_loader_->ResumeReadingBodyFromNet();
}
}
// Helper methods.
@ -828,8 +836,9 @@ void InterceptedRequest::HandleResponseOrRedirectHeaders(
redirect_url_ = redirect_info.has_value() ? redirect_info->new_url : GURL();
original_url_ = request_.url;
if (!redirect_url_.is_empty())
if (!redirect_url_.is_empty()) {
redirect_in_progress_ = true;
}
// |current_response_| may be nullptr when called from OnHeadersReceived.
auto headers =
@ -841,8 +850,9 @@ void InterceptedRequest::HandleResponseOrRedirectHeaders(
id_, request_, redirect_url_, headers.get());
// Pause handling of client messages before waiting on an async callback.
if (proxied_client_receiver_.is_bound())
if (proxied_client_receiver_.is_bound()) {
proxied_client_receiver_.Pause();
}
factory_->request_handler_->OnRequestResponse(
id_, &request_, headers.get(), redirect_info,
@ -884,8 +894,9 @@ void InterceptedRequest::ContinueToHandleOverrideHeaders(int error_code) {
DCHECK(on_headers_received_callback_);
absl::optional<std::string> headers;
if (override_headers_)
if (override_headers_) {
headers = override_headers_->raw_headers();
}
header_client_redirect_url_ = redirect_url_;
std::move(on_headers_received_callback_).Run(net::OK, headers, redirect_url_);
@ -893,8 +904,9 @@ void InterceptedRequest::ContinueToHandleOverrideHeaders(int error_code) {
redirect_url_ = GURL();
// Resume handling of client messages after continuing from an async callback.
if (proxied_client_receiver_.is_bound())
if (proxied_client_receiver_.is_bound()) {
proxied_client_receiver_.Resume();
}
}
net::RedirectInfo InterceptedRequest::MakeRedirectResponseAndInfo(
@ -932,16 +944,18 @@ void InterceptedRequest::ContinueToBeforeRedirect(
request_was_redirected_ = true;
redirect_in_progress_ = false;
if (header_client_redirect_url_.is_valid())
if (header_client_redirect_url_.is_valid()) {
header_client_redirect_url_ = GURL();
}
const GURL redirect_url = redirect_url_;
override_headers_ = nullptr;
redirect_url_ = GURL();
// Resume handling of client messages after continuing from an async callback.
if (proxied_client_receiver_.is_bound())
if (proxied_client_receiver_.is_bound()) {
proxied_client_receiver_.Resume();
}
const auto original_url = request_.url;
const auto original_method = request_.method;
@ -1045,8 +1059,9 @@ void InterceptedRequest::ContinueToResponseStarted(int error_code) {
// Resume handling of client messages after continuing from an async
// callback.
if (proxied_client_receiver_.is_bound())
if (proxied_client_receiver_.is_bound()) {
proxied_client_receiver_.Resume();
}
target_client_->OnReceiveResponse(
std::move(current_response_),
@ -1075,8 +1090,9 @@ void InterceptedRequest::OnProcessRequestHeaders(
if (!modified_headers->IsEmpty() || !removed_headers->empty()) {
request_.headers.MergeFrom(*modified_headers);
for (const std::string& name : *removed_headers)
for (const std::string& name : *removed_headers) {
request_.headers.RemoveHeader(name);
}
}
}
@ -1090,15 +1106,17 @@ void InterceptedRequest::OnURLLoaderClientError() {
void InterceptedRequest::OnURLLoaderError(uint32_t custom_reason,
const std::string& description) {
if (custom_reason == network::mojom::URLLoader::kClientDisconnectReason)
if (custom_reason == network::mojom::URLLoader::kClientDisconnectReason) {
SendErrorCallback(safe_browsing::kNetErrorCodeForSafeBrowsing, true);
}
got_loader_error_ = true;
// If CallOnComplete was already called, then this object is ready to be
// deleted.
if (!target_client_)
if (!target_client_) {
OnDestroy();
}
}
void InterceptedRequest::CallOnComplete(
@ -1106,8 +1124,9 @@ void InterceptedRequest::CallOnComplete(
bool wait_for_loader_error) {
status_ = status;
if (target_client_)
if (target_client_) {
target_client_->OnComplete(status);
}
if (proxied_loader_receiver_.is_bound() &&
(wait_for_loader_error && !got_loader_error_)) {
@ -1149,8 +1168,9 @@ void InterceptedRequest::SendErrorCallback(int error_code,
bool safebrowsing_hit) {
// Ensure we only send one error callback, e.g. to avoid sending two if
// there's both a networking error and safe browsing blocked the request.
if (sent_error_callback_)
if (sent_error_callback_) {
return;
}
sent_error_callback_ = true;
factory_->request_handler_->OnRequestError(id_, request_, error_code,
@ -1228,8 +1248,9 @@ ProxyURLLoaderFactory::ProxyURLLoaderFactory(
proxy_receivers_.set_disconnect_handler(base::BindRepeating(
&ProxyURLLoaderFactory::OnProxyBindingError, base::Unretained(this)));
if (header_client_receiver)
if (header_client_receiver) {
url_loader_header_client_receiver_.Bind(std::move(header_client_receiver));
}
}
ProxyURLLoaderFactory::~ProxyURLLoaderFactory() {
@ -1275,8 +1296,9 @@ void ProxyURLLoaderFactory::CreateProxy(
mojo::PendingReceiver<network::mojom::TrustedURLLoaderHeaderClient>
header_client_receiver;
if (header_client)
if (header_client) {
header_client_receiver = header_client->InitWithNewPipeAndPassReceiver();
}
content::ResourceContext* resource_context =
browser_context->GetResourceContext();
@ -1362,8 +1384,9 @@ void ProxyURLLoaderFactory::OnLoaderCreated(
mojo::PendingReceiver<network::mojom::TrustedHeaderClient> receiver) {
CEF_REQUIRE_IOT();
auto request_it = requests_.find(request_id);
if (request_it != requests_.end())
if (request_it != requests_.end()) {
request_it->second->OnLoaderCreated(std::move(receiver));
}
}
void ProxyURLLoaderFactory::OnLoaderForCorsPreflightCreated(
@ -1382,8 +1405,9 @@ void ProxyURLLoaderFactory::OnTargetFactoryError() {
}
void ProxyURLLoaderFactory::OnProxyBindingError() {
if (proxy_receivers_.empty())
if (proxy_receivers_.empty()) {
target_factory_.reset();
}
MaybeDestroySelf();
}
@ -1399,8 +1423,9 @@ void ProxyURLLoaderFactory::RemoveRequest(InterceptedRequest* request) {
void ProxyURLLoaderFactory::MaybeDestroySelf() {
// Even if all URLLoaderFactory pipes connected to this object have been
// closed it has to stay alive until all active requests have completed.
if (target_factory_.is_bound() || !requests_.empty())
if (target_factory_.is_bound() || !requests_.empty()) {
return;
}
destroyed_ = true;

View File

@ -113,8 +113,9 @@ class HandlerProvider : public base::RefCountedThreadSafe<HandlerProvider> {
void Detach() {
base::AutoLock lock_scope(lock_);
if (!handler_)
if (!handler_) {
return;
}
// Execute on the expected thread.
CEF_POST_TASK(CEF_IOT,
@ -186,8 +187,9 @@ class ReadResponseCallbackWrapper : public CefCallback {
void DoRead() {
CEF_REQUIRE_IOT();
if (!callback_)
if (!callback_) {
return;
}
auto handler = handler_provider_->handler();
if (!handler) {
@ -489,8 +491,9 @@ class ResourceResponseWrapper : public ResourceResponse {
// A |content_length| value may already be specified if the request included
// a Range header.
if (response_length >= 0 && *content_length == -1)
if (response_length >= 0 && *content_length == -1) {
*content_length = response_length;
}
CefResponse::HeaderMap headerMap;
response->GetHeaderMap(headerMap);

View File

@ -165,15 +165,17 @@ class InterceptedRequestHandlerWrapper : public InterceptedRequestHandler {
virtual ~DestructionObserver() {
CEF_REQUIRE_UIT();
if (!registered_)
if (!registered_) {
return;
}
// Verify that the browser or context still exists before attempting to
// remove the observer.
if (browser_info_) {
auto browser = browser_info_->browser();
if (browser)
if (browser) {
browser->RemoveObserver(this);
}
} else if (CefContext::Get()) {
// Network requests may be torn down during shutdown, so we can't check
// CONTEXT_STATE_VALID() here.
@ -345,8 +347,9 @@ class InterceptedRequestHandlerWrapper : public InterceptedRequestHandler {
base::AutoLock lock_scope(lock_);
// May be nullptr if the InterceptedRequestHandlerWrapper has already
// been deleted.
if (!wrapper_)
if (!wrapper_) {
return;
}
wrapper_->SetInitialized(std::move(init_state));
wrapper_ = nullptr;
}
@ -401,8 +404,9 @@ class InterceptedRequestHandlerWrapper : public InterceptedRequestHandler {
// Continue any pending requests.
if (!pending_requests_.empty()) {
for (const auto& request : pending_requests_)
for (const auto& request : pending_requests_) {
request->Run(this);
}
pending_requests_.clear();
}
}
@ -555,8 +559,9 @@ class InterceptedRequestHandlerWrapper : public InterceptedRequestHandler {
// True if there's a possibility that the client might handle the request.
const bool maybe_intercept_request = handler || scheme_factory;
if (!maybe_intercept_request && requestPtr)
if (!maybe_intercept_request && requestPtr) {
requestPtr = nullptr;
}
// May have a handler and/or scheme factory.
state->Reset(handler, scheme_factory, requestPtr, request_was_redirected,
@ -812,16 +817,19 @@ class InterceptedRequestHandlerWrapper : public InterceptedRequestHandler {
return;
}
if (!state->handler_)
if (!state->handler_) {
return;
}
if (!state->pending_response_)
if (!state->pending_response_) {
state->pending_response_ = new CefResponseImpl();
else
} else {
state->pending_response_->SetReadOnly(false);
}
if (headers)
if (headers) {
state->pending_response_->SetResponseHeaders(*headers);
}
state->pending_response_->SetReadOnly(true);
}
@ -1120,8 +1128,9 @@ class InterceptedRequestHandlerWrapper : public InterceptedRequestHandler {
private:
void CallHandlerOnComplete(RequestState* state,
const network::URLLoaderCompletionStatus& status) {
if (!state->handler_ || !state->pending_request_)
if (!state->handler_ || !state->pending_request_) {
return;
}
// The request object may be currently flagged as writable in cases where we
// abort a request that is waiting on a pending callack.
@ -1178,8 +1187,9 @@ class InterceptedRequestHandlerWrapper : public InterceptedRequestHandler {
init_state_->iothread_state_->GetHandler(
init_state_->global_id_, /*require_frame_match=*/false);
if (context_handler) {
if (!requestPtr)
if (!requestPtr) {
requestPtr = MakeRequest(request, request_id, true);
}
handler = context_handler->GetResourceRequestHandler(
init_state_->browser_, init_state_->frame_, requestPtr.get(),
@ -1202,16 +1212,18 @@ class InterceptedRequestHandlerWrapper : public InterceptedRequestHandler {
RequestState* GetState(int32_t request_id) const {
RequestMap::const_iterator it = request_map_.find(request_id);
if (it != request_map_.end())
if (it != request_map_.end()) {
return it->second.get();
}
return nullptr;
}
void RemoveState(int32_t request_id) {
RequestMap::iterator it = request_map_.find(request_id);
DCHECK(it != request_map_.end());
if (it != request_map_.end())
if (it != request_map_.end()) {
request_map_.erase(it);
}
}
// Stop accepting new requests and cancel pending/in-flight requests when the
@ -1269,10 +1281,11 @@ class InterceptedRequestHandlerWrapper : public InterceptedRequestHandler {
bool read_only) {
CefRefPtr<CefRequestImpl> requestPtr = new CefRequestImpl();
requestPtr->Set(request, request_id);
if (read_only)
if (read_only) {
requestPtr->SetReadOnly(true);
else
} else {
requestPtr->SetTrackChanges(true);
}
return requestPtr;
}
@ -1399,8 +1412,9 @@ std::unique_ptr<InterceptedRequestHandler> CreateInterceptedRequestHandler(
// TODO(navigation): Can we determine the |is_download| value?
const bool is_download = false;
url::Origin request_initiator;
if (request.request_initiator.has_value())
if (request.request_initiator.has_value()) {
request_initiator = *request.request_initiator;
}
auto init_state =
std::make_unique<InterceptedRequestHandlerWrapper::InitState>();

View File

@ -142,8 +142,9 @@ void ResponseFilterWrapper::Filter(const char* data, size_t size) {
last_status_ = filter_->Filter(
const_cast<char*>(data_in_ptr), data_in_size, data_in_read,
const_cast<char*>(data_out_ptr), data_out_size, data_out_written);
if (last_status_ == RESPONSE_FILTER_ERROR)
if (last_status_ == RESPONSE_FILTER_ERROR) {
break;
}
// Validate the out values.
if (data_in_read > data_in_size) {
@ -268,13 +269,15 @@ void ResponseFilterWrapper::MaybeSuccess() {
return;
}
if (!read_pending_ && !write_pending_)
if (!read_pending_ && !write_pending_) {
Cleanup(true);
}
}
void ResponseFilterWrapper::Cleanup(bool success) {
if (!success && error_callback_)
if (!success && error_callback_) {
std::move(error_callback_).Run();
}
delete this;
}
@ -290,8 +293,9 @@ mojo::ScopedDataPipeConsumerHandle CreateResponseFilterHandler(
auto filter_wrapper = new ResponseFilterWrapper(
filter, std::move(source_handle), std::move(error_callback));
mojo::ScopedDataPipeConsumerHandle output_handle;
if (!filter_wrapper->CreateOutputHandle(&output_handle))
if (!filter_wrapper->CreateOutputHandle(&output_handle)) {
delete filter_wrapper;
}
return output_handle;
}

View File

@ -79,8 +79,9 @@ class OpenInputStreamWrapper
void CancelOnJobThread() {
DCHECK(job_thread_task_runner_->RunsTasksInCurrentSequence());
if (callback_.is_null())
if (callback_.is_null()) {
return;
}
callback_.Reset();
@ -91,8 +92,9 @@ class OpenInputStreamWrapper
void CancelOnWorkThread() {
DCHECK(work_thread_task_runner_->RunsTasksInCurrentSequence());
if (is_canceled_)
if (is_canceled_) {
return;
}
is_canceled_ = true;
OnCallback(nullptr);
}
@ -100,8 +102,9 @@ class OpenInputStreamWrapper
void OpenOnWorkThread(int32_t request_id,
const network::ResourceRequest& request) {
DCHECK(work_thread_task_runner_->RunsTasksInCurrentSequence());
if (is_canceled_)
if (is_canceled_) {
return;
}
// |delegate_| will remain valid until OnCallback() is executed on
// |job_thread_task_runner_|.
@ -312,8 +315,9 @@ void InputStreamReader::ReadOnWorkThread(scoped_refptr<net::IOBuffer> dest,
pending_callback_id_));
// Check if the callback will execute asynchronously.
if (result && bytes_read == 0)
if (result && bytes_read == 0) {
return;
}
RunReadCallback(result || bytes_read <= 0 ? bytes_read : net::ERR_FAILED);
}
@ -335,8 +339,9 @@ void InputStreamReader::SkipToRequestedRange() {
pending_callback_id_));
// Check if the callback will execute asynchronously.
if (result && skipped == 0)
if (result && skipped == 0) {
return;
}
if (!result || skipped <= 0) {
RunSkipCallback(net::ERR_REQUEST_RANGE_NOT_SATISFIABLE);
@ -383,13 +388,15 @@ void InputStreamReader::ContinueSkipCallbackOnWorkThread(
DCHECK(work_thread_task_runner_->RunsTasksInCurrentSequence());
// Check for out of order callbacks.
if (pending_callback_id_ != callback_id)
if (pending_callback_id_ != callback_id) {
return;
}
DCHECK_LE(bytes_skipped, bytes_to_skip_);
if (bytes_to_skip_ > 0 && bytes_skipped > 0)
if (bytes_to_skip_ > 0 && bytes_skipped > 0) {
bytes_to_skip_ -= bytes_skipped;
}
if (bytes_skipped <= 0) {
RunSkipCallback(net::ERR_REQUEST_RANGE_NOT_SATISFIABLE);
@ -409,8 +416,9 @@ void InputStreamReader::ContinueReadCallbackOnWorkThread(int callback_id,
DCHECK(work_thread_task_runner_->RunsTasksInCurrentSequence());
// Check for out of order callbacks.
if (pending_callback_id_ != callback_id)
if (pending_callback_id_ != callback_id) {
return;
}
RunReadCallback(bytes_read);
}
@ -637,13 +645,15 @@ void StreamReaderURLLoader::HeadersComplete(int orig_status_code,
extra_headers, false /* allow_existing_header_override */);
pending_response->headers = headers;
if (content_length >= 0)
if (content_length >= 0) {
pending_response->content_length = content_length;
}
if (!mime_type.empty()) {
pending_response->mime_type = mime_type;
if (!charset.empty())
if (!charset.empty()) {
pending_response->charset = charset;
}
}
if (header_client_.is_bound()) {
@ -826,8 +836,9 @@ bool StreamReaderURLLoader::ParseRange(const net::HttpRequestHeaders& headers) {
if (net::HttpUtil::ParseRangeHeader(range_header, &ranges)) {
// In case of multi-range request only use the first range.
// We don't support multirange requests.
if (ranges.size() == 1)
if (ranges.size() == 1) {
byte_range_ = ranges[0];
}
} else {
// This happens if the range header could not be parsed or is invalid.
return false;

View File

@ -95,8 +95,9 @@ URLLoaderFactoryGetter::GetURLLoaderFactory() {
DCHECK(task_runner_->RunsTasksInCurrentSequence());
}
if (lazy_factory_)
if (lazy_factory_) {
return lazy_factory_;
}
// Bind on the current thread.
auto loader_factory =

View File

@ -52,8 +52,9 @@ class CefOriginWhitelistManager {
// Verify that the origin entry doesn't already exist.
for (const auto& entry : origin_list_) {
if (entry == info)
if (entry == info) {
return false;
}
}
origin_list_.push_back(info->Clone());
@ -88,8 +89,9 @@ class CefOriginWhitelistManager {
}
}
if (!found)
if (!found) {
return false;
}
SendModifyCrossOriginWhitelistEntry(false, info);
return true;
@ -123,8 +125,9 @@ class CefOriginWhitelistManager {
if (!origin_list_.empty()) {
for (const auto& entry : origin_list_) {
if (IsMatch(source, target, entry))
if (IsMatch(source, target, entry)) {
return true;
}
}
}

View File

@ -57,8 +57,9 @@ void CefBrowserPlatformDelegateOsr::WebContentsCreated(
void CefBrowserPlatformDelegateOsr::RenderViewCreated(
content::RenderViewHost* render_view_host) {
if (view_osr_)
if (view_osr_) {
view_osr_->RenderViewCreated();
}
}
void CefBrowserPlatformDelegateOsr::BrowserCreated(
@ -105,14 +106,16 @@ SkColor CefBrowserPlatformDelegateOsr::GetBackgroundColor() const {
void CefBrowserPlatformDelegateOsr::WasResized() {
CefRenderWidgetHostViewOSR* view = GetOSRHostView();
if (view)
if (view) {
view->WasResized();
}
}
void CefBrowserPlatformDelegateOsr::SendKeyEvent(const CefKeyEvent& event) {
CefRenderWidgetHostViewOSR* view = GetOSRHostView();
if (!view)
if (!view) {
return;
}
content::NativeWebKeyboardEvent web_event =
native_delegate_->TranslateWebKeyEvent(event);
@ -125,8 +128,9 @@ void CefBrowserPlatformDelegateOsr::SendMouseClickEvent(
bool mouseUp,
int clickCount) {
CefRenderWidgetHostViewOSR* view = GetOSRHostView();
if (!view)
if (!view) {
return;
}
blink::WebMouseEvent web_event = native_delegate_->TranslateWebClickEvent(
event, type, mouseUp, clickCount);
@ -137,8 +141,9 @@ void CefBrowserPlatformDelegateOsr::SendMouseMoveEvent(
const CefMouseEvent& event,
bool mouseLeave) {
CefRenderWidgetHostViewOSR* view = GetOSRHostView();
if (!view)
if (!view) {
return;
}
blink::WebMouseEvent web_event =
native_delegate_->TranslateWebMoveEvent(event, mouseLeave);
@ -150,8 +155,9 @@ void CefBrowserPlatformDelegateOsr::SendMouseWheelEvent(
int deltaX,
int deltaY) {
CefRenderWidgetHostViewOSR* view = GetOSRHostView();
if (!view)
if (!view) {
return;
}
blink::WebMouseWheelEvent web_event =
native_delegate_->TranslateWebWheelEvent(event, deltaX, deltaY);
@ -160,14 +166,16 @@ void CefBrowserPlatformDelegateOsr::SendMouseWheelEvent(
void CefBrowserPlatformDelegateOsr::SendTouchEvent(const CefTouchEvent& event) {
CefRenderWidgetHostViewOSR* view = GetOSRHostView();
if (view)
if (view) {
view->SendTouchEvent(event);
}
}
void CefBrowserPlatformDelegateOsr::SetFocus(bool setFocus) {
CefRenderWidgetHostViewOSR* view = GetOSRHostView();
if (view)
if (view) {
view->SetFocus(setFocus);
}
}
gfx::Point CefBrowserPlatformDelegateOsr::GetScreenPoint(
@ -228,42 +236,48 @@ void CefBrowserPlatformDelegateOsr::WasHidden(bool hidden) {
content::WebContentsImpl* web_contents =
static_cast<content::WebContentsImpl*>(web_contents_);
if (web_contents) {
if (hidden)
if (hidden) {
web_contents->WasHidden();
else
} else {
web_contents->WasShown();
}
}
}
bool CefBrowserPlatformDelegateOsr::IsHidden() const {
CefRenderWidgetHostViewOSR* view = GetOSRHostView();
if (view)
if (view) {
return view->is_hidden();
}
return true;
}
void CefBrowserPlatformDelegateOsr::NotifyScreenInfoChanged() {
CefRenderWidgetHostViewOSR* view = GetOSRHostView();
if (view)
if (view) {
view->OnScreenInfoChanged();
}
}
void CefBrowserPlatformDelegateOsr::Invalidate(cef_paint_element_type_t type) {
CefRenderWidgetHostViewOSR* view = GetOSRHostView();
if (view)
if (view) {
view->Invalidate(type);
}
}
void CefBrowserPlatformDelegateOsr::SendExternalBeginFrame() {
CefRenderWidgetHostViewOSR* view = GetOSRHostView();
if (view)
if (view) {
view->SendExternalBeginFrame();
}
}
void CefBrowserPlatformDelegateOsr::SetWindowlessFrameRate(int frame_rate) {
CefRenderWidgetHostViewOSR* view = GetOSRHostView();
if (view)
if (view) {
view->UpdateFrameRate();
}
}
void CefBrowserPlatformDelegateOsr::ImeSetComposition(
@ -283,21 +297,24 @@ void CefBrowserPlatformDelegateOsr::ImeCommitText(
const CefRange& replacement_range,
int relative_cursor_pos) {
CefRenderWidgetHostViewOSR* view = GetOSRHostView();
if (view)
if (view) {
view->ImeCommitText(text, replacement_range, relative_cursor_pos);
}
}
void CefBrowserPlatformDelegateOsr::ImeFinishComposingText(
bool keep_selection) {
CefRenderWidgetHostViewOSR* view = GetOSRHostView();
if (view)
if (view) {
view->ImeFinishComposingText(keep_selection);
}
}
void CefBrowserPlatformDelegateOsr::ImeCancelComposition() {
CefRenderWidgetHostViewOSR* view = GetOSRHostView();
if (view)
if (view) {
view->ImeCancelComposition();
}
}
void CefBrowserPlatformDelegateOsr::DragTargetDragEnter(
@ -306,11 +323,13 @@ void CefBrowserPlatformDelegateOsr::DragTargetDragEnter(
cef_drag_operations_mask_t allowed_ops) {
content::WebContentsImpl* web_contents =
static_cast<content::WebContentsImpl*>(web_contents_);
if (!web_contents)
if (!web_contents) {
return;
}
if (current_rvh_for_drag_)
if (current_rvh_for_drag_) {
DragTargetDragLeave();
}
const gfx::Point client_pt(event.x, event.y);
gfx::PointF transformed_pt;
@ -351,13 +370,15 @@ void CefBrowserPlatformDelegateOsr::DragTargetDragEnter(
void CefBrowserPlatformDelegateOsr::DragTargetDragOver(
const CefMouseEvent& event,
cef_drag_operations_mask_t allowed_ops) {
if (!drag_data_)
if (!drag_data_) {
return;
}
content::WebContentsImpl* web_contents =
static_cast<content::WebContentsImpl*>(web_contents_);
if (!web_contents)
if (!web_contents) {
return;
}
const gfx::Point client_pt(event.x, event.y);
const gfx::Point& screen_pt =
@ -393,8 +414,9 @@ void CefBrowserPlatformDelegateOsr::DragTargetDragOver(
DragTargetDragEnter(drag_data_, event, drag_allowed_ops_);
}
if (!drag_data_)
if (!drag_data_) {
return;
}
blink::DragOperationsMask ops =
static_cast<blink::DragOperationsMask>(allowed_ops);
@ -419,13 +441,15 @@ void CefBrowserPlatformDelegateOsr::DragTargetDragLeave() {
}
void CefBrowserPlatformDelegateOsr::DragTargetDrop(const CefMouseEvent& event) {
if (!drag_data_)
if (!drag_data_) {
return;
}
content::WebContentsImpl* web_contents =
static_cast<content::WebContentsImpl*>(web_contents_);
if (!web_contents)
if (!web_contents) {
return;
}
gfx::Point client_pt(event.x, event.y);
const gfx::Point& screen_pt =
@ -461,8 +485,9 @@ void CefBrowserPlatformDelegateOsr::DragTargetDrop(const CefMouseEvent& event) {
DragTargetDragEnter(drag_data_, event, drag_allowed_ops_);
}
if (!drag_data_)
if (!drag_data_) {
return;
}
{
CefDragDataImpl* data_impl =
@ -505,8 +530,9 @@ void CefBrowserPlatformDelegateOsr::StartDragging(
event_info.location.x(), event_info.location.y());
}
if (!handled)
if (!handled) {
DragSourceSystemDragEnded();
}
}
void CefBrowserPlatformDelegateOsr::UpdateDragCursor(
@ -523,13 +549,15 @@ void CefBrowserPlatformDelegateOsr::DragSourceEndedAt(
int x,
int y,
cef_drag_operations_mask_t op) {
if (!drag_start_rwh_)
if (!drag_start_rwh_) {
return;
}
content::WebContentsImpl* web_contents =
static_cast<content::WebContentsImpl*>(web_contents_);
if (!web_contents)
if (!web_contents) {
return;
}
content::RenderWidgetHostImpl* source_rwh = drag_start_rwh_.get();
const gfx::Point client_loc(gfx::Point(x, y));
@ -565,13 +593,15 @@ void CefBrowserPlatformDelegateOsr::DragSourceEndedAt(
}
void CefBrowserPlatformDelegateOsr::DragSourceSystemDragEnded() {
if (!drag_start_rwh_)
if (!drag_start_rwh_) {
return;
}
content::WebContentsImpl* web_contents =
static_cast<content::WebContentsImpl*>(web_contents_);
if (!web_contents)
if (!web_contents) {
return;
}
web_contents->SystemDragEnded(drag_start_rwh_.get());

View File

@ -78,8 +78,9 @@ void CefLayeredWindowUpdaterOSR::OnAllocatedSharedMemory(
size_t expected_bytes;
bool size_result = viz::ResourceSizes::MaybeSizeInBytes(
pixel_size, viz::ResourceFormat::RGBA_8888, &expected_bytes);
if (!size_result)
if (!size_result) {
return;
}
pixel_size_ = pixel_size;
shared_memory_ = region.Map();

View File

@ -39,10 +39,11 @@ CefMotionEventOSR::CefMotionEventOSR() {
CefMotionEventOSR::~CefMotionEventOSR() {}
int CefMotionEventOSR::GetSourceDeviceId(size_t pointer_index) const {
if (IsValidIndex(pointer_index))
if (IsValidIndex(pointer_index)) {
return pointer(pointer_index).source_device_id;
else
} else {
return -1;
}
}
// Returns true if the touch was valid.
@ -63,10 +64,12 @@ bool CefMotionEventOSR::OnTouch(const CefTouchEvent& touch) {
switch (touch.type) {
case CEF_TET_PRESSED:
id = AddId(touch.id);
if (id == -1)
if (id == -1) {
return false;
if (!AddTouch(touch, id))
}
if (!AddTouch(touch, id)) {
return false;
}
break;
case CEF_TET_MOVED: {
@ -126,15 +129,17 @@ void CefMotionEventOSR::MarkUnchangedTouchPointsAsStationary(
if (event->GetType() == blink::WebInputEvent::Type::kTouchMove ||
event->GetType() == blink::WebInputEvent::Type::kTouchCancel) {
for (size_t i = 0; i < event->touches_length; ++i) {
if (event->touches[i].id != id)
if (event->touches[i].id != id) {
event->touches[i].state = blink::WebTouchPoint::State::kStateStationary;
}
}
}
}
int CefMotionEventOSR::LookupId(int id) {
if (id == -1)
if (id == -1) {
return -1;
}
for (int i = 0; i < blink::WebTouchEvent::kTouchesLengthCap; i++) {
if (id_map_[i] == id) {
@ -145,8 +150,9 @@ int CefMotionEventOSR::LookupId(int id) {
}
int CefMotionEventOSR::AddId(int id) {
if (id == -1 || LookupId(id) >= 0)
if (id == -1 || LookupId(id) >= 0) {
return -1;
}
for (int i = 0; i < blink::WebTouchEvent::kTouchesLengthCap; i++) {
if (id_map_[i] == -1) {
@ -167,8 +173,9 @@ void CefMotionEventOSR::RemoveId(int id) {
}
bool CefMotionEventOSR::AddTouch(const CefTouchEvent& touch, int id) {
if (GetPointerCount() == MotionEvent::MAX_TOUCH_POINT_COUNT)
if (GetPointerCount() == MotionEvent::MAX_TOUCH_POINT_COUNT) {
return false;
}
PushPointer(GetPointerPropertiesFromTouchEvent(touch, id));
return true;
@ -176,8 +183,9 @@ bool CefMotionEventOSR::AddTouch(const CefTouchEvent& touch, int id) {
void CefMotionEventOSR::UpdateTouch(const CefTouchEvent& touch, int id) {
int index_to_update = FindPointerIndexOfId(id);
if (IsValidIndex(index_to_update))
if (IsValidIndex(index_to_update)) {
pointer(index_to_update) = GetPointerPropertiesFromTouchEvent(touch, id);
}
}
void CefMotionEventOSR::UpdateCachedAction(const CefTouchEvent& touch, int id) {

View File

@ -28,8 +28,9 @@ CefRefPtr<CefListValue> ToCefValue(const std::vector<T>& vecData);
template <>
CefRefPtr<CefListValue> ToCefValue<int>(const std::vector<int>& vecData) {
CefRefPtr<CefListValue> value = CefListValue::Create();
for (size_t i = 0; i < vecData.size(); i++)
for (size_t i = 0; i < vecData.size(); i++) {
value->SetInt(i, vecData[i]);
}
return value;
}
@ -43,8 +44,9 @@ CefRefPtr<CefListValue> ToCefValue(uint32_t state) {
// Iterate and find which states are set.
for (unsigned i = static_cast<unsigned>(ax::mojom::Role::kMinValue) + 1;
i <= static_cast<unsigned>(ax::mojom::Role::kMaxValue); i++) {
if (state & (1 << i))
if (state & (1 << i)) {
value->SetString(index++, ToString(static_cast<ax::mojom::State>(i)));
}
}
return value;
}
@ -69,8 +71,9 @@ struct PopulateAxNodeAttributes {
// Int Attributes
void operator()(const std::pair<ax::mojom::IntAttribute, int32_t> attr) {
if (attr.first == ax::mojom::IntAttribute::kNone)
if (attr.first == ax::mojom::IntAttribute::kNone) {
return;
}
switch (attr.first) {
case ax::mojom::IntAttribute::kNone:
@ -201,8 +204,9 @@ struct PopulateAxNodeAttributes {
int index = 0;
// Iterate and find which states are set.
for (unsigned i = 0; i < std::size(textStyleArr); i++) {
if (attr.second & static_cast<int>(textStyleArr[i]))
if (attr.second & static_cast<int>(textStyleArr[i])) {
list->SetString(index++, ToString(textStyleArr[i]));
}
}
attributes->SetList(ToString(attr.first), list);
} break;
@ -225,19 +229,22 @@ struct PopulateAxNodeAttributes {
// Set Bool Attributes.
void operator()(const std::pair<ax::mojom::BoolAttribute, bool> attr) {
if (attr.first != ax::mojom::BoolAttribute::kNone)
if (attr.first != ax::mojom::BoolAttribute::kNone) {
attributes->SetBool(ToString(attr.first), attr.second);
}
}
// Set String Attributes.
void operator()(
const std::pair<ax::mojom::StringAttribute, std::string>& attr) {
if (attr.first != ax::mojom::StringAttribute::kNone)
if (attr.first != ax::mojom::StringAttribute::kNone) {
attributes->SetString(ToString(attr.first), attr.second);
}
}
// Set Float attributes.
void operator()(const std::pair<ax::mojom::FloatAttribute, float>& attr) {
if (attr.first != ax::mojom::FloatAttribute::kNone)
if (attr.first != ax::mojom::FloatAttribute::kNone) {
attributes->SetDouble(ToString(attr.first), attr.second);
}
}
// Set Int list attributes.
@ -252,8 +259,9 @@ struct PopulateAxNodeAttributes {
for (size_t i = 0; i < attr.second.size(); ++i) {
auto type = static_cast<ax::mojom::MarkerType>(attr.second[i]);
if (type == ax::mojom::MarkerType::kNone)
if (type == ax::mojom::MarkerType::kNone) {
continue;
}
static ax::mojom::MarkerType marktypeArr[] = {
ax::mojom::MarkerType::kSpelling, ax::mojom::MarkerType::kGrammar,
@ -261,8 +269,9 @@ struct PopulateAxNodeAttributes {
// Iterate and find which markers are set.
for (unsigned j = 0; j < std::size(marktypeArr); j++) {
if (attr.second[i] & static_cast<int>(marktypeArr[j]))
if (attr.second[i] & static_cast<int>(marktypeArr[j])) {
list->SetString(index++, ToString(marktypeArr[j]));
}
}
}
} else {
@ -277,8 +286,9 @@ struct PopulateAxNodeAttributes {
CefRefPtr<CefDictionaryValue> ToCefValue(const ui::AXNodeData& node) {
CefRefPtr<CefDictionaryValue> value = CefDictionaryValue::Create();
if (node.id != -1)
if (node.id != -1) {
value->SetInt("id", node.id);
}
value->SetString("role", ToString(node.role));
value->SetList("state", ToCefValue(node.state));
@ -308,13 +318,15 @@ CefRefPtr<CefDictionaryValue> ToCefValue(const ui::AXNodeData& node) {
++action_index) {
auto action = static_cast<ax::mojom::Action>(action_index);
if (node.HasAction(action)) {
if (!actions_strings)
if (!actions_strings) {
actions_strings = CefListValue::Create();
}
actions_strings->SetString(actions_idx++, ToString(action));
}
}
if (actions_strings)
if (actions_strings) {
value->SetList("actions", actions_strings);
}
CefRefPtr<CefDictionaryValue> attributes = CefDictionaryValue::Create();
PopulateAxNodeAttributes func(attributes);
@ -346,29 +358,37 @@ CefRefPtr<CefDictionaryValue> ToCefValue(const ui::AXNodeData& node) {
CefRefPtr<CefDictionaryValue> ToCefValue(const ui::AXTreeData& treeData) {
CefRefPtr<CefDictionaryValue> value = CefDictionaryValue::Create();
if (!treeData.tree_id.ToString().empty())
if (!treeData.tree_id.ToString().empty()) {
value->SetString("tree_id", treeData.tree_id.ToString());
}
if (!treeData.parent_tree_id.ToString().empty())
if (!treeData.parent_tree_id.ToString().empty()) {
value->SetString("parent_tree_id", treeData.parent_tree_id.ToString());
}
if (!treeData.focused_tree_id.ToString().empty())
if (!treeData.focused_tree_id.ToString().empty()) {
value->SetString("focused_tree_id", treeData.focused_tree_id.ToString());
}
if (!treeData.doctype.empty())
if (!treeData.doctype.empty()) {
value->SetString("doctype", treeData.doctype);
}
value->SetBool("loaded", treeData.loaded);
if (treeData.loading_progress != 0.0)
if (treeData.loading_progress != 0.0) {
value->SetDouble("loading_progress", treeData.loading_progress);
}
if (!treeData.mimetype.empty())
if (!treeData.mimetype.empty()) {
value->SetString("mimetype", treeData.mimetype);
if (!treeData.url.empty())
}
if (!treeData.url.empty()) {
value->SetString("url", treeData.url);
if (!treeData.title.empty())
}
if (!treeData.title.empty()) {
value->SetString("title", treeData.title);
}
if (treeData.sel_anchor_object_id != -1) {
value->SetInt("sel_anchor_object_id", treeData.sel_anchor_object_id);
@ -383,8 +403,9 @@ CefRefPtr<CefDictionaryValue> ToCefValue(const ui::AXTreeData& treeData) {
ToString(treeData.sel_anchor_affinity));
}
if (treeData.focus_id != -1)
if (treeData.focus_id != -1) {
value->SetInt("focus_id", treeData.focus_id);
}
return value;
}
@ -398,11 +419,13 @@ CefRefPtr<CefDictionaryValue> ToCefValue(const ui::AXTreeUpdate& update) {
value->SetDictionary("tree_data", ToCefValue(update.tree_data));
}
if (update.node_id_to_clear != 0)
if (update.node_id_to_clear != 0) {
value->SetInt("node_id_to_clear", update.node_id_to_clear);
}
if (update.root_id != 0)
if (update.root_id != 0) {
value->SetInt("root_id", update.root_id);
}
value->SetList("nodes", ToCefValue(update.nodes));
@ -413,17 +436,21 @@ CefRefPtr<CefDictionaryValue> ToCefValue(const ui::AXTreeUpdate& update) {
CefRefPtr<CefDictionaryValue> ToCefValue(const ui::AXEvent& event) {
CefRefPtr<CefDictionaryValue> value = CefDictionaryValue::Create();
if (event.event_type != ax::mojom::Event::kNone)
if (event.event_type != ax::mojom::Event::kNone) {
value->SetString("event_type", ToString(event.event_type));
}
if (event.id != -1)
if (event.id != -1) {
value->SetInt("id", event.id);
}
if (event.event_from != ax::mojom::EventFrom::kNone)
if (event.event_from != ax::mojom::EventFrom::kNone) {
value->SetString("event_from", ToString(event.event_from));
}
if (event.action_request_id != -1)
if (event.action_request_id != -1) {
value->SetInt("action_request_id", event.action_request_id);
}
return value;
}
@ -433,8 +460,9 @@ CefRefPtr<CefDictionaryValue> ToCefValue(
const content::AXEventNotificationDetails& eventData) {
CefRefPtr<CefDictionaryValue> value = CefDictionaryValue::Create();
if (!eventData.ax_tree_id.ToString().empty())
if (!eventData.ax_tree_id.ToString().empty()) {
value->SetString("ax_tree_id", eventData.ax_tree_id.ToString());
}
if (eventData.updates.size() > 0) {
CefRefPtr<CefListValue> updates = CefListValue::Create();
@ -464,15 +492,17 @@ CefRefPtr<CefDictionaryValue> ToCefValue(
CefRefPtr<CefDictionaryValue> ToCefValue(const ui::AXRelativeBounds& location) {
CefRefPtr<CefDictionaryValue> value = CefDictionaryValue::Create();
if (location.offset_container_id != -1)
if (location.offset_container_id != -1) {
value->SetInt("offset_container_id", location.offset_container_id);
}
value->SetDictionary("bounds", ToCefValue(location.bounds));
// Transform matrix is private, so we set the string that Clients can parse
// and use if needed.
if (location.transform && !location.transform->IsIdentity())
if (location.transform && !location.transform->IsIdentity()) {
value->SetString("transform", location.transform->ToString());
}
return value;
}
@ -482,11 +512,13 @@ CefRefPtr<CefDictionaryValue> ToCefValue(
const content::AXLocationChangeNotificationDetails& locData) {
CefRefPtr<CefDictionaryValue> value = CefDictionaryValue::Create();
if (locData.id != -1)
if (locData.id != -1) {
value->SetInt("id", locData.id);
}
if (!locData.ax_tree_id.ToString().empty())
if (!locData.ax_tree_id.ToString().empty()) {
value->SetString("ax_tree_id", locData.ax_tree_id.ToString());
}
value->SetDictionary("new_location", ToCefValue(locData.new_location));
@ -497,8 +529,9 @@ template <typename T>
CefRefPtr<CefListValue> ToCefValue(const std::vector<T>& vecData) {
CefRefPtr<CefListValue> value = CefListValue::Create();
for (size_t i = 0; i < vecData.size(); i++)
for (size_t i = 0; i < vecData.size(); i++) {
value->SetDictionary(i, ToCefValue(vecData[i]));
}
return value;
}

View File

@ -14,8 +14,9 @@ const int kDefaultFrameRate = 30;
} // namespace
int ClampFrameRate(int frame_rate) {
if (frame_rate < 1)
if (frame_rate < 1) {
return kDefaultFrameRate;
}
return frame_rate;
}

View File

@ -146,8 +146,9 @@ ui::LatencyInfo CreateLatencyInfo(const blink::WebInputEvent& event) {
}
gfx::Rect GetViewBounds(AlloyBrowserHostImpl* browser) {
if (!browser)
if (!browser) {
return gfx::Rect();
}
CefRect rc;
CefRefPtr<CefRenderHandler> handler =
@ -249,16 +250,18 @@ CefRenderWidgetHostViewOSR::CefRenderWidgetHostViewOSR(
content::RenderWidgetHostImpl* render_widget_host_impl =
content::RenderWidgetHostImpl::From(render_widget_host_);
if (render_widget_host_impl)
if (render_widget_host_impl) {
render_widget_host_impl->SetCompositorForFlingScheduler(compositor_.get());
}
cursor_manager_.reset(new content::CursorManager(this));
// This may result in a call to GetFrameSinkId().
render_widget_host_->SetView(this);
if (GetTextInputManager())
if (GetTextInputManager()) {
GetTextInputManager()->AddObserver(this);
}
if (render_widget_host_->delegate() &&
render_widget_host_->delegate()->GetInputEventRouter()) {
@ -270,8 +273,9 @@ CefRenderWidgetHostViewOSR::CefRenderWidgetHostViewOSR(
// For child/popup views this will be called from the associated InitAs*()
// method.
SetRootLayerSize(false /* force */);
if (!render_widget_host_->is_hidden())
if (!render_widget_host_->is_hidden()) {
Show();
}
}
selection_controller_client_ =
@ -288,8 +292,9 @@ CefRenderWidgetHostViewOSR::~CefRenderWidgetHostViewOSR() {
DCHECK(!child_host_view_);
DCHECK(guest_host_views_.empty());
if (text_input_manager_)
if (text_input_manager_) {
text_input_manager_->RemoveObserver(this);
}
}
void CefRenderWidgetHostViewOSR::ReleaseCompositor() {
@ -355,8 +360,9 @@ bool CefRenderWidgetHostViewOSR::IsSurfaceAvailableForCopy() {
void CefRenderWidgetHostViewOSR::ShowWithVisibility(
content::PageVisibilityState) {
if (is_showing_)
if (is_showing_) {
return;
}
if (!content::GpuDataManagerImpl::GetInstance()->IsGpuCompositingDisabled() &&
!browser_impl_ &&
@ -404,8 +410,9 @@ void CefRenderWidgetHostViewOSR::ShowWithVisibility(
}
void CefRenderWidgetHostViewOSR::Hide() {
if (!is_showing_)
if (!is_showing_) {
return;
}
is_showing_ = false;
@ -452,8 +459,9 @@ CefRenderWidgetHostViewOSR::GetTouchSelectionControllerClientManager() {
}
gfx::Rect CefRenderWidgetHostViewOSR::GetViewBounds() {
if (IsPopupWidget())
if (IsPopupWidget()) {
return popup_position_;
}
return current_view_bounds_;
}
@ -552,14 +560,16 @@ void CefRenderWidgetHostViewOSR::UpdateLocalSurfaceIdFromEmbeddedClient(
const viz::LocalSurfaceId&
CefRenderWidgetHostViewOSR::GetOrCreateLocalSurfaceId() {
if (!parent_local_surface_id_allocator_)
if (!parent_local_surface_id_allocator_) {
AllocateLocalSurfaceId();
}
return GetCurrentLocalSurfaceId();
}
void CefRenderWidgetHostViewOSR::InvalidateLocalSurfaceId() {
if (!parent_local_surface_id_allocator_)
if (!parent_local_surface_id_allocator_) {
return;
}
parent_local_surface_id_allocator_->Invalidate();
}
@ -615,8 +625,9 @@ void CefRenderWidgetHostViewOSR::InitAsPopup(
CefRect widget_pos(client_pos.x(), client_pos.y(), client_pos.width(),
client_pos.height());
if (handler.get())
if (handler.get()) {
handler->OnPopupSize(browser_impl_.get(), widget_pos);
}
// The size doesn't change for popups so we need to force the
// initialization.
@ -632,8 +643,9 @@ content::CursorManager* CefRenderWidgetHostViewOSR::GetCursorManager() {
}
void CefRenderWidgetHostViewOSR::SetIsLoading(bool is_loading) {
if (!is_loading)
if (!is_loading) {
return;
}
// Make sure gesture detection is fresh.
gesture_provider_.ResetDetection();
forward_touch_to_popup_ = false;
@ -650,16 +662,19 @@ void CefRenderWidgetHostViewOSR::Destroy() {
if (has_parent_) {
CancelWidget();
} else {
if (popup_host_view_)
if (popup_host_view_) {
popup_host_view_->CancelWidget();
if (child_host_view_)
}
if (child_host_view_) {
child_host_view_->CancelWidget();
}
if (!guest_host_views_.empty()) {
// Guest RWHVs will be destroyed when the associated RWHVGuest is
// destroyed. This parent RWHV may be destroyed first, so disassociate
// the guest RWHVs here without destroying them.
for (auto guest_host_view : guest_host_views_)
for (auto guest_host_view : guest_host_views_) {
guest_host_view->parent_host_view_ = nullptr;
}
guest_host_views_.clear();
}
Hide();
@ -671,8 +686,9 @@ void CefRenderWidgetHostViewOSR::Destroy() {
void CefRenderWidgetHostViewOSR::UpdateTooltipUnderCursor(
const std::u16string& tooltip_text) {
if (!browser_impl_.get())
if (!browser_impl_.get()) {
return;
}
CefString tooltip(tooltip_text);
CefRefPtr<CefDisplayHandler> handler =
@ -743,15 +759,17 @@ void CefRenderWidgetHostViewOSR::TransformPointToRootSurface(
gfx::PointF* point) {}
gfx::Rect CefRenderWidgetHostViewOSR::GetBoundsInRootWindow() {
if (!browser_impl_.get())
if (!browser_impl_.get()) {
return gfx::Rect();
}
CefRect rc;
CefRefPtr<CefRenderHandler> handler =
browser_impl_->client()->GetRenderHandler();
CHECK(handler);
if (handler->GetRootScreenRect(browser_impl_.get(), rc))
if (handler->GetRootScreenRect(browser_impl_.get(), rc)) {
return gfx::Rect(rc.x, rc.y, rc.width, rc.height);
}
return GetViewBounds();
}
@ -777,8 +795,9 @@ void CefRenderWidgetHostViewOSR::ImeSetComposition(
const CefRange& replacement_range,
const CefRange& selection_range) {
TRACE_EVENT0("cef", "CefRenderWidgetHostViewOSR::ImeSetComposition");
if (!render_widget_host_)
if (!render_widget_host_) {
return;
}
std::vector<ui::ImeTextSpan> web_underlines;
web_underlines.reserve(underlines.size());
@ -804,8 +823,9 @@ void CefRenderWidgetHostViewOSR::ImeCommitText(
const CefRange& replacement_range,
int relative_cursor_pos) {
TRACE_EVENT0("cef", "CefRenderWidgetHostViewOSR::ImeCommitText");
if (!render_widget_host_)
if (!render_widget_host_) {
return;
}
gfx::Range range(replacement_range.from, replacement_range.to);
render_widget_host_->ImeCommitText(text, std::vector<ui::ImeTextSpan>(),
@ -817,8 +837,9 @@ void CefRenderWidgetHostViewOSR::ImeCommitText(
void CefRenderWidgetHostViewOSR::ImeFinishComposingText(bool keep_selection) {
TRACE_EVENT0("cef", "CefRenderWidgetHostViewOSR::ImeFinishComposingText");
if (!render_widget_host_)
if (!render_widget_host_) {
return;
}
render_widget_host_->ImeFinishComposingText(keep_selection);
@ -828,8 +849,9 @@ void CefRenderWidgetHostViewOSR::ImeFinishComposingText(bool keep_selection) {
void CefRenderWidgetHostViewOSR::ImeCancelComposition() {
TRACE_EVENT0("cef", "CefRenderWidgetHostViewOSR::ImeCancelComposition");
if (!render_widget_host_)
if (!render_widget_host_) {
return;
}
render_widget_host_->ImeCancelComposition();
@ -842,15 +864,17 @@ void CefRenderWidgetHostViewOSR::SelectionChanged(const std::u16string& text,
const gfx::Range& range) {
RenderWidgetHostViewBase::SelectionChanged(text, offset, range);
if (!browser_impl_.get())
if (!browser_impl_.get()) {
return;
}
CefString selected_text;
if (!range.is_empty() && !text.empty()) {
size_t pos = range.GetMin() - offset;
size_t n = range.length();
if (pos + n <= text.length())
if (pos + n <= text.length()) {
selected_text = text.substr(pos, n);
}
}
CefRefPtr<CefRenderHandler> handler =
@ -934,8 +958,9 @@ void CefRenderWidgetHostViewOSR::DidNavigate() {
absl::nullopt);
}
}
if (delegated_frame_host_)
if (delegated_frame_host_) {
delegated_frame_host_->DidNavigate();
}
is_first_navigation_ = false;
}
@ -1007,8 +1032,9 @@ bool CefRenderWidgetHostViewOSR::InstallTransparency() {
void CefRenderWidgetHostViewOSR::WasResized() {
// Only one resize will be in-flight at a time.
if (hold_resize_) {
if (!pending_resize_)
if (!pending_resize_) {
pending_resize_ = true;
}
return;
}
@ -1053,16 +1079,18 @@ void CefRenderWidgetHostViewOSR::SynchronizeVisualProperties(
void CefRenderWidgetHostViewOSR::OnScreenInfoChanged() {
TRACE_EVENT0("cef", "CefRenderWidgetHostViewOSR::OnScreenInfoChanged");
if (!render_widget_host_)
if (!render_widget_host_) {
return;
}
SynchronizeVisualProperties(cc::DeadlinePolicy::UseDefaultDeadline(),
absl::nullopt);
if (render_widget_host_->delegate())
if (render_widget_host_->delegate()) {
render_widget_host_->delegate()->SendScreenRects();
else
} else {
render_widget_host_->SendScreenRects();
}
render_widget_host_->NotifyScreenInfoChanged();
@ -1071,16 +1099,18 @@ void CefRenderWidgetHostViewOSR::OnScreenInfoChanged() {
// renderer in the rwhv_aura (current_cursor_.SetScaleFactor)
// Notify the guest hosts if any.
for (auto guest_host_view : guest_host_views_)
for (auto guest_host_view : guest_host_views_) {
guest_host_view->OnScreenInfoChanged();
}
}
void CefRenderWidgetHostViewOSR::Invalidate(
CefBrowserHost::PaintElementType type) {
TRACE_EVENT1("cef", "CefRenderWidgetHostViewOSR::Invalidate", "type", type);
if (!IsPopupWidget() && type == PET_POPUP) {
if (popup_host_view_)
if (popup_host_view_) {
popup_host_view_->Invalidate(type);
}
return;
}
InvalidateInternal(gfx::Rect(SizeInPixels()));
@ -1089,8 +1119,9 @@ void CefRenderWidgetHostViewOSR::Invalidate(
void CefRenderWidgetHostViewOSR::SendExternalBeginFrame() {
DCHECK(external_begin_frame_enabled_);
if (begin_frame_pending_)
if (begin_frame_pending_) {
return;
}
begin_frame_pending_ = true;
base::TimeTicks frame_time = base::TimeTicks::Now();
@ -1104,8 +1135,9 @@ void CefRenderWidgetHostViewOSR::SendExternalBeginFrame() {
DCHECK(begin_frame_args.IsValid());
if (render_widget_host_)
if (render_widget_host_) {
render_widget_host_->ProgressFlingIfNeeded(frame_time);
}
if (compositor_) {
compositor_->IssueExternalBeginFrame(
@ -1319,8 +1351,9 @@ void CefRenderWidgetHostViewOSR::SendTouchEvent(const CefTouchEvent& event) {
}
// Update the touch event first.
if (!pointer_state_.OnTouch(event))
if (!pointer_state_.OnTouch(event)) {
return;
}
if (selection_controller_->WillHandleTouchEvent(pointer_state_)) {
pointer_state_.CleanupRemovedTouchPoints(event);
@ -1337,11 +1370,13 @@ void CefRenderWidgetHostViewOSR::SendTouchEvent(const CefTouchEvent& event) {
// Set unchanged touch point to StateStationary for touchmove and
// touchcancel to make sure only send one ack per WebTouchEvent.
if (!result.succeeded)
if (!result.succeeded) {
pointer_state_.MarkUnchangedTouchPointsAsStationary(&touch_event, event);
}
if (!render_widget_host_)
if (!render_widget_host_) {
return;
}
ui::LatencyInfo latency_info = CreateLatencyInfo(touch_event);
if (ShouldRouteEvents()) {
@ -1363,8 +1398,9 @@ void CefRenderWidgetHostViewOSR::SendTouchEvent(const CefTouchEvent& event) {
}
bool CefRenderWidgetHostViewOSR::ShouldRouteEvents() const {
if (!render_widget_host_->delegate())
if (!render_widget_host_->delegate()) {
return false;
}
// Do not route events that are currently targeted to page popups such as
// <select> element drop-downs, since these cannot contain cross-process
@ -1378,8 +1414,9 @@ bool CefRenderWidgetHostViewOSR::ShouldRouteEvents() const {
}
void CefRenderWidgetHostViewOSR::SetFocus(bool focus) {
if (!render_widget_host_)
if (!render_widget_host_) {
return;
}
content::RenderWidgetHostImpl* widget =
content::RenderWidgetHostImpl::From(render_widget_host_);
@ -1405,8 +1442,9 @@ void CefRenderWidgetHostViewOSR::OnUpdateTextInputStateCalled(
content::RenderWidgetHostViewBase* updated_view,
bool did_update_state) {
const auto state = text_input_manager->GetTextInputState();
if (state && !state->show_ime_if_needed)
if (state && !state->show_ime_if_needed) {
return;
}
CefRenderHandler::TextInputMode mode = CEF_TEXT_INPUT_MODE_NONE;
if (state && state->type != ui::TEXT_INPUT_TYPE_NONE) {
@ -1446,8 +1484,9 @@ void CefRenderWidgetHostViewOSR::OnGestureEvent(
ui::CreateWebGestureEventFromGestureEventData(gesture);
// without this check, forwarding gestures does not work!
if (web_event.GetType() == blink::WebInputEvent::Type::kUndefined)
if (web_event.GetType() == blink::WebInputEvent::Type::kUndefined) {
return;
}
ui::LatencyInfo latency_info = CreateLatencyInfo(web_event);
if (ShouldRouteEvents()) {
@ -1468,8 +1507,9 @@ void CefRenderWidgetHostViewOSR::UpdateFrameRate() {
}
// Notify the guest hosts if any.
for (auto guest_host_view : guest_host_views_)
for (auto guest_host_view : guest_host_views_) {
guest_host_view->UpdateFrameRate();
}
}
gfx::Size CefRenderWidgetHostViewOSR::SizeInPixels() {
@ -1529,8 +1569,9 @@ void CefRenderWidgetHostViewOSR::OnPaint(const gfx::Rect& damage_rect,
DCHECK_GT(cached_scale_factor_, 0);
gfx::Size expected_size =
gfx::ScaleToCeiledSize(GetViewBounds().size(), cached_scale_factor_);
if (pixel_size == expected_size)
if (pixel_size == expected_size) {
ReleaseResizeHold();
}
}
}
@ -1539,8 +1580,9 @@ ui::Layer* CefRenderWidgetHostViewOSR::GetRootLayer() const {
}
ui::TextInputType CefRenderWidgetHostViewOSR::GetTextInputType() {
if (text_input_manager_ && text_input_manager_->GetTextInputState())
if (text_input_manager_ && text_input_manager_->GetTextInputState()) {
return text_input_manager_->GetTextInputState()->type;
}
return ui::TEXT_INPUT_TYPE_NONE;
}
@ -1556,8 +1598,9 @@ void CefRenderWidgetHostViewOSR::SetFrameRate() {
CHECK(browser);
// Only set the frame rate one time.
if (frame_rate_threshold_us_ != 0)
if (frame_rate_threshold_us_ != 0) {
return;
}
int frame_rate =
osr_util::ClampFrameRate(browser->settings().windowless_frame_rate);
@ -1590,8 +1633,9 @@ bool CefRenderWidgetHostViewOSR::SetScreenInfo() {
// Notify the guest hosts if any.
for (auto guest_host_view : guest_host_views_) {
content::RenderWidgetHostImpl* rwhi = guest_host_view->render_widget_host();
if (!rwhi)
if (!rwhi) {
continue;
}
auto guest_view_osr =
static_cast<CefRenderWidgetHostViewOSR*>(rwhi->GetView());
if (guest_view_osr) {
@ -1607,12 +1651,14 @@ bool CefRenderWidgetHostViewOSR::SetViewBounds() {
DCHECK(!hold_resize_);
// Popup bounds are set in InitAsPopup.
if (IsPopupWidget())
if (IsPopupWidget()) {
return false;
}
const gfx::Rect& new_bounds = ::GetViewBounds(browser_impl_.get());
if (new_bounds == current_view_bounds_)
if (new_bounds == current_view_bounds_) {
return false;
}
current_view_bounds_ = new_bounds;
return true;
@ -1621,8 +1667,9 @@ bool CefRenderWidgetHostViewOSR::SetViewBounds() {
bool CefRenderWidgetHostViewOSR::SetRootLayerSize(bool force) {
const bool screen_info_changed = SetScreenInfo();
const bool view_bounds_changed = SetViewBounds();
if (!force && !screen_info_changed && !view_bounds_changed)
if (!force && !screen_info_changed && !view_bounds_changed) {
return false;
}
GetRootLayer()->SetBounds(gfx::Rect(GetViewBounds().size()));
@ -1667,8 +1714,9 @@ void CefRenderWidgetHostViewOSR::ReleaseResizeHold() {
}
void CefRenderWidgetHostViewOSR::CancelWidget() {
if (render_widget_host_)
if (render_widget_host_) {
render_widget_host_->LostCapture();
}
Hide();
@ -1739,8 +1787,9 @@ void CefRenderWidgetHostViewOSR::InvalidateInternal(
void CefRenderWidgetHostViewOSR::RequestImeCompositionUpdate(
bool start_monitoring) {
if (!render_widget_host_)
if (!render_widget_host_) {
return;
}
render_widget_host_->RequestCompositionUpdates(false, start_monitoring);
}
@ -1771,8 +1820,9 @@ viz::FrameSinkId CefRenderWidgetHostViewOSR::AllocateFrameSinkId() {
void CefRenderWidgetHostViewOSR::UpdateBackgroundColorFromRenderer(
SkColor color) {
if (color == background_color_)
if (color == background_color_) {
return;
}
background_color_ = color;
bool opaque = SkColorGetA(color) == SK_AlphaOPAQUE;

Some files were not shown because too many files have changed in this diff Show More