From: Cheng Zhao Date: Thu, 30 Jan 2014 13:57:01 +0000 (+0800) Subject: Append --iframe-security to renderer process. X-Git-Tag: v0.9.5~4^2~8 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=a0b15661edcf2756b382f79101f51a94f7c7639c;p=electron.git Append --iframe-security to renderer process. --- diff --git a/browser/atom_browser_client.cc b/browser/atom_browser_client.cc index 19617002..b5805710 100644 --- a/browser/atom_browser_client.cc +++ b/browser/atom_browser_client.cc @@ -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; diff --git a/browser/atom_browser_client.h b/browser/atom_browser_client.h index 3443f0a7..183b6478 100644 --- a/browser/atom_browser_client.h +++ b/browser/atom_browser_client.h @@ -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( diff --git a/browser/native_window.cc b/browser/native_window.cc index 7b923adf..b8ca401b 100644 --- a/browser/native_window.cc +++ b/browser/native_window.cc @@ -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); diff --git a/browser/native_window.h b/browser/native_window.h index 54cb539d..462d96c1 100644 --- a/browser/native_window.h +++ b/browser/native_window.h @@ -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_; diff --git a/common/options_switches.cc b/common/options_switches.cc index 6f068a19..74ff309b 100644 --- a/common/options_switches.cc +++ b/common/options_switches.cc @@ -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 diff --git a/common/options_switches.h b/common/options_switches.h index ee61044d..fa658d2c 100644 --- a/common/options_switches.h +++ b/common/options_switches.h @@ -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