Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <Cocoa/Cocoa.h> | |
| 6 | |
| 5 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/mac/scoped_nsobject.h" | |
| 6 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 7 #include "content/public/common/content_paths.h" | 10 #include "content/public/common/content_paths.h" |
| 8 #include "content/shell/browser/shell_browser_context.h" | 11 #include "content/shell/browser/shell_browser_context.h" |
| 9 #include "ui/views_content_client/views_content_client.h" | 12 #include "ui/views_content_client/views_content_client.h" |
| 10 #include "ui/views_content_client/views_content_client_main_parts.h" | 13 #include "ui/views_content_client/views_content_client_main_parts.h" |
| 11 | 14 |
| 15 // A simple NSApplicationDelegate that provides a basic mainMenu. | |
| 16 @interface ContentClientAppController : NSObject<NSApplicationDelegate> | |
| 17 @end | |
| 18 | |
| 12 namespace ui { | 19 namespace ui { |
| 13 | 20 |
| 14 namespace { | 21 namespace { |
| 15 | 22 |
| 16 class ViewsContentClientMainPartsMac : public ViewsContentClientMainParts { | 23 class ViewsContentClientMainPartsMac : public ViewsContentClientMainParts { |
| 17 public: | 24 public: |
| 18 ViewsContentClientMainPartsMac( | 25 ViewsContentClientMainPartsMac( |
| 19 const content::MainFunctionParams& content_params, | 26 const content::MainFunctionParams& content_params, |
| 20 ViewsContentClient* views_content_client); | 27 ViewsContentClient* views_content_client); |
| 21 virtual ~ViewsContentClientMainPartsMac() {} | 28 virtual ~ViewsContentClientMainPartsMac(); |
| 22 | 29 |
| 23 // content::BrowserMainParts: | 30 // content::BrowserMainParts: |
| 24 virtual void PreMainMessageLoopRun() OVERRIDE; | 31 virtual void PreMainMessageLoopRun() OVERRIDE; |
| 25 | 32 |
| 26 private: | 33 private: |
| 34 base::scoped_nsobject<ContentClientAppController> app_controller_; | |
| 35 | |
| 27 DISALLOW_COPY_AND_ASSIGN(ViewsContentClientMainPartsMac); | 36 DISALLOW_COPY_AND_ASSIGN(ViewsContentClientMainPartsMac); |
| 28 }; | 37 }; |
| 29 | 38 |
| 30 ViewsContentClientMainPartsMac::ViewsContentClientMainPartsMac( | 39 ViewsContentClientMainPartsMac::ViewsContentClientMainPartsMac( |
| 31 const content::MainFunctionParams& content_params, | 40 const content::MainFunctionParams& content_params, |
| 32 ViewsContentClient* views_content_client) | 41 ViewsContentClient* views_content_client) |
| 33 : ViewsContentClientMainParts(content_params, views_content_client) { | 42 : ViewsContentClientMainParts(content_params, views_content_client) { |
| 34 // Cache the child process path to avoid triggering an AssertIOAllowed. | 43 // Cache the child process path to avoid triggering an AssertIOAllowed. |
| 35 base::FilePath child_process_exe; | 44 base::FilePath child_process_exe; |
| 36 PathService::Get(content::CHILD_PROCESS_EXE, &child_process_exe); | 45 PathService::Get(content::CHILD_PROCESS_EXE, &child_process_exe); |
| 46 | |
| 47 app_controller_.reset([[ContentClientAppController alloc] init]); | |
| 48 [[NSApplication sharedApplication] setDelegate:app_controller_]; | |
| 37 } | 49 } |
| 38 | 50 |
| 39 void ViewsContentClientMainPartsMac::PreMainMessageLoopRun() { | 51 void ViewsContentClientMainPartsMac::PreMainMessageLoopRun() { |
| 40 ViewsContentClientMainParts::PreMainMessageLoopRun(); | 52 ViewsContentClientMainParts::PreMainMessageLoopRun(); |
| 41 | 53 |
| 42 views_content_client()->task().Run(browser_context(), NULL); | 54 views_content_client()->task().Run(browser_context(), NULL); |
| 43 } | 55 } |
| 44 | 56 |
| 57 ViewsContentClientMainPartsMac::~ViewsContentClientMainPartsMac() { | |
| 58 [[NSApplication sharedApplication] setDelegate:nil]; | |
| 59 } | |
| 60 | |
| 45 } // namespace | 61 } // namespace |
| 46 | 62 |
| 47 // static | 63 // static |
| 48 ViewsContentClientMainParts* ViewsContentClientMainParts::Create( | 64 ViewsContentClientMainParts* ViewsContentClientMainParts::Create( |
| 49 const content::MainFunctionParams& content_params, | 65 const content::MainFunctionParams& content_params, |
| 50 ViewsContentClient* views_content_client) { | 66 ViewsContentClient* views_content_client) { |
| 51 return | 67 return |
| 52 new ViewsContentClientMainPartsMac(content_params, views_content_client); | 68 new ViewsContentClientMainPartsMac(content_params, views_content_client); |
| 53 } | 69 } |
| 54 | 70 |
| 55 } // namespace ui | 71 } // namespace ui |
| 72 | |
| 73 @implementation ContentClientAppController | |
| 74 | |
| 75 - (void)applicationDidFinishLaunching:(NSNotification*)aNotification { | |
| 76 // To get key events, we need to set a main menu and have an activation | |
| 77 // policy. | |
| 78 [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; | |
| 79 base::scoped_nsobject<NSMenu> mainMenu([[NSMenu alloc] initWithTitle:@""]); | |
| 80 NSMenuItem* appMenuItem = | |
| 81 [mainMenu addItemWithTitle:@"" action:NULL keyEquivalent:@""]; | |
| 82 [NSApp setMainMenu:mainMenu]; | |
| 83 | |
| 84 base::scoped_nsobject<NSMenu> appMenu([[NSMenu alloc] initWithTitle:@""]); | |
| 85 NSString* appName = [[NSProcessInfo processInfo] processName]; | |
| 86 NSString* quitTitle = [@"Quit " stringByAppendingString:appName]; | |
|
Robert Sesek
2014/06/11 14:53:48
I assume this is all temporary? This would need to
tapted
2014/06/12 09:09:38
Yep - this example code is not shipped, but it mig
tapted
2014/07/21 05:35:55
Sadly, no easy way to do this without pulling in a
| |
| 87 [appMenu addItemWithTitle:quitTitle | |
| 88 action:@selector(terminate:) | |
| 89 keyEquivalent:@"q"]; | |
| 90 [appMenuItem setSubmenu:appMenu]; | |
| 91 } | |
| 92 | |
| 93 @end | |
| OLD | NEW |