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_prefs.h"
     11 #include "chrome/browser/extensions/extension_service.h"
     12 #include "chrome/browser/extensions/extension_system.h"
     13 #include "chrome/browser/profiles/profile.h"
     14 
     15 namespace extensions {
     16 
     17 namespace extension {
     18 
     19 namespace {
     20 
     21 // A preference for storing the extension's update URL data. If not empty, the
     22 // the ExtensionUpdater will append a ap= parameter to the URL when checking if
     23 // a new version of the extension is available.
     24 const char kUpdateURLData[] = "update_url_data";
     25 
     26 }  // namespace
     27 
     28 std::string GetUpdateURLData(const ExtensionPrefs* prefs,
     29                              const std::string& extension_id) {
     30   std::string data;
     31   prefs->ReadPrefAsString(extension_id, kUpdateURLData, &data);
     32   return data;
     33 }
     34 
     35 }  // namespace extension
     36 
     37 bool ExtensionSetUpdateUrlDataFunction::RunImpl() {
     38   std::string data;
     39   EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &data));
     40 
     41   ExtensionPrefs::Get(profile())->UpdateExtensionPref(
     42       extension_id(),
     43       extension::kUpdateURLData,
     44       base::Value::CreateStringValue(data));
     45   return true;
     46 }
     47 
     48 bool ExtensionIsAllowedIncognitoAccessFunction::RunImpl() {
     49   ExtensionService* ext_service =
     50       ExtensionSystem::Get(profile())->extension_service();
     51   const Extension* extension = GetExtension();
     52 
     53   SetResult(Value::CreateBooleanValue(
     54       ext_service->IsIncognitoEnabled(extension->id())));
     55   return true;
     56 }
     57 
     58 bool ExtensionIsAllowedFileSchemeAccessFunction::RunImpl() {
     59   ExtensionService* ext_service =
     60       ExtensionSystem::Get(profile())->extension_service();
     61   const Extension* extension = GetExtension();
     62 
     63   SetResult(Value::CreateBooleanValue(
     64       ext_service->AllowFileAccess(extension)));
     65   return true;
     66 }
     67 
     68 }  // namespace extensions
     69