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

Side by Side Diff: extensions/common/manifest_handlers/incognito_info.cc

Issue 1351223003: Allow extensions to specify that they are not allowed in incognito mode. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Minor formatting Created 5 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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "extensions/common/manifest_handlers/incognito_info.h" 5 #include "extensions/common/manifest_handlers/incognito_info.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "extensions/common/extension.h" 10 #include "extensions/common/extension.h"
11 #include "extensions/common/manifest_constants.h" 11 #include "extensions/common/manifest_constants.h"
12 12
13 namespace extensions { 13 namespace extensions {
14 14
15 namespace keys = manifest_keys; 15 namespace keys = manifest_keys;
16 16
17 IncognitoInfo::IncognitoInfo(bool incognito_split_mode) 17 IncognitoInfo::IncognitoInfo(Mode mode) : mode(mode) {}
18 : split_mode(incognito_split_mode) {
19 }
20 18
21 IncognitoInfo::~IncognitoInfo() { 19 IncognitoInfo::~IncognitoInfo() {
22 } 20 }
23 21
24 // static 22 // static
25 bool IncognitoInfo::IsSplitMode(const Extension* extension) { 23 bool IncognitoInfo::IsSplitMode(const Extension* extension) {
26 IncognitoInfo* info = static_cast<IncognitoInfo*>( 24 IncognitoInfo* info = static_cast<IncognitoInfo*>(
27 extension->GetManifestData(keys::kIncognito)); 25 extension->GetManifestData(keys::kIncognito));
28 return info ? info->split_mode : false; 26 return info ? info->mode == Mode::SPLIT : false;
27 }
28
29 // static
30 bool IncognitoInfo::IsIncognitoAllowed(const Extension* extension) {
31 IncognitoInfo* info =
32 static_cast<IncognitoInfo*>(extension->GetManifestData(keys::kIncognito));
33 return info ? info->mode != Mode::NOT_ALLOWED : true;
29 } 34 }
30 35
31 IncognitoHandler::IncognitoHandler() { 36 IncognitoHandler::IncognitoHandler() {
32 } 37 }
33 38
34 IncognitoHandler::~IncognitoHandler() { 39 IncognitoHandler::~IncognitoHandler() {
35 } 40 }
36 41
37 bool IncognitoHandler::Parse(Extension* extension, base::string16* error) { 42 bool IncognitoHandler::Parse(Extension* extension, base::string16* error) {
38 if (!extension->manifest()->HasKey(keys::kIncognito)) { 43 if (!extension->manifest()->HasKey(keys::kIncognito)) {
39 // Extensions and Chrome apps default to spanning mode. 44 // Extensions and Chrome apps default to spanning mode.
40 // Hosted and legacy packaged apps default to split mode. 45 // Hosted and legacy packaged apps default to split mode.
41 extension->SetManifestData( 46 IncognitoInfo::Mode default_mode =
not at google - send to devlin 2015/09/17 22:59:54 It would be slightly nicer to assign this before t
Not at Google. Contact bengr 2015/09/18 21:24:31 Done.
42 keys::kIncognito, 47 extension->is_hosted_app() || extension->is_legacy_packaged_app()
43 new IncognitoInfo(extension->is_hosted_app() || 48 ? IncognitoInfo::Mode::SPLIT
44 extension->is_legacy_packaged_app())); 49 : IncognitoInfo::Mode::SPANNING;
50 extension->SetManifestData(keys::kIncognito,
51 new IncognitoInfo(default_mode));
45 return true; 52 return true;
46 } 53 }
47 54
48 bool split_mode = false; 55 IncognitoInfo::Mode mode = IncognitoInfo::Mode::SPANNING;
49 std::string incognito_string; 56 std::string incognito_string;
50 if (!extension->manifest()->GetString(keys::kIncognito, &incognito_string)) { 57 if (!extension->manifest()->GetString(keys::kIncognito, &incognito_string)) {
51 *error = base::ASCIIToUTF16(manifest_errors::kInvalidIncognitoBehavior); 58 *error = base::ASCIIToUTF16(manifest_errors::kInvalidIncognitoBehavior);
52 return false; 59 return false;
53 } 60 }
54 61
55 if (incognito_string == manifest_values::kIncognitoSplit) 62 if (incognito_string == manifest_values::kIncognitoSplit)
56 split_mode = true; 63 mode = IncognitoInfo::Mode::SPLIT;
57 else if (incognito_string != manifest_values::kIncognitoSpanning) { 64 else if (incognito_string == manifest_values::kIncognitoSpanning)
58 // If incognito_string == kIncognitoSpanning, it is valid and 65 mode = IncognitoInfo::Mode::SPANNING;
59 // split_mode remains false. 66 else if (incognito_string == manifest_values::kIncognitoNotAllowed)
67 mode = IncognitoInfo::Mode::NOT_ALLOWED;
68 else {
not at google - send to devlin 2015/09/17 22:59:54 don't mix blocks with braces and blocks without th
Not at Google. Contact bengr 2015/09/18 21:24:31 Done.
60 *error = base::ASCIIToUTF16(manifest_errors::kInvalidIncognitoBehavior); 69 *error = base::ASCIIToUTF16(manifest_errors::kInvalidIncognitoBehavior);
61 return false; 70 return false;
62 } 71 }
63 72
64 extension->SetManifestData(keys::kIncognito, new IncognitoInfo(split_mode)); 73 extension->SetManifestData(keys::kIncognito, new IncognitoInfo(mode));
65 return true; 74 return true;
66 } 75 }
67 76
68 bool IncognitoHandler::AlwaysParseForType(Manifest::Type type) const { 77 bool IncognitoHandler::AlwaysParseForType(Manifest::Type type) const {
69 return true; 78 return true;
70 } 79 }
71 80
72 const std::vector<std::string> IncognitoHandler::Keys() const { 81 const std::vector<std::string> IncognitoHandler::Keys() const {
73 return SingleKey(keys::kIncognito); 82 return SingleKey(keys::kIncognito);
74 } 83 }
75 84
76 } // namespace extensions 85 } // namespace extensions
OLDNEW
« extensions/common/extension.cc ('K') | « extensions/common/manifest_handlers/incognito_info.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698