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

Side by Side Diff: chrome/browser/extensions/extension_sync_service.cc

Issue 907533004: [Extensions] Sync the 'allowed scripting on all urls' preference (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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 "chrome/browser/extensions/extension_sync_service.h" 5 #include "chrome/browser/extensions/extension_sync_service.h"
6 6
7 #include <iterator> 7 #include <iterator>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 24 matching lines...) Expand all
35 #include "extensions/common/image_util.h" 35 #include "extensions/common/image_util.h"
36 #include "extensions/common/manifest_constants.h" 36 #include "extensions/common/manifest_constants.h"
37 #include "extensions/common/manifest_handlers/icons_handler.h" 37 #include "extensions/common/manifest_handlers/icons_handler.h"
38 #include "sync/api/sync_change.h" 38 #include "sync/api/sync_change.h"
39 #include "sync/api/sync_error_factory.h" 39 #include "sync/api/sync_error_factory.h"
40 #include "ui/gfx/image/image_family.h" 40 #include "ui/gfx/image/image_family.h"
41 41
42 using extensions::Extension; 42 using extensions::Extension;
43 using extensions::ExtensionPrefs; 43 using extensions::ExtensionPrefs;
44 using extensions::ExtensionRegistry; 44 using extensions::ExtensionRegistry;
45 using extensions::ExtensionSyncData;
45 using extensions::FeatureSwitch; 46 using extensions::FeatureSwitch;
46 47
47 namespace { 48 namespace {
48 49
49 void OnWebApplicationInfoLoaded( 50 void OnWebApplicationInfoLoaded(
50 WebApplicationInfo synced_info, 51 WebApplicationInfo synced_info,
51 base::WeakPtr<ExtensionService> extension_service, 52 base::WeakPtr<ExtensionService> extension_service,
52 const WebApplicationInfo& loaded_info) { 53 const WebApplicationInfo& loaded_info) {
53 DCHECK_EQ(synced_info.app_url, loaded_info.app_url); 54 DCHECK_EQ(synced_info.app_url, loaded_info.app_url);
54 55
55 if (!extension_service) 56 if (!extension_service)
56 return; 57 return;
57 58
58 // Use the old icons if they exist. 59 // Use the old icons if they exist.
59 synced_info.icons = loaded_info.icons; 60 synced_info.icons = loaded_info.icons;
60 CreateOrUpdateBookmarkApp(extension_service.get(), &synced_info); 61 CreateOrUpdateBookmarkApp(extension_service.get(), &synced_info);
61 } 62 }
62 63
64 // Returns the pref value for "all urls enabled" for the given extension id.
65 ExtensionSyncData::OptionalBoolean GetAllowedOnAllUrlsOptionalBoolean(
66 const std::string& extension_id,
67 content::BrowserContext* context) {
68 bool allowed_on_all_urls =
69 extensions::util::AllowedScriptingOnAllUrls(extension_id, context);
70 // If the extension is not allowed on all urls (which is not the default),
71 // then we have to sync the preference.
72 if (!allowed_on_all_urls)
73 return ExtensionSyncData::BOOLEAN_FALSE;
74
75 // If the user has explicitly set a value, then we sync it.
76 if (extensions::util::HasSetAllowedScriptingOnAllUrls(extension_id, context))
77 return ExtensionSyncData::BOOLEAN_TRUE;
78
79 // Otherwise, unset.
80 return ExtensionSyncData::BOOLEAN_UNSET;
81 }
82
63 } // namespace 83 } // namespace
64 84
65 ExtensionSyncService::ExtensionSyncService(Profile* profile, 85 ExtensionSyncService::ExtensionSyncService(Profile* profile,
66 ExtensionPrefs* extension_prefs, 86 ExtensionPrefs* extension_prefs,
67 ExtensionService* extension_service) 87 ExtensionService* extension_service)
68 : profile_(profile), 88 : profile_(profile),
69 extension_prefs_(extension_prefs), 89 extension_prefs_(extension_prefs),
70 extension_service_(extension_service), 90 extension_service_(extension_service),
71 app_sync_bundle_(this), 91 app_sync_bundle_(this),
72 extension_sync_bundle_(this), 92 extension_sync_bundle_(this),
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 return syncer::SyncDataList(); 253 return syncer::SyncDataList();
234 } 254 }
235 255
236 syncer::SyncError ExtensionSyncService::ProcessSyncChanges( 256 syncer::SyncError ExtensionSyncService::ProcessSyncChanges(
237 const tracked_objects::Location& from_here, 257 const tracked_objects::Location& from_here,
238 const syncer::SyncChangeList& change_list) { 258 const syncer::SyncChangeList& change_list) {
239 for (syncer::SyncChangeList::const_iterator i = change_list.begin(); 259 for (syncer::SyncChangeList::const_iterator i = change_list.begin();
240 i != change_list.end(); 260 i != change_list.end();
241 ++i) { 261 ++i) {
242 syncer::ModelType type = i->sync_data().GetDataType(); 262 syncer::ModelType type = i->sync_data().GetDataType();
243 if (type == syncer::EXTENSIONS) { 263 if (type == syncer::EXTENSIONS)
244 extension_sync_bundle_.ProcessSyncChange( 264 extension_sync_bundle_.ProcessSyncChange(ExtensionSyncData(*i));
245 extensions::ExtensionSyncData(*i)); 265 else if (type == syncer::APPS)
246 } else if (type == syncer::APPS) {
247 app_sync_bundle_.ProcessSyncChange(extensions::AppSyncData(*i)); 266 app_sync_bundle_.ProcessSyncChange(extensions::AppSyncData(*i));
248 }
249 } 267 }
250 268
251 extension_prefs_->app_sorting()->FixNTPOrdinalCollisions(); 269 extension_prefs_->app_sorting()->FixNTPOrdinalCollisions();
252 270
253 return syncer::SyncError(); 271 return syncer::SyncError();
254 } 272 }
255 273
256 extensions::ExtensionSyncData ExtensionSyncService::GetExtensionSyncData( 274 ExtensionSyncData ExtensionSyncService::GetExtensionSyncData(
257 const Extension& extension) const { 275 const Extension& extension) const {
258 return extensions::ExtensionSyncData( 276 return ExtensionSyncData(
259 extension, 277 extension,
260 extension_service_->IsExtensionEnabled(extension.id()), 278 extension_service_->IsExtensionEnabled(extension.id()),
261 extensions::util::IsIncognitoEnabled(extension.id(), profile_), 279 extensions::util::IsIncognitoEnabled(extension.id(), profile_),
262 extension_prefs_->HasDisableReason(extension.id(), 280 extension_prefs_->HasDisableReason(extension.id(),
263 Extension::DISABLE_REMOTE_INSTALL)); 281 Extension::DISABLE_REMOTE_INSTALL),
282 GetAllowedOnAllUrlsOptionalBoolean(extension.id(), profile_));
264 } 283 }
265 284
266 extensions::AppSyncData ExtensionSyncService::GetAppSyncData( 285 extensions::AppSyncData ExtensionSyncService::GetAppSyncData(
267 const Extension& extension) const { 286 const Extension& extension) const {
268 return extensions::AppSyncData( 287 return extensions::AppSyncData(
269 extension, 288 extension,
270 extension_service_->IsExtensionEnabled(extension.id()), 289 extension_service_->IsExtensionEnabled(extension.id()),
271 extensions::util::IsIncognitoEnabled(extension.id(), profile_), 290 extensions::util::IsIncognitoEnabled(extension.id(), profile_),
272 extension_prefs_->HasDisableReason(extension.id(), 291 extension_prefs_->HasDisableReason(extension.id(),
273 Extension::DISABLE_REMOTE_INSTALL), 292 Extension::DISABLE_REMOTE_INSTALL),
293 GetAllowedOnAllUrlsOptionalBoolean(extension.id(), profile_),
274 extension_prefs_->app_sorting()->GetAppLaunchOrdinal(extension.id()), 294 extension_prefs_->app_sorting()->GetAppLaunchOrdinal(extension.id()),
275 extension_prefs_->app_sorting()->GetPageOrdinal(extension.id()), 295 extension_prefs_->app_sorting()->GetPageOrdinal(extension.id()),
276 extensions::GetLaunchTypePrefValue(extension_prefs_, extension.id())); 296 extensions::GetLaunchTypePrefValue(extension_prefs_, extension.id()));
277 } 297 }
278 298
279 std::vector<extensions::ExtensionSyncData> 299 std::vector<ExtensionSyncData>
280 ExtensionSyncService::GetExtensionSyncDataList() const { 300 ExtensionSyncService::GetExtensionSyncDataList() const {
281 ExtensionRegistry* registry = ExtensionRegistry::Get(profile_); 301 ExtensionRegistry* registry = ExtensionRegistry::Get(profile_);
282 std::vector<extensions::ExtensionSyncData> extension_sync_list; 302 std::vector<ExtensionSyncData> extension_sync_list;
283 extension_sync_bundle_.GetExtensionSyncDataListHelper( 303 extension_sync_bundle_.GetExtensionSyncDataListHelper(
284 registry->enabled_extensions(), &extension_sync_list); 304 registry->enabled_extensions(), &extension_sync_list);
285 extension_sync_bundle_.GetExtensionSyncDataListHelper( 305 extension_sync_bundle_.GetExtensionSyncDataListHelper(
286 registry->disabled_extensions(), &extension_sync_list); 306 registry->disabled_extensions(), &extension_sync_list);
287 extension_sync_bundle_.GetExtensionSyncDataListHelper( 307 extension_sync_bundle_.GetExtensionSyncDataListHelper(
288 registry->terminated_extensions(), &extension_sync_list); 308 registry->terminated_extensions(), &extension_sync_list);
289 309
290 std::vector<extensions::ExtensionSyncData> pending_extensions = 310 std::vector<ExtensionSyncData> pending_extensions =
291 extension_sync_bundle_.GetPendingData(); 311 extension_sync_bundle_.GetPendingData();
292 extension_sync_list.insert(extension_sync_list.begin(), 312 extension_sync_list.insert(extension_sync_list.begin(),
293 pending_extensions.begin(), 313 pending_extensions.begin(),
294 pending_extensions.end()); 314 pending_extensions.end());
295 315
296 return extension_sync_list; 316 return extension_sync_list;
297 } 317 }
298 318
299 std::vector<extensions::AppSyncData> ExtensionSyncService::GetAppSyncDataList() 319 std::vector<extensions::AppSyncData> ExtensionSyncService::GetAppSyncDataList()
300 const { 320 const {
301 ExtensionRegistry* registry = ExtensionRegistry::Get(profile_); 321 ExtensionRegistry* registry = ExtensionRegistry::Get(profile_);
302 std::vector<extensions::AppSyncData> app_sync_list; 322 std::vector<extensions::AppSyncData> app_sync_list;
303 app_sync_bundle_.GetAppSyncDataListHelper( 323 app_sync_bundle_.GetAppSyncDataListHelper(
304 registry->enabled_extensions(), &app_sync_list); 324 registry->enabled_extensions(), &app_sync_list);
305 app_sync_bundle_.GetAppSyncDataListHelper( 325 app_sync_bundle_.GetAppSyncDataListHelper(
306 registry->disabled_extensions(), &app_sync_list); 326 registry->disabled_extensions(), &app_sync_list);
307 app_sync_bundle_.GetAppSyncDataListHelper( 327 app_sync_bundle_.GetAppSyncDataListHelper(
308 registry->terminated_extensions(), &app_sync_list); 328 registry->terminated_extensions(), &app_sync_list);
309 329
310 std::vector<extensions::AppSyncData> pending_apps = 330 std::vector<extensions::AppSyncData> pending_apps =
311 app_sync_bundle_.GetPendingData(); 331 app_sync_bundle_.GetPendingData();
312 app_sync_list.insert(app_sync_list.begin(), 332 app_sync_list.insert(app_sync_list.begin(),
313 pending_apps.begin(), 333 pending_apps.begin(),
314 pending_apps.end()); 334 pending_apps.end());
315 335
316 return app_sync_list; 336 return app_sync_list;
317 } 337 }
318 338
319 bool ExtensionSyncService::ProcessExtensionSyncData( 339 bool ExtensionSyncService::ProcessExtensionSyncData(
320 const extensions::ExtensionSyncData& extension_sync_data) { 340 const ExtensionSyncData& extension_sync_data) {
321 if (!ProcessExtensionSyncDataHelper(extension_sync_data, 341 if (!ProcessExtensionSyncDataHelper(extension_sync_data,
322 syncer::EXTENSIONS)) { 342 syncer::EXTENSIONS)) {
323 extension_sync_bundle_.AddPendingExtension(extension_sync_data.id(), 343 extension_sync_bundle_.AddPendingExtension(extension_sync_data.id(),
324 extension_sync_data); 344 extension_sync_data);
325 extension_service_->CheckForUpdatesSoon(); 345 extension_service_->CheckForUpdatesSoon();
326 return false; 346 return false;
327 } 347 }
328 348
329 return true; 349 return true;
330 } 350 }
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 return false; 456 return false;
437 } 457 }
438 458
439 bool ExtensionSyncService::IsPendingEnable( 459 bool ExtensionSyncService::IsPendingEnable(
440 const std::string& extension_id) const { 460 const std::string& extension_id) const {
441 return pending_app_enables_.Contains(extension_id) || 461 return pending_app_enables_.Contains(extension_id) ||
442 pending_extension_enables_.Contains(extension_id); 462 pending_extension_enables_.Contains(extension_id);
443 } 463 }
444 464
445 bool ExtensionSyncService::ProcessExtensionSyncDataHelper( 465 bool ExtensionSyncService::ProcessExtensionSyncDataHelper(
446 const extensions::ExtensionSyncData& extension_sync_data, 466 const ExtensionSyncData& extension_sync_data,
447 syncer::ModelType type) { 467 syncer::ModelType type) {
448 const std::string& id = extension_sync_data.id(); 468 const std::string& id = extension_sync_data.id();
449 const Extension* extension = extension_service_->GetInstalledExtension(id); 469 const Extension* extension = extension_service_->GetInstalledExtension(id);
450 470
451 // TODO(bolms): we should really handle this better. The particularly bad 471 // TODO(bolms): we should really handle this better. The particularly bad
452 // case is where an app becomes an extension or vice versa, and we end up with 472 // case is where an app becomes an extension or vice versa, and we end up with
453 // a zombie extension that won't go away. 473 // a zombie extension that won't go away.
454 if (extension && !IsCorrectSyncType(*extension, type)) 474 if (extension && !IsCorrectSyncType(*extension, type))
455 return true; 475 return true;
456 476
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 // be promoted to a regular installed extension and downloading from the Web 525 // be promoted to a regular installed extension and downloading from the Web
506 // Store is not necessary. 526 // Store is not necessary.
507 if (extension && extensions::util::IsEphemeralApp(id, profile_)) 527 if (extension && extensions::util::IsEphemeralApp(id, profile_))
508 extension_service_->PromoteEphemeralApp(extension, true); 528 extension_service_->PromoteEphemeralApp(extension, true);
509 529
510 // Update the incognito flag. 530 // Update the incognito flag.
511 extensions::util::SetIsIncognitoEnabled( 531 extensions::util::SetIsIncognitoEnabled(
512 id, profile_, extension_sync_data.incognito_enabled()); 532 id, profile_, extension_sync_data.incognito_enabled());
513 extension = NULL; // No longer safe to use. 533 extension = NULL; // No longer safe to use.
514 534
535 // Update the all urls flag.
536 if (extension_sync_data.all_urls_enabled() !=
537 ExtensionSyncData::BOOLEAN_UNSET) {
538 bool allowed = extension_sync_data.all_urls_enabled() ==
539 ExtensionSyncData::BOOLEAN_TRUE;
540 extensions::util::SetAllowedScriptingOnAllUrls(id, profile_, allowed);
541 }
542
515 if (extension_installed) { 543 if (extension_installed) {
516 // If the extension is already installed, check if it's outdated. 544 // If the extension is already installed, check if it's outdated.
517 if (version_compare_result < 0) { 545 if (version_compare_result < 0) {
518 // Extension is outdated. 546 // Extension is outdated.
519 return false; 547 return false;
520 } 548 }
521 } else { 549 } else {
522 CHECK(type == syncer::EXTENSIONS || type == syncer::APPS); 550 CHECK(type == syncer::EXTENSIONS || type == syncer::APPS);
523 extensions::PendingExtensionInfo::ShouldAllowInstallPredicate filter = 551 extensions::PendingExtensionInfo::ShouldAllowInstallPredicate filter =
524 (type == syncer::APPS) ? extensions::sync_helper::IsSyncableApp : 552 (type == syncer::APPS) ? extensions::sync_helper::IsSyncableApp :
(...skipping 25 matching lines...) Expand all
550 app_sync_bundle_.SyncChangeIfNeeded(extension); 578 app_sync_bundle_.SyncChangeIfNeeded(extension);
551 else if (extension_service_->is_ready() && !flare_.is_null()) 579 else if (extension_service_->is_ready() && !flare_.is_null())
552 flare_.Run(syncer::APPS); 580 flare_.Run(syncer::APPS);
553 } else if (extensions::util::ShouldSyncExtension(&extension, profile_)) { 581 } else if (extensions::util::ShouldSyncExtension(&extension, profile_)) {
554 if (extension_sync_bundle_.IsSyncing()) 582 if (extension_sync_bundle_.IsSyncing())
555 extension_sync_bundle_.SyncChangeIfNeeded(extension); 583 extension_sync_bundle_.SyncChangeIfNeeded(extension);
556 else if (extension_service_->is_ready() && !flare_.is_null()) 584 else if (extension_service_->is_ready() && !flare_.is_null())
557 flare_.Run(syncer::EXTENSIONS); 585 flare_.Run(syncer::EXTENSIONS);
558 } 586 }
559 } 587 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_sync_service.h ('k') | chrome/browser/extensions/extension_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698