Skip to content

Commit

Permalink
[iOS] Have showcase bundle web resources
Browse files Browse the repository at this point in the history
//ios/web, like //content, has a general assumption that it should be
able to get at its own internal resources via WebClient::GetDataResource().

This is currently not true among all //ios/web embedders, but an upcoming
CL will rely on this functionality. This CL adds bundling of iOS web
resources into Showcase and makes those resources available to //ios/web.

In an ideal world, it seems that Showcase wouldn't be an //ios/web embedder
at all, in which case these requirements would become irrelevant for
Showcase.

Bug: 731588
Change-Id: I19b2f9b103bfe5674ee3e2100cb40174cd30dc4c
Reviewed-on: https://chromium-review.googlesource.com/558063
Commit-Queue: Colin Blundell <blundell@chromium.org>
Reviewed-by: Mark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#484010}
  • Loading branch information
colinblundell authored and Commit Bot committed Jul 3, 2017
1 parent 3f61513 commit 24db7f8
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 2 deletions.
13 changes: 13 additions & 0 deletions ios/showcase/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import("//build/config/ios/rules.gni")
import("//ios/build/chrome_build.gni")
import("//ios/build/config.gni")
import("//ios/third_party/earl_grey/ios_eg_test.gni")
import("//tools/grit/repack.gni")

ios_app_bundle("showcase") {
info_plist = "core/Info.plist"
Expand Down Expand Up @@ -47,11 +48,23 @@ group("all_tests") {
]
}

repack("packed_resources") {
sources = [
"$root_gen_dir/ios/web/ios_web_resources.pak",
]
deps = [
"//ios/web:resources",
]
output = "$target_gen_dir/showcase_resources.pak"
copy_data_to_bundle = true
}

ios_eg_test("ios_showcase_egtests") {
info_plist = "core/Info.plist"
extra_substitutions = [ "IOS_BUNDLE_ID_PREFIX=$ios_app_bundle_id_prefix" ]
deps = [
":features",
":packed_resources",
"//ios/showcase/core:main",

# Add all eg_tests targets below.
Expand Down
1 change: 1 addition & 0 deletions ios/showcase/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ include_rules = [
"+ios/clean",
"+ios/third_party/material_components_ios",
"+ios/third_party/material_roboto_font_loader_ios",
"+ios/web/public",
"+ui/base",
]
5 changes: 5 additions & 0 deletions ios/showcase/core/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ source_set("core") {
"//ios/showcase/common",
"//ios/third_party/material_components_ios",
"//ios/third_party/material_roboto_font_loader_ios",

# TODO(crbug.com/738880): Showcase ideally shouldn't be an embedder of
# //ios/web.
"//ios/web",
"//ios/web/public/app",
"//ui/base",
]
libs = [ "UIKit.framework" ]
Expand Down
46 changes: 44 additions & 2 deletions ios/showcase/core/app_delegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
#import "ios/showcase/core/app_delegate.h"

#include "base/memory/ptr_util.h"
#include "base/path_service.h"
#include "ios/chrome/app/startup/ios_chrome_main.h"
#import "ios/showcase/core/showcase_model.h"
#import "ios/showcase/core/showcase_view_controller.h"
#import "ios/third_party/material_components_ios/src/components/Typography/src/MaterialTypography.h"
#import "ios/web/public/app/web_main_parts.h"
#import "ios/web/public/web_client.h"
#include "ui/base/resource/resource_bundle.h"

#if !defined(__has_feature) || !__has_feature(objc_arc)
Expand All @@ -18,6 +21,42 @@
@implementation AppDelegate
@synthesize window = _window;

namespace {

class ShowcaseWebMainParts : public web::WebMainParts {
void PreMainMessageLoopStart() override {
ResourceBundle::InitSharedInstanceWithLocale(
std::string(), nullptr, ResourceBundle::LOAD_COMMON_RESOURCES);

base::FilePath pak_path;
PathService::Get(base::DIR_MODULE, &pak_path);
ResourceBundle::GetSharedInstance().AddDataPackFromPath(
pak_path.AppendASCII("showcase_resources.pak"), ui::SCALE_FACTOR_100P);
}
};

class ShowcaseWebClient : public web::WebClient {
public:
ShowcaseWebClient() {}
~ShowcaseWebClient() override {}

// WebClient implementation.
std::unique_ptr<web::WebMainParts> CreateWebMainParts() override {
return base::MakeUnique<ShowcaseWebMainParts>();
}
base::StringPiece GetDataResource(
int resource_id,
ui::ScaleFactor scale_factor) const override {
return ResourceBundle::GetSharedInstance().GetRawDataResourceForScale(
resource_id, scale_factor);
}
base::RefCountedMemory* GetDataResourceBytes(int resource_id) const override {
return ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
resource_id);
}
};
}

- (void)setupUI {
ShowcaseViewController* viewController =
[[ShowcaseViewController alloc] initWithRows:[AppDelegate rowsToDisplay]];
Expand All @@ -30,9 +69,12 @@ - (void)setupUI {

- (BOOL)application:(UIApplication*)application
didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
// TODO(crbug.com/738880): Showcase ideally shouldn't be an embedder of
// //ios/web, in which case it wouldn't have to do this. This almost
// certainly means not creating IOSChromeMain.
web::SetWebClient(new ShowcaseWebClient());
base::MakeUnique<IOSChromeMain>();
ResourceBundle::InitSharedInstanceWithLocale(
std::string(), nullptr, ResourceBundle::LOAD_COMMON_RESOURCES);

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self setupUI];
[self.window makeKeyAndVisible];
Expand Down

0 comments on commit 24db7f8

Please sign in to comment.