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

Unified Diff: chrome/browser/net/client_hints.h

Issue 11970002: Added Client-Hints. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Nit Created 7 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/net/client_hints.h
diff --git a/chrome/browser/net/client_hints.h b/chrome/browser/net/client_hints.h
new file mode 100644
index 0000000000000000000000000000000000000000..d689e2b997733a6dd801115f98e65acdc4b3a499
--- /dev/null
+++ b/chrome/browser/net/client_hints.h
@@ -0,0 +1,64 @@
+// 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.
+
+#ifndef CHROME_BROWSER_NET_CLIENT_HINTS_H_
+#define CHROME_BROWSER_NET_CLIENT_HINTS_H_
+
+#include <string>
+
+#include "base/memory/ref_counted.h"
+#include "base/values.h"
+#include "ui/gfx/rect.h"
+
+class ScreenHints {
Ryan Sleevi 2013/01/16 23:19:56 This should be a struct, not a class, given that a
bengr (incorrect) 2013/01/17 01:50:44 Done.
+ public:
+ ScreenHints() : view_bounds(gfx::Rect(0,0)), dpr(0.0), hints_str("") {}
+ ScreenHints(int width, int height, float d, std::string s) :
+ view_bounds(gfx::Rect(width, height)), dpr(d), hints_str(s) {}
+ gfx::Rect view_bounds;
+ float dpr;
Ryan Sleevi 2013/01/16 23:19:56 style: Do not abbreviate dpr like this.
bengr (incorrect) 2013/01/17 01:50:44 Done.
+ std::string hints_str;
+};
+
+typedef std::map<std::pair<int, int>, ScreenHints> ScreenMap;
+namespace content {
+class RenderWidgetHostViewPort;
+}
Ryan Sleevi 2013/01/16 23:19:56 These typedefs should appear before any class defi
bengr (incorrect) 2013/01/17 01:50:44 Done.
+
+// ClientHints is a repository in Chrome for information used
+// to create the Client-Hints request header. For more information, see:
+// https://github.com/igrigorik/http-client-hints/blob/master/
+// draft-grigorik-http-client-hints-00.txt
+
+class ClientHints : public base::RefCountedThreadSafe<ClientHints> {
+ public:
+ static scoped_refptr<ClientHints> create();
+ ~ClientHints();
Ryan Sleevi 2013/01/16 23:19:56 style: create() should be Create() - although it's
bengr (incorrect) 2013/01/17 01:50:44 Done.
+ // Checks to see if screen information is available for the render view with
+ // the given process id and render view id.
+ bool IsScreenInfoAvailable(int process_id, int render_view_id);
+
+ // Returns client hints pertaining to screen information. The format is:
+ // "vh=xx, vw=yy, dpr=zz", where xx, yy, and zz are the viewport height,
+ // viewport width, and device pixel ratio, respectively. These values are the
+ // same as the values returned by the javascript commands:
+ // window.innerHeight, window.innerWidth, and window.devicePixelRatio.
+ // The function should be called only if IsScreenInfoAvailable() returns true.
+ std::string GetScreenInfoHints(int process_id, int render_view_id);
+
+ protected:
+ ClientHints();
Ryan Sleevi 2013/01/16 23:19:56 Do you expect people to be subclassing this? You h
bengr (incorrect) 2013/01/17 01:50:44 I don't expect people to be subclassing this. Done
+
+ private:
+ void FetchScreenInfoOnUIThread(int process_id, int render_view_id);
+ void UpdateScreenInfo(int process_id, int render_view_id,
+ int width, int height,
Ryan Sleevi 2013/01/16 23:19:56 style: viewport_width, viewport_height ?
bengr (incorrect) 2013/01/17 01:50:44 Done.
+ float dpr);
Ryan Sleevi 2013/01/16 23:19:56 style: meaningful name
bengr (incorrect) 2013/01/17 01:50:44 Done.
+
+ ScreenMap screen_hints_;
+
+ DISALLOW_COPY_AND_ASSIGN(ClientHints);
+};
+
+#endif // CHROME_BROWSER_NET_CLIENT_HINTS_H_

Powered by Google App Engine
This is Rietveld 408576698