OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/net/net_error_helper.h" | 5 #include "chrome/renderer/net/net_error_helper.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 return NetErrorHelperCore::NON_ERROR_PAGE; | 61 return NetErrorHelperCore::NON_ERROR_PAGE; |
62 return NetErrorHelperCore::ERROR_PAGE; | 62 return NetErrorHelperCore::ERROR_PAGE; |
63 } | 63 } |
64 | 64 |
65 NetErrorHelperCore::FrameType GetFrameType(const blink::WebFrame* frame) { | 65 NetErrorHelperCore::FrameType GetFrameType(const blink::WebFrame* frame) { |
66 if (!frame->parent()) | 66 if (!frame->parent()) |
67 return NetErrorHelperCore::MAIN_FRAME; | 67 return NetErrorHelperCore::MAIN_FRAME; |
68 return NetErrorHelperCore::SUB_FRAME; | 68 return NetErrorHelperCore::SUB_FRAME; |
69 } | 69 } |
70 | 70 |
71 // Copied from localized_error.cc. | |
72 // TODO(mmenke): Share code? | |
73 bool LocaleIsRTL() { | |
74 #if defined(TOOLKIT_GTK) | |
75 // base::i18n::IsRTL() uses the GTK text direction, which doesn't work within | |
76 // the renderer sandbox. | |
77 return base::i18n::ICUIsRTL(); | |
78 #else | |
79 return base::i18n::IsRTL(); | |
80 #endif | |
81 } | |
82 | |
83 } // namespace | 71 } // namespace |
84 | 72 |
85 NetErrorHelper::NetErrorHelper(RenderFrame* render_frame) | 73 NetErrorHelper::NetErrorHelper(RenderFrame* render_frame) |
86 : RenderFrameObserver(render_frame), | 74 : RenderFrameObserver(render_frame), |
87 content::RenderFrameObserverTracker<NetErrorHelper>(render_frame) { | 75 content::RenderFrameObserverTracker<NetErrorHelper>(render_frame) { |
88 RenderThread::Get()->AddObserver(this); | 76 RenderThread::Get()->AddObserver(this); |
89 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 77 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
90 bool auto_reload_enabled = | 78 bool auto_reload_enabled = |
91 command_line->HasSwitch(switches::kEnableOfflineAutoReload); | 79 command_line->HasSwitch(switches::kEnableOfflineAutoReload); |
92 core_.reset(new NetErrorHelperCore(this, | 80 core_.reset(new NetErrorHelperCore(this, |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 country_code, api_key, search_url); | 322 country_code, api_key, search_url); |
335 } | 323 } |
336 | 324 |
337 void NetErrorHelper::OnNavigationCorrectionsFetched( | 325 void NetErrorHelper::OnNavigationCorrectionsFetched( |
338 const blink::WebURLResponse& response, | 326 const blink::WebURLResponse& response, |
339 const std::string& data) { | 327 const std::string& data) { |
340 // The fetcher may only be deleted after |data| is passed to |core_|. Move | 328 // The fetcher may only be deleted after |data| is passed to |core_|. Move |
341 // it to a temporary to prevent any potential re-entrancy issues. | 329 // it to a temporary to prevent any potential re-entrancy issues. |
342 scoped_ptr<content::ResourceFetcher> fetcher( | 330 scoped_ptr<content::ResourceFetcher> fetcher( |
343 correction_fetcher_.release()); | 331 correction_fetcher_.release()); |
344 if (!response.isNull() && response.httpStatusCode() == 200) { | 332 bool success = (!response.isNull() && response.httpStatusCode() == 200); |
345 core_->OnNavigationCorrectionsFetched( | 333 core_->OnNavigationCorrectionsFetched( |
346 data, render_frame()->GetRenderView()->GetAcceptLanguages(), | 334 succss ? data : "", |
347 LocaleIsRTL()); | 335 render_frame()->GetRenderView()->GetAcceptLanguages(), |
348 } else { | 336 base::i18n::IsRTL()); |
349 core_->OnNavigationCorrectionsFetched( | |
350 "", render_frame()->GetRenderView()->GetAcceptLanguages(), | |
351 LocaleIsRTL()); | |
352 } | |
353 } | 337 } |
354 | 338 |
355 void NetErrorHelper::OnTrackingRequestComplete( | 339 void NetErrorHelper::OnTrackingRequestComplete( |
356 const blink::WebURLResponse& response, | 340 const blink::WebURLResponse& response, |
357 const std::string& data) { | 341 const std::string& data) { |
358 tracking_fetcher_.reset(); | 342 tracking_fetcher_.reset(); |
359 } | 343 } |
OLD | NEW |