Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(478)

Side by Side Diff: chrome/renderer/net/net_error_helper.cc

Issue 2310583002: Convert some NetError[Tab]Helper messages to mojom (Closed)
Patch Set: . Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 if (render_frame->IsMainFrame()) 75 if (render_frame->IsMainFrame())
76 return NetErrorHelperCore::MAIN_FRAME; 76 return NetErrorHelperCore::MAIN_FRAME;
77 return NetErrorHelperCore::SUB_FRAME; 77 return NetErrorHelperCore::SUB_FRAME;
78 } 78 }
79 79
80 } // namespace 80 } // namespace
81 81
82 NetErrorHelper::NetErrorHelper(RenderFrame* render_frame) 82 NetErrorHelper::NetErrorHelper(RenderFrame* render_frame)
83 : RenderFrameObserver(render_frame), 83 : RenderFrameObserver(render_frame),
84 content::RenderFrameObserverTracker<NetErrorHelper>(render_frame), 84 content::RenderFrameObserverTracker<NetErrorHelper>(render_frame),
85 network_diagnostics_client_binding_(this),
85 weak_controller_delegate_factory_(this) { 86 weak_controller_delegate_factory_(this) {
86 RenderThread::Get()->AddObserver(this); 87 RenderThread::Get()->AddObserver(this);
87 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 88 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
88 bool auto_reload_enabled = 89 bool auto_reload_enabled =
89 command_line->HasSwitch(switches::kEnableOfflineAutoReload); 90 command_line->HasSwitch(switches::kEnableOfflineAutoReload);
90 bool auto_reload_visible_only = 91 bool auto_reload_visible_only =
91 command_line->HasSwitch(switches::kEnableOfflineAutoReloadVisibleOnly); 92 command_line->HasSwitch(switches::kEnableOfflineAutoReloadVisibleOnly);
92 // TODO(mmenke): Consider only creating a NetErrorHelperCore for main frames. 93 // TODO(mmenke): Consider only creating a NetErrorHelperCore for main frames.
93 // subframes don't need any of the NetErrorHelperCore's extra logic. 94 // subframes don't need any of the NetErrorHelperCore's extra logic.
94 core_.reset(new NetErrorHelperCore(this, 95 core_.reset(new NetErrorHelperCore(this,
95 auto_reload_enabled, 96 auto_reload_enabled,
96 auto_reload_visible_only, 97 auto_reload_visible_only,
97 !render_frame->IsHidden())); 98 !render_frame->IsHidden()));
99
100 render_frame->AddRoutedInterface(
101 base::Bind(&NetErrorHelper::OnNetworkDiagnosticsClientRequest,
102 base::Unretained(this)));
98 } 103 }
99 104
100 NetErrorHelper::~NetErrorHelper() { 105 NetErrorHelper::~NetErrorHelper() {
101 RenderThread::Get()->RemoveObserver(this); 106 RenderThread::Get()->RemoveObserver(this);
102 } 107 }
103 108
104 void NetErrorHelper::ButtonPressed( 109 void NetErrorHelper::ButtonPressed(
105 error_page::NetErrorHelperCore::Button button) { 110 error_page::NetErrorHelperCore::Button button) {
106 core_->ExecuteButtonPress(button); 111 core_->ExecuteButtonPress(button);
107 } 112 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 150
146 void NetErrorHelper::WasHidden() { 151 void NetErrorHelper::WasHidden() {
147 core_->OnWasHidden(); 152 core_->OnWasHidden();
148 } 153 }
149 154
150 bool NetErrorHelper::OnMessageReceived(const IPC::Message& message) { 155 bool NetErrorHelper::OnMessageReceived(const IPC::Message& message) {
151 bool handled = true; 156 bool handled = true;
152 157
153 IPC_BEGIN_MESSAGE_MAP(NetErrorHelper, message) 158 IPC_BEGIN_MESSAGE_MAP(NetErrorHelper, message)
154 IPC_MESSAGE_HANDLER(ChromeViewMsg_NetErrorInfo, OnNetErrorInfo) 159 IPC_MESSAGE_HANDLER(ChromeViewMsg_NetErrorInfo, OnNetErrorInfo)
155 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetCanShowNetworkDiagnosticsDialog,
156 OnSetCanShowNetworkDiagnosticsDialog);
157 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetNavigationCorrectionInfo, 160 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetNavigationCorrectionInfo,
158 OnSetNavigationCorrectionInfo); 161 OnSetNavigationCorrectionInfo);
159 #if defined(OS_ANDROID) 162 #if defined(OS_ANDROID)
160 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetHasOfflinePages, OnSetHasOfflinePages) 163 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetHasOfflinePages, OnSetHasOfflinePages)
161 #endif 164 #endif
162 IPC_MESSAGE_UNHANDLED(handled = false) 165 IPC_MESSAGE_UNHANDLED(handled = false)
163 IPC_END_MESSAGE_MAP() 166 IPC_END_MESSAGE_MAP()
164 167
165 return handled; 168 return handled;
166 } 169 }
(...skipping 11 matching lines...) Expand all
178 bool is_ignoring_cache, 181 bool is_ignoring_cache,
179 std::string* error_html) { 182 std::string* error_html) {
180 core_->GetErrorHTML(GetFrameType(render_frame()), error, is_failed_post, 183 core_->GetErrorHTML(GetFrameType(render_frame()), error, is_failed_post,
181 is_ignoring_cache, error_html); 184 is_ignoring_cache, error_html);
182 } 185 }
183 186
184 bool NetErrorHelper::ShouldSuppressErrorPage(const GURL& url) { 187 bool NetErrorHelper::ShouldSuppressErrorPage(const GURL& url) {
185 return core_->ShouldSuppressErrorPage(GetFrameType(render_frame()), url); 188 return core_->ShouldSuppressErrorPage(GetFrameType(render_frame()), url);
186 } 189 }
187 190
191 mojom::NetworkDiagnostics* NetErrorHelper::GetRemoteNetworkDiagnostics() {
192 if (!remote_network_diagnostics_)
193 render_frame()->GetRemoteRoutedInterface(&remote_network_diagnostics_);
194 return remote_network_diagnostics_.get();
195 }
196
188 void NetErrorHelper::GenerateLocalizedErrorPage( 197 void NetErrorHelper::GenerateLocalizedErrorPage(
189 const blink::WebURLError& error, 198 const blink::WebURLError& error,
190 bool is_failed_post, 199 bool is_failed_post,
191 bool can_show_network_diagnostics_dialog, 200 bool can_show_network_diagnostics_dialog,
192 bool has_offline_pages, 201 bool has_offline_pages,
193 std::unique_ptr<ErrorPageParams> params, 202 std::unique_ptr<ErrorPageParams> params,
194 bool* reload_button_shown, 203 bool* reload_button_shown,
195 bool* show_saved_copy_button_shown, 204 bool* show_saved_copy_button_shown,
196 bool* show_cached_copy_button_shown, 205 bool* show_cached_copy_button_shown,
197 bool* show_offline_pages_button_shown, 206 bool* show_offline_pages_button_shown,
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 base::StringPiece16(web_frame->dataSource()->request().httpMethod()), 324 base::StringPiece16(web_frame->dataSource()->request().httpMethod()),
316 "POST")); 325 "POST"));
317 326
318 blink::WebURLRequest request(page_url); 327 blink::WebURLRequest request(page_url);
319 request.setCachePolicy(blink::WebCachePolicy::ReturnCacheDataDontLoad); 328 request.setCachePolicy(blink::WebCachePolicy::ReturnCacheDataDontLoad);
320 request.setRequestorOrigin(blink::WebSecurityOrigin::createUnique()); 329 request.setRequestorOrigin(blink::WebSecurityOrigin::createUnique());
321 web_frame->loadRequest(request); 330 web_frame->loadRequest(request);
322 } 331 }
323 332
324 void NetErrorHelper::DiagnoseError(const GURL& page_url) { 333 void NetErrorHelper::DiagnoseError(const GURL& page_url) {
325 render_frame()->Send(new ChromeViewHostMsg_RunNetworkDiagnostics( 334 GetRemoteNetworkDiagnostics()->RunNetworkDiagnostics(page_url);
326 render_frame()->GetRoutingID(), page_url));
327 } 335 }
328 336
329 void NetErrorHelper::ShowOfflinePages() { 337 void NetErrorHelper::ShowOfflinePages() {
330 #if defined(OS_ANDROID) 338 #if defined(OS_ANDROID)
331 render_frame()->Send(new ChromeViewHostMsg_ShowOfflinePages( 339 render_frame()->Send(new ChromeViewHostMsg_ShowOfflinePages(
332 render_frame()->GetRoutingID())); 340 render_frame()->GetRoutingID()));
333 #endif // defined(OS_ANDROID) 341 #endif // defined(OS_ANDROID)
334 } 342 }
335 343
336 void NetErrorHelper::OnNetErrorInfo(int status_num) { 344 void NetErrorHelper::OnNetErrorInfo(int status_num) {
337 DCHECK(status_num >= 0 && status_num < error_page::DNS_PROBE_MAX); 345 DCHECK(status_num >= 0 && status_num < error_page::DNS_PROBE_MAX);
338 346
339 DVLOG(1) << "Received status " << DnsProbeStatusToString(status_num); 347 DVLOG(1) << "Received status " << DnsProbeStatusToString(status_num);
340 348
341 core_->OnNetErrorInfo(static_cast<DnsProbeStatus>(status_num)); 349 core_->OnNetErrorInfo(static_cast<DnsProbeStatus>(status_num));
342 } 350 }
343 351
344 void NetErrorHelper::OnSetCanShowNetworkDiagnosticsDialog(
345 bool can_use_local_diagnostics_service) {
346 core_->OnSetCanShowNetworkDiagnosticsDialog(
347 can_use_local_diagnostics_service);
348 }
349
350 void NetErrorHelper::OnSetNavigationCorrectionInfo( 352 void NetErrorHelper::OnSetNavigationCorrectionInfo(
351 const GURL& navigation_correction_url, 353 const GURL& navigation_correction_url,
352 const std::string& language, 354 const std::string& language,
353 const std::string& country_code, 355 const std::string& country_code,
354 const std::string& api_key, 356 const std::string& api_key,
355 const GURL& search_url) { 357 const GURL& search_url) {
356 core_->OnSetNavigationCorrectionInfo(navigation_correction_url, language, 358 core_->OnSetNavigationCorrectionInfo(navigation_correction_url, language,
357 country_code, api_key, search_url); 359 country_code, api_key, search_url);
358 } 360 }
359 361
360 void NetErrorHelper::OnNavigationCorrectionsFetched( 362 void NetErrorHelper::OnNavigationCorrectionsFetched(
361 const blink::WebURLResponse& response, 363 const blink::WebURLResponse& response,
362 const std::string& data) { 364 const std::string& data) {
363 // The fetcher may only be deleted after |data| is passed to |core_|. Move 365 // The fetcher may only be deleted after |data| is passed to |core_|. Move
364 // it to a temporary to prevent any potential re-entrancy issues. 366 // it to a temporary to prevent any potential re-entrancy issues.
365 std::unique_ptr<content::ResourceFetcher> fetcher( 367 std::unique_ptr<content::ResourceFetcher> fetcher(
366 correction_fetcher_.release()); 368 correction_fetcher_.release());
367 bool success = (!response.isNull() && response.httpStatusCode() == 200); 369 bool success = (!response.isNull() && response.httpStatusCode() == 200);
368 core_->OnNavigationCorrectionsFetched(success ? data : "", 370 core_->OnNavigationCorrectionsFetched(success ? data : "",
369 base::i18n::IsRTL()); 371 base::i18n::IsRTL());
370 } 372 }
371 373
372 void NetErrorHelper::OnTrackingRequestComplete( 374 void NetErrorHelper::OnTrackingRequestComplete(
373 const blink::WebURLResponse& response, 375 const blink::WebURLResponse& response,
374 const std::string& data) { 376 const std::string& data) {
375 tracking_fetcher_.reset(); 377 tracking_fetcher_.reset();
376 } 378 }
377 379
380 void NetErrorHelper::OnNetworkDiagnosticsClientRequest(
381 mojom::NetworkDiagnosticsClientAssociatedRequest request) {
382 DCHECK(!network_diagnostics_client_binding_.is_bound());
383 network_diagnostics_client_binding_.Bind(std::move(request));
384 }
385
386 void NetErrorHelper::SetCanShowNetworkDiagnosticsDialog(bool can_show) {
387 core_->OnSetCanShowNetworkDiagnosticsDialog(can_show);
388 }
389
378 #if defined(OS_ANDROID) 390 #if defined(OS_ANDROID)
379 void NetErrorHelper::OnSetHasOfflinePages(bool has_offline_pages) { 391 void NetErrorHelper::OnSetHasOfflinePages(bool has_offline_pages) {
380 core_->OnSetHasOfflinePages(has_offline_pages); 392 core_->OnSetHasOfflinePages(has_offline_pages);
381 } 393 }
382 #endif // defined(OS_ANDROID) 394 #endif // defined(OS_ANDROID)
OLDNEW
« chrome/common/network_diagnostics.mojom ('K') | « chrome/renderer/net/net_error_helper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698