summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
Diffstat (limited to 'webkit')
-rw-r--r--webkit/glue/plugins/plugin_lib_posix.cc28
-rw-r--r--webkit/glue/plugins/plugin_list_posix.cc10
2 files changed, 25 insertions, 13 deletions
diff --git a/webkit/glue/plugins/plugin_lib_posix.cc b/webkit/glue/plugins/plugin_lib_posix.cc
index 6541a66..00e85e4 100644
--- a/webkit/glue/plugins/plugin_lib_posix.cc
+++ b/webkit/glue/plugins/plugin_lib_posix.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -9,8 +9,14 @@
#include <sys/exec_elf.h>
#else
#include <elf.h>
+#include <fcntl.h>
#endif
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include "base/eintr_wrapper.h"
+#include "base/file_util.h"
#include "base/string_util.h"
#include "base/sys_string_conversions.h"
#include "base/utf_string_conversions.h"
@@ -33,16 +39,22 @@ enum nsPluginVariable {
// the current architecture (e.g. 32-bit ELF on 32-bit build).
// Returns false on other errors as well.
bool ELFMatchesCurrentArchitecture(const FilePath& filename) {
- FILE* file = fopen(filename.value().c_str(), "rb");
- if (!file)
+ // First make sure we can open the file and it is in fact, a regular file.
+ struct stat stat_buf;
+ // Open with O_NONBLOCK so we don't block on pipes.
+ int fd = open(filename.value().c_str(), O_RDONLY|O_NONBLOCK);
+ if (fd < 0)
+ return false;
+ bool ret = (fstat(fd, &stat_buf) >= 0 && S_ISREG(stat_buf.st_mode));
+ if (HANDLE_EINTR(close(fd)) < 0)
+ return false;
+ if (!ret)
return false;
- char buffer[5];
- if (fread(buffer, 5, 1, file) != 1) {
- fclose(file);
+ const size_t kELFBufferSize = 5;
+ char buffer[kELFBufferSize];
+ if (!file_util::ReadFile(filename, buffer, kELFBufferSize))
return false;
- }
- fclose(file);
if (buffer[0] != ELFMAG0 ||
buffer[1] != ELFMAG1 ||
diff --git a/webkit/glue/plugins/plugin_list_posix.cc b/webkit/glue/plugins/plugin_list_posix.cc
index f46a84b..0daa4b5 100644
--- a/webkit/glue/plugins/plugin_list_posix.cc
+++ b/webkit/glue/plugins/plugin_list_posix.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -94,9 +94,9 @@ void PluginList::GetPluginDirectories(std::vector<FilePath>* plugin_dirs) {
// 2) NS_USER_PLUGINS_DIR: ~/.mozilla/plugins.
// This is a de-facto standard, so even though we're not Mozilla, let's
// look in there too.
- const char* home = getenv("HOME");
- if (home)
- plugin_dirs->push_back(FilePath(home).Append(".mozilla/plugins"));
+ FilePath home = file_util::GetHomeDir();
+ if (!home.empty())
+ plugin_dirs->push_back(home.Append(".mozilla/plugins"));
// 3) NS_SYSTEM_PLUGINS_DIR:
// This varies across different browsers and versions, so check 'em all.
@@ -213,4 +213,4 @@ bool PluginList::ShouldLoadPlugin(const WebPluginInfo& info,
return true;
}
-} // namespace NPAPI
+} // namespace NPAPI