]> khamidou — GitHub mirrors - electron.git/commitdiff
Append --iframe-security to renderer process.
authorCheng Zhao <zcbenz@gmail.com>
Thu, 30 Jan 2014 13:57:01 +0000 (21:57 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Thu, 30 Jan 2014 13:57:01 +0000 (21:57 +0800)
browser/atom_browser_client.cc
browser/atom_browser_client.h
browser/native_window.cc
browser/native_window.h
common/options_switches.cc
common/options_switches.h

index 19617002a816d1ef4d08028865594ffda2176bdf..b580571024956f57cd5fff1f32f0d20e74b4b6c6 100644 (file)
@@ -4,9 +4,15 @@
 
 #include "browser/atom_browser_client.h"
 
+#include "base/command_line.h"
 #include "browser/atom_browser_context.h"
 #include "browser/atom_browser_main_parts.h"
+#include "browser/native_window.h"
 #include "browser/net/atom_url_request_context_getter.h"
+#include "browser/window_list.h"
+#include "common/options_switches.h"
+#include "content/public/browser/render_process_host.h"
+#include "content/public/browser/web_contents.h"
 #include "webkit/common/webpreferences.h"
 
 namespace atom {
@@ -54,6 +60,23 @@ bool AtomBrowserClient::ShouldSwapProcessesForNavigation(
   return true;
 }
 
+void AtomBrowserClient::AppendExtraCommandLineSwitches(
+    CommandLine* command_line,
+    int child_process_id) {
+  // Append --iframe-security to renderer process.
+  WindowList* list = WindowList::GetInstance();
+  for (WindowList::const_iterator iter = list->begin(); iter != list->end();
+       ++iter) {
+    NativeWindow* window = *iter;
+    int id = window->GetWebContents()->GetRenderProcessHost()->GetID();
+    if (id == child_process_id) {
+      command_line->AppendSwitchASCII(switches::kIframeSecurity,
+                                      window->iframe_security());
+      return;
+    }
+  }
+}
+
 brightray::BrowserMainParts* AtomBrowserClient::OverrideCreateBrowserMainParts(
     const content::MainFunctionParams&) {
   return new AtomBrowserMainParts;
index 3443f0a707d9eebb0bfafec27c6e2892027f304f..183b647837ecca0c324b0d716d11a92e696aa1fe 100644 (file)
@@ -25,6 +25,8 @@ class AtomBrowserClient : public brightray::BrowserClient {
       content::SiteInstance* site_instance,
       const GURL& current_url,
       const GURL& new_url) OVERRIDE;
+  virtual void AppendExtraCommandLineSwitches(CommandLine* command_line,
+                                              int child_process_id) OVERRIDE;
 
  private:
   virtual brightray::BrowserMainParts* OverrideCreateBrowserMainParts(
index 7b923adf2c3bc20c2bdfba2a2ac7459b163a2fd9..b8ca401b8aaa4f8ab0e2299c729df29e8c19677f 100644 (file)
@@ -48,16 +48,19 @@ NativeWindow::NativeWindow(content::WebContents* web_contents,
     : content::WebContentsObserver(web_contents),
       has_frame_(true),
       is_closed_(false),
+      iframe_security_("full"),
       weak_factory_(this),
       inspectable_web_contents_(
           brightray::InspectableWebContents::Create(web_contents)) {
   options->GetBoolean(switches::kFrame, &has_frame_);
 
+  // Read icon before window is created.
   std::string icon;
-  if (options->GetString(switches::kIcon, &icon)) {
-    if (!SetIcon(icon))
-      LOG(ERROR) << "Failed to set icon to " << icon;
-  }
+  if (options->GetString(switches::kIcon, &icon) && !SetIcon(icon))
+    LOG(ERROR) << "Failed to set icon to " << icon;
+
+  // Read iframe security before any navigation.
+  options->GetString(switches::kIframeSecurity, &iframe_security_);
 
   web_contents->SetDelegate(this);
 
index 54cb539d755de01453a2191b257ab0ab496ca801..462d96c199554c64c2cfe009f14645467186aa75 100644 (file)
@@ -140,6 +140,7 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
   }
 
   bool has_frame() const { return has_frame_; }
+  std::string iframe_security() const { return iframe_security_; }
 
  protected:
   explicit NativeWindow(content::WebContents* web_contents,
@@ -219,6 +220,9 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
   // The windows has been closed.
   bool is_closed_;
 
+  // The security token of iframe.
+  std::string iframe_security_;
+
   // Closure that would be called when window is unresponsive when closing,
   // it should be cancelled when we can prove that the window is responsive.
   base::CancelableClosure window_unresposive_closure_;
index 6f068a19d258b101a0f0bb3c422e0a374d6f2345..74ff309b25bf95c03efba7e93296ea2dd3391b2b 100644 (file)
@@ -31,6 +31,8 @@ const char kKiosk[] = "kiosk";
 // Make windows stays on the top of all other windows.
 const char kAlwaysOnTop[] = "always-on-top";
 
+const char kIframeSecurity[] = "iframe-security";
+
 }  // namespace switches
 
 }  // namespace atom
index ee61044df2ef47be41334fd0f9976d351c037cc1..fa658d2c9a3a24dfe7003a70d2d58d62db8ccb40 100644 (file)
@@ -26,6 +26,7 @@ extern const char kResizable[];
 extern const char kFullscreen[];
 extern const char kKiosk[];
 extern const char kAlwaysOnTop[];
+extern const char kIframeSecurity[];
 
 }  // namespace switches