Skip to content

Commit

Permalink
[Android WebView] Pass .pak fds & regions to child services
Browse files Browse the repository at this point in the history
Retrieving fds & regions from ResourceBundle and passing them as
additional mapped files.

BUG=522205

Review URL: https://codereview.chromium.org/1306323002

Cr-Commit-Position: refs/heads/master@{#345075}
  • Loading branch information
mnaganov authored and Commit bot committed Aug 24, 2015
1 parent 671edb9 commit db95992
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 2 deletions.
1 change: 1 addition & 0 deletions android_webview/android_webview.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@
'common/android_webview_message_generator.h',
'common/aw_content_client.cc',
'common/aw_content_client.h',
'common/aw_descriptors.h',
'common/aw_hit_test_data.cc',
'common/aw_hit_test_data.h',
'common/aw_message_port_messages.h',
Expand Down
15 changes: 15 additions & 0 deletions android_webview/browser/aw_content_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "android_webview/browser/net/aw_url_request_context_getter.h"
#include "android_webview/browser/net_disk_cache_remover.h"
#include "android_webview/browser/renderer_host/aw_resource_dispatcher_host_delegate.h"
#include "android_webview/common/aw_descriptors.h"
#include "android_webview/common/render_view_messages.h"
#include "android_webview/common/url_constants.h"
#include "base/android/locale_utils.h"
Expand All @@ -37,6 +38,7 @@
#include "net/ssl/ssl_cert_request_info.h"
#include "net/ssl/ssl_info.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/resource/resource_bundle_android.h"
#include "ui/resources/grit/ui_resources.h"

using content::ResourceType;
Expand Down Expand Up @@ -453,6 +455,19 @@ bool AwContentBrowserClient::AllowPepperSocketAPI(
return false;
}

void AwContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
const base::CommandLine& command_line,
int child_process_id,
content::FileDescriptorInfo* mappings,
std::map<int, base::MemoryMappedFile::Region>* regions) {
int fd = ui::GetMainAndroidPackFd(
&(*regions)[kAndroidWebViewMainPakDescriptor]);
mappings->Share(kAndroidWebViewMainPakDescriptor, fd);

fd = ui::GetLocalePackFd(&(*regions)[kAndroidWebViewLocalePakDescriptor]);
mappings->Share(kAndroidWebViewLocalePakDescriptor, fd);
}

void AwContentBrowserClient::OverrideWebkitPrefs(
content::RenderViewHost* rvh,
content::WebPreferences* web_prefs) {
Expand Down
5 changes: 5 additions & 0 deletions android_webview/browser/aw_content_browser_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ class AwContentBrowserClient : public content::ContentBrowserClient {
const GURL& url,
bool private_api,
const content::SocketPermissionRequest* params) override;
void GetAdditionalMappedFilesForChildProcess(
const base::CommandLine& command_line,
int child_process_id,
content::FileDescriptorInfo* mappings,
std::map<int, base::MemoryMappedFile::Region>* regions) override;
void OverrideWebkitPrefs(content::RenderViewHost* rvh,
content::WebPreferences* web_prefs) override;
#if defined(VIDEO_HOLE)
Expand Down
15 changes: 15 additions & 0 deletions android_webview/common/aw_descriptors.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ANDROID_WEBVIEW_COMMON_AW_DESCRIPTORS_H_
#define ANDROID_WEBVIEW_COMMON_AW_DESCRIPTORS_H_

#include "content/public/common/content_descriptors.h"

enum {
kAndroidWebViewLocalePakDescriptor = kContentIPCDescriptorMax + 1,
kAndroidWebViewMainPakDescriptor,
};

#endif // ANDROID_WEBVIEW_COMMON_AW_DESCRIPTORS_H_
22 changes: 20 additions & 2 deletions android_webview/lib/main/aw_main_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "android_webview/browser/aw_content_browser_client.h"
#include "android_webview/browser/browser_view_renderer.h"
#include "android_webview/browser/scoped_allow_wait_for_legacy_web_view_api.h"
#include "android_webview/common/aw_descriptors.h"
#include "android_webview/common/aw_switches.h"
#include "android_webview/crash_reporter/aw_microdump_crash_reporter.h"
#include "android_webview/lib/aw_browser_dependency_factory_impl.h"
Expand Down Expand Up @@ -36,6 +37,7 @@
#include "gpu/command_buffer/client/gl_in_process_context.h"
#include "gpu/command_buffer/service/gpu_switches.h"
#include "media/base/media_switches.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/events/gesture_detection/gesture_configuration.h"

namespace android_webview {
Expand Down Expand Up @@ -138,14 +140,30 @@ bool AwMainDelegate::BasicStartupComplete(int* exit_code) {
}

void AwMainDelegate::PreSandboxStartup() {
// TODO(torne): When we have a separate renderer process, we need to handle
// being passed open FDs for the resource paks here.
#if defined(ARCH_CPU_ARM_FAMILY)
// Create an instance of the CPU class to parse /proc/cpuinfo and cache
// cpu_brand info.
base::CPU cpu_info;
#endif

const base::CommandLine& command_line =
*base::CommandLine::ForCurrentProcess();
std::string process_type =
command_line.GetSwitchValueASCII(switches::kProcessType);
if (process_type == switches::kRendererProcess) {
auto global_descriptors = base::GlobalDescriptors::GetInstance();
int pak_fd = global_descriptors->Get(kAndroidWebViewLocalePakDescriptor);
base::MemoryMappedFile::Region pak_region =
global_descriptors->GetRegion(kAndroidWebViewLocalePakDescriptor);
ResourceBundle::InitSharedInstanceWithPakFileRegion(base::File(pak_fd),
pak_region);
pak_fd = global_descriptors->Get(kAndroidWebViewMainPakDescriptor);
pak_region =
global_descriptors->GetRegion(kAndroidWebViewMainPakDescriptor);
ResourceBundle::GetSharedInstance().AddDataPackFromFileRegion(
base::File(pak_fd), pak_region, ui::SCALE_FACTOR_NONE);
}

crash_reporter::EnableMicrodumpCrashReporter();
}

Expand Down

0 comments on commit db95992

Please sign in to comment.