Add AtomBrowserClient::IsRendererUsesNativeWindowOpen

This commit is contained in:
Ryohei Ikegami 2017-03-19 17:25:45 +09:00
parent f7935b429a
commit 054ba7a964
2 changed files with 32 additions and 20 deletions

View file

@ -109,19 +109,26 @@ bool AtomBrowserClient::ShouldCreateNewSiteInstance(
content::SiteInstance::GetSiteForURL(browser_context, url) != src_url; content::SiteInstance::GetSiteForURL(browser_context, url) != src_url;
} }
void AtomBrowserClient::AddSandboxedRendererId(int process_id) { void AtomBrowserClient::AddProcessPreferences(int process_id, AtomBrowserClient::ProcessPreferences prefs) {
base::AutoLock auto_lock(sandboxed_renderers_lock_); base::AutoLock auto_lock(process_preferences_lock_);
sandboxed_renderers_.insert(process_id); process_preferences_[process_id] = prefs;
} }
void AtomBrowserClient::RemoveSandboxedRendererId(int process_id) { void AtomBrowserClient::RemoveProcessPreferences(int process_id) {
base::AutoLock auto_lock(sandboxed_renderers_lock_); base::AutoLock auto_lock(process_preferences_lock_);
sandboxed_renderers_.erase(process_id); process_preferences_.erase(process_id);
} }
bool AtomBrowserClient::IsRendererSandboxed(int process_id) { bool AtomBrowserClient::IsRendererSandboxed(int process_id) {
base::AutoLock auto_lock(sandboxed_renderers_lock_); base::AutoLock auto_lock(process_preferences_lock_);
return sandboxed_renderers_.count(process_id); 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( void AtomBrowserClient::RenderProcessWillLaunch(
@ -133,11 +140,12 @@ void AtomBrowserClient::RenderProcessWillLaunch(
new WidevineCdmMessageFilter(process_id, host->GetBrowserContext())); new WidevineCdmMessageFilter(process_id, host->GetBrowserContext()));
content::WebContents* web_contents = GetWebContentsFromProcessID(process_id); content::WebContents* web_contents = GetWebContentsFromProcessID(process_id);
if (WebContentsPreferences::IsSandboxed(web_contents)) { ProcessPreferences process_prefs;
AddSandboxedRendererId(host->GetID()); process_prefs.sandbox = WebContentsPreferences::IsSandboxed(web_contents);
// ensure the sandboxed renderer id is removed later process_prefs.native_window_open = WebContentsPreferences::IsNativeWindowOpenEnabled(web_contents);
host->AddObserver(this); AddProcessPreferences(host->GetID(), process_prefs);
} // ensure the ProcessPreferences is removed later
host->AddObserver(this);
} }
content::SpeechRecognitionManagerDelegate* content::SpeechRecognitionManagerDelegate*
@ -375,7 +383,7 @@ void AtomBrowserClient::RenderProcessHostDestroyed(
break; break;
} }
} }
RemoveSandboxedRendererId(process_id); RemoveProcessPreferences(process_id);
} }
} // namespace atom } // namespace atom

View file

@ -114,16 +114,20 @@ class AtomBrowserClient : public brightray::BrowserClient,
bool ShouldCreateNewSiteInstance(content::BrowserContext* browser_context, bool ShouldCreateNewSiteInstance(content::BrowserContext* browser_context,
content::SiteInstance* current_instance, content::SiteInstance* current_instance,
const GURL& dest_url); const GURL& dest_url);
// Add/remove a process id to `sandboxed_renderers_`. struct ProcessPreferences {
void AddSandboxedRendererId(int process_id); bool sandbox;
void RemoveSandboxedRendererId(int process_id); bool native_window_open;
};
void AddProcessPreferences(int process_id, ProcessPreferences prefs);
void RemoveProcessPreferences(int process_id);
bool IsRendererSandboxed(int process_id); bool IsRendererSandboxed(int process_id);
bool IsRendererUsesNativeWindowOpen(int process_id);
// pending_render_process => current_render_process. // pending_render_process => current_render_process.
std::map<int, int> pending_processes_; std::map<int, int> pending_processes_;
// Set that contains the process ids of all sandboxed renderers
std::set<int> sandboxed_renderers_; std::map<int, ProcessPreferences> process_preferences_;
base::Lock sandboxed_renderers_lock_; base::Lock process_preferences_lock_;
std::unique_ptr<AtomResourceDispatcherHostDelegate> std::unique_ptr<AtomResourceDispatcherHostDelegate>
resource_dispatcher_host_delegate_; resource_dispatcher_host_delegate_;