Fix dereferencing nullptr
authordeepak1556 <hop2deep@gmail.com>
Sat, 21 Jan 2017 09:26:58 +0000 (14:56 +0530)
committerdeepak1556 <hop2deep@gmail.com>
Sat, 21 Jan 2017 09:26:58 +0000 (14:56 +0530)
RenderWidgetHostView might not be available when
the navigator fails to load a url.

atom/browser/api/atom_api_web_contents.cc

index c4762c10b9f05233bbeb3007997b15d5ff57e702..dca69a8ce726e35274d2295fee87529a662ddab4 100644 (file)
@@ -900,14 +900,16 @@ void WebContents::LoadURL(const GURL& url, const mate::Dictionary& options) {
   // We have to call it right after LoadURL because the RenderViewHost is only
   // created after loading a page.
   const auto view = web_contents()->GetRenderWidgetHostView();
-  WebContentsPreferences* web_preferences =
-      WebContentsPreferences::FromWebContents(web_contents());
-  std::string color_name;
-  if (web_preferences->web_preferences()->GetString(options::kBackgroundColor,
-                                                    &color_name)) {
-    view->SetBackgroundColor(ParseHexColor(color_name));
-  } else {
-    view->SetBackgroundColor(SK_ColorTRANSPARENT);
+  if (view) {
+    WebContentsPreferences* web_preferences =
+        WebContentsPreferences::FromWebContents(web_contents());
+    std::string color_name;
+    if (web_preferences->web_preferences()->GetString(options::kBackgroundColor,
+                                                      &color_name)) {
+      view->SetBackgroundColor(ParseHexColor(color_name));
+    } else {
+      view->SetBackgroundColor(SK_ColorTRANSPARENT);
+    }
   }
 }