]> khamidou — GitHub mirrors - electron.git/commitdiff
Add custom ResourceDispatcherHostDelegate.
authorCheng Zhao <zcbenz@gmail.com>
Mon, 11 Aug 2014 06:08:23 +0000 (14:08 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Mon, 11 Aug 2014 06:08:23 +0000 (14:08 +0800)
atom.gyp
atom/browser/atom_browser_client.cc
atom/browser/atom_browser_client.h
atom/browser/atom_resource_dispatcher_host_delegate.cc [new file with mode: 0644]
atom/browser/atom_resource_dispatcher_host_delegate.h [new file with mode: 0644]
atom/browser/default_app/index.html

index bf8b33655d4e768b42b0ab1867dabee793c4dfe7..1dbf2c41a5537e1ab4bc32abfaaafd071681d458 100644 (file)
--- a/atom.gyp
+++ b/atom.gyp
@@ -92,6 +92,8 @@
       'atom/browser/atom_browser_main_parts_mac.mm',
       'atom/browser/atom_javascript_dialog_manager.cc',
       'atom/browser/atom_javascript_dialog_manager.h',
+      'atom/browser/atom_resource_dispatcher_host_delegate.cc',
+      'atom/browser/atom_resource_dispatcher_host_delegate.h',
       'atom/browser/browser.cc',
       'atom/browser/browser.h',
       'atom/browser/browser_linux.cc',
index b62bc37b4b4e5271da6ef284bdc3516a90c3a1ac..d43b46783ce804758a5df78d390616f1c7a0109f 100644 (file)
@@ -6,11 +6,13 @@
 
 #include "atom/browser/atom_browser_context.h"
 #include "atom/browser/atom_browser_main_parts.h"
+#include "atom/browser/atom_resource_dispatcher_host_delegate.h"
 #include "atom/browser/native_window.h"
 #include "atom/browser/net/atom_url_request_context_getter.h"
 #include "atom/browser/window_list.h"
 #include "content/public/browser/render_process_host.h"
 #include "content/public/browser/render_view_host.h"
+#include "content/public/browser/resource_dispatcher_host.h"
 #include "content/public/browser/site_instance.h"
 #include "content/public/browser/web_contents.h"
 #include "ui/base/l10n/l10n_util.h"
@@ -54,6 +56,12 @@ net::URLRequestContextGetter* AtomBrowserClient::CreateRequestContext(
       CreateRequestContext(protocol_handlers);
 }
 
+void AtomBrowserClient::ResourceDispatcherHostCreated() {
+  resource_dispatcher_delegate_.reset(new AtomResourceDispatcherHostDelegate);
+  content::ResourceDispatcherHost::Get()->SetDelegate(
+      resource_dispatcher_delegate_.get());
+}
+
 void AtomBrowserClient::OverrideWebkitPrefs(
     content::RenderViewHost* render_view_host,
     const GURL& url,
index 8f74dcfae6dffd4693aafdbaa4cc6bbf386e35c6..afbc895f09eb11ac80dc08ed8b599e4bd83d5235 100644 (file)
@@ -11,6 +11,8 @@
 
 namespace atom {
 
+class AtomResourceDispatcherHostDelegate;
+
 class AtomBrowserClient : public brightray::BrowserClient {
  public:
   AtomBrowserClient();
@@ -22,6 +24,7 @@ class AtomBrowserClient : public brightray::BrowserClient {
       content::BrowserContext* browser_context,
       content::ProtocolHandlerMap* protocol_handlers,
       content::ProtocolHandlerScopedVector protocol_interceptors) OVERRIDE;
+  virtual void ResourceDispatcherHostCreated() OVERRIDE;
   virtual void OverrideWebkitPrefs(content::RenderViewHost* render_view_host,
                                    const GURL& url,
                                    WebPreferences* prefs) OVERRIDE;
@@ -37,6 +40,8 @@ class AtomBrowserClient : public brightray::BrowserClient {
   virtual brightray::BrowserMainParts* OverrideCreateBrowserMainParts(
       const content::MainFunctionParams&) OVERRIDE;
 
+  scoped_ptr<AtomResourceDispatcherHostDelegate> resource_dispatcher_delegate_;
+
   // The render process which would be swapped out soon.
   content::RenderProcessHost* dying_render_process_;
 
diff --git a/atom/browser/atom_resource_dispatcher_host_delegate.cc b/atom/browser/atom_resource_dispatcher_host_delegate.cc
new file mode 100644 (file)
index 0000000..49038e6
--- /dev/null
@@ -0,0 +1,31 @@
+// Copyright (c) 2014 GitHub, Inc. All rights reserved.
+// Use of this source code is governed by the MIT license that can be
+// found in the LICENSE file.
+
+#include "atom/browser/atom_resource_dispatcher_host_delegate.h"
+
+#include "base/logging.h"
+#include "net/http/http_response_headers.h"
+#include "net/url_request/url_request.h"
+
+namespace atom {
+
+AtomResourceDispatcherHostDelegate::AtomResourceDispatcherHostDelegate() {
+}
+
+AtomResourceDispatcherHostDelegate::~AtomResourceDispatcherHostDelegate() {
+}
+
+void AtomResourceDispatcherHostDelegate::OnResponseStarted(
+    net::URLRequest* request,
+    content::ResourceContext* resource_context,
+    content::ResourceResponse* response,
+    IPC::Sender* sender) {
+  /*
+  net::HttpResponseHeaders* response_headers = request->response_headers();
+  if (response_headers && response_headers->HasHeader("x-frame-options"))
+    response_headers->RemoveHeader("x-frame-options");
+  */
+}
+
+}  // namespace atom
diff --git a/atom/browser/atom_resource_dispatcher_host_delegate.h b/atom/browser/atom_resource_dispatcher_host_delegate.h
new file mode 100644 (file)
index 0000000..10e993b
--- /dev/null
@@ -0,0 +1,31 @@
+// Copyright (c) 2014 GitHub, Inc. All rights reserved.
+// Use of this source code is governed by the MIT license that can be
+// found in the LICENSE file.
+
+#ifndef ATOM_BROWSER_ATOM_RESOURCE_DISPATCHER_HOST_DELEGATE_H_
+#define ATOM_BROWSER_ATOM_RESOURCE_DISPATCHER_HOST_DELEGATE_H_
+
+#include "base/compiler_specific.h"
+#include "content/public/browser/resource_dispatcher_host_delegate.h"
+
+namespace atom {
+
+class AtomResourceDispatcherHostDelegate
+    : public content::ResourceDispatcherHostDelegate {
+ public:
+  AtomResourceDispatcherHostDelegate();
+  virtual ~AtomResourceDispatcherHostDelegate();
+
+  // content::ResourceDispatcherHostDelegate:
+  virtual void OnResponseStarted(net::URLRequest* request,
+                                 content::ResourceContext* resource_context,
+                                 content::ResourceResponse* response,
+                                 IPC::Sender* sender) OVERRIDE;
+
+ private:
+  DISALLOW_COPY_AND_ASSIGN(AtomResourceDispatcherHostDelegate);
+};
+
+}  // namespace atom
+
+#endif  // ATOM_BROWSER_ATOM_RESOURCE_DISPATCHER_HOST_DELEGATE_H_
index df6001242836acc312c37ec34c3139043726216e..1a689d8a6b3361c9b5af511a90aa3461cb8f9beb 100644 (file)
@@ -62,6 +62,8 @@
   </style>
 </head>
 <body>
+  <iframe src="http://google.com"></iframe>
+  <iframe src="http://baidu.com"></iframe>
   <script>
     var execPath = require('remote').process.execPath;
     var command = execPath + ' path-to-your-app';