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