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

Side by Side Diff: Source/core/css/MediaValues.cpp

Issue 252683007: Protect MediaValuesCached creation when RenderView is missing (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixed fix Created 6 years, 7 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "config.h" 5 #include "config.h"
6 #include "core/css/MediaValues.h" 6 #include "core/css/MediaValues.h"
7 7
8 #include "core/css/CSSHelper.h" 8 #include "core/css/CSSHelper.h"
9 #include "core/css/MediaValuesCached.h" 9 #include "core/css/MediaValuesCached.h"
10 #include "core/css/MediaValuesDynamic.h" 10 #include "core/css/MediaValuesDynamic.h"
(...skipping 12 matching lines...) Expand all
23 23
24 namespace WebCore { 24 namespace WebCore {
25 25
26 PassRefPtr<MediaValues> MediaValues::createDynamicIfFrameExists(LocalFrame* fram e) 26 PassRefPtr<MediaValues> MediaValues::createDynamicIfFrameExists(LocalFrame* fram e)
27 { 27 {
28 if (frame) 28 if (frame)
29 return MediaValuesDynamic::create(frame); 29 return MediaValuesDynamic::create(frame);
30 return MediaValuesCached::create(); 30 return MediaValuesCached::create();
31 } 31 }
32 32
33 static float getEffectiveZoom(LocalFrame* frame)
34 {
35 ASSERT(frame->document());
36 RenderView* view = (frame->document()->renderView());
eseidel 2014/04/26 05:04:05 The parens aren't needed.
37 if (!view)
38 return 1.0;
39 RenderStyle* style = view->style();
40 if (!style)
41 return 1.0;
42 return style->effectiveZoom();
43 }
44
33 int MediaValues::calculateViewportWidth(LocalFrame* frame) const 45 int MediaValues::calculateViewportWidth(LocalFrame* frame) const
34 { 46 {
35 ASSERT(frame && frame->view() && frame->document()); 47 ASSERT(frame && frame->view());
36 int viewportWidth = frame->view()->layoutSize(IncludeScrollbars).width(); 48 int viewportWidth = frame->view()->layoutSize(IncludeScrollbars).width();
37 return adjustForAbsoluteZoom(viewportWidth, frame->document()->renderView()) ; 49 return adjustForAbsoluteZoom(viewportWidth, getEffectiveZoom(frame));
38 } 50 }
39 51
40 int MediaValues::calculateViewportHeight(LocalFrame* frame) const 52 int MediaValues::calculateViewportHeight(LocalFrame* frame) const
41 { 53 {
42 ASSERT(frame && frame->view() && frame->document()); 54 ASSERT(frame && frame->view());
43 int viewportHeight = frame->view()->layoutSize(IncludeScrollbars).height(); 55 int viewportHeight = frame->view()->layoutSize(IncludeScrollbars).height();
44 return adjustForAbsoluteZoom(viewportHeight, frame->document()->renderView() ); 56 return adjustForAbsoluteZoom(viewportHeight, getEffectiveZoom(frame));
45 } 57 }
46 58
47 int MediaValues::calculateDeviceWidth(LocalFrame* frame) const 59 int MediaValues::calculateDeviceWidth(LocalFrame* frame) const
48 { 60 {
49 ASSERT(frame && frame->view() && frame->settings() && frame->host()); 61 ASSERT(frame && frame->view() && frame->settings() && frame->host());
50 int deviceWidth = static_cast<int>(screenRect(frame->view()).width()); 62 int deviceWidth = static_cast<int>(screenRect(frame->view()).width());
51 if (frame->settings()->reportScreenSizeInPhysicalPixelsQuirk()) 63 if (frame->settings()->reportScreenSizeInPhysicalPixelsQuirk())
52 deviceWidth = lroundf(deviceWidth * frame->host()->deviceScaleFactor()); 64 deviceWidth = lroundf(deviceWidth * frame->host()->deviceScaleFactor());
53 return deviceWidth; 65 return deviceWidth;
54 } 66 }
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 default: 207 default:
196 return false; 208 return false;
197 } 209 }
198 210
199 ASSERT(factor > 0); 211 ASSERT(factor > 0);
200 result = roundForImpreciseConversion<int>(value*factor); 212 result = roundForImpreciseConversion<int>(value*factor);
201 return true; 213 return true;
202 } 214 }
203 215
204 } // namespace 216 } // namespace
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698