Simplify how we find NativeWindow from WebContents

This commit is contained in:
Cheng Zhao 2015-05-20 10:27:16 +08:00
parent cda8b119e2
commit 7c69c2846b
4 changed files with 8 additions and 16 deletions

View file

@ -51,9 +51,7 @@ v8::Persistent<v8::ObjectTemplate> template_;
NativeWindow* GetWindowFromGuest(const content::WebContents* guest) { NativeWindow* GetWindowFromGuest(const content::WebContents* guest) {
WebViewManager::WebViewInfo info; WebViewManager::WebViewInfo info;
if (WebViewManager::GetInfoForProcess(guest->GetRenderProcessHost(), &info)) if (WebViewManager::GetInfoForProcess(guest->GetRenderProcessHost(), &info))
return NativeWindow::FromRenderView( return NativeWindow::FromWebContents(info.embedder);
info.embedder->GetRenderProcessHost()->GetID(),
info.embedder->GetRoutingID());
else else
return nullptr; return nullptr;
} }

View file

@ -124,8 +124,7 @@ void AtomBrowserClient::OverrideWebkitPrefs(
return; return;
} }
NativeWindow* window = NativeWindow::FromRenderView( NativeWindow* window = NativeWindow::FromWebContents(web_contents);
process->GetID(), render_view_host->GetRoutingID());
if (window) if (window)
window->OverrideWebkitPrefs(prefs); window->OverrideWebkitPrefs(prefs);
} }

View file

@ -169,18 +169,13 @@ NativeWindow* NativeWindow::Create(const mate::Dictionary& options) {
} }
// static // static
NativeWindow* NativeWindow::FromRenderView(int process_id, int routing_id) { NativeWindow* NativeWindow::FromWebContents(
// Stupid iterating. content::WebContents* web_contents) {
WindowList& window_list = *WindowList::GetInstance(); WindowList& window_list = *WindowList::GetInstance();
for (auto w = window_list.begin(); w != window_list.end(); ++w) { for (NativeWindow* window : window_list) {
auto& window = *w; if (window->GetWebContents() == web_contents)
content::WebContents* web_contents = window->GetWebContents();
int window_process_id = web_contents->GetRenderProcessHost()->GetID();
int window_routing_id = web_contents->GetRoutingID();
if (window_routing_id == routing_id && window_process_id == process_id)
return window; return window;
} }
return nullptr; return nullptr;
} }

View file

@ -91,8 +91,8 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
// managing the window's live. // managing the window's live.
static NativeWindow* Create(const mate::Dictionary& options); static NativeWindow* Create(const mate::Dictionary& options);
// Find a window from its process id and routing id. // Find a window from its WebContents
static NativeWindow* FromRenderView(int process_id, int routing_id); static NativeWindow* FromWebContents(content::WebContents* web_contents);
void InitFromOptions(const mate::Dictionary& options); void InitFromOptions(const mate::Dictionary& options);