| 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> | 5 #import <Cocoa/Cocoa.h> |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/mac/scoped_nsobject.h" | 8 #include "base/mac/scoped_nsobject.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "content/public/browser/context_factory.h" |
| 10 #include "content/public/common/content_paths.h" | 11 #include "content/public/common/content_paths.h" |
| 11 #include "content/shell/browser/shell_browser_context.h" | 12 #include "content/shell/browser/shell_browser_context.h" |
| 13 #include "ui/views/test/desktop_test_views_delegate.h" |
| 12 #include "ui/views_content_client/views_content_client.h" | 14 #include "ui/views_content_client/views_content_client.h" |
| 13 #include "ui/views_content_client/views_content_client_main_parts.h" | 15 #include "ui/views_content_client/views_content_client_main_parts.h" |
| 14 | 16 |
| 15 // A simple NSApplicationDelegate that provides a basic mainMenu and can | 17 // A simple NSApplicationDelegate that provides a basic mainMenu and can |
| 16 // activate a task when the application has finished loading. | 18 // activate a task when the application has finished loading. |
| 17 @interface ViewsContentClientAppController : NSObject<NSApplicationDelegate> { | 19 @interface ViewsContentClientAppController : NSObject<NSApplicationDelegate> { |
| 18 @private | 20 @private |
| 19 base::Closure task_; | 21 base::Closure task_; |
| 20 } | 22 } |
| 21 | 23 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 33 ViewsContentClientMainPartsMac( | 35 ViewsContentClientMainPartsMac( |
| 34 const content::MainFunctionParams& content_params, | 36 const content::MainFunctionParams& content_params, |
| 35 ViewsContentClient* views_content_client); | 37 ViewsContentClient* views_content_client); |
| 36 virtual ~ViewsContentClientMainPartsMac(); | 38 virtual ~ViewsContentClientMainPartsMac(); |
| 37 | 39 |
| 38 // content::BrowserMainParts: | 40 // content::BrowserMainParts: |
| 39 virtual void PreMainMessageLoopRun() OVERRIDE; | 41 virtual void PreMainMessageLoopRun() OVERRIDE; |
| 40 | 42 |
| 41 private: | 43 private: |
| 42 base::scoped_nsobject<ViewsContentClientAppController> app_controller_; | 44 base::scoped_nsobject<ViewsContentClientAppController> app_controller_; |
| 45 scoped_ptr<views::ViewsDelegate> composited_views_delegate_; |
| 43 | 46 |
| 44 DISALLOW_COPY_AND_ASSIGN(ViewsContentClientMainPartsMac); | 47 DISALLOW_COPY_AND_ASSIGN(ViewsContentClientMainPartsMac); |
| 45 }; | 48 }; |
| 46 | 49 |
| 50 class CompositedTestViewsDelegate : public views::DesktopTestViewsDelegate { |
| 51 public: |
| 52 virtual ui::ContextFactory* GetContextFactory() OVERRIDE { |
| 53 return content::GetContextFactory(); |
| 54 } |
| 55 }; |
| 56 |
| 47 ViewsContentClientMainPartsMac::ViewsContentClientMainPartsMac( | 57 ViewsContentClientMainPartsMac::ViewsContentClientMainPartsMac( |
| 48 const content::MainFunctionParams& content_params, | 58 const content::MainFunctionParams& content_params, |
| 49 ViewsContentClient* views_content_client) | 59 ViewsContentClient* views_content_client) |
| 50 : ViewsContentClientMainParts(content_params, views_content_client) { | 60 : ViewsContentClientMainParts(content_params, views_content_client) { |
| 51 // Cache the child process path to avoid triggering an AssertIOAllowed. | 61 // Cache the child process path to avoid triggering an AssertIOAllowed. |
| 52 base::FilePath child_process_exe; | 62 base::FilePath child_process_exe; |
| 53 PathService::Get(content::CHILD_PROCESS_EXE, &child_process_exe); | 63 PathService::Get(content::CHILD_PROCESS_EXE, &child_process_exe); |
| 54 | 64 |
| 55 app_controller_.reset([[ViewsContentClientAppController alloc] init]); | 65 app_controller_.reset([[ViewsContentClientAppController alloc] init]); |
| 56 [[NSApplication sharedApplication] setDelegate:app_controller_]; | 66 [[NSApplication sharedApplication] setDelegate:app_controller_]; |
| 57 } | 67 } |
| 58 | 68 |
| 59 void ViewsContentClientMainPartsMac::PreMainMessageLoopRun() { | 69 void ViewsContentClientMainPartsMac::PreMainMessageLoopRun() { |
| 60 ViewsContentClientMainParts::PreMainMessageLoopRun(); | 70 ViewsContentClientMainParts::PreMainMessageLoopRun(); |
| 61 | 71 |
| 72 views_delegate_.reset(); // FIXME |
| 73 |
| 74 // If run with --enable-delegated-renderer, the GPU channel factory and image |
| 75 // transport factory for communicating with the GPU process should already be |
| 76 // initialized. This is the default on Mac as of r281692. Otherwise, this file |
| 77 // needs a content/browser dependency and some initialization steps here. |
| 78 composited_views_delegate_.reset(new CompositedTestViewsDelegate); |
| 79 |
| 62 // On Mac, the task must be deferred to applicationDidFinishLaunching. If not, | 80 // On Mac, the task must be deferred to applicationDidFinishLaunching. If not, |
| 63 // the widget can activate, but (even if configured) the mainMenu won't be | 81 // the widget can activate, but (even if configured) the mainMenu won't be |
| 64 // ready to switch over in the OSX UI, so it will look strange. | 82 // ready to switch over in the OSX UI, so it will look strange. |
| 65 NSWindow* window_context = nil; | 83 NSWindow* window_context = nil; |
| 66 [app_controller_ setTask:base::Bind(views_content_client()->task(), | 84 [app_controller_ setTask:base::Bind(views_content_client()->task(), |
| 67 base::Unretained(browser_context()), | 85 base::Unretained(browser_context()), |
| 68 base::Unretained(window_context))]; | 86 base::Unretained(window_context))]; |
| 69 } | 87 } |
| 70 | 88 |
| 71 ViewsContentClientMainPartsMac::~ViewsContentClientMainPartsMac() { | 89 ViewsContentClientMainPartsMac::~ViewsContentClientMainPartsMac() { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 NSString* quitTitle = [@"Quit " stringByAppendingString:appName]; | 127 NSString* quitTitle = [@"Quit " stringByAppendingString:appName]; |
| 110 [appMenu addItemWithTitle:quitTitle | 128 [appMenu addItemWithTitle:quitTitle |
| 111 action:@selector(terminate:) | 129 action:@selector(terminate:) |
| 112 keyEquivalent:@"q"]; | 130 keyEquivalent:@"q"]; |
| 113 [appMenuItem setSubmenu:appMenu]; | 131 [appMenuItem setSubmenu:appMenu]; |
| 114 | 132 |
| 115 task_.Run(); | 133 task_.Run(); |
| 116 } | 134 } |
| 117 | 135 |
| 118 @end | 136 @end |
| OLD | NEW |