summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-23 00:55:08 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-23 00:55:08 +0000
commit70d6650d6f65b91dbcb67847aaae640d041aa592 (patch)
treebc3c91e1e67a825a30e730491a267a6c0201b1b2 /content
parent0a075d63f82146768aac85366fa28ae8dcb5cfa9 (diff)
downloadchromium_src-70d6650d6f65b91dbcb67847aaae640d041aa592.zip
chromium_src-70d6650d6f65b91dbcb67847aaae640d041aa592.tar.gz
chromium_src-70d6650d6f65b91dbcb67847aaae640d041aa592.tar.bz2
For the SSL cert status, convert anonymous enum that gives bit values into a typedefed uint32. This allows code all over Chromium to use an explicit type instead of "int". This also means the individual named bit constants themselves have the same explicit type. I find the resulting code to be noticeably clearer. This also exposed a bug in SSLErrorInfo::GetErrorsForCertStatus() where not having an explicit type allowed a function argument ordering bug to creep in, so I claim this is safer too.
Normally this makes things like DCHECK_EQ() unhappy, but when I'd originally tested this I didn't seem to need to make any changes due to that. Will be watching the trybots... The original motiviation for this change was to find a way to eliminate some cases of passing anonymous-typed values as template arguments (which happens when you use a value from the enum in e.g. EXPECT_EQ()), which is technically illegal in C++03, though we don't warn about it. Simply naming the enum would have done this, but this would have encouraged readers to actually use the enum name as a type, which for a bitfield is inappropriate for the reason given in the first paragraph. BUG=92247 TEST=Compiles Review URL: http://codereview.chromium.org/7969023 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@102415 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r--content/browser/load_from_memory_cache_details.cc2
-rw-r--r--content/browser/load_from_memory_cache_details.h7
-rw-r--r--content/browser/renderer_host/resource_request_details.h5
-rw-r--r--content/browser/ssl/ssl_manager.cc14
-rw-r--r--content/browser/ssl/ssl_manager.h14
-rw-r--r--content/browser/ssl/ssl_policy.cc3
-rw-r--r--content/browser/ssl/ssl_request_info.cc2
-rw-r--r--content/browser/ssl/ssl_request_info.h7
-rw-r--r--content/browser/tab_contents/navigation_entry.h7
-rw-r--r--content/browser/tab_contents/navigation_entry_unittest.cc7
-rw-r--r--content/browser/tab_contents/provisional_load_details.h5
-rw-r--r--content/browser/tab_contents/tab_contents.cc5
12 files changed, 46 insertions, 32 deletions
diff --git a/content/browser/load_from_memory_cache_details.cc b/content/browser/load_from_memory_cache_details.cc
index 8574112..ed80587 100644
--- a/content/browser/load_from_memory_cache_details.cc
+++ b/content/browser/load_from_memory_cache_details.cc
@@ -8,7 +8,7 @@ LoadFromMemoryCacheDetails::LoadFromMemoryCacheDetails(
const GURL& url,
int pid,
int cert_id,
- int cert_status)
+ net::CertStatus cert_status)
: url_(url),
pid_(pid),
cert_id_(cert_id),
diff --git a/content/browser/load_from_memory_cache_details.h b/content/browser/load_from_memory_cache_details.h
index 0689792..4524014 100644
--- a/content/browser/load_from_memory_cache_details.h
+++ b/content/browser/load_from_memory_cache_details.h
@@ -8,6 +8,7 @@
#include "base/basictypes.h"
#include "googleurl/src/gurl.h"
+#include "net/base/cert_status_flags.h"
class LoadFromMemoryCacheDetails {
public:
@@ -15,19 +16,19 @@ class LoadFromMemoryCacheDetails {
const GURL& url,
int pid,
int cert_id,
- int cert_status);
+ net::CertStatus cert_status);
~LoadFromMemoryCacheDetails();
const GURL& url() const { return url_; }
int pid() const { return pid_; }
int ssl_cert_id() const { return cert_id_; }
- int ssl_cert_status() const { return cert_status_; }
+ net::CertStatus ssl_cert_status() const { return cert_status_; }
private:
GURL url_;
int pid_;
int cert_id_;
- int cert_status_;
+ net::CertStatus cert_status_;
DISALLOW_COPY_AND_ASSIGN(LoadFromMemoryCacheDetails);
};
diff --git a/content/browser/renderer_host/resource_request_details.h b/content/browser/renderer_host/resource_request_details.h
index f76b326..8bc070b 100644
--- a/content/browser/renderer_host/resource_request_details.h
+++ b/content/browser/renderer_host/resource_request_details.h
@@ -13,6 +13,7 @@
#include <string>
#include "googleurl/src/gurl.h"
+#include "net/base/cert_status_flags.h"
#include "net/base/host_port_pair.h"
#include "net/url_request/url_request_status.h"
#include "webkit/glue/resource_type.h"
@@ -37,7 +38,7 @@ class ResourceRequestDetails {
int origin_child_id() const { return origin_child_id_; }
const net::URLRequestStatus& status() const { return status_; }
int ssl_cert_id() const { return ssl_cert_id_; }
- int ssl_cert_status() const { return ssl_cert_status_; }
+ net::CertStatus ssl_cert_status() const { return ssl_cert_status_; }
ResourceType::Type resource_type() const { return resource_type_; }
net::HostPortPair socket_address() const { return socket_address_; }
@@ -51,7 +52,7 @@ class ResourceRequestDetails {
int origin_child_id_;
net::URLRequestStatus status_;
int ssl_cert_id_;
- int ssl_cert_status_;
+ net::CertStatus ssl_cert_status_;
ResourceType::Type resource_type_;
net::HostPortPair socket_address_;
};
diff --git a/content/browser/ssl/ssl_manager.cc b/content/browser/ssl/ssl_manager.cc
index 2f88040..6ae6fb9 100644
--- a/content/browser/ssl/ssl_manager.cc
+++ b/content/browser/ssl/ssl_manager.cc
@@ -55,12 +55,12 @@ void SSLManager::NotifySSLInternalStateChanged(
// static
std::string SSLManager::SerializeSecurityInfo(int cert_id,
- int cert_status,
+ net::CertStatus cert_status,
int security_bits,
int ssl_connection_status) {
Pickle pickle;
pickle.WriteInt(cert_id);
- pickle.WriteInt(cert_status);
+ pickle.WriteUInt32(cert_status);
pickle.WriteInt(security_bits);
pickle.WriteInt(ssl_connection_status);
return std::string(static_cast<const char*>(pickle.data()), pickle.size());
@@ -69,7 +69,7 @@ std::string SSLManager::SerializeSecurityInfo(int cert_id,
// static
bool SSLManager::DeserializeSecurityInfo(const std::string& state,
int* cert_id,
- int* cert_status,
+ net::CertStatus* cert_status,
int* security_bits,
int* ssl_connection_status) {
DCHECK(cert_id && cert_status && security_bits && ssl_connection_status);
@@ -86,7 +86,7 @@ bool SSLManager::DeserializeSecurityInfo(const std::string& state,
Pickle pickle(state.data(), static_cast<int>(state.size()));
void * iter = NULL;
return pickle.ReadInt(&iter, cert_id) &&
- pickle.ReadInt(&iter, cert_status) &&
+ pickle.ReadUInt32(&iter, cert_status) &&
pickle.ReadInt(&iter, security_bits) &&
pickle.ReadInt(&iter, ssl_connection_status);
}
@@ -124,8 +124,10 @@ void SSLManager::DidCommitProvisionalLoad(
if (details->is_main_frame) {
if (entry) {
// Decode the security details.
- int ssl_cert_id, ssl_cert_status, ssl_security_bits,
- ssl_connection_status;
+ int ssl_cert_id;
+ net::CertStatus ssl_cert_status;
+ int ssl_security_bits;
+ int ssl_connection_status;
DeserializeSecurityInfo(details->serialized_security_info,
&ssl_cert_id,
&ssl_cert_status,
diff --git a/content/browser/ssl/ssl_manager.h b/content/browser/ssl/ssl_manager.h
index 1e59e7b..24892bf 100644
--- a/content/browser/ssl/ssl_manager.h
+++ b/content/browser/ssl/ssl_manager.h
@@ -15,6 +15,7 @@
#include "content/common/notification_observer.h"
#include "content/common/notification_registrar.h"
#include "googleurl/src/gurl.h"
+#include "net/base/cert_status_flags.h"
#include "net/base/net_errors.h"
class LoadFromMemoryCacheDetails;
@@ -57,14 +58,15 @@ class SSLManager : public NotificationObserver {
// Convenience methods for serializing/deserializing the security info.
static std::string SerializeSecurityInfo(int cert_id,
- int cert_status,
+ net::CertStatus cert_status,
int security_bits,
int connection_status);
- CONTENT_EXPORT static bool DeserializeSecurityInfo(const std::string& state,
- int* cert_id,
- int* cert_status,
- int* security_bits,
- int* connection_status);
+ CONTENT_EXPORT static bool DeserializeSecurityInfo(
+ const std::string& state,
+ int* cert_id,
+ net::CertStatus* cert_status,
+ int* security_bits,
+ int* connection_status);
// Construct an SSLManager for the specified tab.
// If |delegate| is NULL, SSLPolicy::GetDefaultPolicy() is used.
diff --git a/content/browser/ssl/ssl_policy.cc b/content/browser/ssl/ssl_policy.cc
index 1d7c981..1d9f3f6 100644
--- a/content/browser/ssl/ssl_policy.cc
+++ b/content/browser/ssl/ssl_policy.cc
@@ -131,7 +131,8 @@ void SSLPolicy::UpdateEntry(NavigationEntry* entry, TabContents* tab_contents) {
// If CERT_STATUS_UNABLE_TO_CHECK_REVOCATION is the only certificate error,
// don't lower the security style to SECURITY_STYLE_AUTHENTICATION_BROKEN.
- int cert_errors = entry->ssl().cert_status() & net::CERT_STATUS_ALL_ERRORS;
+ net::CertStatus cert_errors =
+ entry->ssl().cert_status() & net::CERT_STATUS_ALL_ERRORS;
if (cert_errors) {
if (cert_errors != net::CERT_STATUS_UNABLE_TO_CHECK_REVOCATION)
entry->ssl().set_security_style(SECURITY_STYLE_AUTHENTICATION_BROKEN);
diff --git a/content/browser/ssl/ssl_request_info.cc b/content/browser/ssl/ssl_request_info.cc
index 19d4e4d..0459b6a 100644
--- a/content/browser/ssl/ssl_request_info.cc
+++ b/content/browser/ssl/ssl_request_info.cc
@@ -8,7 +8,7 @@ SSLRequestInfo::SSLRequestInfo(const GURL& url,
ResourceType::Type resource_type,
int child_id,
int ssl_cert_id,
- int ssl_cert_status)
+ net::CertStatus ssl_cert_status)
: url_(url),
resource_type_(resource_type),
child_id_(child_id),
diff --git a/content/browser/ssl/ssl_request_info.h b/content/browser/ssl/ssl_request_info.h
index 1ab433d..a7f9fbe 100644
--- a/content/browser/ssl/ssl_request_info.h
+++ b/content/browser/ssl/ssl_request_info.h
@@ -10,6 +10,7 @@
#include "base/memory/ref_counted.h"
#include "googleurl/src/gurl.h"
+#include "net/base/cert_status_flags.h"
#include "webkit/glue/resource_type.h"
// SSLRequestInfo wraps up the information SSLPolicy needs about a request in
@@ -21,13 +22,13 @@ class SSLRequestInfo : public base::RefCounted<SSLRequestInfo> {
ResourceType::Type resource_type,
int child_id,
int ssl_cert_id,
- int ssl_cert_status);
+ net::CertStatus ssl_cert_status);
const GURL& url() const { return url_; }
ResourceType::Type resource_type() const { return resource_type_; }
int child_id() const { return child_id_; }
int ssl_cert_id() const { return ssl_cert_id_; }
- int ssl_cert_status() const { return ssl_cert_status_; }
+ net::CertStatus ssl_cert_status() const { return ssl_cert_status_; }
private:
friend class base::RefCounted<SSLRequestInfo>;
@@ -38,7 +39,7 @@ class SSLRequestInfo : public base::RefCounted<SSLRequestInfo> {
ResourceType::Type resource_type_;
int child_id_;
int ssl_cert_id_;
- int ssl_cert_status_;
+ net::CertStatus ssl_cert_status_;
DISALLOW_COPY_AND_ASSIGN(SSLRequestInfo);
};
diff --git a/content/browser/tab_contents/navigation_entry.h b/content/browser/tab_contents/navigation_entry.h
index 2ed55b8..40bc8a8 100644
--- a/content/browser/tab_contents/navigation_entry.h
+++ b/content/browser/tab_contents/navigation_entry.h
@@ -15,6 +15,7 @@
#include "content/common/page_type.h"
#include "content/common/security_style.h"
#include "googleurl/src/gurl.h"
+#include "net/base/cert_status_flags.h"
#include "third_party/skia/include/core/SkBitmap.h"
class SiteInstance;
@@ -75,10 +76,10 @@ class CONTENT_EXPORT NavigationEntry {
return cert_id_;
}
- void set_cert_status(int ssl_cert_status) {
+ void set_cert_status(net::CertStatus ssl_cert_status) {
cert_status_ = ssl_cert_status;
}
- int cert_status() const {
+ net::CertStatus cert_status() const {
return cert_status_;
}
@@ -125,7 +126,7 @@ class CONTENT_EXPORT NavigationEntry {
// See the accessors above for descriptions.
SecurityStyle security_style_;
int cert_id_;
- int cert_status_;
+ net::CertStatus cert_status_;
int security_bits_;
int connection_status_;
int content_status_;
diff --git a/content/browser/tab_contents/navigation_entry_unittest.cc b/content/browser/tab_contents/navigation_entry_unittest.cc
index ee7d083..bbd6e34 100644
--- a/content/browser/tab_contents/navigation_entry_unittest.cc
+++ b/content/browser/tab_contents/navigation_entry_unittest.cc
@@ -105,7 +105,7 @@ TEST_F(NavigationEntryTest, NavigationEntrySSLStatus) {
EXPECT_EQ(SECURITY_STYLE_UNKNOWN, entry1_.get()->ssl().security_style());
EXPECT_EQ(SECURITY_STYLE_UNKNOWN, entry2_.get()->ssl().security_style());
EXPECT_EQ(0, entry1_.get()->ssl().cert_id());
- EXPECT_EQ(0, entry1_.get()->ssl().cert_status());
+ EXPECT_EQ(0U, entry1_.get()->ssl().cert_status());
EXPECT_EQ(-1, entry1_.get()->ssl().security_bits());
EXPECT_FALSE(entry1_.get()->ssl().displayed_insecure_content());
EXPECT_FALSE(entry1_.get()->ssl().ran_insecure_content());
@@ -113,13 +113,14 @@ TEST_F(NavigationEntryTest, NavigationEntrySSLStatus) {
// Change from the defaults
entry2_.get()->ssl().set_security_style(SECURITY_STYLE_AUTHENTICATED);
entry2_.get()->ssl().set_cert_id(4);
- entry2_.get()->ssl().set_cert_status(1);
+ entry2_.get()->ssl().set_cert_status(net::CERT_STATUS_COMMON_NAME_INVALID);
entry2_.get()->ssl().set_security_bits(0);
entry2_.get()->ssl().set_displayed_insecure_content();
EXPECT_EQ(SECURITY_STYLE_AUTHENTICATED,
entry2_.get()->ssl().security_style());
EXPECT_EQ(4, entry2_.get()->ssl().cert_id());
- EXPECT_EQ(1, entry2_.get()->ssl().cert_status());
+ EXPECT_EQ(net::CERT_STATUS_COMMON_NAME_INVALID,
+ entry2_.get()->ssl().cert_status());
EXPECT_EQ(0, entry2_.get()->ssl().security_bits());
EXPECT_TRUE(entry2_.get()->ssl().displayed_insecure_content());
diff --git a/content/browser/tab_contents/provisional_load_details.h b/content/browser/tab_contents/provisional_load_details.h
index 0e8331f..87d6569 100644
--- a/content/browser/tab_contents/provisional_load_details.h
+++ b/content/browser/tab_contents/provisional_load_details.h
@@ -11,6 +11,7 @@
#include "base/basictypes.h"
#include "content/common/page_transition_types.h"
#include "googleurl/src/gurl.h"
+#include "net/base/cert_status_flags.h"
// This class captures some of the information associated to the provisional
// load of a frame. It is provided as Details with the
@@ -48,7 +49,7 @@ class ProvisionalLoadDetails {
int ssl_cert_id() const { return ssl_cert_id_; }
- int ssl_cert_status() const { return ssl_cert_status_; }
+ net::CertStatus ssl_cert_status() const { return ssl_cert_status_; }
int ssl_security_bits() const { return ssl_security_bits_; }
@@ -65,7 +66,7 @@ class ProvisionalLoadDetails {
bool is_main_frame_;
bool is_in_page_navigation_;
int ssl_cert_id_;
- int ssl_cert_status_;
+ net::CertStatus ssl_cert_status_;
int ssl_security_bits_;
int ssl_connection_status_;
bool is_error_page_;
diff --git a/content/browser/tab_contents/tab_contents.cc b/content/browser/tab_contents/tab_contents.cc
index 73bbe5b..75836e2 100644
--- a/content/browser/tab_contents/tab_contents.cc
+++ b/content/browser/tab_contents/tab_contents.cc
@@ -1030,7 +1030,10 @@ void TabContents::OnDidLoadResourceFromMemoryCache(
cache.Increment();
// Send out a notification that we loaded a resource from our memory cache.
- int cert_id = 0, cert_status = 0, security_bits = -1, connection_status = 0;
+ int cert_id = 0;
+ net::CertStatus cert_status = 0;
+ int security_bits = -1;
+ int connection_status = 0;
SSLManager::DeserializeSecurityInfo(security_info,
&cert_id, &cert_status,
&security_bits,