| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "webkit/tools/test_shell/test_shell.h" | 5 #include "webkit/tools/test_shell/test_shell.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <commdlg.h> | 8 #include <commdlg.h> |
| 9 #include <objbase.h> | 9 #include <objbase.h> |
| 10 #include <process.h> | 10 #include <process.h> |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 // Helper method for getting the path to the test shell resources directory. | 119 // Helper method for getting the path to the test shell resources directory. |
| 120 FilePath GetResourcesFilePath() { | 120 FilePath GetResourcesFilePath() { |
| 121 FilePath path; | 121 FilePath path; |
| 122 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 122 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
| 123 path = path.AppendASCII("webkit"); | 123 path = path.AppendASCII("webkit"); |
| 124 path = path.AppendASCII("tools"); | 124 path = path.AppendASCII("tools"); |
| 125 path = path.AppendASCII("test_shell"); | 125 path = path.AppendASCII("test_shell"); |
| 126 return path.AppendASCII("resources"); | 126 return path.AppendASCII("resources"); |
| 127 } | 127 } |
| 128 | 128 |
| 129 static StringPiece GetRawDataResource(HMODULE module, int resource_id) { | 129 static base::StringPiece GetRawDataResource(HMODULE module, int resource_id) { |
| 130 void* data_ptr; | 130 void* data_ptr; |
| 131 size_t data_size; | 131 size_t data_size; |
| 132 return base::GetDataResourceFromModule(module, resource_id, &data_ptr, | 132 return base::GetDataResourceFromModule(module, resource_id, &data_ptr, |
| 133 &data_size) ? | 133 &data_size) |
| 134 StringPiece(static_cast<char*>(data_ptr), data_size) : StringPiece(); | 134 ? base::StringPiece(static_cast<char*>(data_ptr), data_size) |
| 135 : base::StringPiece(); |
| 135 } | 136 } |
| 136 | 137 |
| 137 // This is called indirectly by the network layer to access resources. | 138 // This is called indirectly by the network layer to access resources. |
| 138 StringPiece NetResourceProvider(int key) { | 139 base::StringPiece NetResourceProvider(int key) { |
| 139 return GetRawDataResource(::GetModuleHandle(NULL), key); | 140 return GetRawDataResource(::GetModuleHandle(NULL), key); |
| 140 } | 141 } |
| 141 | 142 |
| 142 } // namespace | 143 } // namespace |
| 143 | 144 |
| 144 // Initialize static member variable | 145 // Initialize static member variable |
| 145 HINSTANCE TestShell::instance_handle_; | 146 HINSTANCE TestShell::instance_handle_; |
| 146 | 147 |
| 147 ///////////////////////////////////////////////////////////////////////////// | 148 ///////////////////////////////////////////////////////////////////////////// |
| 148 // static methods on TestShell | 149 // static methods on TestShell |
| (...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 648 result->assign(info.lpstrFile); | 649 result->assign(info.lpstrFile); |
| 649 return true; | 650 return true; |
| 650 } | 651 } |
| 651 | 652 |
| 652 // static | 653 // static |
| 653 void TestShell::ShowStartupDebuggingDialog() { | 654 void TestShell::ShowStartupDebuggingDialog() { |
| 654 MessageBox(NULL, L"attach to me?", L"test_shell", MB_OK); | 655 MessageBox(NULL, L"attach to me?", L"test_shell", MB_OK); |
| 655 } | 656 } |
| 656 | 657 |
| 657 // static | 658 // static |
| 658 StringPiece TestShell::NetResourceProvider(int key) { | 659 base::StringPiece TestShell::NetResourceProvider(int key) { |
| 659 return GetRawDataResource(::GetModuleHandle(NULL), key); | 660 return GetRawDataResource(::GetModuleHandle(NULL), key); |
| 660 } | 661 } |
| 661 | 662 |
| 662 | 663 |
| 663 ///////////////////////////////////////////////////////////////////////////// | 664 ///////////////////////////////////////////////////////////////////////////// |
| 664 // WebKit glue functions | 665 // WebKit glue functions |
| 665 | 666 |
| 666 namespace webkit_glue { | 667 namespace webkit_glue { |
| 667 | 668 |
| 668 string16 GetLocalizedString(int message_id) { | 669 string16 GetLocalizedString(int message_id) { |
| 669 wchar_t localized[MAX_LOADSTRING]; | 670 wchar_t localized[MAX_LOADSTRING]; |
| 670 int length = LoadString(GetModuleHandle(NULL), message_id, | 671 int length = LoadString(GetModuleHandle(NULL), message_id, |
| 671 localized, MAX_LOADSTRING); | 672 localized, MAX_LOADSTRING); |
| 672 if (!length && GetLastError() == ERROR_RESOURCE_NAME_NOT_FOUND) { | 673 if (!length && GetLastError() == ERROR_RESOURCE_NAME_NOT_FOUND) { |
| 673 NOTREACHED(); | 674 NOTREACHED(); |
| 674 return L"No string for this identifier!"; | 675 return L"No string for this identifier!"; |
| 675 } | 676 } |
| 676 return string16(localized, length); | 677 return string16(localized, length); |
| 677 } | 678 } |
| 678 | 679 |
| 679 // TODO(tc): Convert this to using resources from test_shell.rc. | 680 // TODO(tc): Convert this to using resources from test_shell.rc. |
| 680 StringPiece GetDataResource(int resource_id) { | 681 base::StringPiece GetDataResource(int resource_id) { |
| 681 switch (resource_id) { | 682 switch (resource_id) { |
| 682 case IDR_BROKENIMAGE: { | 683 case IDR_BROKENIMAGE: { |
| 683 // Use webkit's broken image icon (16x16) | 684 // Use webkit's broken image icon (16x16) |
| 684 static std::string broken_image_data; | 685 static std::string broken_image_data; |
| 685 if (broken_image_data.empty()) { | 686 if (broken_image_data.empty()) { |
| 686 FilePath path = GetResourcesFilePath(); | 687 FilePath path = GetResourcesFilePath(); |
| 687 path = path.AppendASCII("missingImage.gif"); | 688 path = path.AppendASCII("missingImage.gif"); |
| 688 bool success = file_util::ReadFileToString(path, &broken_image_data); | 689 bool success = file_util::ReadFileToString(path, &broken_image_data); |
| 689 if (!success) { | 690 if (!success) { |
| 690 LOG(FATAL) << "Failed reading: " << path.value(); | 691 LOG(FATAL) << "Failed reading: " << path.value(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 723 case IDR_MEDIA_SOUND_NONE_BUTTON: | 724 case IDR_MEDIA_SOUND_NONE_BUTTON: |
| 724 case IDR_MEDIA_SOUND_DISABLED: | 725 case IDR_MEDIA_SOUND_DISABLED: |
| 725 case IDR_MEDIA_SLIDER_THUMB: | 726 case IDR_MEDIA_SLIDER_THUMB: |
| 726 case IDR_MEDIA_VOLUME_SLIDER_THUMB: | 727 case IDR_MEDIA_VOLUME_SLIDER_THUMB: |
| 727 return NetResourceProvider(resource_id); | 728 return NetResourceProvider(resource_id); |
| 728 | 729 |
| 729 default: | 730 default: |
| 730 break; | 731 break; |
| 731 } | 732 } |
| 732 | 733 |
| 733 return StringPiece(); | 734 return base::StringPiece(); |
| 734 } | 735 } |
| 735 | 736 |
| 736 HCURSOR LoadCursor(int cursor_id) { | 737 HCURSOR LoadCursor(int cursor_id) { |
| 737 return NULL; | 738 return NULL; |
| 738 } | 739 } |
| 739 | 740 |
| 740 void GetPlugins(bool refresh, std::vector<WebPluginInfo>* plugins) { | 741 void GetPlugins(bool refresh, std::vector<WebPluginInfo>* plugins) { |
| 741 NPAPI::PluginList::Singleton()->GetPlugins(refresh, plugins); | 742 NPAPI::PluginList::Singleton()->GetPlugins(refresh, plugins); |
| 742 } | 743 } |
| 743 | 744 |
| 744 bool EnsureFontLoaded(HFONT font) { | 745 bool EnsureFontLoaded(HFONT font) { |
| 745 return true; | 746 return true; |
| 746 } | 747 } |
| 747 | 748 |
| 748 bool DownloadUrl(const std::string& url, HWND caller_window) { | 749 bool DownloadUrl(const std::string& url, HWND caller_window) { |
| 749 return false; | 750 return false; |
| 750 } | 751 } |
| 751 | 752 |
| 752 } // namespace webkit_glue | 753 } // namespace webkit_glue |
| OLD | NEW |