OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import <AppKit/AppKit.h> | 5 #import <AppKit/AppKit.h> |
6 | 6 |
7 #include "base/environment.h" | 7 #include "base/environment.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "content/common/plugin_carbon_interpose_constants_mac.h" | 10 #include "content/common/plugin_carbon_interpose_constants_mac.h" |
11 #include "content/plugin/plugin_interpose_util_mac.h" | 11 #include "content/plugin/plugin_interpose_util_mac.h" |
12 #include "content/public/common/content_client.h" | 12 #include "content/public/common/content_client.h" |
13 | 13 |
14 namespace content { | 14 namespace content { |
15 | 15 |
16 #if !defined(__LP64__) | 16 #if !defined(__LP64__) |
17 void TrimInterposeEnvironment() { | 17 void TrimInterposeEnvironment() { |
18 scoped_ptr<base::Environment> env(base::Environment::Create()); | 18 scoped_ptr<base::Environment> env(base::Environment::Create()); |
19 | 19 |
20 std::string interpose_list; | 20 std::string interpose_list; |
21 if (!env->GetVar(plugin_interpose_strings::kDYLDInsertLibrariesKey, | 21 if (!env->GetVar(kDYLDInsertLibrariesKey, &interpose_list)) { |
22 &interpose_list)) { | |
23 LOG(INFO) << "No Carbon Interpose library found."; | 22 LOG(INFO) << "No Carbon Interpose library found."; |
24 return; | 23 return; |
25 } | 24 } |
26 | 25 |
27 // The list is a :-separated list of paths. Because we append our interpose | 26 // The list is a :-separated list of paths. Because we append our interpose |
28 // library just before forking in plugin_process_host.cc, the only cases we | 27 // library just before forking in plugin_process_host.cc, the only cases we |
29 // need to handle are: | 28 // need to handle are: |
30 // 1) The whole string is "<kInterposeLibraryPath>", so just clear it, or | 29 // 1) The whole string is "<kInterposeLibraryPath>", so just clear it, or |
31 // 2) ":<kInterposeLibraryPath>" is the end of the string, so trim and re-set. | 30 // 2) ":<kInterposeLibraryPath>" is the end of the string, so trim and re-set. |
32 std::string interpose_library_path = | 31 std::string interpose_library_path = |
33 GetContentClient()->GetCarbonInterposePath(); | 32 GetContentClient()->GetCarbonInterposePath(); |
34 DCHECK_GE(interpose_list.size(), interpose_library_path.size()); | 33 DCHECK_GE(interpose_list.size(), interpose_library_path.size()); |
35 size_t suffix_offset = interpose_list.size() - interpose_library_path.size(); | 34 size_t suffix_offset = interpose_list.size() - interpose_library_path.size(); |
36 if (suffix_offset == 0 && | 35 if (suffix_offset == 0 && |
37 interpose_list == interpose_library_path) { | 36 interpose_list == interpose_library_path) { |
38 env->UnSetVar(plugin_interpose_strings::kDYLDInsertLibrariesKey); | 37 env->UnSetVar(kDYLDInsertLibrariesKey); |
39 } else if (suffix_offset > 0 && interpose_list[suffix_offset - 1] == ':' && | 38 } else if (suffix_offset > 0 && interpose_list[suffix_offset - 1] == ':' && |
40 interpose_list.substr(suffix_offset) == interpose_library_path) { | 39 interpose_list.substr(suffix_offset) == interpose_library_path) { |
41 std::string trimmed_list = interpose_list.substr(0, suffix_offset - 1); | 40 std::string trimmed_list = interpose_list.substr(0, suffix_offset - 1); |
42 env->SetVar(plugin_interpose_strings::kDYLDInsertLibrariesKey, | 41 env->SetVar(kDYLDInsertLibrariesKey, trimmed_list.c_str()); |
43 trimmed_list.c_str()); | |
44 } else { | 42 } else { |
45 NOTREACHED() << "Missing Carbon interposing library"; | 43 NOTREACHED() << "Missing Carbon interposing library"; |
46 } | 44 } |
47 } | 45 } |
48 #endif | 46 #endif |
49 | 47 |
50 void InitializeChromeApplication() { | 48 void InitializeChromeApplication() { |
51 [NSApplication sharedApplication]; | 49 [NSApplication sharedApplication]; |
52 mac_plugin_interposing::SetUpCocoaInterposing(); | 50 mac_plugin_interposing::SetUpCocoaInterposing(); |
53 } | 51 } |
54 | 52 |
55 } // namespace content | 53 } // namespace content |
OLD | NEW |