/src/mozilla-central/ipc/glue/ScopedXREEmbed.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #include "ScopedXREEmbed.h" |
8 | | |
9 | | #include "base/command_line.h" |
10 | | #include "base/string_util.h" |
11 | | |
12 | | #include "nsIFile.h" |
13 | | |
14 | | #include "nsCOMPtr.h" |
15 | | #include "nsServiceManagerUtils.h" |
16 | | #include "nsString.h" |
17 | | #include "nsXULAppAPI.h" |
18 | | |
19 | | using mozilla::ipc::ScopedXREEmbed; |
20 | | |
21 | | ScopedXREEmbed::ScopedXREEmbed() |
22 | | : mShouldKillEmbedding(false) |
23 | 0 | { |
24 | 0 | NS_LogInit(); |
25 | 0 | } |
26 | | |
27 | | ScopedXREEmbed::~ScopedXREEmbed() |
28 | 0 | { |
29 | 0 | Stop(); |
30 | 0 | NS_LogTerm(); |
31 | 0 | } |
32 | | |
33 | | void |
34 | | ScopedXREEmbed::SetAppDir(const nsACString& aPath) |
35 | 0 | { |
36 | 0 | bool flag; |
37 | 0 | nsresult rv = |
38 | 0 | XRE_GetFileFromPath(aPath.BeginReading(), getter_AddRefs(mAppDir)); |
39 | 0 | if (NS_FAILED(rv) || |
40 | 0 | NS_FAILED(mAppDir->Exists(&flag)) || !flag) { |
41 | 0 | NS_WARNING("Invalid application directory passed to content process."); |
42 | 0 | mAppDir = nullptr; |
43 | 0 | } |
44 | 0 | } |
45 | | |
46 | | void |
47 | | ScopedXREEmbed::Start() |
48 | 0 | { |
49 | 0 | nsCOMPtr<nsIFile> localFile; |
50 | 0 | nsresult rv = XRE_GetBinaryPath(getter_AddRefs(localFile)); |
51 | 0 | if (NS_FAILED(rv)) |
52 | 0 | return; |
53 | 0 | |
54 | 0 | nsCOMPtr<nsIFile> parent; |
55 | 0 | rv = localFile->GetParent(getter_AddRefs(parent)); |
56 | 0 | if (NS_FAILED(rv)) |
57 | 0 | return; |
58 | 0 | |
59 | 0 | localFile = do_QueryInterface(parent); |
60 | 0 | NS_ENSURE_TRUE_VOID(localFile); |
61 | 0 |
|
62 | | #ifdef OS_MACOSX |
63 | | if (XRE_IsContentProcess()) { |
64 | | // We're an XPCOM-using subprocess. Walk out of |
65 | | // [subprocess].app/Contents/MacOS to the real GRE dir. |
66 | | rv = localFile->GetParent(getter_AddRefs(parent)); |
67 | | if (NS_FAILED(rv)) |
68 | | return; |
69 | | |
70 | | localFile = do_QueryInterface(parent); |
71 | | NS_ENSURE_TRUE_VOID(localFile); |
72 | | |
73 | | rv = localFile->GetParent(getter_AddRefs(parent)); |
74 | | if (NS_FAILED(rv)) |
75 | | return; |
76 | | |
77 | | localFile = do_QueryInterface(parent); |
78 | | NS_ENSURE_TRUE_VOID(localFile); |
79 | | |
80 | | rv = localFile->GetParent(getter_AddRefs(parent)); |
81 | | if (NS_FAILED(rv)) |
82 | | return; |
83 | | |
84 | | localFile = do_QueryInterface(parent); |
85 | | NS_ENSURE_TRUE_VOID(localFile); |
86 | | |
87 | | rv = localFile->SetNativeLeafName(NS_LITERAL_CSTRING("Resources")); |
88 | | if (NS_FAILED(rv)) { |
89 | | return; |
90 | | } |
91 | | } |
92 | | #endif |
93 | |
|
94 | 0 | if (mAppDir) |
95 | 0 | rv = XRE_InitEmbedding2(localFile, mAppDir, nullptr); |
96 | 0 | else |
97 | 0 | rv = XRE_InitEmbedding2(localFile, localFile, nullptr); |
98 | 0 | if (NS_FAILED(rv)) |
99 | 0 | return; |
100 | 0 | |
101 | 0 | mShouldKillEmbedding = true; |
102 | 0 | } |
103 | | |
104 | | void |
105 | | ScopedXREEmbed::Stop() |
106 | 0 | { |
107 | 0 | if (mShouldKillEmbedding) { |
108 | 0 | XRE_TermEmbedding(); |
109 | 0 | mShouldKillEmbedding = false; |
110 | 0 | } |
111 | 0 | } |