Browse Source

Put common constants in atom_constants

Cheng Zhao 9 years ago
parent
commit
0f17a0163d

+ 0 - 2
atom/browser/net/js_asker.cc

@@ -11,8 +11,6 @@
 
 namespace atom {
 
-const std::string kCorsHeader("Access-Control-Allow-Origin: *");
-
 namespace internal {
 
 namespace {

+ 0 - 3
atom/browser/net/js_asker.h

@@ -5,8 +5,6 @@
 #ifndef ATOM_BROWSER_NET_JS_ASKER_H_
 #define ATOM_BROWSER_NET_JS_ASKER_H_
 
-#include <string>
-
 #include "base/callback.h"
 #include "base/memory/ref_counted.h"
 #include "base/memory/weak_ptr.h"
@@ -19,7 +17,6 @@
 #include "v8/include/v8.h"
 
 namespace atom {
-extern const std::string kCorsHeader;
 
 using JavaScriptHandler =
     base::Callback<void(const net::URLRequest*, v8::Local<v8::Value>)>;

+ 3 - 2
atom/browser/net/url_request_async_asar_job.cc

@@ -6,6 +6,8 @@
 
 #include <string>
 
+#include "atom/common/atom_constants.h"
+
 namespace atom {
 
 URLRequestAsyncAsarJob::URLRequestAsyncAsarJob(
@@ -36,12 +38,11 @@ void URLRequestAsyncAsarJob::StartAsync(scoped_ptr<base::Value> options) {
   }
 }
 
-
 void URLRequestAsyncAsarJob::GetResponseInfo(net::HttpResponseInfo* info) {
   std::string status("HTTP/1.1 200 OK");
   net::HttpResponseHeaders* headers = new net::HttpResponseHeaders(status);
 
-  headers->AddHeader(kCorsHeader);
+  headers->AddHeader(kCORSHeader);
   info->headers = headers;
 }
 

+ 2 - 1
atom/browser/net/url_request_buffer_job.cc

@@ -6,6 +6,7 @@
 
 #include <string>
 
+#include "atom/common/atom_constants.h"
 #include "base/strings/string_number_conversions.h"
 #include "net/base/net_errors.h"
 
@@ -50,7 +51,7 @@ void URLRequestBufferJob::GetResponseInfo(net::HttpResponseInfo* info) {
   status.append("\0\0", 2);
   net::HttpResponseHeaders* headers = new net::HttpResponseHeaders(status);
 
-  headers->AddHeader(kCorsHeader);
+  headers->AddHeader(kCORSHeader);
 
   if (!mime_type_.empty()) {
     std::string content_type_header(net::HttpRequestHeaders::kContentType);

+ 2 - 1
atom/browser/net/url_request_string_job.cc

@@ -6,6 +6,7 @@
 
 #include <string>
 
+#include "atom/common/atom_constants.h"
 #include "net/base/net_errors.h"
 
 namespace atom {
@@ -32,7 +33,7 @@ void URLRequestStringJob::GetResponseInfo(net::HttpResponseInfo* info) {
   std::string status("HTTP/1.1 200 OK");
   net::HttpResponseHeaders* headers = new net::HttpResponseHeaders(status);
 
-  headers->AddHeader(kCorsHeader);
+  headers->AddHeader(kCORSHeader);
 
   if (!mime_type_.empty()) {
     std::string content_type_header(net::HttpRequestHeaders::kContentType);

+ 11 - 0
atom/common/atom_constants.cc

@@ -0,0 +1,11 @@
+// Copyright (c) 2015 GitHub, Inc.
+// Use of this source code is governed by the MIT license that can be
+// found in the LICENSE file.
+
+#include "atom/common/atom_constants.h"
+
+namespace atom {
+
+const char* kCORSHeader = "Access-Control-Allow-Origin: *";
+
+}  // namespace atom

+ 15 - 0
atom/common/atom_constants.h

@@ -0,0 +1,15 @@
+// Copyright (c) 2015 GitHub, Inc.
+// Use of this source code is governed by the MIT license that can be
+// found in the LICENSE file.
+
+#ifndef ATOM_COMMON_ATOM_CONSTANTS_H_
+#define ATOM_COMMON_ATOM_CONSTANTS_H_
+
+namespace atom {
+
+// Header to ignore CORS.
+extern const char* kCORSHeader;
+
+}  // namespace atom
+
+#endif  // ATOM_COMMON_ATOM_CONSTANTS_H_

+ 2 - 0
filenames.gypi

@@ -286,6 +286,8 @@
       'atom/common/asar/scoped_temporary_file.h',
       'atom/common/atom_command_line.cc',
       'atom/common/atom_command_line.h',
+      'atom/common/atom_constants.cc',
+      'atom/common/atom_constants.h',
       'atom/common/common_message_generator.cc',
       'atom/common/common_message_generator.h',
       'atom/common/crash_reporter/crash_reporter.cc',