Chromium Code Reviews| Index: chrome/browser/net/client_hints.cc |
| diff --git a/chrome/browser/net/client_hints.cc b/chrome/browser/net/client_hints.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..de6cd7c6a3a9af00b0e539b566b43d5519522752 |
| --- /dev/null |
| +++ b/chrome/browser/net/client_hints.cc |
| @@ -0,0 +1,83 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/net/client_hints.h" |
| + |
| +#include "base/logging.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/stringprintf.h" |
| +#include "content/public/browser/browser_thread.h" |
| +#include "content/public/browser/render_view_host.h" |
| +#include "content/public/browser/render_widget_host_view.h" |
| +#include "webkit/glue/webkit_glue.h" |
| + |
| +using content::BrowserThread; |
| +using content::RenderViewHost; |
| +using content::RenderWidgetHostViewPort; |
| + |
| +ClientHints::ClientHints() { |
| +} |
| + |
| +ClientHints::~ClientHints() { |
| +} |
| + |
| +bool ClientHints::RetrieveScreenInfoIfUnavailable(int process_id, |
| + int render_view_id) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| + BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| + base::Bind(&ClientHints::FetchScreenInfoOnUIThread, this, |
| + process_id, render_view_id)); |
| + return IsScreenInfoAvailable(process_id, render_view_id); |
| +} |
| + |
| +bool ClientHints::IsScreenInfoAvailable(int process_id, int render_view_id) { |
| + ScreenMap::iterator it = |
| + screen_hints_.find(std::pair<int, int>(process_id, render_view_id)); |
| + if (it == screen_hints_.end()) |
| + return false; |
| + |
| + return true; |
| +} |
| + |
| +std::string ClientHints::GetScreenInfoHints(int process_id, |
| + int render_view_id) { |
| + ScreenMap::iterator it = |
| + screen_hints_.find(std::pair<int, int>(process_id, render_view_id)); |
| + DCHECK(it != screen_hints_.end()); |
| + return (*it).second.hints_str; |
| +} |
| + |
| +void ClientHints::FetchScreenInfoOnUIThread(int process_id, |
| + int render_view_id) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + RenderViewHost* render_view_host = |
| + RenderViewHost::FromID(process_id, render_view_id); |
| + if (render_view_host == NULL || render_view_host->GetView() == NULL) |
| + return; |
| + WebKit::WebScreenInfo screen_info; |
| +#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
|
| + render_view_host->GetView()->GetScreenInfo(&screen_info); |
| +#else |
| + screen_info.deviceScaleFactor = 0.0; |
|
igrigorik
2013/02/09 17:06:30
Is there a specific reason for 0.0? I think by def
|
| +#endif |
| + gfx::Rect rect = render_view_host->GetView()->GetViewBounds(); |
| + BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| + base::Bind(&ClientHints::UpdateScreenInfo, this, |
| + process_id, render_view_id, rect.width(), rect.height(), |
| + screen_info.deviceScaleFactor)); |
| +} |
| + |
| +void ClientHints::UpdateScreenInfo(int process_id, int render_view_id, |
| + int width, int height, |
| + float dpr) { |
| + std::string screen_info_hints; |
| + screen_info_hints = base::StringPrintf("vh=%d, vw=%d", height, width); |
| +#if defined(OS_POSIX) || defined(USE_AURA) |
| + 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.
|
| +#endif |
| + screen_hints_[std::pair<int, int>(process_id, render_view_id)] = |
| + ScreenHints(width, height, dpr, screen_info_hints); |
| +} |
| + |
| + |