OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/renderer/render_view.h" | 5 #include "chrome/renderer/render_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 #include "chrome/renderer/webplugin_delegate_proxy.h" | 60 #include "chrome/renderer/webplugin_delegate_proxy.h" |
61 #include "chrome/renderer/websharedworker_proxy.h" | 61 #include "chrome/renderer/websharedworker_proxy.h" |
62 #include "chrome/renderer/webworker_proxy.h" | 62 #include "chrome/renderer/webworker_proxy.h" |
63 #include "grit/generated_resources.h" | 63 #include "grit/generated_resources.h" |
64 #include "grit/renderer_resources.h" | 64 #include "grit/renderer_resources.h" |
65 #include "net/base/data_url.h" | 65 #include "net/base/data_url.h" |
66 #include "net/base/escape.h" | 66 #include "net/base/escape.h" |
67 #include "net/base/net_errors.h" | 67 #include "net/base/net_errors.h" |
68 #include "skia/ext/bitmap_platform_device.h" | 68 #include "skia/ext/bitmap_platform_device.h" |
69 #include "skia/ext/image_operations.h" | 69 #include "skia/ext/image_operations.h" |
| 70 #if defined(OS_WIN) |
| 71 // TODO(port): The compact language detection library works only for Windows. |
70 #include "third_party/cld/bar/toolbar/cld/i18n/encodings/compact_lang_det/win/cl
d_unicodetext.h" | 72 #include "third_party/cld/bar/toolbar/cld/i18n/encodings/compact_lang_det/win/cl
d_unicodetext.h" |
| 73 #endif |
71 #include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityCache.h" | 74 #include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityCache.h" |
72 #include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityObject.h" | 75 #include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityObject.h" |
73 #include "third_party/WebKit/WebKit/chromium/public/WebCString.h" | 76 #include "third_party/WebKit/WebKit/chromium/public/WebCString.h" |
74 #include "third_party/WebKit/WebKit/chromium/public/WebDataSource.h" | 77 #include "third_party/WebKit/WebKit/chromium/public/WebDataSource.h" |
75 #include "third_party/WebKit/WebKit/chromium/public/WebDevToolsAgent.h" | 78 #include "third_party/WebKit/WebKit/chromium/public/WebDevToolsAgent.h" |
76 #include "third_party/WebKit/WebKit/chromium/public/WebDocument.h" | 79 #include "third_party/WebKit/WebKit/chromium/public/WebDocument.h" |
77 #include "third_party/WebKit/WebKit/chromium/public/WebDragData.h" | 80 #include "third_party/WebKit/WebKit/chromium/public/WebDragData.h" |
78 #include "third_party/WebKit/WebKit/chromium/public/WebFileChooserParams.h" | 81 #include "third_party/WebKit/WebKit/chromium/public/WebFileChooserParams.h" |
79 #include "third_party/WebKit/WebKit/chromium/public/WebFormElement.h" | 82 #include "third_party/WebKit/WebKit/chromium/public/WebFormElement.h" |
80 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" | 83 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 | 216 |
214 // The maximum number of popups that can be spawned from one page. | 217 // The maximum number of popups that can be spawned from one page. |
215 static const int kMaximumNumberOfUnacknowledgedPopups = 25; | 218 static const int kMaximumNumberOfUnacknowledgedPopups = 25; |
216 | 219 |
217 static const char* const kUnreachableWebDataURL = | 220 static const char* const kUnreachableWebDataURL = |
218 "chrome://chromewebdata/"; | 221 "chrome://chromewebdata/"; |
219 | 222 |
220 static const char* const kBackForwardNavigationScheme = "history"; | 223 static const char* const kBackForwardNavigationScheme = "history"; |
221 | 224 |
222 // The string returned in DetectLanguage if we failed to detect the language. | 225 // The string returned in DetectLanguage if we failed to detect the language. |
223 static const char* const kUnknownLanguageCode = "und"; | 226 static const char* const kUnknownLanguageCode = "unknown"; |
224 | 227 |
225 static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) { | 228 static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) { |
226 WebVector<WebURL> urls; | 229 WebVector<WebURL> urls; |
227 ds->redirectChain(urls); | 230 ds->redirectChain(urls); |
228 result->reserve(urls.size()); | 231 result->reserve(urls.size()); |
229 for (size_t i = 0; i < urls.size(); ++i) | 232 for (size_t i = 0; i < urls.size(); ++i) |
230 result->push_back(urls[i]); | 233 result->push_back(urls[i]); |
231 } | 234 } |
232 | 235 |
233 static bool UrlMatchesPermissions( | 236 static bool UrlMatchesPermissions( |
(...skipping 2838 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3072 return; | 3075 return; |
3073 } | 3076 } |
3074 | 3077 |
3075 Send(new ViewHostMsg_PageLanguageDetermined(routing_id_, DetectLanguage())); | 3078 Send(new ViewHostMsg_PageLanguageDetermined(routing_id_, DetectLanguage())); |
3076 } | 3079 } |
3077 | 3080 |
3078 std::string RenderView::DetectLanguage() { | 3081 std::string RenderView::DetectLanguage() { |
3079 if (!webview() || is_loading_) | 3082 if (!webview() || is_loading_) |
3080 return kUnknownLanguageCode; | 3083 return kUnknownLanguageCode; |
3081 | 3084 |
| 3085 std::string language = kUnknownLanguageCode; |
| 3086 #if defined(OS_WIN) // CLD is only available on Windows at this time. |
3082 WebFrame* main_frame = webview()->mainFrame(); | 3087 WebFrame* main_frame = webview()->mainFrame(); |
3083 std::wstring contents; | 3088 std::wstring contents; |
3084 CaptureText(main_frame, &contents); | 3089 CaptureText(main_frame, &contents); |
3085 return DetermineTextLanguage(contents); | 3090 language = DetermineTextLanguage(contents); |
| 3091 #endif |
| 3092 |
| 3093 return language; |
3086 } | 3094 } |
3087 | 3095 |
3088 // static | 3096 // static |
3089 std::string RenderView::DetermineTextLanguage(const std::wstring& text) { | 3097 std::string RenderView::DetermineTextLanguage(const std::wstring& text) { |
3090 std::string language = kUnknownLanguageCode; | 3098 std::string language = kUnknownLanguageCode; |
| 3099 #if defined(OS_WIN) // CLD is only available on Windows at this time. |
3091 int num_languages = 0; | 3100 int num_languages = 0; |
3092 bool is_reliable = false; | 3101 bool is_reliable = false; |
3093 string16 input = WideToUTF16(text); | |
3094 Language cld_language = | 3102 Language cld_language = |
3095 DetectLanguageOfUnicodeText(NULL, input.c_str(), true, &is_reliable, | 3103 DetectLanguageOfUnicodeText(NULL, text.c_str(), true, &is_reliable, |
3096 &num_languages, NULL); | 3104 &num_languages, NULL); |
3097 if (cld_language != NUM_LANGUAGES && cld_language != UNKNOWN_LANGUAGE && | 3105 if (cld_language != NUM_LANGUAGES && cld_language != UNKNOWN_LANGUAGE && |
3098 cld_language != TG_UNKNOWN_LANGUAGE) { | 3106 cld_language != TG_UNKNOWN_LANGUAGE) { |
3099 // We should not use LanguageCode_ISO_639_1 because it does not cover all th
e | 3107 language = LanguageCodeISO639_1(cld_language); |
3100 // languages CLD can detect. As a result, it'll return the invalid language | |
3101 // code for tradtional Chinese among others. |LanguageCode| will go through | |
3102 // ISO 639-1, ISO-639-2 and 'other' tables to do the 'right' thing. | |
3103 language = LanguageCode(cld_language); | |
3104 } | 3108 } |
| 3109 #endif |
3105 return language; | 3110 return language; |
3106 } | 3111 } |
3107 | 3112 |
3108 void RenderView::DnsPrefetch(const std::vector<std::string>& host_names) { | 3113 void RenderView::DnsPrefetch(const std::vector<std::string>& host_names) { |
3109 Send(new ViewHostMsg_DnsPrefetch(host_names)); | 3114 Send(new ViewHostMsg_DnsPrefetch(host_names)); |
3110 } | 3115 } |
3111 | 3116 |
3112 void RenderView::OnZoom(PageZoom::Function function) { | 3117 void RenderView::OnZoom(PageZoom::Function function) { |
3113 if (!webview()) // Not sure if this can happen, but no harm in being safe. | 3118 if (!webview()) // Not sure if this can happen, but no harm in being safe. |
3114 return; | 3119 return; |
(...skipping 929 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4044 new PluginMsg_SignalModalDialogEvent(host_window_)); | 4049 new PluginMsg_SignalModalDialogEvent(host_window_)); |
4045 | 4050 |
4046 message->EnableMessagePumping(); // Runs a nested message loop. | 4051 message->EnableMessagePumping(); // Runs a nested message loop. |
4047 bool rv = Send(message); | 4052 bool rv = Send(message); |
4048 | 4053 |
4049 PluginChannelHost::Broadcast( | 4054 PluginChannelHost::Broadcast( |
4050 new PluginMsg_ResetModalDialogEvent(host_window_)); | 4055 new PluginMsg_ResetModalDialogEvent(host_window_)); |
4051 | 4056 |
4052 return rv; | 4057 return rv; |
4053 } | 4058 } |
OLD | NEW |