Home | History | Annotate | Download | only in module
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "chrome/browser/extensions/api/module/module.h"
      6 
      7 #include <string>
      8 
      9 #include "base/values.h"
     10 #include "chrome/browser/extensions/extension_service.h"
     11 #include "chrome/browser/extensions/extension_util.h"
     12 #include "chrome/browser/profiles/profile.h"
     13 #include "chrome/common/extensions/manifest_url_handler.h"
     14 #include "extensions/browser/extension_prefs.h"
     15 #include "extensions/browser/extension_system.h"
     16 
     17 namespace extensions {
     18 
     19 namespace extension {
     20 
     21 namespace {
     22 
     23 // A preference for storing the extension's update URL data. If not empty, the
     24 // the ExtensionUpdater will append a ap= parameter to the URL when checking if
     25 // a new version of the extension is available.
     26 const char kUpdateURLData[] = "update_url_data";
     27 
     28 }  // namespace
     29 
     30 std::string GetUpdateURLData(const ExtensionPrefs* prefs,
     31                              const std::string& extension_id) {
     32   std::string data;
     33   prefs->ReadPrefAsString(extension_id, kUpdateURLData, &data);
     34   return data;
     35 }
     36 
     37 }  // namespace extension
     38 
     39 bool ExtensionSetUpdateUrlDataFunction::RunSync() {
     40   std::string data;
     41   EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &data));
     42 
     43   const Extension* extension = GetExtension();
     44 
     45   if (ManifestURL::UpdatesFromGallery(extension)) {
     46     return false;
     47   }
     48 
     49   ExtensionPrefs::Get(GetProfile())->UpdateExtensionPref(
     50       extension_id(), extension::kUpdateURLData, new base::StringValue(data));
     51   return true;
     52 }
     53 
     54 bool ExtensionIsAllowedIncognitoAccessFunction::RunSync() {
     55   SetResult(new base::FundamentalValue(
     56       util::IsIncognitoEnabled(extension_id(), GetProfile())));
     57   return true;
     58 }
     59 
     60 bool ExtensionIsAllowedFileSchemeAccessFunction::RunSync() {
     61   SetResult(new base::FundamentalValue(
     62       util::AllowFileAccess(extension_id(), GetProfile())));
     63   return true;
     64 }
     65 
     66 }  // namespace extensions
     67