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

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: Add expectations for IncognitoInfo to test 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) {
43 // Extensions and Chrome apps default to spanning mode.
44 // Hosted and legacy packaged apps default to split mode.
45 IncognitoInfo::Mode mode =
46 extension->is_hosted_app() || extension->is_legacy_packaged_app()
47 ? IncognitoInfo::Mode::SPLIT
48 : IncognitoInfo::Mode::SPANNING;
38 if (!extension->manifest()->HasKey(keys::kIncognito)) { 49 if (!extension->manifest()->HasKey(keys::kIncognito)) {
39 // Extensions and Chrome apps default to spanning mode. 50 extension->SetManifestData(keys::kIncognito, new IncognitoInfo(mode));
40 // Hosted and legacy packaged apps default to split mode.
41 extension->SetManifestData(
42 keys::kIncognito,
43 new IncognitoInfo(extension->is_hosted_app() ||
44 extension->is_legacy_packaged_app()));
45 return true; 51 return true;
46 } 52 }
47 53
48 bool split_mode = false;
49 std::string incognito_string; 54 std::string incognito_string;
50 if (!extension->manifest()->GetString(keys::kIncognito, &incognito_string)) { 55 if (!extension->manifest()->GetString(keys::kIncognito, &incognito_string)) {
51 *error = base::ASCIIToUTF16(manifest_errors::kInvalidIncognitoBehavior); 56 *error = base::ASCIIToUTF16(manifest_errors::kInvalidIncognitoBehavior);
52 return false; 57 return false;
53 } 58 }
54 59
55 if (incognito_string == manifest_values::kIncognitoSplit) 60 if (incognito_string == manifest_values::kIncognitoSplit) {
56 split_mode = true; 61 mode = IncognitoInfo::Mode::SPLIT;
57 else if (incognito_string != manifest_values::kIncognitoSpanning) { 62 } else if (incognito_string == manifest_values::kIncognitoSpanning) {
58 // If incognito_string == kIncognitoSpanning, it is valid and 63 mode = IncognitoInfo::Mode::SPANNING;
59 // split_mode remains false. 64 } else if (incognito_string == manifest_values::kIncognitoNotAllowed) {
65 mode = IncognitoInfo::Mode::NOT_ALLOWED;
66 } else {
60 *error = base::ASCIIToUTF16(manifest_errors::kInvalidIncognitoBehavior); 67 *error = base::ASCIIToUTF16(manifest_errors::kInvalidIncognitoBehavior);
61 return false; 68 return false;
62 } 69 }
63 70
64 extension->SetManifestData(keys::kIncognito, new IncognitoInfo(split_mode)); 71 extension->SetManifestData(keys::kIncognito, new IncognitoInfo(mode));
65 return true; 72 return true;
66 } 73 }
67 74
68 bool IncognitoHandler::AlwaysParseForType(Manifest::Type type) const { 75 bool IncognitoHandler::AlwaysParseForType(Manifest::Type type) const {
69 return true; 76 return true;
70 } 77 }
71 78
72 const std::vector<std::string> IncognitoHandler::Keys() const { 79 const std::vector<std::string> IncognitoHandler::Keys() const {
73 return SingleKey(keys::kIncognito); 80 return SingleKey(keys::kIncognito);
74 } 81 }
75 82
76 } // namespace extensions 83 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698