OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/chrome_render_view_observer.h" | 5 #include "chrome/renderer/chrome_render_view_observer.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 TranslateHelper* translate_helper) | 223 TranslateHelper* translate_helper) |
224 : content::RenderViewObserver(render_view), | 224 : content::RenderViewObserver(render_view), |
225 chrome_render_process_observer_(chrome_render_process_observer), | 225 chrome_render_process_observer_(chrome_render_process_observer), |
226 extension_dispatcher_(extension_dispatcher), | 226 extension_dispatcher_(extension_dispatcher), |
227 content_settings_(content_settings), | 227 content_settings_(content_settings), |
228 translate_helper_(translate_helper), | 228 translate_helper_(translate_helper), |
229 phishing_classifier_(NULL), | 229 phishing_classifier_(NULL), |
230 last_indexed_page_id_(-1), | 230 last_indexed_page_id_(-1), |
231 allow_displaying_insecure_content_(false), | 231 allow_displaying_insecure_content_(false), |
232 allow_running_insecure_content_(false), | 232 allow_running_insecure_content_(false), |
| 233 garbled_text_detection_enabled_(false), |
233 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | 234 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
234 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 235 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
235 if (command_line.HasSwitch(switches::kDomAutomationController)) { | 236 if (command_line.HasSwitch(switches::kDomAutomationController)) { |
236 int old_bindings = render_view->GetEnabledBindings(); | 237 int old_bindings = render_view->GetEnabledBindings(); |
237 render_view->SetEnabledBindings( | 238 render_view->SetEnabledBindings( |
238 old_bindings |= content::BINDINGS_POLICY_DOM_AUTOMATION); | 239 old_bindings |= content::BINDINGS_POLICY_DOM_AUTOMATION); |
239 } | 240 } |
240 render_view->GetWebView()->setPermissionClient(this); | 241 render_view->GetWebView()->setPermissionClient(this); |
241 if (!command_line.HasSwitch(switches::kDisableClientSidePhishingDetection)) | 242 if (!command_line.HasSwitch(switches::kDisableClientSidePhishingDetection)) |
242 OnSetClientSidePhishingDetection(true); | 243 OnSetClientSidePhishingDetection(true); |
(...skipping 20 matching lines...) Expand all Loading... |
263 OnSetClientSidePhishingDetection) | 264 OnSetClientSidePhishingDetection) |
264 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetVisuallyDeemphasized, | 265 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetVisuallyDeemphasized, |
265 OnSetVisuallyDeemphasized) | 266 OnSetVisuallyDeemphasized) |
266 #if defined(OS_CHROMEOS) | 267 #if defined(OS_CHROMEOS) |
267 IPC_MESSAGE_HANDLER(ChromeViewMsg_StartFrameSniffer, OnStartFrameSniffer) | 268 IPC_MESSAGE_HANDLER(ChromeViewMsg_StartFrameSniffer, OnStartFrameSniffer) |
268 #endif | 269 #endif |
269 IPC_MESSAGE_HANDLER(ChromeViewMsg_GetFPS, OnGetFPS) | 270 IPC_MESSAGE_HANDLER(ChromeViewMsg_GetFPS, OnGetFPS) |
270 IPC_MESSAGE_HANDLER(ChromeViewMsg_AddStrictSecurityHost, | 271 IPC_MESSAGE_HANDLER(ChromeViewMsg_AddStrictSecurityHost, |
271 OnAddStrictSecurityHost) | 272 OnAddStrictSecurityHost) |
272 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAsInterstitial, OnSetAsInterstitial) | 273 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAsInterstitial, OnSetAsInterstitial) |
| 274 IPC_MESSAGE_HANDLER(ChromeViewMsg_ReloadFromCache, OnReloadFromCache) |
| 275 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetGarbledTextDetectionEnableState, |
| 276 OnSetGarbledTextDetectionEnableState) |
273 IPC_MESSAGE_UNHANDLED(handled = false) | 277 IPC_MESSAGE_UNHANDLED(handled = false) |
274 IPC_END_MESSAGE_MAP() | 278 IPC_END_MESSAGE_MAP() |
275 | 279 |
276 // Filter only. | 280 // Filter only. |
277 IPC_BEGIN_MESSAGE_MAP(ChromeRenderViewObserver, message) | 281 IPC_BEGIN_MESSAGE_MAP(ChromeRenderViewObserver, message) |
278 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetIsPrerendering, OnSetIsPrerendering); | 282 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetIsPrerendering, OnSetIsPrerendering); |
279 IPC_END_MESSAGE_MAP() | 283 IPC_END_MESSAGE_MAP() |
280 | 284 |
281 return handled; | 285 return handled; |
282 } | 286 } |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 | 368 |
365 void ChromeRenderViewObserver::OnAddStrictSecurityHost( | 369 void ChromeRenderViewObserver::OnAddStrictSecurityHost( |
366 const std::string& host) { | 370 const std::string& host) { |
367 strict_security_hosts_.insert(host); | 371 strict_security_hosts_.insert(host); |
368 } | 372 } |
369 | 373 |
370 void ChromeRenderViewObserver::OnSetAsInterstitial() { | 374 void ChromeRenderViewObserver::OnSetAsInterstitial() { |
371 content_settings_->SetAsInterstitial(); | 375 content_settings_->SetAsInterstitial(); |
372 } | 376 } |
373 | 377 |
| 378 void ChromeRenderViewObserver::OnReloadFromCache() { |
| 379 WebFrame* main_frame = render_view()->GetWebView()->mainFrame(); |
| 380 if (main_frame) |
| 381 main_frame->reloadFromCache(); |
| 382 } |
| 383 |
| 384 void ChromeRenderViewObserver::OnSetGarbledTextDetectionEnableState( |
| 385 bool enabled) { |
| 386 garbled_text_detection_enabled_ = enabled; |
| 387 } |
| 388 |
374 void ChromeRenderViewObserver::Navigate(const GURL& url) { | 389 void ChromeRenderViewObserver::Navigate(const GURL& url) { |
375 // Execute cache clear operations that were postponed until a navigation | 390 // Execute cache clear operations that were postponed until a navigation |
376 // event (including tab reload). | 391 // event (including tab reload). |
377 if (chrome_render_process_observer_) | 392 if (chrome_render_process_observer_) |
378 chrome_render_process_observer_->ExecutePendingClearCache(); | 393 chrome_render_process_observer_->ExecutePendingClearCache(); |
379 AboutHandler::MaybeHandle(url); | 394 AboutHandler::MaybeHandle(url); |
380 } | 395 } |
381 | 396 |
382 void ChromeRenderViewObserver::OnSetClientSidePhishingDetection( | 397 void ChromeRenderViewObserver::OnSetClientSidePhishingDetection( |
383 bool enable_phishing_detection) { | 398 bool enable_phishing_detection) { |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
803 last_indexed_page_id_ = load_id; | 818 last_indexed_page_id_ = load_id; |
804 | 819 |
805 // Get the URL for this page. | 820 // Get the URL for this page. |
806 GURL url(main_frame->document().url()); | 821 GURL url(main_frame->document().url()); |
807 if (url.is_empty()) { | 822 if (url.is_empty()) { |
808 if (!preliminary_capture) | 823 if (!preliminary_capture) |
809 last_indexed_url_ = GURL(); | 824 last_indexed_url_ = GURL(); |
810 return; | 825 return; |
811 } | 826 } |
812 | 827 |
| 828 if (garbled_text_detection_enabled_) { |
| 829 std::vector<GURL> garbled_urls; |
| 830 for (WebKit::WebFrame* frame = render_view()->GetWebView()->mainFrame(); |
| 831 frame; frame = frame->traverseNext(false)) { |
| 832 if (frame->document().shouldUseEncodingDetector()) |
| 833 garbled_urls.push_back(frame->document().url()); |
| 834 } |
| 835 |
| 836 if (!garbled_urls.empty()) { |
| 837 Send(new ChromeViewHostMsg_GarbledTextDetected( |
| 838 routing_id(), garbled_urls)); |
| 839 } |
| 840 } |
| 841 |
813 // If the page id is unchanged, check whether the URL (ignoring fragments) | 842 // If the page id is unchanged, check whether the URL (ignoring fragments) |
814 // has changed. If so, we need to reindex. Otherwise, assume this is a | 843 // has changed. If so, we need to reindex. Otherwise, assume this is a |
815 // reload, in-page navigation, or some other load type where we don't want to | 844 // reload, in-page navigation, or some other load type where we don't want to |
816 // reindex. Note: subframe navigations after onload increment the page id, | 845 // reindex. Note: subframe navigations after onload increment the page id, |
817 // so these will trigger a reindex. | 846 // so these will trigger a reindex. |
818 GURL stripped_url(StripRef(url)); | 847 GURL stripped_url(StripRef(url)); |
819 if (same_page_id && stripped_url == last_indexed_url_) | 848 if (same_page_id && stripped_url == last_indexed_url_) |
820 return; | 849 return; |
821 | 850 |
822 if (!preliminary_capture) | 851 if (!preliminary_capture) |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1075 reinterpret_cast<const unsigned char*>(&data[0]); | 1104 reinterpret_cast<const unsigned char*>(&data[0]); |
1076 | 1105 |
1077 return decoder.Decode(src_data, data.size()); | 1106 return decoder.Decode(src_data, data.size()); |
1078 } | 1107 } |
1079 return SkBitmap(); | 1108 return SkBitmap(); |
1080 } | 1109 } |
1081 | 1110 |
1082 bool ChromeRenderViewObserver::IsStrictSecurityHost(const std::string& host) { | 1111 bool ChromeRenderViewObserver::IsStrictSecurityHost(const std::string& host) { |
1083 return (strict_security_hosts_.find(host) != strict_security_hosts_.end()); | 1112 return (strict_security_hosts_.find(host) != strict_security_hosts_.end()); |
1084 } | 1113 } |
OLD | NEW |