Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / content / shell / app / shell_main_delegate_mac.mm
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/shell/app/shell_main_delegate_mac.h"
6
7 #include <unistd.h>
8
9 #include "base/command_line.h"
10 #include "base/files/file_path.h"
11 #include "base/logging.h"
12 #include "base/mac/foundation_util.h"
13 #include "base/mac/scoped_nsobject.h"
14 #include "content/public/common/content_switches.h"
15 #include "content/shell/app/paths_mac.h"
16 #include "content/shell/common/shell_switches.h"
17
18 namespace content {
19
20 void EnsureCorrectResolutionSettings() {
21   // Exit early if this isn't a browser process.
22   if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kProcessType))
23     return;
24
25   NSString* const kHighResolutionCapable = @"NSHighResolutionCapable";
26   base::FilePath info_plist = GetInfoPlistPath();
27   base::scoped_nsobject<NSMutableDictionary> info_dict(
28       [[NSMutableDictionary alloc]
29           initWithContentsOfFile:base::mac::FilePathToNSString(info_plist)]);
30
31   bool running_layout_tests =
32       CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree);
33   bool not_high_resolution_capable =
34       [info_dict objectForKey:kHighResolutionCapable] &&
35       [[info_dict objectForKey:kHighResolutionCapable] isEqualToNumber:@(NO)];
36   if (running_layout_tests == not_high_resolution_capable)
37     return;
38
39   // We need to update our Info.plist before we can continue.
40   [info_dict setObject:@(!running_layout_tests) forKey:kHighResolutionCapable];
41   CHECK([info_dict writeToFile:base::mac::FilePathToNSString(info_plist)
42                     atomically:YES]);
43
44   const CommandLine::StringVector& original_argv =
45       CommandLine::ForCurrentProcess()->argv();
46   char** argv = new char*[original_argv.size() + 1];
47   for (unsigned i = 0; i < original_argv.size(); ++i)
48     argv[i] = const_cast<char*>(original_argv.at(i).c_str());
49   argv[original_argv.size()] = NULL;
50
51   CHECK(execvp(argv[0], argv));
52 }
53
54 }  // namespace content