| OLD | NEW |
| 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 "extensions/common/manifest_handlers/options_page_info.h" | 5 #include "extensions/common/manifest_handlers/options_page_info.h" |
| 6 | 6 |
| 7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "extensions/common/api/extensions_manifest_types.h" | 10 #include "extensions/common/api/extensions_manifest_types.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 return info && info->open_in_tab_; | 104 return info && info->open_in_tab_; |
| 105 } | 105 } |
| 106 | 106 |
| 107 scoped_ptr<OptionsPageInfo> OptionsPageInfo::Create( | 107 scoped_ptr<OptionsPageInfo> OptionsPageInfo::Create( |
| 108 Extension* extension, | 108 Extension* extension, |
| 109 const base::Value* options_ui_value, | 109 const base::Value* options_ui_value, |
| 110 const std::string& options_page_string, | 110 const std::string& options_page_string, |
| 111 std::vector<InstallWarning>* install_warnings, | 111 std::vector<InstallWarning>* install_warnings, |
| 112 base::string16* error) { | 112 base::string16* error) { |
| 113 GURL options_page; | 113 GURL options_page; |
| 114 // Chrome styling is always opt-in. |
| 114 bool chrome_style = false; | 115 bool chrome_style = false; |
| 116 // Extensions can opt in or out to opening in a tab, and users can choose via |
| 117 // the --embedded-extension-options flag which should be the default. |
| 115 bool open_in_tab = !FeatureSwitch::embedded_extension_options()->IsEnabled(); | 118 bool open_in_tab = !FeatureSwitch::embedded_extension_options()->IsEnabled(); |
| 116 | 119 |
| 117 // Parse the options_ui object. | 120 // Parse the options_ui object. |
| 118 if (options_ui_value && | 121 if (options_ui_value) { |
| 119 FeatureSwitch::embedded_extension_options()->IsEnabled()) { | |
| 120 base::string16 options_ui_error; | 122 base::string16 options_ui_error; |
| 121 | 123 |
| 122 scoped_ptr<OptionsUI> options_ui = | 124 scoped_ptr<OptionsUI> options_ui = |
| 123 OptionsUI::FromValue(*options_ui_value, &options_ui_error); | 125 OptionsUI::FromValue(*options_ui_value, &options_ui_error); |
| 124 if (!options_ui_error.empty()) { | 126 if (!options_ui_error.empty()) { |
| 125 // OptionsUI::FromValue populates |error| both when there are | 127 // OptionsUI::FromValue populates |error| both when there are |
| 126 // errors (in which case |options_ui| will be NULL) and warnings | 128 // errors (in which case |options_ui| will be NULL) and warnings |
| 127 // (in which case |options_ui| will be valid). Either way, show it | 129 // (in which case |options_ui| will be valid). Either way, show it |
| 128 // as an install warning. | 130 // as an install warning. |
| 129 install_warnings->push_back( | 131 install_warnings->push_back( |
| 130 InstallWarning(base::UTF16ToASCII(options_ui_error))); | 132 InstallWarning(base::UTF16ToASCII(options_ui_error))); |
| 131 } | 133 } |
| 132 | 134 |
| 133 if (options_ui) { | 135 if (options_ui) { |
| 134 base::string16 options_parse_error; | 136 base::string16 options_parse_error; |
| 135 if (!ParseOptionsUrl(extension, | 137 if (!ParseOptionsUrl(extension, |
| 136 options_ui->page, | 138 options_ui->page, |
| 137 keys::kOptionsUI, | 139 keys::kOptionsUI, |
| 138 &options_parse_error, | 140 &options_parse_error, |
| 139 &options_page)) { | 141 &options_page)) { |
| 140 install_warnings->push_back( | 142 install_warnings->push_back( |
| 141 InstallWarning(base::UTF16ToASCII(options_parse_error))); | 143 InstallWarning(base::UTF16ToASCII(options_parse_error))); |
| 142 } | 144 } |
| 143 chrome_style = | 145 if (options_ui->chrome_style.get()) |
| 144 options_ui->chrome_style.get() && *options_ui->chrome_style; | 146 chrome_style = *options_ui->chrome_style; |
| 145 open_in_tab = options_ui->open_in_tab.get() && *options_ui->open_in_tab; | 147 if (options_ui->open_in_tab.get()) |
| 148 open_in_tab = *options_ui->open_in_tab; |
| 146 } | 149 } |
| 147 } | 150 } |
| 148 | 151 |
| 149 // Parse the legacy options_page entry if there was no entry for | 152 // Parse the legacy options_page entry if there was no entry for |
| 150 // options_ui.page. | 153 // options_ui.page. |
| 151 if (!options_page_string.empty() && !options_page.is_valid()) { | 154 if (!options_page_string.empty() && !options_page.is_valid()) { |
| 152 if (!ParseOptionsUrl(extension, | 155 if (!ParseOptionsUrl(extension, |
| 153 options_page_string, | 156 options_page_string, |
| 154 keys::kOptionsPage, | 157 keys::kOptionsPage, |
| 155 error, | 158 error, |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 } | 220 } |
| 218 return true; | 221 return true; |
| 219 } | 222 } |
| 220 | 223 |
| 221 const std::vector<std::string> OptionsPageManifestHandler::Keys() const { | 224 const std::vector<std::string> OptionsPageManifestHandler::Keys() const { |
| 222 static const char* keys[] = {keys::kOptionsPage, keys::kOptionsUI}; | 225 static const char* keys[] = {keys::kOptionsPage, keys::kOptionsUI}; |
| 223 return std::vector<std::string>(keys, keys + arraysize(keys)); | 226 return std::vector<std::string>(keys, keys + arraysize(keys)); |
| 224 } | 227 } |
| 225 | 228 |
| 226 } // namespace extensions | 229 } // namespace extensions |
| OLD | NEW |