OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "android_webview/lib/main/aw_main_delegate.h" | 5 #include "android_webview/lib/main/aw_main_delegate.h" |
6 | 6 |
7 #include "android_webview/browser/aw_content_browser_client.h" | 7 #include "android_webview/browser/aw_content_browser_client.h" |
8 #include "android_webview/browser/in_process_renderer/in_process_renderer_client .h" | 8 #include "android_webview/browser/in_process_renderer/in_process_renderer_client .h" |
9 #include "android_webview/browser/scoped_allow_wait_for_legacy_web_view_api.h" | |
9 #include "android_webview/common/aw_switches.h" | 10 #include "android_webview/common/aw_switches.h" |
10 #include "android_webview/lib/aw_browser_dependency_factory_impl.h" | 11 #include "android_webview/lib/aw_browser_dependency_factory_impl.h" |
11 #include "android_webview/native/aw_geolocation_permission_context.h" | 12 #include "android_webview/native/aw_geolocation_permission_context.h" |
12 #include "android_webview/native/aw_quota_manager_bridge_impl.h" | 13 #include "android_webview/native/aw_quota_manager_bridge_impl.h" |
13 #include "android_webview/native/aw_web_contents_view_delegate.h" | 14 #include "android_webview/native/aw_web_contents_view_delegate.h" |
14 #include "android_webview/renderer/aw_content_renderer_client.h" | 15 #include "android_webview/renderer/aw_content_renderer_client.h" |
15 #include "base/command_line.h" | 16 #include "base/command_line.h" |
17 #include "base/lazy_instance.h" | |
16 #include "base/logging.h" | 18 #include "base/logging.h" |
17 #include "base/memory/scoped_ptr.h" | 19 #include "base/memory/scoped_ptr.h" |
18 #include "content/public/browser/browser_main_runner.h" | 20 #include "content/public/browser/browser_main_runner.h" |
19 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
20 #include "content/public/common/content_switches.h" | 22 #include "content/public/common/content_switches.h" |
21 #include "webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" | 23 #include "webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" |
22 | 24 |
23 namespace android_webview { | 25 namespace android_webview { |
24 | 26 |
27 namespace { | |
28 | |
29 base::LazyInstance<scoped_ptr<ScopedAllowWaitForLegacyWebViewApi> > | |
30 g_allow_wait_in_ui_thread = LAZY_INSTANCE_INITIALIZER; | |
31 | |
32 bool UIAndRendererCompositorThreadsNotMerged() { | |
33 return CommandLine::ForCurrentProcess()->HasSwitch( | |
34 switches::kNoMergeUIAndRendererCompositorThreads); | |
35 } | |
36 } | |
37 | |
25 AwMainDelegate::AwMainDelegate() { | 38 AwMainDelegate::AwMainDelegate() { |
26 } | 39 } |
27 | 40 |
28 AwMainDelegate::~AwMainDelegate() { | 41 AwMainDelegate::~AwMainDelegate() { |
29 } | 42 } |
30 | 43 |
31 bool AwMainDelegate::BasicStartupComplete(int* exit_code) { | 44 bool AwMainDelegate::BasicStartupComplete(int* exit_code) { |
32 content::SetContentClient(&content_client_); | 45 content::SetContentClient(&content_client_); |
33 | 46 |
34 webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl | 47 webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl |
35 ::EnableVirtualizedContext(); | 48 ::EnableVirtualizedContext(); |
36 | 49 |
37 CommandLine* cl = CommandLine::ForCurrentProcess(); | 50 CommandLine* cl = CommandLine::ForCurrentProcess(); |
38 // Set the command line to enable synchronous API compatibility. | 51 if (UIAndRendererCompositorThreadsNotMerged()) { |
39 if (cl->HasSwitch(switches::kMergeUIAndRendererCompositorThreads)) { | 52 cl->AppendSwitch(switches::kEnableWebViewSynchronousAPIs); |
53 } else { | |
54 // Set the command line to enable synchronous API compatibility. | |
40 cl->AppendSwitch(switches::kEnableSynchronousRendererCompositor); | 55 cl->AppendSwitch(switches::kEnableSynchronousRendererCompositor); |
41 } else { | |
42 cl->AppendSwitch(switches::kEnableWebViewSynchronousAPIs); | |
43 } | 56 } |
44 | |
45 return false; | 57 return false; |
46 } | 58 } |
47 | 59 |
48 void AwMainDelegate::PreSandboxStartup() { | 60 void AwMainDelegate::PreSandboxStartup() { |
49 // TODO(torne): When we have a separate renderer process, we need to handle | 61 // TODO(torne): When we have a separate renderer process, we need to handle |
50 // being passed open FDs for the resource paks here. | 62 // being passed open FDs for the resource paks here. |
51 } | 63 } |
52 | 64 |
53 void AwMainDelegate::SandboxInitialized(const std::string& process_type) { | 65 void AwMainDelegate::SandboxInitialized(const std::string& process_type) { |
54 // TODO(torne): Adjust linux OOM score here. | 66 // TODO(torne): Adjust linux OOM score here. |
55 } | 67 } |
56 | 68 |
57 int AwMainDelegate::RunProcess( | 69 int AwMainDelegate::RunProcess( |
58 const std::string& process_type, | 70 const std::string& process_type, |
59 const content::MainFunctionParams& main_function_params) { | 71 const content::MainFunctionParams& main_function_params) { |
60 if (process_type.empty()) { | 72 if (process_type.empty()) { |
61 AwBrowserDependencyFactoryImpl::InstallInstance(); | 73 AwBrowserDependencyFactoryImpl::InstallInstance(); |
62 | 74 |
63 browser_runner_.reset(content::BrowserMainRunner::Create()); | 75 browser_runner_.reset(content::BrowserMainRunner::Create()); |
64 int exit_code = browser_runner_->Initialize(main_function_params); | 76 int exit_code = browser_runner_->Initialize(main_function_params); |
65 DCHECK(exit_code < 0); | 77 DCHECK(exit_code < 0); |
66 | 78 |
79 if (!UIAndRendererCompositorThreadsNotMerged()) { | |
boliu
2013/05/08 12:46:03
Leave a comment that this is temporary until we re
joth
2013/05/08 12:49:11
+1
| |
80 g_allow_wait_in_ui_thread.Get().reset( | |
81 new ScopedAllowWaitForLegacyWebViewApi()); | |
82 } | |
83 | |
67 // Return 0 so that we do NOT trigger the default behavior. On Android, the | 84 // Return 0 so that we do NOT trigger the default behavior. On Android, the |
68 // UI message loop is managed by the Java application. | 85 // UI message loop is managed by the Java application. |
69 return 0; | 86 return 0; |
70 } | 87 } |
71 | 88 |
72 return -1; | 89 return -1; |
73 } | 90 } |
74 | 91 |
75 void AwMainDelegate::ProcessExiting(const std::string& process_type) { | 92 void AwMainDelegate::ProcessExiting(const std::string& process_type) { |
76 // TODO(torne): Clean up resources when we handle them. | 93 // TODO(torne): Clean up resources when we handle them. |
77 | 94 |
78 logging::CloseLogFile(); | 95 logging::CloseLogFile(); |
79 } | 96 } |
80 | 97 |
81 content::ContentBrowserClient* | 98 content::ContentBrowserClient* |
82 AwMainDelegate::CreateContentBrowserClient() { | 99 AwMainDelegate::CreateContentBrowserClient() { |
83 content_browser_client_.reset(new AwContentBrowserClient(this)); | 100 content_browser_client_.reset(new AwContentBrowserClient(this)); |
84 return content_browser_client_.get(); | 101 return content_browser_client_.get(); |
85 } | 102 } |
86 | 103 |
87 content::ContentRendererClient* | 104 content::ContentRendererClient* |
88 AwMainDelegate::CreateContentRendererClient() { | 105 AwMainDelegate::CreateContentRendererClient() { |
89 // None of this makes sense for multiprocess. | 106 // None of this makes sense for multiprocess. |
90 DCHECK(CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)); | 107 DCHECK(CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)); |
91 // During transition period allow running in either threading mode; eventually | 108 // During transition period allow running in either threading mode; eventually |
92 // only the compositor/UI thread merge mode will be supported. | 109 // only the compositor/UI thread merge mode will be supported. |
93 const bool merge_threads = | 110 const bool no_merge_threads = UIAndRendererCompositorThreadsNotMerged(); |
94 CommandLine::ForCurrentProcess()->HasSwitch( | |
95 switches::kMergeUIAndRendererCompositorThreads); | |
96 content_renderer_client_.reset( | 111 content_renderer_client_.reset( |
97 merge_threads ? new InProcessRendererClient() : | 112 no_merge_threads ? new AwContentRendererClient() : |
98 new AwContentRendererClient()); | 113 new InProcessRendererClient()); |
99 return content_renderer_client_.get(); | 114 return content_renderer_client_.get(); |
100 } | 115 } |
101 | 116 |
102 AwQuotaManagerBridge* AwMainDelegate::CreateAwQuotaManagerBridge( | 117 AwQuotaManagerBridge* AwMainDelegate::CreateAwQuotaManagerBridge( |
103 AwBrowserContext* browser_context) { | 118 AwBrowserContext* browser_context) { |
104 return new AwQuotaManagerBridgeImpl(browser_context); | 119 return new AwQuotaManagerBridgeImpl(browser_context); |
105 } | 120 } |
106 | 121 |
107 content::GeolocationPermissionContext* | 122 content::GeolocationPermissionContext* |
108 AwMainDelegate::CreateGeolocationPermission( | 123 AwMainDelegate::CreateGeolocationPermission( |
109 AwBrowserContext* browser_context) { | 124 AwBrowserContext* browser_context) { |
110 return AwGeolocationPermissionContext::Create(browser_context); | 125 return AwGeolocationPermissionContext::Create(browser_context); |
111 } | 126 } |
112 | 127 |
113 content::WebContentsViewDelegate* AwMainDelegate::CreateViewDelegate( | 128 content::WebContentsViewDelegate* AwMainDelegate::CreateViewDelegate( |
114 content::WebContents* web_contents) { | 129 content::WebContents* web_contents) { |
115 return AwWebContentsViewDelegate::Create(web_contents); | 130 return AwWebContentsViewDelegate::Create(web_contents); |
116 } | 131 } |
117 | 132 |
118 } // namespace android_webview | 133 } // namespace android_webview |
OLD | NEW |