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

Side by Side Diff: content/renderer/manifest/manifest_parser.cc

Issue 576073004: Add support for 'orientation' in Manifest. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@manifest_display
Patch Set: Created 6 years, 3 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
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 "content/renderer/manifest/manifest_parser.h" 5 #include "content/renderer/manifest/manifest_parser.h"
6 6
7 #include "base/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "base/strings/nullable_string16.h" 8 #include "base/strings/nullable_string16.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 else if (LowerCaseEqualsASCII(display.string(), "standalone")) 93 else if (LowerCaseEqualsASCII(display.string(), "standalone"))
94 return Manifest::DISPLAY_MODE_STANDALONE; 94 return Manifest::DISPLAY_MODE_STANDALONE;
95 else if (LowerCaseEqualsASCII(display.string(), "minimal-ui")) 95 else if (LowerCaseEqualsASCII(display.string(), "minimal-ui"))
96 return Manifest::DISPLAY_MODE_MINIMAL_UI; 96 return Manifest::DISPLAY_MODE_MINIMAL_UI;
97 else if (LowerCaseEqualsASCII(display.string(), "browser")) 97 else if (LowerCaseEqualsASCII(display.string(), "browser"))
98 return Manifest::DISPLAY_MODE_BROWSER; 98 return Manifest::DISPLAY_MODE_BROWSER;
99 else 99 else
100 return Manifest::DISPLAY_MODE_UNSPECIFIED; 100 return Manifest::DISPLAY_MODE_UNSPECIFIED;
101 } 101 }
102 102
103 // Parses the 'orientation' field of the manifest, as defined in:
104 // http://w3c.github.io/manifest/#dfn-steps-for-processing-the-orientation-membe r
105 // Returns the parsed WebScreenOrientationLockType if any,
106 // WebScreenOrientationLockDefault if the parsing failed.
107 blink::WebScreenOrientationLockType ParseOrientation(
108 const base::DictionaryValue& dictionary) {
109 base::NullableString16 orientation =
110 ParseString(dictionary, "orientation", Trim);
111
112 if (orientation.is_null())
113 return blink::WebScreenOrientationLockDefault;
114
115 if (LowerCaseEqualsASCII(orientation.string(), "any"))
116 return blink::WebScreenOrientationLockAny;
117 else if (LowerCaseEqualsASCII(orientation.string(), "natural"))
118 return blink::WebScreenOrientationLockNatural;
119 else if (LowerCaseEqualsASCII(orientation.string(), "landscape"))
120 return blink::WebScreenOrientationLockLandscape;
121 else if (LowerCaseEqualsASCII(orientation.string(), "landscape-primary"))
122 return blink::WebScreenOrientationLockLandscapePrimary;
123 else if (LowerCaseEqualsASCII(orientation.string(), "landscape-secondary"))
124 return blink::WebScreenOrientationLockLandscapeSecondary;
125 else if (LowerCaseEqualsASCII(orientation.string(), "portrait"))
126 return blink::WebScreenOrientationLockPortrait;
127 else if (LowerCaseEqualsASCII(orientation.string(), "portrait-primary"))
128 return blink::WebScreenOrientationLockPortraitPrimary;
129 else if (LowerCaseEqualsASCII(orientation.string(), "portrait-secondary"))
130 return blink::WebScreenOrientationLockPortraitSecondary;
131 else
132 return blink::WebScreenOrientationLockDefault;
133 }
134
103 } // anonymous namespace 135 } // anonymous namespace
104 136
105 Manifest ManifestParser::Parse(const base::StringPiece& json, 137 Manifest ManifestParser::Parse(const base::StringPiece& json,
106 const GURL& manifest_url, 138 const GURL& manifest_url,
107 const GURL& document_url) { 139 const GURL& document_url) {
108 scoped_ptr<base::Value> value(base::JSONReader::Read(json)); 140 scoped_ptr<base::Value> value(base::JSONReader::Read(json));
109 if (!value) { 141 if (!value) {
110 // TODO(mlamouri): get the JSON parsing error and report it to the developer 142 // TODO(mlamouri): get the JSON parsing error and report it to the developer
111 // console. 143 // console.
112 return Manifest(); 144 return Manifest();
(...skipping 10 matching lines...) Expand all
123 // TODO(mlamouri): provide a custom message to the developer console. 155 // TODO(mlamouri): provide a custom message to the developer console.
124 return Manifest(); 156 return Manifest();
125 } 157 }
126 158
127 Manifest manifest; 159 Manifest manifest;
128 160
129 manifest.name = ParseName(*dictionary); 161 manifest.name = ParseName(*dictionary);
130 manifest.short_name = ParseShortName(*dictionary); 162 manifest.short_name = ParseShortName(*dictionary);
131 manifest.start_url = ParseStartURL(*dictionary, manifest_url, document_url); 163 manifest.start_url = ParseStartURL(*dictionary, manifest_url, document_url);
132 manifest.display = ParseDisplay(*dictionary); 164 manifest.display = ParseDisplay(*dictionary);
165 manifest.orientation = ParseOrientation(*dictionary);
133 166
134 return manifest; 167 return manifest;
135 } 168 }
136 169
137 } // namespace content 170 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698