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

Side by Side Diff: content/browser/loader/async_resource_handler.cc

Issue 1804023002: Fix page zoom to be frame-centric for out-of-process frames. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Don't use WeakPtr for PostTask on UI thread. Created 4 years, 8 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) 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 "content/browser/loader/async_resource_handler.h" 5 #include "content/browser/loader/async_resource_handler.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h"
10 #include "base/command_line.h" 11 #include "base/command_line.h"
11 #include "base/containers/hash_tables.h" 12 #include "base/containers/hash_tables.h"
12 #include "base/debug/alias.h" 13 #include "base/debug/alias.h"
13 #include "base/feature_list.h" 14 #include "base/feature_list.h"
14 #include "base/logging.h" 15 #include "base/logging.h"
15 #include "base/macros.h" 16 #include "base/macros.h"
16 #include "base/memory/shared_memory.h" 17 #include "base/memory/shared_memory.h"
17 #include "base/metrics/histogram_macros.h" 18 #include "base/metrics/histogram_macros.h"
18 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
19 #include "base/time/time.h" 20 #include "base/time/time.h"
20 #include "content/browser/devtools/devtools_netlog_observer.h" 21 #include "content/browser/devtools/devtools_netlog_observer.h"
21 #include "content/browser/host_zoom_map_impl.h" 22 #include "content/browser/host_zoom_map_impl.h"
22 #include "content/browser/loader/resource_buffer.h" 23 #include "content/browser/loader/resource_buffer.h"
23 #include "content/browser/loader/resource_dispatcher_host_impl.h" 24 #include "content/browser/loader/resource_dispatcher_host_impl.h"
24 #include "content/browser/loader/resource_message_filter.h" 25 #include "content/browser/loader/resource_message_filter.h"
25 #include "content/browser/loader/resource_request_info_impl.h" 26 #include "content/browser/loader/resource_request_info_impl.h"
26 #include "content/browser/resource_context_impl.h" 27 #include "content/browser/resource_context_impl.h"
27 #include "content/common/resource_messages.h" 28 #include "content/common/resource_messages.h"
28 #include "content/common/view_messages.h" 29 #include "content/common/view_messages.h"
30 #include "content/public/browser/render_view_host.h"
29 #include "content/public/browser/resource_dispatcher_host_delegate.h" 31 #include "content/public/browser/resource_dispatcher_host_delegate.h"
30 #include "content/public/common/content_features.h" 32 #include "content/public/common/content_features.h"
31 #include "content/public/common/resource_response.h" 33 #include "content/public/common/resource_response.h"
32 #include "net/base/io_buffer.h" 34 #include "net/base/io_buffer.h"
33 #include "net/base/load_flags.h" 35 #include "net/base/load_flags.h"
34 #include "net/log/net_log.h" 36 #include "net/log/net_log.h"
35 #include "net/url_request/redirect_info.h" 37 #include "net/url_request/redirect_info.h"
36 38
37 using base::TimeDelta; 39 using base::TimeDelta;
38 using base::TimeTicks; 40 using base::TimeTicks;
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 response->head.request_start = request()->creation_time(); 309 response->head.request_start = request()->creation_time();
308 response->head.response_start = TimeTicks::Now(); 310 response->head.response_start = TimeTicks::Now();
309 // TODO(davidben): Is it necessary to pass the new first party URL for 311 // TODO(davidben): Is it necessary to pass the new first party URL for
310 // cookies? The only case where it can change is top-level navigation requests 312 // cookies? The only case where it can change is top-level navigation requests
311 // and hopefully those will eventually all be owned by the browser. It's 313 // and hopefully those will eventually all be owned by the browser. It's
312 // possible this is still needed while renderer-owned ones exist. 314 // possible this is still needed while renderer-owned ones exist.
313 return info->filter()->Send(new ResourceMsg_ReceivedRedirect( 315 return info->filter()->Send(new ResourceMsg_ReceivedRedirect(
314 GetRequestID(), redirect_info, response->head)); 316 GetRequestID(), redirect_info, response->head));
315 } 317 }
316 318
319 namespace {
320
321 // Defined here to be close to OnResponseStarted(), which is the only caller.
322 void SetZoomLevelForViewFromWebContents(
323 ResourceRequestInfo::WebContentsGetter request_web_contents_getter,
324 int render_process_id,
325 int render_view_id,
326 const GURL request_url) {
327 DCHECK_CURRENTLY_ON(BrowserThread::UI);
328
329 WebContents* web_contents = request_web_contents_getter.Run();
330 if (!web_contents)
331 return;
332
333 double zoom_level = HostZoomMap::GetZoomLevel(web_contents);
334
335 RenderViewHost* render_view_host =
336 RenderViewHost::FromID(render_process_id, render_view_id);
337 if (!render_view_host)
338 return;
339
340 render_view_host->Send(new ViewMsg_SetZoomLevelForLoadingURL(
341 render_view_id, request_url, zoom_level));
342 }
343
344 } // namespace anonymous
345
317 bool AsyncResourceHandler::OnResponseStarted(ResourceResponse* response, 346 bool AsyncResourceHandler::OnResponseStarted(ResourceResponse* response,
318 bool* defer) { 347 bool* defer) {
319 // For changes to the main frame, inform the renderer of the new URL's 348 // For changes to the main frame, inform the renderer of the new URL's
320 // per-host settings before the request actually commits. This way the 349 // per-host settings before the request actually commits. This way the
321 // renderer will be able to set these precisely at the time the 350 // renderer will be able to set these precisely at the time the
322 // request commits, avoiding the possibility of e.g. zooming the old content 351 // request commits, avoiding the possibility of e.g. zooming the old content
323 // or of having to layout the new content twice. 352 // or of having to layout the new content twice.
324 353
325 response_started_ticks_ = base::TimeTicks::Now(); 354 response_started_ticks_ = base::TimeTicks::Now();
326 355
(...skipping 23 matching lines...) Expand all
350 if (info->GetResourceType() == RESOURCE_TYPE_MAIN_FRAME && host_zoom_map) { 379 if (info->GetResourceType() == RESOURCE_TYPE_MAIN_FRAME && host_zoom_map) {
351 const GURL& request_url = request()->url(); 380 const GURL& request_url = request()->url();
352 int render_process_id = info->GetChildID(); 381 int render_process_id = info->GetChildID();
353 int render_view_id = info->GetRouteID(); 382 int render_view_id = info->GetRouteID();
354 383
355 double zoom_level = host_zoom_map->GetZoomLevelForView( 384 double zoom_level = host_zoom_map->GetZoomLevelForView(
356 request_url, render_process_id, render_view_id); 385 request_url, render_process_id, render_view_id);
357 386
358 info->filter()->Send(new ViewMsg_SetZoomLevelForLoadingURL( 387 info->filter()->Send(new ViewMsg_SetZoomLevelForLoadingURL(
359 render_view_id, request_url, zoom_level)); 388 render_view_id, request_url, zoom_level));
389 } else if (info->GetResourceType() == RESOURCE_TYPE_SUB_FRAME &&
390 host_zoom_map) {
391 // Sub-frames should use the zoom level of their web-contents, regardless of
392 // their URL. We must access the WebContents on the UI thread.
393 BrowserThread::PostTask(
394 BrowserThread::UI, FROM_HERE,
395 base::Bind(
396 &SetZoomLevelForViewFromWebContents,
397 info->GetWebContentsGetterForRequest(),
398 info->GetChildID(),
399 info->GetRouteID(),
400 request()->url()));
360 } 401 }
361 402
362 // If the parent handler downloaded the resource to a file, grant the child 403 // If the parent handler downloaded the resource to a file, grant the child
363 // read permissions on it. 404 // read permissions on it.
364 if (!response->head.download_file_path.empty()) { 405 if (!response->head.download_file_path.empty()) {
365 rdh_->RegisterDownloadedTempFile( 406 rdh_->RegisterDownloadedTempFile(
366 info->GetChildID(), info->GetRequestID(), 407 info->GetChildID(), info->GetRequestID(),
367 response->head.download_file_path); 408 response->head.download_file_path);
368 } 409 }
369 410
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 } else { 642 } else {
602 UMA_HISTOGRAM_CUSTOM_COUNTS( 643 UMA_HISTOGRAM_CUSTOM_COUNTS(
603 "Net.ResourceLoader.ResponseStartToEnd.Over_512kB", 644 "Net.ResourceLoader.ResponseStartToEnd.Over_512kB",
604 elapsed_time, 1, 100000, 100); 645 elapsed_time, 1, 100000, 100);
605 } 646 }
606 647
607 inlining_helper_->RecordHistogram(elapsed_time); 648 inlining_helper_->RecordHistogram(elapsed_time);
608 } 649 }
609 650
610 } // namespace content 651 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698