2010-10-23 19:00:47 +02:00
|
|
|
// Copyright (c) 2010 The Chromium Embedded Framework Authors.
|
|
|
|
// Portions copyright (c) 2006-2008 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.
|
|
|
|
|
|
|
|
#include "base/compiler_specific.h"
|
|
|
|
|
2011-01-27 00:54:54 +01:00
|
|
|
#include "third_party/WebKit/Source/WebCore/config.h"
|
2010-10-23 19:00:47 +02:00
|
|
|
|
|
|
|
#include "browser_webkit_glue.h"
|
|
|
|
|
|
|
|
#undef LOG
|
|
|
|
#include "base/file_util.h"
|
|
|
|
#include "base/logging.h"
|
2011-01-07 22:34:20 +01:00
|
|
|
#include "base/mac/mac_util.h"
|
2010-10-23 19:00:47 +02:00
|
|
|
#include "base/path_service.h"
|
2011-09-23 02:16:03 +02:00
|
|
|
#include "base/utf_string_conversions.h"
|
2010-10-23 19:00:47 +02:00
|
|
|
#include "grit/webkit_resources.h"
|
2011-02-15 19:07:24 +01:00
|
|
|
#include "ui/base/resource/data_pack.h"
|
2010-10-23 19:00:47 +02:00
|
|
|
#include "webkit/glue/webkit_glue.h"
|
|
|
|
|
|
|
|
namespace webkit_glue {
|
|
|
|
|
|
|
|
// Data pack resource. This is a pointer to the mmapped resources file.
|
2011-02-15 19:07:24 +01:00
|
|
|
static ui::DataPack* g_resource_data_pack = NULL;
|
2010-10-23 19:00:47 +02:00
|
|
|
|
2010-11-15 16:39:56 +01:00
|
|
|
void InitializeDataPak() {
|
|
|
|
// mmap the data pack which holds strings used by WebCore.
|
|
|
|
// TODO(port): Allow the embedder to customize the pak name.
|
2011-02-15 19:07:24 +01:00
|
|
|
g_resource_data_pack = new ui::DataPack;
|
2010-11-15 16:39:56 +01:00
|
|
|
NSString *resource_path =
|
2011-01-07 22:34:20 +01:00
|
|
|
[base::mac::MainAppBundle() pathForResource:@"cefclient" ofType:@"pak"];
|
2010-11-15 16:39:56 +01:00
|
|
|
FilePath resources_pak_path([resource_path fileSystemRepresentation]);
|
|
|
|
if (!g_resource_data_pack->Load(resources_pak_path))
|
|
|
|
LOG(FATAL) << "failed to load cefclient.pak";
|
|
|
|
}
|
|
|
|
|
2010-10-23 19:00:47 +02:00
|
|
|
// Helper method for getting the path to the CEF resources directory.
|
|
|
|
FilePath GetResourcesFilePath() {
|
|
|
|
FilePath path;
|
|
|
|
// We need to know if we're bundled or not to know which path to use.
|
2011-01-07 22:34:20 +01:00
|
|
|
if (base::mac::AmIBundled()) {
|
2010-10-23 19:00:47 +02:00
|
|
|
PathService::Get(base::DIR_EXE, &path);
|
|
|
|
path = path.Append(FilePath::kParentDirectory);
|
|
|
|
return path.AppendASCII("Resources");
|
|
|
|
} else {
|
2010-11-15 16:39:56 +01:00
|
|
|
// TODO(port): Allow the embedder to customize the resource path.
|
2010-10-23 19:00:47 +02:00
|
|
|
PathService::Get(base::DIR_SOURCE_ROOT, &path);
|
|
|
|
path = path.AppendASCII("src");
|
|
|
|
path = path.AppendASCII("cef");
|
2010-11-15 16:39:56 +01:00
|
|
|
path = path.AppendASCII("tests");
|
|
|
|
path = path.AppendASCII("cefclient");
|
|
|
|
return path.AppendASCII("res");
|
2010-10-23 19:00:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
string16 GetLocalizedString(int message_id) {
|
|
|
|
base::StringPiece res;
|
|
|
|
if (!g_resource_data_pack->GetStringPiece(message_id, &res)) {
|
|
|
|
LOG(FATAL) << "failed to load webkit string with id " << message_id;
|
|
|
|
}
|
2011-09-23 02:16:03 +02:00
|
|
|
|
2011-09-23 02:30:54 +02:00
|
|
|
// Data packs hold strings as either UTF8 or UTF16.
|
|
|
|
string16 msg;
|
|
|
|
switch (g_resource_data_pack->GetTextEncodingType()) {
|
|
|
|
case ui::DataPack::UTF8:
|
|
|
|
msg = UTF8ToUTF16(res);
|
|
|
|
break;
|
|
|
|
case ui::DataPack::UTF16:
|
|
|
|
msg = string16(reinterpret_cast<const char16*>(res.data()),
|
|
|
|
res.length() / 2);
|
|
|
|
break;
|
|
|
|
case ui::DataPack::BINARY:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return msg;
|
2010-10-23 19:00:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
base::StringPiece NetResourceProvider(int key) {
|
|
|
|
base::StringPiece res;
|
|
|
|
g_resource_data_pack->GetStringPiece(key, &res);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
base::StringPiece GetDataResource(int resource_id) {
|
|
|
|
switch (resource_id) {
|
|
|
|
case IDR_BROKENIMAGE: {
|
|
|
|
// Use webkit's broken image icon (16x16)
|
|
|
|
static std::string broken_image_data;
|
|
|
|
if (broken_image_data.empty()) {
|
|
|
|
FilePath path = GetResourcesFilePath();
|
|
|
|
// In order to match WebKit's colors for the missing image, we have to
|
|
|
|
// use a PNG. The GIF doesn't have the color range needed to correctly
|
|
|
|
// match the TIFF they use in Safari.
|
|
|
|
path = path.AppendASCII("missingImage.png");
|
|
|
|
bool success = file_util::ReadFileToString(path, &broken_image_data);
|
|
|
|
if (!success) {
|
|
|
|
LOG(FATAL) << "Failed reading: " << path.value();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return broken_image_data;
|
|
|
|
}
|
|
|
|
case IDR_TEXTAREA_RESIZER: {
|
|
|
|
// Use webkit's text area resizer image.
|
|
|
|
static std::string resize_corner_data;
|
|
|
|
if (resize_corner_data.empty()) {
|
|
|
|
FilePath path = GetResourcesFilePath();
|
|
|
|
path = path.AppendASCII("textAreaResizeCorner.png");
|
|
|
|
bool success = file_util::ReadFileToString(path, &resize_corner_data);
|
|
|
|
if (!success) {
|
|
|
|
LOG(FATAL) << "Failed reading: " << path.value();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return resize_corner_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
case IDR_SEARCH_CANCEL:
|
|
|
|
case IDR_SEARCH_CANCEL_PRESSED:
|
|
|
|
case IDR_SEARCH_MAGNIFIER:
|
|
|
|
case IDR_SEARCH_MAGNIFIER_RESULTS:
|
|
|
|
case IDR_MEDIA_PAUSE_BUTTON:
|
|
|
|
case IDR_MEDIA_PLAY_BUTTON:
|
|
|
|
case IDR_MEDIA_PLAY_BUTTON_DISABLED:
|
|
|
|
case IDR_MEDIA_SOUND_FULL_BUTTON:
|
|
|
|
case IDR_MEDIA_SOUND_NONE_BUTTON:
|
|
|
|
case IDR_MEDIA_SOUND_DISABLED:
|
|
|
|
case IDR_MEDIA_SLIDER_THUMB:
|
|
|
|
case IDR_MEDIA_VOLUME_SLIDER_THUMB:
|
|
|
|
case IDR_INPUT_SPEECH:
|
|
|
|
case IDR_INPUT_SPEECH_RECORDING:
|
|
|
|
case IDR_INPUT_SPEECH_WAITING:
|
|
|
|
return NetResourceProvider(resource_id);
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return base::StringPiece();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DidLoadPlugin(const std::string& filename) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void DidUnloadPlugin(const std::string& filename) {
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace webkit_glue
|