Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(209)

Unified Diff: ui/views_content_client/views_content_client_main_parts_mac.mm

Issue 309483009: Remaining bits to get views_examples_with_content_exe to work on Mac (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase to master@r275900 Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/views_content_client/views_content_client_main_parts_mac.mm
diff --git a/ui/views_content_client/views_content_client_main_parts_mac.mm b/ui/views_content_client/views_content_client_main_parts_mac.mm
index 8d2f12bcf8c00263564fc6dc518f6cb32949dc5c..8180b6f8adc03baf3feae7d56617ed081cf01c6b 100644
--- a/ui/views_content_client/views_content_client_main_parts_mac.mm
+++ b/ui/views_content_client/views_content_client_main_parts_mac.mm
@@ -2,13 +2,20 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#import <Cocoa/Cocoa.h>
+
#include "base/files/file_path.h"
+#include "base/mac/scoped_nsobject.h"
#include "base/path_service.h"
#include "content/public/common/content_paths.h"
#include "content/shell/browser/shell_browser_context.h"
#include "ui/views_content_client/views_content_client.h"
#include "ui/views_content_client/views_content_client_main_parts.h"
+// A simple NSApplicationDelegate that provides a basic mainMenu.
+@interface ContentClientAppController : NSObject<NSApplicationDelegate>
+@end
+
namespace ui {
namespace {
@@ -18,12 +25,14 @@ class ViewsContentClientMainPartsMac : public ViewsContentClientMainParts {
ViewsContentClientMainPartsMac(
const content::MainFunctionParams& content_params,
ViewsContentClient* views_content_client);
- virtual ~ViewsContentClientMainPartsMac() {}
+ virtual ~ViewsContentClientMainPartsMac();
// content::BrowserMainParts:
virtual void PreMainMessageLoopRun() OVERRIDE;
private:
+ base::scoped_nsobject<ContentClientAppController> app_controller_;
+
DISALLOW_COPY_AND_ASSIGN(ViewsContentClientMainPartsMac);
};
@@ -34,6 +43,9 @@ ViewsContentClientMainPartsMac::ViewsContentClientMainPartsMac(
// Cache the child process path to avoid triggering an AssertIOAllowed.
base::FilePath child_process_exe;
PathService::Get(content::CHILD_PROCESS_EXE, &child_process_exe);
+
+ app_controller_.reset([[ContentClientAppController alloc] init]);
+ [[NSApplication sharedApplication] setDelegate:app_controller_];
}
void ViewsContentClientMainPartsMac::PreMainMessageLoopRun() {
@@ -42,6 +54,10 @@ void ViewsContentClientMainPartsMac::PreMainMessageLoopRun() {
views_content_client()->task().Run(browser_context(), NULL);
}
+ViewsContentClientMainPartsMac::~ViewsContentClientMainPartsMac() {
+ [[NSApplication sharedApplication] setDelegate:nil];
+}
+
} // namespace
// static
@@ -53,3 +69,25 @@ ViewsContentClientMainParts* ViewsContentClientMainParts::Create(
}
} // namespace ui
+
+@implementation ContentClientAppController
+
+- (void)applicationDidFinishLaunching:(NSNotification*)aNotification {
+ // To get key events, we need to set a main menu and have an activation
+ // policy.
+ [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
+ base::scoped_nsobject<NSMenu> mainMenu([[NSMenu alloc] initWithTitle:@""]);
+ NSMenuItem* appMenuItem =
+ [mainMenu addItemWithTitle:@"" action:NULL keyEquivalent:@""];
+ [NSApp setMainMenu:mainMenu];
+
+ base::scoped_nsobject<NSMenu> appMenu([[NSMenu alloc] initWithTitle:@""]);
+ NSString* appName = [[NSProcessInfo processInfo] processName];
+ 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
+ [appMenu addItemWithTitle:quitTitle
+ action:@selector(terminate:)
+ keyEquivalent:@"q"];
+ [appMenuItem setSubmenu:appMenu];
+}
+
+@end
« ui/views/cocoa/bridged_content_view.mm ('K') | « ui/views/widget/native_widget_mac.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698