OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/net/client_hints.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "base/memory/scoped_ptr.h" | |
9 #include "base/stringprintf.h" | |
10 #include "content/public/browser/browser_thread.h" | |
11 #include "content/public/browser/render_view_host.h" | |
12 #include "content/public/browser/render_widget_host_view.h" | |
13 #include "webkit/glue/webkit_glue.h" | |
14 | |
15 using content::BrowserThread; | |
16 using content::RenderViewHost; | |
17 using content::RenderWidgetHostViewPort; | |
18 | |
19 ClientHints::ClientHints() { | |
20 } | |
21 | |
22 ClientHints::~ClientHints() { | |
23 } | |
24 | |
25 bool ClientHints::RetrieveScreenInfoIfUnavailable(int process_id, | |
26 int render_view_id) { | |
27 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
28 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
29 base::Bind(&ClientHints::FetchScreenInfoOnUIThread, this, | |
30 process_id, render_view_id)); | |
31 return IsScreenInfoAvailable(process_id, render_view_id); | |
32 } | |
33 | |
34 bool ClientHints::IsScreenInfoAvailable(int process_id, int render_view_id) { | |
35 ScreenMap::iterator it = | |
36 screen_hints_.find(std::pair<int, int>(process_id, render_view_id)); | |
37 if (it == screen_hints_.end()) | |
38 return false; | |
39 | |
40 return true; | |
41 } | |
42 | |
43 std::string ClientHints::GetScreenInfoHints(int process_id, | |
44 int render_view_id) { | |
45 ScreenMap::iterator it = | |
46 screen_hints_.find(std::pair<int, int>(process_id, render_view_id)); | |
47 DCHECK(it != screen_hints_.end()); | |
48 return (*it).second.hints_str; | |
49 } | |
50 | |
51 void ClientHints::FetchScreenInfoOnUIThread(int process_id, | |
52 int render_view_id) { | |
53 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
54 RenderViewHost* render_view_host = | |
55 RenderViewHost::FromID(process_id, render_view_id); | |
56 if (render_view_host == NULL || render_view_host->GetView() == NULL) | |
57 return; | |
58 WebKit::WebScreenInfo screen_info; | |
59 #if defined(OS_POSIX) || defined(USE_AURA) | |
jam
2013/01/17 18:14:35
why are you doing this only for these too?
GetScr
bengr (incorrect)
2013/01/18 02:12:00
I now get the device pixel ratio more directly.
O
| |
60 render_view_host->GetView()->GetScreenInfo(&screen_info); | |
61 #else | |
62 screen_info.deviceScaleFactor = 0.0; | |
igrigorik
2013/02/09 17:06:30
Is there a specific reason for 0.0? I think by def
| |
63 #endif | |
64 gfx::Rect rect = render_view_host->GetView()->GetViewBounds(); | |
65 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | |
66 base::Bind(&ClientHints::UpdateScreenInfo, this, | |
67 process_id, render_view_id, rect.width(), rect.height(), | |
68 screen_info.deviceScaleFactor)); | |
69 } | |
70 | |
71 void ClientHints::UpdateScreenInfo(int process_id, int render_view_id, | |
72 int width, int height, | |
73 float dpr) { | |
74 std::string screen_info_hints; | |
75 screen_info_hints = base::StringPrintf("vh=%d, vw=%d", height, width); | |
76 #if defined(OS_POSIX) || defined(USE_AURA) | |
77 screen_info_hints += base::StringPrintf(", dpr=%0.3g", dpr); | |
Ryan Sleevi
2013/01/17 01:57:56
StringAppendF(screen_info_hints, ", dpr=%0.3g", dp
bengr (incorrect)
2013/01/18 02:12:00
Done.
| |
78 #endif | |
79 screen_hints_[std::pair<int, int>(process_id, render_view_id)] = | |
80 ScreenHints(width, height, dpr, screen_info_hints); | |
81 } | |
82 | |
83 | |
OLD | NEW |