Get the path of the plugin interposing library from the embedder, since they're the ones who bundle it. Make content still work without it. This allows plugins to work inside content_shell.

BUG=90448
Review URL: https://chromiumcodereview.appspot.com/10806075

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@147965 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/common/chrome_content_client.cc b/chrome/common/chrome_content_client.cc
index 98642532..df9d507 100644
--- a/chrome/common/chrome_content_client.cc
+++ b/chrome/common/chrome_content_client.cc
@@ -75,6 +75,9 @@
 const char kGTalkPluginExtension[] = ".googletalk";
 const char kGTalkPluginDescription[] = "Google Talk Plugin";
 
+const char kInterposeLibraryPath[] =
+    "@executable_path/../../../libplugin_carbon_interpose.dylib";
+
 #if defined(ENABLE_REMOTING)
 #if defined(GOOGLE_CHROME_BUILD)
 const char kRemotingViewerPluginName[] = "Chrome Remote Desktop Viewer";
@@ -532,6 +535,10 @@
   }
   return false;
 }
+
+std::string ChromeContentClient::GetCarbonInterposePath() const {
+  return std::string(kInterposeLibraryPath);
+}
 #endif
 
 bool ChromeContentClient::GetBundledFieldTrialPepperFlash(
diff --git a/chrome/common/chrome_content_client.h b/chrome/common/chrome_content_client.h
index 0eaa5b4..c799f88 100644
--- a/chrome/common/chrome_content_client.h
+++ b/chrome/common/chrome_content_client.h
@@ -46,6 +46,7 @@
   virtual bool GetSandboxProfileForSandboxType(
       int sandbox_type,
       int* sandbox_profile_resource_id) const OVERRIDE;
+  virtual std::string GetCarbonInterposePath() const OVERRIDE;
 #endif
 
   // Gets information about the bundled Pepper Flash for field trial.
diff --git a/content/browser/plugin_process_host.cc b/content/browser/plugin_process_host.cc
index f355012..23cac73d 100644
--- a/content/browser/plugin_process_host.cc
+++ b/content/browser/plugin_process_host.cc
@@ -261,14 +261,17 @@
 #if defined(OS_POSIX)
   base::EnvironmentVector env;
 #if defined(OS_MACOSX) && !defined(__LP64__)
-  // Add our interposing library for Carbon. This is stripped back out in
-  // plugin_main.cc, so changes here should be reflected there.
-  std::string interpose_list(plugin_interpose_strings::kInterposeLibraryPath);
-  const char* existing_list =
-      getenv(plugin_interpose_strings::kDYLDInsertLibrariesKey);
-  if (existing_list) {
-    interpose_list.insert(0, ":");
-    interpose_list.insert(0, existing_list);
+  std::string interpose_list =
+      content::GetContentClient()->GetCarbonInterposePath();
+  if (!interpose_list.empty()) {
+    // Add our interposing library for Carbon. This is stripped back out in
+    // plugin_main.cc, so changes here should be reflected there.
+    const char* existing_list =
+        getenv(plugin_interpose_strings::kDYLDInsertLibrariesKey);
+    if (existing_list) {
+      interpose_list.insert(0, ":");
+      interpose_list.insert(0, existing_list);
+    }
   }
   env.push_back(std::pair<std::string, std::string>(
       plugin_interpose_strings::kDYLDInsertLibrariesKey,
diff --git a/content/common/plugin_carbon_interpose_constants_mac.cc b/content/common/plugin_carbon_interpose_constants_mac.cc
index 2ff5dd0..ae7b43c 100644
--- a/content/common/plugin_carbon_interpose_constants_mac.cc
+++ b/content/common/plugin_carbon_interpose_constants_mac.cc
@@ -9,8 +9,6 @@
 namespace plugin_interpose_strings {
 
 const char kDYLDInsertLibrariesKey[] = "DYLD_INSERT_LIBRARIES";
-const char kInterposeLibraryPath[] =
-    "@executable_path/../../../libplugin_carbon_interpose.dylib";
 
 }  // namespace plugin_interpose_strings
 
diff --git a/content/common/plugin_carbon_interpose_constants_mac.h b/content/common/plugin_carbon_interpose_constants_mac.h
index a5882355..00877fa 100644
--- a/content/common/plugin_carbon_interpose_constants_mac.h
+++ b/content/common/plugin_carbon_interpose_constants_mac.h
@@ -11,7 +11,6 @@
 namespace plugin_interpose_strings {
 
 extern const char kDYLDInsertLibrariesKey[];
-extern const char kInterposeLibraryPath[];
 
 }  // namespace plugin_interpose_strings
 
diff --git a/content/plugin/plugin_main_mac.mm b/content/plugin/plugin_main_mac.mm
index 6d28fd83..7bdbb424 100644
--- a/content/plugin/plugin_main_mac.mm
+++ b/content/plugin/plugin_main_mac.mm
@@ -9,6 +9,7 @@
 #include "base/string_util.h"
 #include "content/common/plugin_carbon_interpose_constants_mac.h"
 #include "content/plugin/plugin_interpose_util_mac.h"
+#include "content/public/common/content_client.h"
 
 #if !defined(__LP64__)
 void TrimInterposeEnvironment() {
@@ -17,7 +18,7 @@
   std::string interpose_list;
   if (!env->GetVar(plugin_interpose_strings::kDYLDInsertLibrariesKey,
                    &interpose_list)) {
-    NOTREACHED() << "No interposing libraries set";
+    LOG(INFO) << "No Carbon Interpose library found.";
     return;
   }
 
@@ -26,8 +27,8 @@
   // need to handle are:
   // 1) The whole string is "<kInterposeLibraryPath>", so just clear it, or
   // 2) ":<kInterposeLibraryPath>" is the end of the string, so trim and re-set.
-  std::string interpose_library_path(
-      plugin_interpose_strings::kInterposeLibraryPath);
+  std::string interpose_library_path =
+      content::GetContentClient()->GetCarbonInterposePath();
   DCHECK_GE(interpose_list.size(), interpose_library_path.size());
   size_t suffix_offset = interpose_list.size() - interpose_library_path.size();
   if (suffix_offset == 0 &&
diff --git a/content/public/common/content_client.cc b/content/public/common/content_client.cc
index 2b43403..14867c10 100644
--- a/content/public/common/content_client.cc
+++ b/content/public/common/content_client.cc
@@ -85,6 +85,10 @@
     int* sandbox_profile_resource_id) const {
   return false;
 }
+
+std::string ContentClient::GetCarbonInterposePath() const {
+  return std::string();
+}
 #endif
 
 }  // namespace content
diff --git a/content/public/common/content_client.h b/content/public/common/content_client.h
index c812d3d0..12d52b9 100644
--- a/content/public/common/content_client.h
+++ b/content/public/common/content_client.h
@@ -139,6 +139,10 @@
   virtual bool GetSandboxProfileForSandboxType(
       int sandbox_type,
       int* sandbox_profile_resource_id) const;
+
+  // Gets the Carbon interposing path to give to DYLD. Returns an empty string
+  // if the embedder doesn't bundle it.
+  virtual std::string GetCarbonInterposePath() const;
 #endif
 
   void set_browser_for_testing(ContentBrowserClient* c) { browser_ = c; }