diff options
author | tkent@google.com <tkent@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-07 06:01:24 +0000 |
---|---|---|
committer | tkent@google.com <tkent@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-07 06:01:24 +0000 |
commit | ce80b5c9c1a1ecfa965c3e7a8f8381140047fcea (patch) | |
tree | aa10b2f3270c950685cef0d68c1114e692dcca5b /webkit | |
parent | 014e6c5d3be7410f2c3d827da6ddb9d70720317b (diff) | |
download | chromium_src-ce80b5c9c1a1ecfa965c3e7a8f8381140047fcea.zip chromium_src-ce80b5c9c1a1ecfa965c3e7a8f8381140047fcea.tar.gz chromium_src-ce80b5c9c1a1ecfa965c3e7a8f8381140047fcea.tar.bz2 |
Add resource loading and resource retrieval code for Mac.
This changes will fix dozens of LayoutTest failures.
The code in platform_support_mac.mm is almost identical with test_shell_mac.mm.
test_webview_delegate.cc:
Revert a part of r40610. Depending from test_shell to
webkit_support.cc makes a symbol conflict because webkit_support.cc
depends on platform_support_mac.mm and platform_support_mac.mm has
webkit_glue::GetLocalizedString() and webkit_glue::GetDataResource(),
which are defined in test_shell too.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/2002007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46661 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/support/platform_support_mac.mm | 107 | ||||
-rw-r--r-- | webkit/support/webkit_support.gypi | 3 | ||||
-rw-r--r-- | webkit/support/webkit_support_glue.cc | 3 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_webview_delegate.cc | 38 |
4 files changed, 148 insertions, 3 deletions
diff --git a/webkit/support/platform_support_mac.mm b/webkit/support/platform_support_mac.mm index c404342..0cfb758 100644 --- a/webkit/support/platform_support_mac.mm +++ b/webkit/support/platform_support_mac.mm @@ -7,9 +7,17 @@ #import <AppKit/AppKit.h> #import <Foundation/Foundation.h> +#include "base/data_pack.h" +#include "base/file_util.h" #include "base/logging.h" +#include "base/mac_util.h" +#include "base/path_service.h" +#include "base/string16.h" +#include "grit/webkit_resources.h" #include "third_party/WebKit/WebKit/mac/WebCoreSupport/WebSystemInterface.h" +static base::DataPack* g_resource_data_pack = NULL; + namespace webkit_support { static NSAutoreleasePool* autorelease_pool; @@ -22,6 +30,16 @@ void BeforeInitialize() { } void AfterIniitalize() { + // Load a data pack. + g_resource_data_pack = new base::DataPack; + NSString* resource_path = + [mac_util::MainAppBundle() pathForResource:@"DumpRenderTree" + ofType:@"pak"]; + FilePath resources_pak_path([resource_path fileSystemRepresentation]); + if (!g_resource_data_pack->Load(resources_pak_path)) { + LOG(FATAL) << "failed to load DumpRenderTree.pak"; + } + // Load font files in the resource folder. static const char* const fontFileNames[] = { "AHEM____.TTF", @@ -58,6 +76,95 @@ void BeforeShutdown() { void AfterShutdown() { [autorelease_pool drain]; + delete g_resource_data_pack; } } // namespace webkit_support + +namespace webkit_glue { + +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; + } + return string16(reinterpret_cast<const char16*>(res.data()), + res.length() / 2); +} + +// Helper method for getting the path to the test shell resources directory. +static FilePath GetResourcesFilePath() { + FilePath path; + // We assume the application is bundled. + if (!mac_util::AmIBundled()) { + LOG(FATAL) << "Failed to locate resources. The applicaiton is not bundled."; + } + PathService::Get(base::DIR_EXE, &path); + path = path.Append(FilePath::kParentDirectory); + return path.AppendASCII("Resources"); +} + +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.ToWStringHack(), + &broken_image_data); + if (!success) { + LOG(FATAL) << "Failed reading: " << path.value(); + } + } + return broken_image_data; + } + case IDR_FEED_PREVIEW: + // It is necessary to return a feed preview template that contains + // a {{URL}} substring where the feed URL should go; see the code + // that computes feed previews in feed_preview.cc:MakeFeedPreview. + // This fixes issue #932714. + return "Feed preview for {{URL}}"; + 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.ToWStringHack(), + &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: { + base::StringPiece res; + g_resource_data_pack->GetStringPiece(resource_id, &res); + return res; + } + + default: + break; + } + return base::StringPiece(); +} + +} // namespace webkit_glue diff --git a/webkit/support/webkit_support.gypi b/webkit/support/webkit_support.gypi index 40caa8e..ec34cda 100644 --- a/webkit/support/webkit_support.gypi +++ b/webkit/support/webkit_support.gypi @@ -17,6 +17,9 @@ 'database', 'glue', ], + 'include_dirs': [ + '<(SHARED_INTERMEDIATE_DIR)/webkit', # for a header generated by grit + ], 'sources': [ 'default_plugin_stubs_win.cc', 'platform_support.h', diff --git a/webkit/support/webkit_support_glue.cc b/webkit/support/webkit_support_glue.cc index 860583e..df0f7da 100644 --- a/webkit/support/webkit_support_glue.cc +++ b/webkit/support/webkit_support_glue.cc @@ -45,6 +45,8 @@ bool IsProtocolSupportedForMedia(const GURL& url) { return false; } +#if !defined(OS_MACOSX) +// These functions should be implemented in platform_support_*.cc string16 GetLocalizedString(int message_id) { // TODO(tkent): implement this. return string16(); @@ -54,6 +56,7 @@ base::StringPiece GetDataResource(int resource_id) { // TODO(tkent): implement this. return ""; } +#endif void CloseCurrentConnections() { } diff --git a/webkit/tools/test_shell/test_webview_delegate.cc b/webkit/tools/test_shell/test_webview_delegate.cc index 2cffc29..169412e 100644 --- a/webkit/tools/test_shell/test_webview_delegate.cc +++ b/webkit/tools/test_shell/test_webview_delegate.cc @@ -44,14 +44,18 @@ #include "third_party/WebKit/WebKit/chromium/public/WebWindowFeatures.h" #include "webkit/appcache/web_application_cache_host_impl.h" #include "webkit/glue/glue_serialize.h" +#include "webkit/glue/media/buffered_data_source.h" +#include "webkit/glue/media/media_resource_loader_bridge_factory.h" +#include "webkit/glue/media/simple_data_source.h" +#include "webkit/glue/media/video_renderer_impl.h" #include "webkit/glue/plugins/webplugin_impl.h" #include "webkit/glue/plugins/plugin_list.h" #include "webkit/glue/plugins/webplugin_delegate_impl.h" #include "webkit/glue/webdropdata.h" -#include "webkit/glue/webpreferences.h" #include "webkit/glue/webkit_glue.h" +#include "webkit/glue/webmediaplayer_impl.h" +#include "webkit/glue/webpreferences.h" #include "webkit/glue/window_open_disposition.h" -#include "webkit/support/webkit_support.h" #include "webkit/tools/test_shell/accessibility_controller.h" #include "webkit/tools/test_shell/mock_spellcheck.h" #include "webkit/tools/test_shell/notification_presenter.h" @@ -670,7 +674,35 @@ WebWorker* TestWebViewDelegate::createWorker( WebMediaPlayer* TestWebViewDelegate::createMediaPlayer( WebFrame* frame, WebMediaPlayerClient* client) { - return webkit_support::CreateMediaPlayer(frame, client); + scoped_refptr<media::FilterFactoryCollection> factory = + new media::FilterFactoryCollection(); + + appcache::WebApplicationCacheHostImpl* appcache_host = + appcache::WebApplicationCacheHostImpl::FromFrame(frame); + + // TODO(hclam): this is the same piece of code as in RenderView, maybe they + // should be grouped together. + webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory = + new webkit_glue::MediaResourceLoaderBridgeFactory( + GURL(), // referrer + "null", // frame origin + "null", // main_frame_origin + base::GetCurrentProcId(), + appcache_host ? appcache_host->host_id() : appcache::kNoHostId, + 0); + // A simple data source that keeps all data in memory. + media::FilterFactory* simple_data_source_factory = + webkit_glue::SimpleDataSource::CreateFactory(MessageLoop::current(), + bridge_factory); + // A sophisticated data source that does memory caching. + media::FilterFactory* buffered_data_source_factory = + webkit_glue::BufferedDataSource::CreateFactory(MessageLoop::current(), + bridge_factory); + factory->AddFactory(buffered_data_source_factory); + factory->AddFactory(simple_data_source_factory); + return new webkit_glue::WebMediaPlayerImpl( + client, factory, + new webkit_glue::VideoRendererImpl::FactoryFactory(false)); } WebApplicationCacheHost* TestWebViewDelegate::createApplicationCacheHost( |