]> khamidou — GitHub mirrors - electron.git/commitdiff
Simplify how we find NativeWindow from WebContents
authorCheng Zhao <zcbenz@gmail.com>
Wed, 20 May 2015 02:27:16 +0000 (10:27 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Wed, 20 May 2015 02:27:16 +0000 (10:27 +0800)
atom/browser/api/atom_api_web_contents.cc
atom/browser/atom_browser_client.cc
atom/browser/native_window.cc
atom/browser/native_window.h

index e228a064f4138d22403c8df08e705b07e9b40da0..6da2fbf86f46a4b67afb1dbb16cff57ffcc110b3 100644 (file)
@@ -51,9 +51,7 @@ v8::Persistent<v8::ObjectTemplate> template_;
 NativeWindow* GetWindowFromGuest(const content::WebContents* guest) {
   WebViewManager::WebViewInfo info;
   if (WebViewManager::GetInfoForProcess(guest->GetRenderProcessHost(), &info))
-    return NativeWindow::FromRenderView(
-        info.embedder->GetRenderProcessHost()->GetID(),
-        info.embedder->GetRoutingID());
+    return NativeWindow::FromWebContents(info.embedder);
   else
     return nullptr;
 }
index fbc09d9fe15fb39ceda0ad142c86c872ff99fa90..23674035e1d30494aa3b712a34120f026362046c 100644 (file)
@@ -124,8 +124,7 @@ void AtomBrowserClient::OverrideWebkitPrefs(
     return;
   }
 
-  NativeWindow* window = NativeWindow::FromRenderView(
-      process->GetID(), render_view_host->GetRoutingID());
+  NativeWindow* window = NativeWindow::FromWebContents(web_contents);
   if (window)
     window->OverrideWebkitPrefs(prefs);
 }
index 5bef1acfb8722cc37653511b486f5f78ce114607..8bc2c4616fe8aee296203070fa178538c35b38e2 100644 (file)
@@ -169,18 +169,13 @@ NativeWindow* NativeWindow::Create(const mate::Dictionary& options) {
 }
 
 // static
-NativeWindow* NativeWindow::FromRenderView(int process_id, int routing_id) {
-  // Stupid iterating.
+NativeWindow* NativeWindow::FromWebContents(
+    content::WebContents* web_contents) {
   WindowList& window_list = *WindowList::GetInstance();
-  for (auto w = window_list.begin(); w != window_list.end(); ++w) {
-    auto& window = *w;
-    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)
+  for (NativeWindow* window : window_list) {
+    if (window->GetWebContents() == web_contents)
       return window;
   }
-
   return nullptr;
 }
 
index 32c3493cdbf8b18f5a0204b03e34d88409bcb3ba..39c58625ad2dd87f618bb5436edbd0d677ba7bec 100644 (file)
@@ -91,8 +91,8 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
   // managing the window's live.
   static NativeWindow* Create(const mate::Dictionary& options);
 
-  // Find a window from its process id and routing id.
-  static NativeWindow* FromRenderView(int process_id, int routing_id);
+  // Find a window from its WebContents
+  static NativeWindow* FromWebContents(content::WebContents* web_contents);
 
   void InitFromOptions(const mate::Dictionary& options);