Chromium Code Reviews| 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 "base/logging.h" | |
| 6 #include "base/memory/scoped_ptr.h" | |
| 7 #include "chrome/browser/net/client_hints.h" | |
|
Ryan Sleevi
2013/01/16 23:19:56
style: This should be first, followed by a new lin
bengr (incorrect)
2013/01/17 01:50:44
Done.
| |
| 8 #include "content/public/browser/browser_thread.h" | |
| 9 #include "content/public/browser/render_view_host.h" | |
| 10 #include "content/public/browser/render_widget_host_view.h" | |
| 11 #include "third_party/WebKit/Source/Platform/chromium/public/WebScreenInfo.h" | |
|
Ryan Sleevi
2013/01/16 23:19:56
I didn't think this was legal? I thought only the
bengr (incorrect)
2013/01/17 01:50:44
Done.
| |
| 12 | |
| 13 using content::BrowserThread; | |
| 14 using content::RenderViewHost; | |
| 15 using content::RenderWidgetHostViewPort; | |
| 16 | |
| 17 scoped_refptr<ClientHints> ClientHints::create() { | |
| 18 return make_scoped_refptr(new ClientHints()); | |
| 19 } | |
| 20 | |
| 21 ClientHints::ClientHints() { | |
| 22 } | |
| 23 | |
| 24 ClientHints::~ClientHints() { | |
| 25 } | |
| 26 | |
| 27 bool ClientHints::IsScreenInfoAvailable(int process_id, int render_view_id) { | |
| 28 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 29 // TODO(bengr): Decide if we should do this thread hopping on every request. | |
| 30 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 31 base::Bind(&ClientHints::FetchScreenInfoOnUIThread, this, | |
| 32 process_id, render_view_id)); | |
| 33 ScreenMap::iterator it = | |
| 34 screen_hints_.find(std::pair<int, int>(process_id, render_view_id)); | |
| 35 if (it != screen_hints_.end()) { | |
|
Ryan Sleevi
2013/01/16 23:19:56
style: Put it as error handling first
if (it == s
bengr (incorrect)
2013/01/17 01:50:44
Done.
| |
| 36 return true; | |
| 37 } | |
| 38 return false; | |
| 39 } | |
| 40 | |
| 41 std::string ClientHints::GetScreenInfoHints(int process_id, | |
| 42 int render_view_id) { | |
| 43 DCHECK(screen_hints_.find(std::pair<int, int>(process_id, render_view_id)) != | |
| 44 screen_hints_.end()); | |
| 45 return screen_hints_[ | |
| 46 std::pair<int, int>(process_id, render_view_id)].hints_str; | |
|
Ryan Sleevi
2013/01/16 23:19:56
You're forcing a double-find for the DCHECK. Furth
bengr (incorrect)
2013/01/17 01:50:44
Removed double-find. I don't understand your secon
| |
| 47 } | |
| 48 | |
| 49 void ClientHints::FetchScreenInfoOnUIThread(int process_id, | |
| 50 int render_view_id) { | |
| 51 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 52 RenderViewHost* render_view_host = | |
| 53 RenderViewHost::FromID(process_id, render_view_id); | |
| 54 if (render_view_host != NULL && render_view_host->GetView() != NULL) { | |
|
Ryan Sleevi
2013/01/16 23:19:56
style: Put error handling first, with early return
bengr (incorrect)
2013/01/17 01:50:44
Done.
| |
| 55 WebKit::WebScreenInfo screen_info; | |
| 56 #if defined(OS_POSIX) || defined(USE_AURA) | |
| 57 render_view_host->GetView()->GetScreenInfo(&screen_info); | |
| 58 #else | |
| 59 screen_info.deviceScaleFactor = 0.0; | |
| 60 #endif | |
| 61 gfx::Rect rect = render_view_host->GetView()->GetViewBounds(); | |
| 62 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | |
| 63 base::Bind(&ClientHints::UpdateScreenInfo, this, | |
| 64 process_id, render_view_id, rect.width(), rect.height(), | |
| 65 screen_info.deviceScaleFactor)); | |
| 66 } | |
| 67 } | |
| 68 | |
| 69 void ClientHints::UpdateScreenInfo(int process_id, int render_view_id, | |
| 70 int width, int height, | |
| 71 float dpr) { | |
| 72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 73 std::ostringstream value; | |
|
Ryan Sleevi
2013/01/16 23:19:56
NACK: This is forbidden in the style guide.
http
bengr (incorrect)
2013/01/17 01:50:44
Done.
| |
| 74 value << "vh=" << height << ", vw=" << width; | |
| 75 #if defined(OS_POSIX) || defined(USE_AURA) | |
| 76 value << ", dpr=" << dpr; | |
| 77 #endif | |
| 78 screen_hints_[std::pair<int, int>(process_id, render_view_id)] = | |
| 79 ScreenHints(width, height, dpr, value.str()); | |
| 80 } | |
| 81 | |
| 82 | |
| OLD | NEW |