From 054ba7a964f86ee17a3feae9377a20e16652438e Mon Sep 17 00:00:00 2001 From: Ryohei Ikegami Date: Sun, 19 Mar 2017 17:25:45 +0900 Subject: [PATCH] Add AtomBrowserClient::IsRendererUsesNativeWindowOpen --- atom/browser/atom_browser_client.cc | 36 ++++++++++++++++++----------- atom/browser/atom_browser_client.h | 16 ++++++++----- 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/atom/browser/atom_browser_client.cc b/atom/browser/atom_browser_client.cc index d0bbf4ad535f..7de71cc7fce9 100644 --- a/atom/browser/atom_browser_client.cc +++ b/atom/browser/atom_browser_client.cc @@ -109,19 +109,26 @@ bool AtomBrowserClient::ShouldCreateNewSiteInstance( content::SiteInstance::GetSiteForURL(browser_context, url) != src_url; } -void AtomBrowserClient::AddSandboxedRendererId(int process_id) { - base::AutoLock auto_lock(sandboxed_renderers_lock_); - sandboxed_renderers_.insert(process_id); +void AtomBrowserClient::AddProcessPreferences(int process_id, AtomBrowserClient::ProcessPreferences prefs) { + base::AutoLock auto_lock(process_preferences_lock_); + process_preferences_[process_id] = prefs; } -void AtomBrowserClient::RemoveSandboxedRendererId(int process_id) { - base::AutoLock auto_lock(sandboxed_renderers_lock_); - sandboxed_renderers_.erase(process_id); +void AtomBrowserClient::RemoveProcessPreferences(int process_id) { + base::AutoLock auto_lock(process_preferences_lock_); + process_preferences_.erase(process_id); } bool AtomBrowserClient::IsRendererSandboxed(int process_id) { - base::AutoLock auto_lock(sandboxed_renderers_lock_); - return sandboxed_renderers_.count(process_id); + base::AutoLock auto_lock(process_preferences_lock_); + auto it = process_preferences_.find(process_id); + return it != process_preferences_.end() && it->second.sandbox; +} + +bool AtomBrowserClient::IsRendererUsesNativeWindowOpen(int process_id) { + base::AutoLock auto_lock(process_preferences_lock_); + auto it = process_preferences_.find(process_id); + return it != process_preferences_.end() && it->second.native_window_open; } void AtomBrowserClient::RenderProcessWillLaunch( @@ -133,11 +140,12 @@ void AtomBrowserClient::RenderProcessWillLaunch( new WidevineCdmMessageFilter(process_id, host->GetBrowserContext())); content::WebContents* web_contents = GetWebContentsFromProcessID(process_id); - if (WebContentsPreferences::IsSandboxed(web_contents)) { - AddSandboxedRendererId(host->GetID()); - // ensure the sandboxed renderer id is removed later - host->AddObserver(this); - } + ProcessPreferences process_prefs; + process_prefs.sandbox = WebContentsPreferences::IsSandboxed(web_contents); + process_prefs.native_window_open = WebContentsPreferences::IsNativeWindowOpenEnabled(web_contents); + AddProcessPreferences(host->GetID(), process_prefs); + // ensure the ProcessPreferences is removed later + host->AddObserver(this); } content::SpeechRecognitionManagerDelegate* @@ -375,7 +383,7 @@ void AtomBrowserClient::RenderProcessHostDestroyed( break; } } - RemoveSandboxedRendererId(process_id); + RemoveProcessPreferences(process_id); } } // namespace atom diff --git a/atom/browser/atom_browser_client.h b/atom/browser/atom_browser_client.h index c2a7d5edd0f4..6ceb49a99c88 100644 --- a/atom/browser/atom_browser_client.h +++ b/atom/browser/atom_browser_client.h @@ -114,16 +114,20 @@ class AtomBrowserClient : public brightray::BrowserClient, bool ShouldCreateNewSiteInstance(content::BrowserContext* browser_context, content::SiteInstance* current_instance, const GURL& dest_url); - // Add/remove a process id to `sandboxed_renderers_`. - void AddSandboxedRendererId(int process_id); - void RemoveSandboxedRendererId(int process_id); + struct ProcessPreferences { + bool sandbox; + bool native_window_open; + }; + void AddProcessPreferences(int process_id, ProcessPreferences prefs); + void RemoveProcessPreferences(int process_id); bool IsRendererSandboxed(int process_id); + bool IsRendererUsesNativeWindowOpen(int process_id); // pending_render_process => current_render_process. std::map pending_processes_; - // Set that contains the process ids of all sandboxed renderers - std::set sandboxed_renderers_; - base::Lock sandboxed_renderers_lock_; + + std::map process_preferences_; + base::Lock process_preferences_lock_; std::unique_ptr resource_dispatcher_host_delegate_;